Interface Move<Solution_>
- Type Parameters:
Solution_-
- All Known Implementing Classes:
AbstractMove,ChainedChangeMove,ChangeMove,CompositeMove,LegacyMoveAdapter,ListAssignMove,ListChangeMove,ListUnassignMove,NoChangeMove
PlanningVariables of 1 or more PlanningEntitys
in the working PlanningSolution.
Usually the move holds a direct reference to each PlanningEntity of the PlanningSolution
which it will change when execute(MutableSolutionView) is called.
It is recommended for the moves to not touch shadow variables,
the solver will update shadow variables after move execution is complete.
If the move has to touch shadow variables, it is responsible for updating them
consistently across the entire dependency graph.
For tabu search, a Move should implement Object.equals(Object) and Object.hashCode(),
extractPlanningEntities() and extractPlanningValues().
This package and all of its contents are part of the Move Streams API, which is under development and is only offered as a preview feature. There are no guarantees for backward compatibility; any class, method, or field may change or be removed without prior notice, although we will strive to avoid this as much as possible.
We encourage you to try the API and give us feedback on your experience with it, before we finalize the API. Please direct your feedback to Timefold Solver Github.
-
Method Summary
Modifier and TypeMethodDescriptiondefault Stringdescribe()Describes the move type for statistical purposes.voidexecute(MutableSolutionView<Solution_> solutionView) Runs the move and optionally records the changes done, so that they can be undone later.default Collection<?>Returns all planning entities that this move is changing.default Collection<?>Returns all planning values that this move is assigning to entity variables.Rebases a move from an originScoreDirectorto another destinationScoreDirectorwhich is usually on anotherThread.toString()The solver will make sure to only call this when the move is actually printed out during debug logging.
-
Method Details
-
execute
Runs 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
Rebases 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.This method is thread-safe.
- 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
-
extractPlanningEntities
Returns all planning entities that this move is changing. Required for entity tabu.This method is only called after
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.- Returns:
- Each entity only once.
-
extractPlanningValues
Returns all planning values that this move is assigning to entity variables. Required for value tabu.This method is only called after
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.- Returns:
- Each value only once.
-
describe
Describes the move type for statistical purposes. For example, a move which changes a variable "computer" on a class "Process" could be described as "ChangeMove(Process.computer)".The format is not formalized. Never parse the
Stringreturned by this method.- Returns:
- Non-empty
Stringthat describes the move type.
-
toString
String toString()The solver will make sure to only call this when the move is actually printed out during debug logging.
-