Interface ListVariableListener<Solution_,Entity_,Element_>
- Type Parameters:
Solution_
- the solution type, the class with thePlanningSolution
annotationEntity_
-Element_
- > the type of elements of the source list variable
- All Superinterfaces:
AbstractVariableListener<Solution_,
,Entity_> AutoCloseable
,Closeable
- All Known Implementing Classes:
ExternalizedIndexVariableSupply
,ExternalizedSingletonListInverseVariableSupply
,IndexVariableListener
,NextElementVariableListener
,PreviousElementVariableListener
,SingletonListInverseVariableListener
public interface ListVariableListener<Solution_,Entity_,Element_>
extends AbstractVariableListener<Solution_,Entity_>
A listener sourced on a
PlanningListVariable
.
Changes shadow variables when a genuine source list variable changes.
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
afterListVariableChanged
(ScoreDirector<Solution_> scoreDirector, Entity_ entity, int fromIndex, int toIndex) Tells the listener that some elements within the range starting atfromIndex
(inclusive) and ending attoIndex
(exclusive) changed.void
afterListVariableElementUnassigned
(ScoreDirector<Solution_> scoreDirector, Element_ element) The listener must unset all shadow variables it is responsible for when an element is unassigned from the source list variable.void
beforeListVariableChanged
(ScoreDirector<Solution_> scoreDirector, Entity_ entity, int fromIndex, int toIndex) Tells the listener that some elements within the range starting atfromIndex
(inclusive) and ending attoIndex
(exclusive) will change.Methods inherited from interface org.optaplanner.core.api.domain.variable.AbstractVariableListener
afterEntityAdded, afterEntityRemoved, beforeEntityAdded, beforeEntityRemoved, close, resetWorkingSolution
-
Method Details
-
afterListVariableElementUnassigned
The listener must unset all shadow variables it is responsible for when an element is unassigned from the source list variable. For example, aTask
'sstartTime
shadow variable must be reset tonull
after a task is unassigned fromEmployee.tasks
when the move that assigned it there is undone during Construction Heuristic phase.- Parameters:
scoreDirector
- score directorelement
- the unassigned element
-
beforeListVariableChanged
void beforeListVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity, int fromIndex, int toIndex) Tells the listener that some elements within the range starting atfromIndex
(inclusive) and ending attoIndex
(exclusive) will change. Be aware that theafterListVariableChanged(org.optaplanner.core.api.score.director.ScoreDirector<Solution_>, Entity_, int, int)
call after the change is done often has a differentfromIndex
andtoIndex
because 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:
fromIndex
is greater than or equal to 0;toIndex
is less than or equal to the list variable size.toIndex
is 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 (
fromIndex
equalstoIndex
) if none of the existing list variable elements are going to be changed.- 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
void afterListVariableChanged(ScoreDirector<Solution_> scoreDirector, Entity_ entity, int fromIndex, int toIndex) Tells 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:
fromIndex
is greater than or equal to 0;toIndex
is less than or equal to the list variable size.toIndex
is 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 (
fromIndex
equalstoIndex
) if none of the existing list variable elements have changed.- Parameters:
scoreDirector
- score directorentity
- entity with the changed list variablefromIndex
- low endpoint (inclusive) of the changed rangetoIndex
- high endpoint (exclusive) of the changed range
-