Interface VariableListener<Solution_,Entity_>
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotationEntity_
-
- 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 basic
PlanningVariable
.
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
Modifier and TypeMethodDescriptionvoid
afterVariableChanged
(ScoreDirector<Solution_> scoreDirector, Entity_ entity) void
beforeVariableChanged
(ScoreDirector<Solution_> scoreDirector, Entity_ entity) default boolean
When set totrue
, this has a performance loss.Methods inherited from interface org.optaplanner.core.api.domain.variable.AbstractVariableListener
afterEntityAdded, afterEntityRemoved, beforeEntityAdded, beforeEntityRemoved, close, resetWorkingSolution
-
Method Details
-
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
- Parameters:
scoreDirector
- never nullentity
- never null
-
afterVariableChanged
- Parameters:
scoreDirector
- never nullentity
- never null
-