Class AbstractScoreDirector<Solution_,Score_ extends Score<Score_>,Factory_ extends AbstractScoreDirectorFactory<Solution_,Score_>>
- java.lang.Object
-
- ai.timefold.solver.core.impl.score.director.AbstractScoreDirector<Solution_,Score_,Factory_>
-
- All Implemented Interfaces:
ScoreDirector<Solution_>,InnerScoreDirector<Solution_,Score_>,AutoCloseable,Cloneable
- Direct Known Subclasses:
EasyScoreDirector,IncrementalScoreDirector
public abstract class AbstractScoreDirector<Solution_,Score_ extends Score<Score_>,Factory_ extends AbstractScoreDirectorFactory<Solution_,Score_>> extends Object implements InnerScoreDirector<Solution_,Score_>, Cloneable
Abstract superclass forScoreDirector.Implementation note: Extending classes should follow these guidelines:
- before* method: last statement should be a call to the super method
- after* method: first statement should be a call to the super method
- See Also:
ScoreDirector
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallChangesWillBeUndoneBeforeStepEndsprotected longcalculationCountprotected booleanconstraintMatchEnabledPreferenceprotected booleanexpectShadowVariablesInCorrectStateprotected org.slf4j.Loggerloggerprotected booleanlookUpEnabledprotected LookUpManagerlookUpManagerprotected Factory_scoreDirectorFactoryprotected VariableListenerSupport<Solution_>variableListenerSupportprotected longworkingEntityListRevisionprotected IntegerworkingInitScoreprotected Solution_workingSolution
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractScoreDirector(Factory_ scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, boolean expectShadowVariablesInCorrectState)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)voidafterEntityAdded(Object entity)voidafterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)voidafterEntityRemoved(Object entity)voidafterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex)Notify the score director after a list variable changes.voidafterListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex)voidafterListVariableElementAssigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)Call this for each element that was assigned (added to a list variable of one entity without being removed from a list variable of another entity).voidafterListVariableElementAssigned(Object entity, String variableName, Object element)voidafterListVariableElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)Call this for each element that was unassigned (removed from a list variable of one entity without being added to a list variable of another entity).voidafterListVariableElementUnassigned(Object entity, String variableName, Object element)voidafterProblemFactAdded(Object problemFact)voidafterProblemFactRemoved(Object problemFact)voidafterProblemPropertyChanged(Object problemFactOrEntity)voidafterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)voidafterVariableChanged(Object entity, String variableName)voidassertExpectedUndoMoveScore(Move<Solution_> move, Score_ beforeMoveScore)Asserts that if theScoreis calculated for the currentworking solutionin the currentScoreDirector(with incremental calculation residue), it is equal to the parameterbeforeMoveScore.voidassertExpectedWorkingScore(Score_ expectedWorkingScore, Object completedAction)Asserts that if theScoreis calculated for the currentworking solutionin the currentScoreDirector(with possibly incremental calculation residue), it is equal to the parameterexpectedWorkingScore.voidassertNonNullPlanningIds()Asserts that none of the planning facts fromScoreDirector.getWorkingSolution()havePlanningIds with a null value.voidassertPredictedScoreFromScratch(Score_ workingScore, Object completedAction)Asserts that if theScoreis calculated for the currentworking solutionin a freshScoreDirector(with no incremental calculation residue), it is equal to the parameterpredictedScore.voidassertShadowVariablesAreNotStale(Score_ expectedWorkingScore, Object completedAction)Asserts that if allVariableListeners are forcibly triggered, and therefore all shadow variables are updated if needed, that none of the shadow variables of theworking solutionchange, Then also asserts that theScorecalculated for theworking solutionafterwards is equal to the parameterexpectedWorkingScore.voidassertWorkingScoreFromScratch(Score_ workingScore, Object completedAction)Asserts that if theScoreis calculated for the currentworking solutionin a freshScoreDirector(with no incremental calculation residue), it is equal to the parameterworkingScore.voidbeforeEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)voidbeforeEntityAdded(Object entity)voidbeforeEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)voidbeforeEntityRemoved(Object entity)voidbeforeListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex)Notify the score director before a list variable changes.voidbeforeListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex)voidbeforeListVariableElementAssigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)Call this for each element that will be assigned (added to a list variable of one entity without being removed from a list variable of another entity).voidbeforeListVariableElementAssigned(Object entity, String variableName, Object element)voidbeforeListVariableElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)Call this for each element that will be unassigned (removed from a list variable of one entity without being added to a list variable of another entity).voidbeforeListVariableElementUnassigned(Object entity, String variableName, Object element)voidbeforeProblemFactAdded(Object problemFact)voidbeforeProblemFactRemoved(Object problemFact)voidbeforeProblemPropertyChanged(Object problemFactOrEntity)voidbeforeVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)voidbeforeVariableChanged(Object entity, String variableName)protected StringbuildScoreCorruptionAnalysis(InnerScoreDirector<Solution_,Score_> uncorruptedScoreDirector, boolean predicted)protected StringbuildShadowVariableAnalysis(boolean predicted)voidchangeVariableFacade(VariableDescriptor<Solution_> variableDescriptor, Object entity, Object newValue)AbstractScoreDirector<Solution_,Score_,Factory_>clone()Clones thisScoreDirectorand itsworking solution.Solution_cloneSolution(Solution_ originalSolution)Returns a planning clone of the solution, which is not a shallow clone nor a deep clone nor a partition clone.Solution_cloneWorkingSolution()Returns a planning clone of the solution, which is not a shallow clone nor a deep clone nor a partition clone.voidclose()Needs to be called after use because some implementations need to clean up their resources.InnerScoreDirector<Solution_,Score_>createChildThreadScoreDirector(ChildThreadType childThreadType)Score_doAndProcessMove(Move<Solution_> move, boolean assertMoveScoreFromScratch)voiddoAndProcessMove(Move<Solution_> move, boolean assertMoveScoreFromScratch, Consumer<Score_> moveProcessor)booleanexpectShadowVariablesInCorrectState()Inverse shadow variables have a fail-fast for cases where the shadow variable doesn't actually point to its correct inverse.voidforceTriggerVariableListeners()UnlikeScoreDirector.triggerVariableListeners()which only triggers notifications already in the queue, this triggers every variable listener on every genuine variable.longgetCalculationCount()ScoreDefinition<Score_>getScoreDefinition()Factory_getScoreDirectorFactory()SolutionDescriptor<Solution_>getSolutionDescriptor()SupplyManagergetSupplyManager()longgetWorkingEntityListRevision()Solution_getWorkingSolution()ThePlanningSolutionthat is used to calculate theScore.voidincrementCalculationCount()protected booleanisConstraintConfiguration(Object problemFactOrEntity)booleanisWorkingEntityListDirty(long expectedWorkingEntityListRevision)<E> ElookUpWorkingObject(E externalObject)Translates an entity or fact instance (often from anotherThreador JVM) to thisScoreDirector's internal working instance.<E> ElookUpWorkingObjectOrReturnNull(E externalObject)As defined byScoreDirector.lookUpWorkingObject(Object), but doesn't fail fast if no workingObject was ever added for the externalObject.voidoverwriteConstraintMatchEnabledPreference(boolean constraintMatchEnabledPreference)voidresetCalculationCount()voidsetAllChangesWillBeUndoneBeforeStepEnds(boolean allChangesWillBeUndoneBeforeStepEnds)Do not waste performance by propagating changes to step (or higher) mechanisms.protected voidsetCalculatedScore(Score_ score)protected voidsetWorkingEntityListDirty()voidsetWorkingSolution(Solution_ workingSolution)Note: resetting the working solution does NOT substitute the calls to before/after methods of theProblemChangeDirectorduringproblem changes, as these calls are propagated tovariable listeners, which update shadow variables in theworking solutionto keep it consistent.StringtoString()voidtriggerVariableListeners()-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ai.timefold.solver.core.impl.score.director.InnerScoreDirector
calculateScore, getConstraintMatchTotalMap, getIndictmentMap, isConstraintMatchEnabled, requiresFlushing
-
-
-
-
Field Detail
-
logger
protected final transient org.slf4j.Logger logger
-
scoreDirectorFactory
protected final Factory_ extends AbstractScoreDirectorFactory<Solution_,Score_> scoreDirectorFactory
-
lookUpEnabled
protected final boolean lookUpEnabled
-
lookUpManager
protected final LookUpManager lookUpManager
-
expectShadowVariablesInCorrectState
protected final boolean expectShadowVariablesInCorrectState
-
variableListenerSupport
protected final VariableListenerSupport<Solution_> variableListenerSupport
-
constraintMatchEnabledPreference
protected boolean constraintMatchEnabledPreference
-
workingSolution
protected Solution_ workingSolution
-
workingEntityListRevision
protected long workingEntityListRevision
-
workingInitScore
protected Integer workingInitScore
-
allChangesWillBeUndoneBeforeStepEnds
protected boolean allChangesWillBeUndoneBeforeStepEnds
-
calculationCount
protected long calculationCount
-
-
Constructor Detail
-
AbstractScoreDirector
protected AbstractScoreDirector(Factory_ scoreDirectorFactory, boolean lookUpEnabled, boolean constraintMatchEnabledPreference, boolean expectShadowVariablesInCorrectState)
-
-
Method Detail
-
getScoreDirectorFactory
public Factory_ getScoreDirectorFactory()
- Specified by:
getScoreDirectorFactoryin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- never null
-
getSolutionDescriptor
public SolutionDescriptor<Solution_> getSolutionDescriptor()
- Specified by:
getSolutionDescriptorin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- never null
-
getScoreDefinition
public ScoreDefinition<Score_> getScoreDefinition()
- Specified by:
getScoreDefinitionin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- never null
-
expectShadowVariablesInCorrectState
public boolean expectShadowVariablesInCorrectState()
Description copied from interface:InnerScoreDirectorInverse shadow variables have a fail-fast for cases where the shadow variable doesn't actually point to its correct inverse. This is very useful to pinpoint improperly initialized solutions.However,
SolutionManager.update(Object)exists precisely for the purpose of initializing solutions. And when this API is used, the fail-fast must not be triggered as it is guaranteed and expected that the inverse relationships will be wrong. In fact, they will be null.For this case and this case only, this method is allowed to return false. All other cases must return true, otherwise a very valuable fail-fast is lost.
- Specified by:
expectShadowVariablesInCorrectStatein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- false if the fail-fast on shadow variables should not be triggered
-
overwriteConstraintMatchEnabledPreference
public void overwriteConstraintMatchEnabledPreference(boolean constraintMatchEnabledPreference)
- Specified by:
overwriteConstraintMatchEnabledPreferencein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
constraintMatchEnabledPreference- false if aScoreDirectorimplementation should not doConstraintMatchtracking even if it supports it.
-
getWorkingSolution
public Solution_ getWorkingSolution()
Description copied from interface:ScoreDirectorThePlanningSolutionthat is used to calculate theScore.Because a
Scoreis best calculated incrementally (by deltas), theScoreDirectorneeds to be notified when itsworking solutionchanges.- Specified by:
getWorkingSolutionin interfaceScoreDirector<Solution_>- Returns:
- never null
-
getWorkingEntityListRevision
public long getWorkingEntityListRevision()
- Specified by:
getWorkingEntityListRevisionin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- used to check
InnerScoreDirector.isWorkingEntityListDirty(long)later on
-
setAllChangesWillBeUndoneBeforeStepEnds
public void setAllChangesWillBeUndoneBeforeStepEnds(boolean allChangesWillBeUndoneBeforeStepEnds)
Description copied from interface:InnerScoreDirectorDo not waste performance by propagating changes to step (or higher) mechanisms.- Specified by:
setAllChangesWillBeUndoneBeforeStepEndsin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
allChangesWillBeUndoneBeforeStepEnds- true if all changes will be undone
-
getCalculationCount
public long getCalculationCount()
- Specified by:
getCalculationCountin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- at least 0L
-
resetCalculationCount
public void resetCalculationCount()
- Specified by:
resetCalculationCountin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
incrementCalculationCount
public void incrementCalculationCount()
- Specified by:
incrementCalculationCountin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
getSupplyManager
public SupplyManager getSupplyManager()
- Specified by:
getSupplyManagerin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- never null
-
setWorkingSolution
public void setWorkingSolution(Solution_ workingSolution)
Note: resetting the working solution does NOT substitute the calls to before/after methods of theProblemChangeDirectorduringproblem changes, as these calls are propagated tovariable listeners, which update shadow variables in theworking solutionto keep it consistent.- Specified by:
setWorkingSolutionin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
workingSolution- never null
-
assertNonNullPlanningIds
public void assertNonNullPlanningIds()
Description copied from interface:InnerScoreDirectorAsserts that none of the planning facts fromScoreDirector.getWorkingSolution()havePlanningIds with a null value.- Specified by:
assertNonNullPlanningIdsin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
doAndProcessMove
public Score_ doAndProcessMove(Move<Solution_> move, boolean assertMoveScoreFromScratch)
- Specified by:
doAndProcessMovein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
move- never nullassertMoveScoreFromScratch- true will hurt performance- Returns:
- never null
-
doAndProcessMove
public void doAndProcessMove(Move<Solution_> move, boolean assertMoveScoreFromScratch, Consumer<Score_> moveProcessor)
- Specified by:
doAndProcessMovein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
move- never nullassertMoveScoreFromScratch- true will hurt performancemoveProcessor- never null, use this to store the score as well as call the acceptor and forager
-
isWorkingEntityListDirty
public boolean isWorkingEntityListDirty(long expectedWorkingEntityListRevision)
- Specified by:
isWorkingEntityListDirtyin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
expectedWorkingEntityListRevision- an- Returns:
- true if the entityList might have a different set of instances now
-
setWorkingEntityListDirty
protected void setWorkingEntityListDirty()
-
cloneWorkingSolution
public Solution_ cloneWorkingSolution()
Description copied from interface:InnerScoreDirectorReturns a planning clone of the solution, which is not a shallow clone nor a deep clone nor a partition clone.- Specified by:
cloneWorkingSolutionin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Returns:
- never null, planning clone
-
cloneSolution
public Solution_ cloneSolution(Solution_ originalSolution)
Description copied from interface:InnerScoreDirectorReturns a planning clone of the solution, which is not a shallow clone nor a deep clone nor a partition clone.- Specified by:
cloneSolutionin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
originalSolution- never null- Returns:
- never null, planning clone
-
triggerVariableListeners
public void triggerVariableListeners()
- Specified by:
triggerVariableListenersin interfaceScoreDirector<Solution_>
-
forceTriggerVariableListeners
public void forceTriggerVariableListeners()
Description copied from interface:InnerScoreDirectorUnlikeScoreDirector.triggerVariableListeners()which only triggers notifications already in the queue, this triggers every variable listener on every genuine variable. This is useful inSolutionManager.update(Object)to fill in shadow variable values.- Specified by:
forceTriggerVariableListenersin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
setCalculatedScore
protected void setCalculatedScore(Score_ score)
-
clone
public AbstractScoreDirector<Solution_,Score_,Factory_> clone()
Description copied from interface:InnerScoreDirectorClones thisScoreDirectorand itsworking solution. UseScoreDirector.getWorkingSolution()to retrieve theworking solutionof that clone.This is heavy method, because it usually breaks incremental score calculation. Use it sparingly. Therefore it's best to clone lazily by delaying the clone call as long as possible.
-
createChildThreadScoreDirector
public InnerScoreDirector<Solution_,Score_> createChildThreadScoreDirector(ChildThreadType childThreadType)
- Specified by:
createChildThreadScoreDirectorin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
close
public void close()
Description copied from interface:InnerScoreDirectorNeeds to be called after use because some implementations need to clean up their resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
beforeEntityAdded
public final void beforeEntityAdded(Object entity)
- Specified by:
beforeEntityAddedin interfaceScoreDirector<Solution_>
-
afterEntityAdded
public final void afterEntityAdded(Object entity)
- Specified by:
afterEntityAddedin interfaceScoreDirector<Solution_>
-
beforeVariableChanged
public final void beforeVariableChanged(Object entity, String variableName)
- Specified by:
beforeVariableChangedin interfaceScoreDirector<Solution_>
-
afterVariableChanged
public final void afterVariableChanged(Object entity, String variableName)
- Specified by:
afterVariableChangedin interfaceScoreDirector<Solution_>
-
beforeListVariableElementAssigned
public void beforeListVariableElementAssigned(Object entity, String variableName, Object element)
- Specified by:
beforeListVariableElementAssignedin interfaceScoreDirector<Solution_>
-
afterListVariableElementAssigned
public void afterListVariableElementAssigned(Object entity, String variableName, Object element)
- Specified by:
afterListVariableElementAssignedin interfaceScoreDirector<Solution_>
-
beforeListVariableElementUnassigned
public void beforeListVariableElementUnassigned(Object entity, String variableName, Object element)
- Specified by:
beforeListVariableElementUnassignedin interfaceScoreDirector<Solution_>
-
afterListVariableElementUnassigned
public void afterListVariableElementUnassigned(Object entity, String variableName, Object element)
- Specified by:
afterListVariableElementUnassignedin interfaceScoreDirector<Solution_>
-
beforeListVariableChanged
public void beforeListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex)
- Specified by:
beforeListVariableChangedin interfaceScoreDirector<Solution_>
-
afterListVariableChanged
public void afterListVariableChanged(Object entity, String variableName, int fromIndex, int toIndex)
- Specified by:
afterListVariableChangedin interfaceScoreDirector<Solution_>
-
beforeEntityRemoved
public final void beforeEntityRemoved(Object entity)
- Specified by:
beforeEntityRemovedin interfaceScoreDirector<Solution_>
-
afterEntityRemoved
public final void afterEntityRemoved(Object entity)
- Specified by:
afterEntityRemovedin interfaceScoreDirector<Solution_>
-
beforeEntityAdded
public void beforeEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
-
afterEntityAdded
public void afterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity)
-
beforeVariableChanged
public void beforeVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)
- Specified by:
beforeVariableChangedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
afterVariableChanged
public void afterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity)
- Specified by:
afterVariableChangedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
changeVariableFacade
public void changeVariableFacade(VariableDescriptor<Solution_> variableDescriptor, Object entity, Object newValue)
- Specified by:
changeVariableFacadein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>
-
beforeListVariableElementAssigned
public void beforeListVariableElementAssigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)
Description copied from interface:InnerScoreDirectorCall this for each element that will be assigned (added to a list variable of one entity without being removed from a list variable of another entity).- Specified by:
beforeListVariableElementAssignedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
variableDescriptor- the list variable descriptorelement- the assigned element
-
afterListVariableElementAssigned
public void afterListVariableElementAssigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)
Description copied from interface:InnerScoreDirectorCall this for each element that was assigned (added to a list variable of one entity without being removed from a list variable of another entity).- Specified by:
afterListVariableElementAssignedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
variableDescriptor- the list variable descriptorelement- the assigned element
-
beforeListVariableElementUnassigned
public void beforeListVariableElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)
Description copied from interface:InnerScoreDirectorCall this for each element that will be unassigned (removed from a list variable of one entity without being added to a list variable of another entity).- Specified by:
beforeListVariableElementUnassignedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
variableDescriptor- the list variable descriptorelement- the unassigned element
-
afterListVariableElementUnassigned
public void afterListVariableElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element)
Description copied from interface:InnerScoreDirectorCall this for each element that was unassigned (removed from a list variable of one entity without being added to a list variable of another entity).- Specified by:
afterListVariableElementUnassignedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
variableDescriptor- the list variable descriptorelement- the unassigned element
-
beforeListVariableChanged
public void beforeListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex)
Description copied from interface:InnerScoreDirectorNotify the score director before a list variable changes.The list variable change includes:
- Changing position (index) of one or more elements.
- Removing one or more elements from the list variable.
- Adding one or more elements to the list variable.
- Any mix of the above.
fromIndex(inclusive) and ends attoIndex(exclusive).The range has to comply with the following contract:
fromIndexmust be greater than or equal to 0;toIndexmust be less than or equal to the list variable size.toIndexmust be greater than or equal tofromIndex.- The range must contain all elements that are going to be changed.
- The range is allowed to contain elements that are not going to be changed.
- The range may be empty (
fromIndexequalstoIndex) if none of the existing list variable elements are going to be changed.
InnerScoreDirector.beforeListVariableElementUnassigned(ListVariableDescriptor, Object)must be called for each element that will be unassigned (removed from a list variable of one entity without being added to a list variable of another entity).- Specified by:
beforeListVariableChangedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
variableDescriptor- descriptor of the list variable being changedentity- the entity owning the list variable being changedfromIndex- low endpoint (inclusive) of the changed rangetoIndex- high endpoint (exclusive) of the changed range
-
afterListVariableChanged
public void afterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex)
Description copied from interface:InnerScoreDirectorNotify the score director after a list variable changes.The list variable change includes:
- Changing position (index) of one or more elements.
- Removing one or more elements from the list variable.
- Adding one or more elements to the list variable.
- Any mix of the above.
fromIndex(inclusive) and ends attoIndex(exclusive).The range has to comply with the following contract:
fromIndexmust be greater than or equal to 0;toIndexmust be less than or equal to the list variable size.toIndexmust be greater than or equal tofromIndex.- The range must contain all elements that have changed.
- The range is allowed to contain elements that have not changed.
- The range may be empty (
fromIndexequalstoIndex) if none of the existing list variable elements have changed.
InnerScoreDirector.afterListVariableElementUnassigned(ListVariableDescriptor, Object)must be called for each element that was unassigned (removed from a list variable of one entity without being added to a list variable of another entity).- Specified by:
afterListVariableChangedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
variableDescriptor- descriptor of the list variable being changedentity- the entity owning the list variable being changedfromIndex- low endpoint (inclusive) of the changed rangetoIndex- high endpoint (exclusive) of the changed range
-
beforeEntityRemoved
public void beforeEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
-
afterEntityRemoved
public void afterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity)
-
beforeProblemFactAdded
public void beforeProblemFactAdded(Object problemFact)
- Specified by:
beforeProblemFactAddedin interfaceScoreDirector<Solution_>
-
afterProblemFactAdded
public void afterProblemFactAdded(Object problemFact)
- Specified by:
afterProblemFactAddedin interfaceScoreDirector<Solution_>
-
beforeProblemPropertyChanged
public void beforeProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
beforeProblemPropertyChangedin interfaceScoreDirector<Solution_>
-
afterProblemPropertyChanged
public void afterProblemPropertyChanged(Object problemFactOrEntity)
- Specified by:
afterProblemPropertyChangedin interfaceScoreDirector<Solution_>
-
beforeProblemFactRemoved
public void beforeProblemFactRemoved(Object problemFact)
- Specified by:
beforeProblemFactRemovedin interfaceScoreDirector<Solution_>
-
afterProblemFactRemoved
public void afterProblemFactRemoved(Object problemFact)
- Specified by:
afterProblemFactRemovedin interfaceScoreDirector<Solution_>
-
lookUpWorkingObject
public <E> E lookUpWorkingObject(E externalObject)
Description copied from interface:ScoreDirectorTranslates an entity or fact instance (often from anotherThreador JVM) to thisScoreDirector's internal working instance. Useful for move rebasing and in aProblemChange.Matching is determined by the
LookUpStrategyTypeonPlanningSolution. Matching uses aPlanningIdby default.- Specified by:
lookUpWorkingObjectin interfaceScoreDirector<Solution_>- Type Parameters:
E- the object type- Parameters:
externalObject- sometimes null- Returns:
- null if externalObject is null
-
lookUpWorkingObjectOrReturnNull
public <E> E lookUpWorkingObjectOrReturnNull(E externalObject)
Description copied from interface:ScoreDirectorAs defined byScoreDirector.lookUpWorkingObject(Object), but doesn't fail fast if no workingObject was ever added for the externalObject. It's recommended to useScoreDirector.lookUpWorkingObject(Object)instead, especially in move rebasing code.- Specified by:
lookUpWorkingObjectOrReturnNullin interfaceScoreDirector<Solution_>- Type Parameters:
E- the object type- Parameters:
externalObject- sometimes null- Returns:
- null if externalObject is null or if there is no workingObject for externalObject
-
assertExpectedWorkingScore
public void assertExpectedWorkingScore(Score_ expectedWorkingScore, Object completedAction)
Description copied from interface:InnerScoreDirectorAsserts that if theScoreis calculated for the currentworking solutionin the currentScoreDirector(with possibly incremental calculation residue), it is equal to the parameterexpectedWorkingScore.Used to assert that skipping
InnerScoreDirector.calculateScore()(when the score is otherwise determined) is correct.- Specified by:
assertExpectedWorkingScorein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
expectedWorkingScore- never nullcompletedAction- sometimes null, when assertion fails then the completedAction'sObject.toString()is included in the exception message
-
assertShadowVariablesAreNotStale
public void assertShadowVariablesAreNotStale(Score_ expectedWorkingScore, Object completedAction)
Description copied from interface:InnerScoreDirectorAsserts that if allVariableListeners are forcibly triggered, and therefore all shadow variables are updated if needed, that none of the shadow variables of theworking solutionchange, Then also asserts that theScorecalculated for theworking solutionafterwards is equal to the parameterexpectedWorkingScore.Used to assert that the shadow variables' state is consistent with the genuine variables' state.
- Specified by:
assertShadowVariablesAreNotStalein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
expectedWorkingScore- never nullcompletedAction- sometimes null, when assertion fails then the completedAction'sObject.toString()is included in the exception message
-
buildShadowVariableAnalysis
protected String buildShadowVariableAnalysis(boolean predicted)
- Parameters:
predicted- true if the score was predicted and might have been calculated on another thread- Returns:
- never null
-
assertWorkingScoreFromScratch
public void assertWorkingScoreFromScratch(Score_ workingScore, Object completedAction)
Description copied from interface:InnerScoreDirectorAsserts that if theScoreis calculated for the currentworking solutionin a freshScoreDirector(with no incremental calculation residue), it is equal to the parameterworkingScore.Furthermore, if the assert fails, a score corruption analysis might be included in the exception message.
- Specified by:
assertWorkingScoreFromScratchin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
workingScore- never nullcompletedAction- sometimes null, when assertion fails then the completedAction'sObject.toString()is included in the exception message- See Also:
InnerScoreDirectorFactory.assertScoreFromScratch(Solution_)
-
assertPredictedScoreFromScratch
public void assertPredictedScoreFromScratch(Score_ workingScore, Object completedAction)
Description copied from interface:InnerScoreDirectorAsserts that if theScoreis calculated for the currentworking solutionin a freshScoreDirector(with no incremental calculation residue), it is equal to the parameterpredictedScore.Furthermore, if the assert fails, a score corruption analysis might be included in the exception message.
- Specified by:
assertPredictedScoreFromScratchin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
workingScore- never nullcompletedAction- sometimes null, when assertion fails then the completedAction'sObject.toString()is included in the exception message- See Also:
InnerScoreDirectorFactory.assertScoreFromScratch(Solution_)
-
assertExpectedUndoMoveScore
public void assertExpectedUndoMoveScore(Move<Solution_> move, Score_ beforeMoveScore)
Description copied from interface:InnerScoreDirectorAsserts that if theScoreis calculated for the currentworking solutionin the currentScoreDirector(with incremental calculation residue), it is equal to the parameterbeforeMoveScore.Furthermore, if the assert fails, a score corruption analysis might be included in the exception message.
- Specified by:
assertExpectedUndoMoveScorein interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>>- Parameters:
move- never nullbeforeMoveScore- never null
-
buildScoreCorruptionAnalysis
protected String buildScoreCorruptionAnalysis(InnerScoreDirector<Solution_,Score_> uncorruptedScoreDirector, boolean predicted)
- Parameters:
uncorruptedScoreDirector- never nullpredicted- true if the score was predicted and might have been calculated on another thread- Returns:
- never null
-
isConstraintConfiguration
protected boolean isConstraintConfiguration(Object problemFactOrEntity)
-
-