Class ListSwapMove<Solution_,Entity_,Value_>
- Type Parameters:
Solution_- the solution type, the class with thePlanningSolutionannotationEntity_- the entity type, the class with thePlanningEntityannotationValue_- the variable type, the type of the property with thePlanningVariableannotation
- All Implemented Interfaces:
Move<Solution_>
list variable.
Each element is identified by an entity instance and an index in that entity's list variable.
The swap move has two sides called left and right.
The element at leftIndex in leftEntity's list variable
is replaced by the element at rightIndex in rightEntity's list variable and vice versa.
Left and right entity can be the same instance.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedListSwapMove(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ leftEntity, int leftIndex, Entity_ rightEntity, int rightIndex) Create a move that swaps a list variable element atleftEntity.listVariable[leftIndex]withrightEntity.listVariable[rightIndex]. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidexecute(MutableSolutionView<Solution_> solutionView) Runs the move and optionally records the changes done, so that they can be undone later.intReturns all planning entities that this move is changing.Returns all planning values that this move is assigning to entity variables.intinthashCode()Rebases a move from an originScoreDirectorto another destinationScoreDirectorwhich is usually on anotherThread.toString()Methods inherited from class ai.timefold.solver.core.impl.move.AbstractMove
describe, getVariableDescriptor, getVariableDescriptor, getVariableDescriptor
-
Constructor Details
-
ListSwapMove
protected ListSwapMove(PlanningListVariableMetaModel<Solution_, Entity_, Value_> variableMetaModel, Entity_ leftEntity, int leftIndex, Entity_ rightEntity, int rightIndex) Create a move that swaps a list variable element atleftEntity.listVariable[leftIndex]withrightEntity.listVariable[rightIndex].ListSwapMove anatomy
/ rightEntity right element \ | / rightIndex | | | A {Ann[0]} <-> Y {Bob[1]} | | | left element / | \ leftIndex \ leftEntityExample
GIVEN Ann.tasks = [A, B, C] Bob.tasks = [X, Y] WHEN ListSwapMove: A {Ann[0]} <-> Y {Bob[1]} THEN Ann.tasks = [Y, B, C] Bob.tasks = [X, A]- Parameters:
variableMetaModel- describes the variable to be changed by this moveleftEntity- together withleftIndexidentifies the left element to be movedleftIndex- together withleftEntityidentifies the left element to be movedrightEntity- together withrightIndexidentifies the right element to be movedrightIndex- together withrightEntityidentifies the right element to be moved
-
-
Method Details
-
getLeftEntity
-
getLeftIndex
public int getLeftIndex() -
getRightEntity
-
getRightIndex
public int getRightIndex() -
execute
Description copied from interface:MoveRuns the move and optionally records the changes done, so that they can be undone later.- Parameters:
solutionView- Exposes all possible mutative operations on the variables. Remembers those mutative operations and can replay them in reverse order when the solver needs to undo the move. Do not store this parameter in a field.
-
rebase
Description copied from interface:MoveRebases a move from an originScoreDirectorto another destinationScoreDirectorwhich is usually on anotherThread. It is necessary for multithreaded solving to function.The new move returned by this method translates the entities and problem facts to the destination
PlanningSolutionof the destinationScoreDirector, That destinationPlanningSolutionis a deep planning clone (or an even deeper clone) of the originPlanningSolutionthat this move has been generated from.That new move does the exact same change as this move, resulting in the same
PlanningSolutionstate, presuming that destinationPlanningSolutionwas in the same state as the originalPlanningSolutionto begin with.An implementation of this method typically iterates through every entity and fact instance in this move, translates each one to the destination
ScoreDirectorwithRebaser.rebase(Object)and creates a new move instance of the same move type, using those translated instances.The destination
PlanningSolutioncan be in a different state than the originalPlanningSolution. So, rebasing can only depend on the identity ofplanning entitiesandproblem facts, which are usually declared by aPlanningIdon those classes. It must not depend on the state of theplanning variables. One thread might rebase a move before, amid or after another thread does that same move instance.The default implementation throws an
UnsupportedOperationException, making multithreaded solving impossible unless the move class implements this method.- Parameters:
rebaser- Do not store this parameter in a field- Returns:
- New move that does the same change as this move on another solution instance
-
variableMetaModels
- Specified by:
variableMetaModelsin classAbstractMove<Solution_>
-
getPlanningEntities
Description copied from interface:MoveReturns all planning entities that this move is changing. Required for entity tabu.This method is only called after
Move.execute(MutableSolutionView), which might affect the return values.Duplicate entries in the returned
Collectionare best avoided. The returnedCollectionis recommended to be in a stable order. For example, useListorLinkedHashSet, but notHashSet.The default implementation throws an
UnsupportedOperationException, making tabu search impossible unless the move class implements this method.- Returns:
- Each entity only once.
-
getPlanningValues
Description copied from interface:MoveReturns all planning values that this move is assigning to entity variables. Required for value tabu.This method is only called after
Move.execute(MutableSolutionView), which might affect the return values.Duplicate entries in the returned
Collectionare best avoided. The returnedCollectionis recommended to be in a stable order. For example, useListorLinkedHashSet, but notHashSet.The default implementation throws an
UnsupportedOperationException, making tabu search impossible unless the move class implements this method.- Returns:
- Each value only once. May contain null.
-
equals
-
hashCode
public int hashCode() -
toString
- Specified by:
toStringin classAbstractMove<Solution_>
-