Interface ListVariableStateSupply<Solution_>
- Type Parameters:
Solution_-
- All Superinterfaces:
AbstractVariableListener<Solution_,,Object> AutoCloseable,Closeable,IndexVariableSupply,ListVariableListener<Solution_,,Object, Object> SingletonInverseVariableSupply,SourcedVariableListener<Solution_>,Supply
public interface ListVariableStateSupply<Solution_>
extends SourcedVariableListener<Solution_>, ListVariableListener<Solution_,Object,Object>, SingletonInverseVariableSupply, IndexVariableSupply
Single source of truth for all information about elements inside
list variables.
Shadow variables can be connected to this class to save on iteration costs
that would've been incurred otherwise if using variable listeners for each of them independently.
This way, there is only one variable listener for all such shadow variables,
and therefore only a single iteration to update all the information.
If a particular shadow variable is externalized,
it means that there is a field on an entity holding the value of the shadow variable.
In this case, we will attempt to use that value.
Otherwise, we will keep an internal track of all the possible shadow variables
(IndexShadowVariable,
InverseRelationShadowVariable,
PreviousElementShadowVariable,
NextElementShadowVariable),
and use values from this internal representation.
- See Also:
-
The logic of switching between internal and externalized shadow variables.The external representation of these shadow variables, which doesn't care whether the variable is internal or externalized.
-
Method Summary
Modifier and TypeMethodDescriptionvoidexternalize(IndexShadowVariableDescriptor<Solution_> shadowVariableDescriptor) voidexternalize(InverseRelationShadowVariableDescriptor<Solution_> shadowVariableDescriptor) voidexternalize(NextElementShadowVariableDescriptor<Solution_> shadowVariableDescriptor) voidexternalize(PreviousElementShadowVariableDescriptor<Solution_> shadowVariableDescriptor) getElementPosition(Object value) getNextElement(Object element) getPreviousElement(Object element) intConsider calling this beforeisAssigned(Object)to eliminate some map accesses.booleanisAssigned(Object element) booleanMethods inherited from interface ai.timefold.solver.core.api.domain.variable.AbstractVariableListener
afterEntityAdded, afterEntityRemoved, beforeEntityAdded, beforeEntityRemoved, close, resetWorkingSolutionMethods inherited from interface ai.timefold.solver.core.impl.domain.variable.index.IndexVariableSupply
getIndexMethods inherited from interface ai.timefold.solver.core.api.domain.variable.ListVariableListener
afterListVariableChanged, afterListVariableElementUnassigned, beforeListVariableChangedMethods inherited from interface ai.timefold.solver.core.impl.domain.variable.inverserelation.SingletonInverseVariableSupply
getInverseSingleton
-
Method Details
-
externalize
-
externalize
-
externalize
-
externalize
-
getSourceVariableDescriptor
ListVariableDescriptor<Solution_> getSourceVariableDescriptor()- Specified by:
getSourceVariableDescriptorin interfaceSourcedVariableListener<Solution_>
-
isAssigned
- Parameters:
element- never null- Returns:
- true if the element is contained in a list variable of any entity.
-
isPinned
- Parameters:
element- never null- Returns:
- true if the element is in a pinned part of a list variable of any entity
-
getElementPosition
- Parameters:
value- never null- Returns:
- never null
-
getUnassignedCount
int getUnassignedCount()Consider calling this beforeisAssigned(Object)to eliminate some map accesses. If unassigned count is 0,isAssigned(Object)is guaranteed to return true.- Returns:
- number of elements for which
isAssigned(Object)would return false.
-
getPreviousElement
- Parameters:
element- never null- Returns:
- null if the element is the first element in the list
-
getNextElement
- Parameters:
element- never null- Returns:
- null if the element is the last element in the list
-