Class MoveDirector<Solution_,Score_ extends Score<Score_>>
java.lang.Object
ai.timefold.solver.core.impl.move.MoveDirector<Solution_,Score_>
- All Implemented Interfaces:
InnerMutableSolutionView<Solution_>,MutableSolutionView<Solution_>,Rebaser,SolutionView<Solution_>
@NullMarked
public sealed class MoveDirector<Solution_,Score_ extends Score<Score_>>
extends Object
implements InnerMutableSolutionView<Solution_>, Rebaser
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <Entity_,Value_>
voidassignValueAndAdd(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ planningValue, Entity_ destinationEntity, int destinationIndex) Puts a given value at a particular index in a given entity'splanning list variable.final <Entity_,Value_>
voidassignValueAndSet(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ planningValue, Entity_ destinationEntity, int destinationIndex) Puts a given value at a particular index in a given entity'splanning list variable, much likeList.set(int, Object).final <Entity_,Value_>
voidchangeVariable(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, @Nullable Value_ newValue) Changes the value of abasic planning variableof a given entity.<Entity_,Value_>
intcountValues(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity) Reads the value of alist planning variableand returns its length.final voidExecute a given move and make sure shadow variables are up to date after that.final InnerScore<Score_>executeTemporary(Move<Solution_> move) <Result_> Result_executeTemporary(Move<Solution_> move, MoveDirector.TemporaryMovePostprocessor<Solution_, Score_, Result_> postprocessor) protected static <Solution_,Entity_, Value_>
ElementPositiongetPositionOf(InnerScoreDirector<Solution_, ?> scoreDirector, PlanningListVariableMetaModel<Solution_, Entity_, Value_> listVariableDescriptor, Value_ value) <Entity_,Value_>
ElementPositiongetPositionOf(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ value) Locates a given value in anylist planning variable.final <Entity_,Value_>
Value_getValue(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity) Reads the value of abasic planning variableof a given entity.final <Entity_,Value_>
Value_getValueAtIndex(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, int index) Reads the value of alist planning variableof a given entity at a specific index.<Value_> booleanisPinned(EntityDescriptor<Solution_> entityDescriptor, @Nullable Value_ entity) <Value_> booleanisPinned(ListVariableDescriptor<Solution_> listVariableDescriptor, @Nullable Value_ value) <Entity_,Value_>
booleanisPinned(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, @Nullable Value_ value) Checking if aPlanningListVariable's value is pinned requires checking: the entity'sPlanningPinfield, the entity'sPlanningPinToIndexfield, and the value's position in the list variable. As this is complex, this method is provided as a convenience.<Entity_,Value_>
booleanisPinned(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, @Nullable Entity_ entity) Checks if aPlanningEntitywith a basicPlanningVariableis pinned.<Entity_,Value_>
booleanisValueInRange(GenuineVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, @Nullable Entity_ entity, @Nullable Value_ value) Checks if a given value is present in the value range of a genuine planning variable.final <Entity_,Value_>
Value_moveValueBetweenLists(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, Entity_ destinationEntity, int destinationIndex) Moves a value from one entity'splanning list variableto another.final <Entity_,Value_>
Value_moveValueInList(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, int destinationIndex) Moves a value within one entity'splanning list variable.final <T> @Nullable Trebase(@Nullable T problemFactOrPlanningEntity) Translates an entity or fact instance (often from anotherThread) to anotherScoreDirector's internal working instance.<Entity_,Value_>
Value_shiftValue(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, int offset) Moves a value within one entity'splanning list variable, by the given offset.<Entity_,Value_>
voidswapValuesBetweenLists(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ leftEntity, int leftIndex, Entity_ rightEntity, int rightIndex) Swaps two values between two entities'planning list variable.<Entity_,Value_>
voidswapValuesInList(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, int leftIndex, int rightIndex) Swaps two values within one entity'splanning list variable.<Entity_,Value_>
Value_unassignValue(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, int index) Removes a value from a given entity'splanning list variableat a given index.<Entity_,Value_>
voidunassignValue(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ value) Removes a given value from theplanning list variablethat it's part of.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.timefold.solver.core.preview.api.move.MutableSolutionView
assignValue, assignValueAndAdd, assignValueAndSet, moveValueBetweenLists, shiftValue, unassignValueMethods inherited from interface ai.timefold.solver.core.preview.api.move.SolutionView
isValueInRange
-
Field Details
-
externalScoreDirector
-
-
Constructor Details
-
MoveDirector
-
-
Method Details
-
assignValueAndAdd
public final <Entity_,Value_> void assignValueAndAdd(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ planningValue, Entity_ destinationEntity, int destinationIndex) Description copied from interface:MutableSolutionViewPuts a given value at a particular index in a given entity'splanning list variable. Moves all values at or after the index to the right, much likeList.add(int, Object).- Specified by:
assignValueAndAddin interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.planningValue- The value to be assigned to a list variable.destinationEntity- The entity whose list variable is to be changed.destinationIndex- The index in the list variable at which the value is to be assigned, moving the pre-existing value at that index and all subsequent values to the right.
-
assignValueAndSet
public final <Entity_,Value_> void assignValueAndSet(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ planningValue, Entity_ destinationEntity, int destinationIndex) Description copied from interface:MutableSolutionViewPuts a given value at a particular index in a given entity'splanning list variable, much likeList.set(int, Object). The original value at that index becomes unassigned. If the destination index is equal to the list size, the value is appended to the end of the list without unassigning any value.- Specified by:
assignValueAndSetin interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.planningValue- The value to be assigned to a list variable.destinationEntity- The entity whose list variable is to be changed.destinationIndex- The index in the list variable at which the value is to be assigned, unassigning the pre-existing value at that index.
-
unassignValue
public <Entity_,Value_> void unassignValue(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ value) Description copied from interface:MutableSolutionViewRemoves a given value from theplanning list variablethat it's part of. Shifts any subsequent values to the left.- Specified by:
unassignValuein interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.value- The value to be removed from a list variable.
-
unassignValue
public <Entity_,Value_> Value_ unassignValue(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, int index) Description copied from interface:MutableSolutionViewRemoves a value from a given entity'splanning list variableat a given index. Shifts any subsequent values to the left.- Specified by:
unassignValuein interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.entity- The entity whose element is to be removed from a list variable.index- The index in entity's list variable which contains the value to be removed; Acceptable values range from zero to one less than list size. All values after the index are shifted to the left.- Returns:
- the removed value
-
changeVariable
public final <Entity_,Value_> void changeVariable(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, @Nullable Value_ newValue) Description copied from interface:MutableSolutionViewChanges the value of abasic planning variableof a given entity.- Specified by:
changeVariablein interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.entity- The entity whose variable value is to be changed.newValue- maybe null, if unassigning the variable
-
moveValueBetweenLists
public final <Entity_,Value_> Value_ moveValueBetweenLists(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, Entity_ destinationEntity, int destinationIndex) Description copied from interface:MutableSolutionViewMoves a value from one entity'splanning list variableto another. To move values within the same entity, useMutableSolutionView.shiftValue(PlanningListVariableMetaModel, Object, int, int)instead.- Specified by:
moveValueBetweenListsin interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.sourceEntity- The entity from which the value will be removed.sourceIndex- The index in the source entity's list variable which contains the value to be moved; Acceptable values range from zero to one less than list size. All values after the index are shifted to the left.destinationEntity- The entity to which the value will be added.destinationIndex- The index in the destination entity's list variable to which the value will be moved; Acceptable values range from zero to equal to list size. All values at or after the index are shifted to the right. To append to the end of the list, use the list size as index.- Returns:
- the value that was moved
-
moveValueInList
public final <Entity_,Value_> Value_ moveValueInList(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, int destinationIndex) Description copied from interface:MutableSolutionViewMoves a value within one entity'splanning list variable. Behaves as if the value is first removed from the source index, shifting all later values to the left, and then inserted at the destination index. This means that, to move the item to the end of the list, the destination index must equal the list size minus one.- Specified by:
moveValueInListin interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.sourceEntity- The entity whose variable value is to be changed.sourceIndex- The index in the source entity's list variable which contains the value to be moved; Acceptable values range from zero to one less than list size. All values after the index are shifted to the left.destinationIndex- The index in the source entity's list variable to which the value will be moved; Acceptable values range from zero to one less than list size. All values at or after the index are shifted to the right.- Returns:
- the value that was moved
- See Also:
-
shiftValue
public <Entity_,Value_> Value_ shiftValue(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, int offset) Description copied from interface:MutableSolutionViewMoves a value within one entity'splanning list variable, by the given offset.- Specified by:
shiftValuein interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.sourceEntity- The entity whose variable value is to be changed.sourceIndex- The index in the source entity's list variable which contains the value to be moved; Acceptable values range from zero to one less than list size.offset- By how much to move the value; positive values move to the right, negative values to the left. The offset must not be zero. The offset must not move the value out of bounds.- Returns:
- the value that was moved
- See Also:
-
swapValuesBetweenLists
public <Entity_,Value_> void swapValuesBetweenLists(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ leftEntity, int leftIndex, Entity_ rightEntity, int rightIndex) Description copied from interface:MutableSolutionViewSwaps two values between two entities'planning list variable.- Specified by:
swapValuesBetweenListsin interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.leftEntity- The first entity whose variable value is to be swapped.leftIndex- The index in the left entity's list variable which contains the value to be swapped; Acceptable values range from zero to one less than list size.rightEntity- The second entity whose variable value is to be swapped.rightIndex- The index in the right entity's list variable which contains the other value to be swapped; Acceptable values range from zero to one less than list size.
-
swapValuesInList
public <Entity_,Value_> void swapValuesInList(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, int leftIndex, int rightIndex) Description copied from interface:MutableSolutionViewSwaps two values within one entity'splanning list variable.- Specified by:
swapValuesInListin interfaceMutableSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable to be changed.entity- The entity whose variable values are to be swapped.leftIndex- The index in the entity's list variable which contains the value to be swapped; Acceptable values range from zero to one less than list size.rightIndex- The index in the entity's list variable which contains the other value to be swapped; Acceptable values range from zero to one less than list size.
-
isValueInRange
public <Entity_,Value_> boolean isValueInRange(GenuineVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, @Nullable Entity_ entity, @Nullable Value_ value) Description copied from interface:SolutionViewChecks if a given value is present in the value range of a genuine planning variable. If the value range is defined onentity, theentityargument must not be null.- Specified by:
isValueInRangein interfaceSolutionView<Solution_>- Type Parameters:
Entity_- generic type of the entity that the variable is defined onValue_- generic type of the value that the variable can take- Parameters:
variableMetaModel- variable in questionentity- entity that the value would be applied to; must be of a type that the variable is defined onvalue- value to check- Returns:
- true if the value is acceptable for the variable
-
execute
Execute a given move and make sure shadow variables are up to date after that. -
executeTemporary
-
executeTemporary
public <Result_> Result_ executeTemporary(Move<Solution_> move, MoveDirector.TemporaryMovePostprocessor<Solution_, Score_, Result_> postprocessor) -
getValue
public final <Entity_,Value_> Value_ getValue(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity) Description copied from interface:SolutionViewReads the value of abasic planning variableof a given entity.- Specified by:
getValuein interfaceSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable whose value is to be read.entity- The entity whose variable is to be read.- Returns:
- The value of the variable on the entity.
-
countValues
public <Entity_,Value_> int countValues(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity) Description copied from interface:SolutionViewReads the value of alist planning variableand returns its length.- Specified by:
countValuesin interfaceSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable whose value is to be read.entity- The entity whose variable is to be read.- Returns:
- The number of values in the list variable.
-
getValueAtIndex
public final <Entity_,Value_> Value_ getValueAtIndex(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ entity, int index) Description copied from interface:SolutionViewReads the value of alist planning variableof a given entity at a specific index.- Specified by:
getValueAtIndexin interfaceSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable whose value is to be read.entity- The entity whose variable is to be read.index- >= 0- Returns:
- The value at the given index in the list variable.
-
getPositionOf
public <Entity_,Value_> ElementPosition getPositionOf(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Value_ value) Description copied from interface:SolutionViewLocates a given value in anylist planning variable.- Specified by:
getPositionOfin interfaceSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable whose value is to be read.value- The value to locate.- Returns:
- the location of the value in the variable
-
isPinned
public <Entity_,Value_> boolean isPinned(PlanningVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, @Nullable Entity_ entity) Description copied from interface:SolutionViewChecks if aPlanningEntitywith a basicPlanningVariableis pinned.- Specified by:
isPinnedin interfaceSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable whose value is to be read.entity- The entity to check if it is pinned.- Returns:
- boolean indicating if the value is pinned in the variable
-
isPinned
public <Value_> boolean isPinned(EntityDescriptor<Solution_> entityDescriptor, @Nullable Value_ entity) -
getPositionOf
protected static <Solution_,Entity_, ElementPosition getPositionOfValue_> (InnerScoreDirector<Solution_, ?> scoreDirector, PlanningListVariableMetaModel<Solution_, Entity_, Value_> listVariableDescriptor, Value_ value) -
isPinned
public <Entity_,Value_> boolean isPinned(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, @Nullable Value_ value) Description copied from interface:SolutionViewChecking if aPlanningListVariable's value is pinned requires checking:- the entity's
PlanningPinfield, - the entity's
PlanningPinToIndexfield, - and the value's position in the list variable.
- Specified by:
isPinnedin interfaceSolutionView<Solution_>- Parameters:
variableMetaModel- Describes the variable whose value is to be read.value- The value to check if it is pinned; may be null, in which case the method returns false.- Returns:
- boolean indicating if the value is pinned in the variable
- the entity's
-
isPinned
public <Value_> boolean isPinned(ListVariableDescriptor<Solution_> listVariableDescriptor, @Nullable Value_ value) -
rebase
public final <T> @Nullable T rebase(@Nullable T problemFactOrPlanningEntity) Description copied from interface:RebaserTranslates an entity or fact instance (often from anotherThread) to anotherScoreDirector's internal working instance. Useful for move rebasing and in aProblemChangeand for multi-threaded solving.Matching is determined by the
LookUpStrategyTypeonPlanningSolution. Matching uses aPlanningIdby default. -
getScoreDirector
- Specified by:
getScoreDirectorin interfaceInnerMutableSolutionView<Solution_>
-