Class ListVariableTracker<Solution_>
java.lang.Object
ai.timefold.solver.core.impl.domain.variable.listener.support.violation.ListVariableTracker<Solution_>
- All Implemented Interfaces:
AbstractVariableListener<Solution_,,Object> ListVariableListener<Solution_,,Object, Object> SourcedVariableListener<Solution_>,Supply,Closeable,AutoCloseable
public class ListVariableTracker<Solution_>
extends Object
implements SourcedVariableListener<Solution_>, ListVariableListener<Solution_,Object,Object>, Supply
Tracks variable listener events for a given
PlanningListVariable.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassIn order for theListVariableTrackerto be registered as a variable listener, it needs to be passed to theInnerScoreDirector.getSupplyManager(), which requires aDemand. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEntityAdded(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) voidafterEntityRemoved(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) voidafterListVariableChanged(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity, int fromIndex, int toIndex) Tells the listener that some elements within the range starting atfromIndex(inclusive) and ending attoIndex(exclusive) changed.voidafterListVariableElementUnassigned(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object element) The listener must unset all shadow variables it is responsible for when an element is unassigned from the source list variable.voidbeforeEntityAdded(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) voidbeforeEntityRemoved(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) voidbeforeListVariableChanged(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity, int fromIndex, int toIndex) Tells the listener that some elements within the range starting atfromIndex(inclusive) and ending attoIndex(exclusive) will change.demand()getEntitiesMissingBeforeAfterEvents(List<VariableId<Solution_>> changedVariables) voidresetWorkingSolution(@NonNull ScoreDirector<Solution_> scoreDirector) Called when the entire working solution changes.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.domain.variable.AbstractVariableListener
close
-
Constructor Details
-
ListVariableTracker
-
-
Method Details
-
getSourceVariableDescriptor
- Specified by:
getSourceVariableDescriptorin interfaceSourcedVariableListener<Solution_>
-
resetWorkingSolution
Description copied from interface:AbstractVariableListenerCalled when the entire working solution changes. In this event, the other before..()/after...() methods will not be called. At this point, implementations should clear state, if any.- Specified by:
resetWorkingSolutionin interfaceAbstractVariableListener<Solution_,Object>
-
beforeEntityAdded
public void beforeEntityAdded(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) - Specified by:
beforeEntityAddedin interfaceAbstractVariableListener<Solution_,Object>
-
afterEntityAdded
public void afterEntityAdded(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) - Specified by:
afterEntityAddedin interfaceAbstractVariableListener<Solution_,Object>
-
beforeEntityRemoved
public void beforeEntityRemoved(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) - Specified by:
beforeEntityRemovedin interfaceAbstractVariableListener<Solution_,Object>
-
afterEntityRemoved
public void afterEntityRemoved(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity) - Specified by:
afterEntityRemovedin interfaceAbstractVariableListener<Solution_,Object>
-
afterListVariableElementUnassigned
public void afterListVariableElementUnassigned(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object element) Description copied from interface:ListVariableListenerThe listener must unset all shadow variables it is responsible for when an element is unassigned from the source list variable. For example, aTask'sstartTimeshadow variable must be reset tonullafter a task is unassigned fromEmployee.taskswhen the move that assigned it there is undone during Construction Heuristic phase.- Specified by:
afterListVariableElementUnassignedin interfaceListVariableListener<Solution_,Object, Object> - Parameters:
scoreDirector- score directorelement- the unassigned element
-
beforeListVariableChanged
public void beforeListVariableChanged(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity, int fromIndex, int toIndex) Description copied from interface:ListVariableListenerTells the listener that some elements within the range starting atfromIndex(inclusive) and ending attoIndex(exclusive) will change. Be aware that theListVariableListener.afterListVariableChanged(ai.timefold.solver.core.api.score.director.ScoreDirector<Solution_>, Entity_, int, int)call after the change is done often has a differentfromIndexandtoIndexbecause the number of elements in the list variable can change.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.
The range has the following properties:
fromIndexis greater than or equal to 0;toIndexis less than or equal to the list variable size.toIndexis greater than or equal tofromIndex.- The range contains all elements that are going to be changed.
- The range may 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.
- Specified by:
beforeListVariableChangedin interfaceListVariableListener<Solution_,Object, Object> - Parameters:
scoreDirector- score directorentity- entity with the changed list variablefromIndex- low endpoint (inclusive) of the changed rangetoIndex- high endpoint (exclusive) of the changed range
-
afterListVariableChanged
public void afterListVariableChanged(@NonNull ScoreDirector<Solution_> scoreDirector, @NonNull Object entity, int fromIndex, int toIndex) Description copied from interface:ListVariableListenerTells the listener that some elements within the range starting atfromIndex(inclusive) and ending attoIndex(exclusive) changed.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.
The range has the following properties:
fromIndexis greater than or equal to 0;toIndexis less than or equal to the list variable size.toIndexis greater than or equal tofromIndex.- The range contains all elements that have changed.
- The range may contain elements that have not changed.
- The range may be empty (
fromIndexequalstoIndex) if none of the existing list variable elements have changed.
- Specified by:
afterListVariableChangedin interfaceListVariableListener<Solution_,Object, Object> - Parameters:
scoreDirector- score directorentity- entity with the changed list variablefromIndex- low endpoint (inclusive) of the changed rangetoIndex- high endpoint (exclusive) of the changed range
-
getEntitiesMissingBeforeAfterEvents
public List<String> getEntitiesMissingBeforeAfterEvents(List<VariableId<Solution_>> changedVariables) -
demand
-