Class ExternalizedIndexVariableSupply<Solution_>
- java.lang.Object
-
- org.optaplanner.core.impl.domain.variable.index.ExternalizedIndexVariableSupply<Solution_>
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,AbstractVariableListener<Solution_,Object>
,ListVariableListener<Solution_,Object,Object>
,IndexVariableSupply
,SourcedVariableListener<Solution_>
,Supply
public class ExternalizedIndexVariableSupply<Solution_> extends Object implements SourcedVariableListener<Solution_>, ListVariableListener<Solution_,Object,Object>, IndexVariableSupply
Alternative toIndexVariableListener
.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Object,Integer>
indexMap
protected ListVariableDescriptor<Solution_>
sourceVariableDescriptor
-
Constructor Summary
Constructors Constructor Description ExternalizedIndexVariableSupply(ListVariableDescriptor<Solution_> sourceVariableDescriptor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterEntityAdded(ScoreDirector<Solution_> scoreDirector, Object entity)
void
afterEntityRemoved(ScoreDirector<Solution_> scoreDirector, Object entity)
void
afterListVariableChanged(ScoreDirector<Solution_> scoreDirector, Object 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, Object element)
The listener must unset all shadow variables it is responsible for when an element is unassigned from the source list variable.void
beforeEntityAdded(ScoreDirector<Solution_> scoreDirector, Object entity)
void
beforeEntityRemoved(ScoreDirector<Solution_> scoreDirector, Object entity)
void
beforeListVariableChanged(ScoreDirector<Solution_> scoreDirector, Object entity, int fromIndex, int toIndex)
Tells the listener that some elements within the range starting atfromIndex
(inclusive) and ending attoIndex
(exclusive) will change.void
close()
Called before thisAbstractVariableListener
is thrown away and not used anymore.Integer
getIndex(Object element)
GetplanningValue
's index in thelist variable
it is an element of.VariableDescriptor<Solution_>
getSourceVariableDescriptor()
void
resetWorkingSolution(ScoreDirector<Solution_> scoreDirector)
Called when the entire working solution changes.String
toString()
-
-
-
Field Detail
-
sourceVariableDescriptor
protected final ListVariableDescriptor<Solution_> sourceVariableDescriptor
-
-
Constructor Detail
-
ExternalizedIndexVariableSupply
public ExternalizedIndexVariableSupply(ListVariableDescriptor<Solution_> sourceVariableDescriptor)
-
-
Method Detail
-
getSourceVariableDescriptor
public VariableDescriptor<Solution_> getSourceVariableDescriptor()
- Specified by:
getSourceVariableDescriptor
in interfaceSourcedVariableListener<Solution_>
-
resetWorkingSolution
public void resetWorkingSolution(ScoreDirector<Solution_> scoreDirector)
Description copied from interface:AbstractVariableListener
Called when the entire working solution changes. In this event, the other before..()/after...() methods will not be called. At this point, implementations should clear state, if any.- Specified by:
resetWorkingSolution
in interfaceAbstractVariableListener<Solution_,Object>
- Parameters:
scoreDirector
- never null
-
close
public void close()
Description copied from interface:AbstractVariableListener
Called before thisAbstractVariableListener
is thrown away and not used anymore.- Specified by:
close
in interfaceAbstractVariableListener<Solution_,Object>
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
beforeEntityAdded
public void beforeEntityAdded(ScoreDirector<Solution_> scoreDirector, Object entity)
- Specified by:
beforeEntityAdded
in interfaceAbstractVariableListener<Solution_,Object>
- Parameters:
scoreDirector
- never nullentity
- never null
-
afterEntityAdded
public void afterEntityAdded(ScoreDirector<Solution_> scoreDirector, Object entity)
- Specified by:
afterEntityAdded
in interfaceAbstractVariableListener<Solution_,Object>
- Parameters:
scoreDirector
- never nullentity
- never null
-
afterListVariableElementUnassigned
public void afterListVariableElementUnassigned(ScoreDirector<Solution_> scoreDirector, Object element)
Description copied from interface:ListVariableListener
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.- Specified by:
afterListVariableElementUnassigned
in interfaceListVariableListener<Solution_,Object,Object>
- Parameters:
scoreDirector
- score directorelement
- the unassigned element
-
beforeListVariableChanged
public void beforeListVariableChanged(ScoreDirector<Solution_> scoreDirector, Object entity, int fromIndex, int toIndex)
Description copied from interface:ListVariableListener
Tells the listener that some elements within the range starting atfromIndex
(inclusive) and ending attoIndex
(exclusive) will change. Be aware that theListVariableListener.afterListVariableChanged(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.- Specified by:
beforeListVariableChanged
in interfaceListVariableListener<Solution_,Object,Object>
- 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
public void afterListVariableChanged(ScoreDirector<Solution_> scoreDirector, Object entity, int fromIndex, int toIndex)
Description copied from interface:ListVariableListener
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.- Specified by:
afterListVariableChanged
in interfaceListVariableListener<Solution_,Object,Object>
- Parameters:
scoreDirector
- score directorentity
- entity with the changed list variablefromIndex
- low endpoint (inclusive) of the changed rangetoIndex
- high endpoint (exclusive) of the changed range
-
beforeEntityRemoved
public void beforeEntityRemoved(ScoreDirector<Solution_> scoreDirector, Object entity)
- Specified by:
beforeEntityRemoved
in interfaceAbstractVariableListener<Solution_,Object>
- Parameters:
scoreDirector
- never nullentity
- never null
-
afterEntityRemoved
public void afterEntityRemoved(ScoreDirector<Solution_> scoreDirector, Object entity)
- Specified by:
afterEntityRemoved
in interfaceAbstractVariableListener<Solution_,Object>
- Parameters:
scoreDirector
- never nullentity
- never null
-
getIndex
public Integer getIndex(Object element)
Description copied from interface:IndexVariableSupply
GetplanningValue
's index in thelist variable
it is an element of.- Specified by:
getIndex
in interfaceIndexVariableSupply
- Parameters:
element
- never null- Returns:
planningValue
's index in the list variable it is an element of ornull
if the value is unassigned
-
-