Class VariableChangeRecordingScoreDirector<Solution_,Score_ extends Score<Score_>>
- All Implemented Interfaces:
ScoreDirector<Solution_>,RevertableScoreDirector<Solution_>,VariableDescriptorAwareScoreDirector<Solution_>
-
Constructor Summary
ConstructorsConstructorDescriptionVariableChangeRecordingScoreDirector(ScoreDirector<Solution_> backingScoreDirector) VariableChangeRecordingScoreDirector(ScoreDirector<Solution_> backingScoreDirector, boolean requiresIndexCache) -
Method Summary
Modifier and TypeMethodDescriptionvoidafterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) Notify the score director after a list variable changes.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).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).voidafterVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity) voidbeforeListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) Notify the score director before a list variable changes.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).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).voidbeforeVariableChanged(VariableDescriptor<Solution_> variableDescriptor, Object entity) Use this method to get a copy of all non-commited changes executed by the director so far.Returns the score director to which events are delegated.TheVariableChangeRecordingScoreDirectorscore director includes two main tasks: tracking any variable change and firing events to a delegated score director.ThePlanningSolutionthat is used to calculate theScore.<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.voidvoidUse this method to revert all changes made by moves.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.api.score.director.ScoreDirector
afterEntityAdded, afterEntityRemoved, afterProblemFactAdded, afterProblemFactRemoved, afterProblemPropertyChanged, beforeEntityAdded, beforeEntityRemoved, beforeProblemFactAdded, beforeProblemFactRemoved, beforeProblemPropertyChangedMethods inherited from interface ai.timefold.solver.core.impl.score.director.VariableDescriptorAwareScoreDirector
afterListVariableChanged, afterListVariableElementAssigned, afterListVariableElementUnassigned, afterVariableChanged, beforeListVariableChanged, beforeListVariableElementAssigned, beforeListVariableElementUnassigned, beforeVariableChanged, changeVariableFacade
-
Constructor Details
-
VariableChangeRecordingScoreDirector
-
VariableChangeRecordingScoreDirector
public VariableChangeRecordingScoreDirector(ScoreDirector<Solution_> backingScoreDirector, boolean requiresIndexCache)
-
-
Method Details
-
copyChanges
Description copied from interface:RevertableScoreDirectorUse this method to get a copy of all non-commited changes executed by the director so far.- Specified by:
copyChangesin interfaceRevertableScoreDirector<Solution_>
-
undoChanges
public void undoChanges()Description copied from interface:RevertableScoreDirectorUse this method to revert all changes made by moves. The score director that implements this logic must be able to track every single change in the solution and restore it to its original state.- Specified by:
undoChangesin interfaceRevertableScoreDirector<Solution_>
-
beforeVariableChanged
- Specified by:
beforeVariableChangedin interfaceVariableDescriptorAwareScoreDirector<Solution_>
-
afterVariableChanged
- Specified by:
afterVariableChangedin interfaceVariableDescriptorAwareScoreDirector<Solution_>
-
beforeListVariableChanged
public void beforeListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex, int toIndex) Description copied from interface:VariableDescriptorAwareScoreDirectorNotify 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.
VariableDescriptorAwareScoreDirector.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 interfaceVariableDescriptorAwareScoreDirector<Solution_>- 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: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_>- 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
-
beforeListVariableElementAssigned
public void beforeListVariableElementAssigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element) Description copied from interface:VariableDescriptorAwareScoreDirectorCall 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 interfaceVariableDescriptorAwareScoreDirector<Solution_>- Parameters:
variableDescriptor- the list variable descriptorelement- the assigned element
-
afterListVariableElementAssigned
public void afterListVariableElementAssigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element) Description copied from interface:VariableDescriptorAwareScoreDirectorCall 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 interfaceVariableDescriptorAwareScoreDirector<Solution_>- Parameters:
variableDescriptor- the list variable descriptorelement- the assigned element
-
beforeListVariableElementUnassigned
public void beforeListVariableElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element) Description copied from interface:VariableDescriptorAwareScoreDirectorCall 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 interfaceVariableDescriptorAwareScoreDirector<Solution_>- Parameters:
variableDescriptor- the list variable descriptorelement- the unassigned element
-
afterListVariableElementUnassigned
public void afterListVariableElementUnassigned(ListVariableDescriptor<Solution_> variableDescriptor, Object element) Description copied from interface:VariableDescriptorAwareScoreDirectorCall 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 interfaceVariableDescriptorAwareScoreDirector<Solution_>- Parameters:
variableDescriptor- the list variable descriptorelement- the unassigned element
-
getSolutionDescriptor
- Specified by:
getSolutionDescriptorin interfaceVariableDescriptorAwareScoreDirector<Solution_>
-
getBacking
Returns the score director to which events are delegated. -
getNonDelegating
TheVariableChangeRecordingScoreDirectorscore director includes two main tasks: tracking any variable change and firing events to a delegated score director. This method returns a copy of the score director that only tracks variable changes without firing any delegated score director events. -
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_>
-
getVariableDescriptorCache
- Specified by:
getVariableDescriptorCachein interfaceVariableDescriptorAwareScoreDirector<Solution_>
-
triggerVariableListeners
public void triggerVariableListeners()- Specified by:
triggerVariableListenersin 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- 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- Returns:
- null if externalObject is null or if there is no workingObject for externalObject
-