Class BavetConstraintStreamScoreDirector<Solution_,Score_ extends Score<Score_>>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotation
- All Implemented Interfaces:
ScoreDirector<Solution_>,InnerScoreDirector<Solution_,,Score_> VariableDescriptorAwareScoreDirector<Solution_>,AutoCloseable,Cloneable
ScoreDirector, which only recalculates the Score
of the part of the working solution that changed,
instead of the going through the entire PlanningSolution. This is incremental calculation, which is fast.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classNested classes/interfaces inherited from class ai.timefold.solver.core.impl.score.director.AbstractScoreDirector
AbstractScoreDirector.AbstractScoreDirectorBuilder<Solution_,Score_ extends Score<Score_>, Factory_ extends AbstractScoreDirectorFactory<Solution_, Score_, Factory_>, Builder_ extends AbstractScoreDirector.AbstractScoreDirectorBuilder<Solution_, Score_, Factory_, Builder_>> -
Field Summary
Fields inherited from class ai.timefold.solver.core.impl.score.director.AbstractScoreDirector
constraintMatchPolicy, logger, scoreDirectorFactory, variableListenerSupport, workingSolution -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEntityAdded(EntityDescriptor<Solution_> entityDescriptor, Object entity) voidafterEntityRemoved(EntityDescriptor<Solution_> entityDescriptor, Object entity) voidafterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) Notify the score director after a list variable changes.voidafterProblemFactAdded(Object problemFact) voidafterProblemFactRemoved(Object problemFact) voidafterProblemPropertyChanged(Object problemFactOrEntity) voidafterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity) Calculates theScoreand updates theworking solutionaccordingly.voidThe function is exclusively available for the Bavet score director, and its use must be approached with caution.voidclose()Needs to be called after use because some implementations need to clean up their resources.Explains the impact of each planning entity or problem fact on theScore.Exposed for debugging purposes, so that we can hook into it from tests and while reproducing issues.booleanA derived score director is created from a root score director.booleanSome score directors keep a set of changes that they only apply whenInnerScoreDirector.calculateScore()is called.voidsetWorkingSolution(Solution_ workingSolution) Theworking solutionmust never be the same instance as thebest solution, it should be a (un)changed clone.Methods inherited from class ai.timefold.solver.core.impl.score.director.AbstractScoreDirector
afterListVariableElementAssigned, afterListVariableElementUnassigned, assertExpectedUndoMoveScore, assertExpectedWorkingScore, assertPredictedScoreFromScratch, assertShadowVariablesAreNotStale, assertWorkingScoreFromScratch, beforeEntityAdded, beforeEntityRemoved, beforeListVariableChanged, beforeListVariableElementAssigned, beforeListVariableElementUnassigned, beforeProblemFactAdded, beforeProblemFactRemoved, beforeProblemPropertyChanged, beforeVariableChanged, buildScoreCorruptionAnalysis, buildShadowVariableAnalysis, clearVariableListenerEvents, clone, cloneSolution, createChildThreadScoreDirector, executeMove, executeTemporaryMove, expectShadowVariablesInCorrectState, forceTriggerVariableListeners, getCalculationCount, getConstraintMatchPolicy, getListVariableStateSupply, getMoveDirector, getScoreDefinition, getScoreDirectorFactory, getSolutionCorruptionAfterUndo, getSolutionDescriptor, getSupplyManager, getVariableDescriptorCache, getWorkingEntityListRevision, getWorkingGenuineEntityCount, getWorkingInitScore, getWorkingSolution, incrementCalculationCount, isConstraintConfiguration, isWorkingEntityListDirty, isWorkingSolutionInitialized, lookUpWorkingObject, lookUpWorkingObjectOrReturnNull, resetCalculationCount, setAllChangesWillBeUndoneBeforeStepEnds, setCalculatedScore, setMoveRepository, setWorkingEntityListDirty, setWorkingSolution, toString, triggerVariableListenersMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.impl.score.director.InnerScoreDirector
afterEntityAdded, afterEntityRemoved, beforeEntityAdded, beforeEntityRemoved, buildScoreAnalysis, cloneWorkingSolutionMethods inherited from interface ai.timefold.solver.core.impl.score.director.VariableDescriptorAwareScoreDirector
afterListVariableChanged, afterListVariableElementAssigned, afterListVariableElementUnassigned, afterVariableChanged, beforeListVariableChanged, beforeListVariableElementAssigned, beforeListVariableElementUnassigned, beforeVariableChanged, changeVariableFacade
-
Method Details
-
clearShadowVariablesListenerQueue
public void clearShadowVariablesListenerQueue()The function is exclusively available for the Bavet score director, and its use must be approached with caution. The primary purpose of this method is to enable theConstraintVerifierto ignore events related to shadow variables when testing constraints that do not rely on them. -
setWorkingSolution
Description copied from interface:InnerScoreDirectorTheworking solutionmust never be the same instance as thebest solution, it should be a (un)changed clone.- Parameters:
workingSolution- never null
-
calculateScore
Description copied from interface:InnerScoreDirectorCalculates theScoreand updates theworking solutionaccordingly.- Returns:
- never null, the
Scoreof theworking solution
-
getConstraintMatchTotalMap
Description copied from interface:InnerScoreDirectorExplains theScoreofInnerScoreDirector.calculateScore()by splitting it up perConstraint.The sum of
ConstraintMatchTotal.getScore()equalsInnerScoreDirector.calculateScore().Call
InnerScoreDirector.calculateScore()before calling this method, unless that method has already been called since the lastPlanningVariablechanges.- Returns:
- never null, the key is the constraintId
(to create one, use
ConstraintRef.composeConstraintId(String, String)). If a constraint is present in the problem but resulted in no matches, it will still be in the map with aConstraintMatchTotal.getConstraintMatchSet()size of 0. - See Also:
-
getIndictmentMap
Description copied from interface:InnerScoreDirectorExplains the impact of each planning entity or problem fact on theScore. AnIndictmentis basically the inverse of aConstraintMatchTotal: it is aScoretotal for eachconstraint justification.The sum of
ConstraintMatchTotal.getScore()differs fromInnerScoreDirector.calculateScore()because eachConstraintMatch.getScore()is counted for eachconstraint justification.Call
InnerScoreDirector.calculateScore()before calling this method, unless that method has already been called since the lastPlanningVariablechanges.- Returns:
- never null, the key is a
problem factor aplanning entity - See Also:
-
requiresFlushing
public boolean requiresFlushing()Description copied from interface:InnerScoreDirectorSome score directors keep a set of changes that they only apply whenInnerScoreDirector.calculateScore()is called. Until that happens, this set accumulates and could possibly act as a memory leak.- Returns:
- true if the score director can potentially cause a memory leak due to unflushed changes.
-
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_>> - Overrides:
closein classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
afterEntityAdded
- Specified by:
afterEntityAddedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>> - Overrides:
afterEntityAddedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
afterVariableChanged
- Specified by:
afterVariableChangedin interfaceVariableDescriptorAwareScoreDirector<Solution_>- Overrides:
afterVariableChangedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
afterListVariableChanged
public void afterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) Description copied from interface:VariableDescriptorAwareScoreDirectorNotify 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.
VariableDescriptorAwareScoreDirector.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 interfaceVariableDescriptorAwareScoreDirector<Solution_>- Overrides:
afterListVariableChangedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<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
-
afterEntityRemoved
- Specified by:
afterEntityRemovedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>> - Overrides:
afterEntityRemovedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
afterProblemFactAdded
- Specified by:
afterProblemFactAddedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>> - Specified by:
afterProblemFactAddedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemFactAddedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
afterProblemPropertyChanged
- Specified by:
afterProblemPropertyChangedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>> - Specified by:
afterProblemPropertyChangedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemPropertyChangedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
afterProblemFactRemoved
- Specified by:
afterProblemFactRemovedin interfaceInnerScoreDirector<Solution_,Score_ extends Score<Score_>> - Specified by:
afterProblemFactRemovedin interfaceScoreDirector<Solution_>- Overrides:
afterProblemFactRemovedin classAbstractScoreDirector<Solution_,Score_ extends Score<Score_>, BavetConstraintStreamScoreDirectorFactory<Solution_, Score_ extends Score<Score_>>>
-
getSession
Exposed for debugging purposes, so that we can hook into it from tests and while reproducing issues.- Returns:
- null before first
setWorkingSolution(Object)or afterclose().
-
isDerived
public boolean isDerived()Description copied from interface:InnerScoreDirectorA derived score director is created from a root score director. The derived score director can be used to create separate* instances for use cases like multithreaded solving.
-