Interface VariableListener<Solution_,Entity_>

Type Parameters:
Solution_ - the solution type, the class with the PlanningSolution annotation
Entity_ -
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 Details

    • requiresUniqueEntityEvents

      default boolean requiresUniqueEntityEvents()
      When set to true, this has a performance loss. When set to false, 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 null
      entity - never null
    • afterVariableChanged

      void afterVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity)
      Parameters:
      scoreDirector - never null
      entity - never null