Interface VariableListener<Solution_,Entity_>
-
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationEntity_-
- All Superinterfaces:
AbstractVariableListener<Solution_,Entity_>,AutoCloseable,Closeable
- All Known Subinterfaces:
CustomShadowVariable.NullVariableListener
- All Known Implementing Classes:
AnchorVariableListener,CollectionInverseVariableListener,ExternalizedAnchorVariableSupply,ExternalizedCollectionInverseVariableSupply,ExternalizedSingletonInverseVariableSupply,SingletonInverseVariableListener
public interface VariableListener<Solution_,Entity_> extends AbstractVariableListener<Solution_,Entity_>
A listener sourced on a basicPlanningVariable.Changes shadow variables when a source basic planning variable changes. The source variable can be either a genuine or a shadow variable.
Important: it must only change the shadow variable(s) for which it's configured! It should never change a genuine variable or a problem fact. It can change its shadow variable(s) on multiple entity instances (for example: an arrivalTime change affects all trailing entities too).
It is recommended to keep implementations stateless. If state must be implemented, implementations may need to override the default methods (
AbstractVariableListener.resetWorkingSolution(ScoreDirector),AbstractVariableListener.close()).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidafterVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity)voidbeforeVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity)default booleanrequiresUniqueEntityEvents()When set totrue, this has a performance loss.-
Methods inherited from interface ai.timefold.solver.core.api.domain.variable.AbstractVariableListener
afterEntityAdded, afterEntityRemoved, beforeEntityAdded, beforeEntityRemoved, close, resetWorkingSolution
-
-
-
-
Method Detail
-
requiresUniqueEntityEvents
default boolean requiresUniqueEntityEvents()
When set totrue, this has a performance loss. When set tofalse, it's easier to make the listener implementation correct and fast.- Returns:
- true to guarantee that each of the before/after methods is only called once per entity instance per operation type (add, change or remove).
-
beforeVariableChanged
void beforeVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity)
- Parameters:
scoreDirector- never nullentity- never null
-
afterVariableChanged
void afterVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity)
- Parameters:
scoreDirector- never nullentity- never null
-
-