Interface ListVariableStateSupply<Solution_,Entity_,Element_>
- Type Parameters:
Solution_-
- All Superinterfaces:
AutoCloseable,Closeable,IndexVariableSupply,InnerListVariableListener<Solution_,,Entity_, Element_> InnerVariableListener<Solution_,,ListElementsChangeEvent<Entity_>> SingletonInverseVariableSupply,SourcedListVariableListener<Solution_,,Entity_, Element_> SourcedVariableListener<Solution_,,ListElementsChangeEvent<Entity_>> Supply
@NullMarked
public interface ListVariableStateSupply<Solution_,Entity_,Element_>
extends SourcedListVariableListener<Solution_,Entity_,Element_>, 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(Element_ value) @Nullable Element_getNextElement(Element_ element) @Nullable Element_getPreviousElement(Element_ element) intConsider calling this beforeisAssigned(Object)to eliminate some map accesses.booleanisAssigned(Element_ element) booleanMethods inherited from interface ai.timefold.solver.core.impl.domain.variable.index.IndexVariableSupply
getIndexMethods inherited from interface ai.timefold.solver.core.impl.domain.variable.InnerListVariableListener
afterListElementUnassignedMethods inherited from interface ai.timefold.solver.core.impl.domain.variable.InnerVariableListener
afterChange, beforeChange, close, requiresUniqueEntityEvents, resetWorkingSolutionMethods 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_,Entity_>
-
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
-