Interface Move<Solution_>

Type Parameters:
Solution_ -
All Known Subinterfaces:
Move<Solution_>
All Known Implementing Classes:
AbstractMove, AbstractMove, AbstractSimplifiedMove, AbstractUndoMove, ChainedChangeMove, ChainedSwapMove, ChangeMove, ChangeMove, CompositeMove, CompositeMove, KOptListMove, KOptMove, ListAssignMove, ListAssignMove, ListChangeMove, ListChangeMove, ListRuinRecreateMove, ListSwapMove, ListSwapMove, ListUnassignMove, ListUnassignMove, NoChangeMove, PillarChangeMove, PillarSwapMove, RuinRecreateMove, SubChainChangeMove, SubChainReversingChangeMove, SubChainReversingSwapMove, SubChainSwapMove, SubListChangeMove, SubListSwapMove, SubListUnassignMove, SwapMove, SwapMove, TailChainSwapMove, TwoOptListMove

@NullMarked public interface Move<Solution_>
A Move represents a change of 1 or more 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(), getPlanningEntities() and getPlanningValues().

This package and all of its contents are part of the Neighborhoods 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 or to Timefold Discord.

See Also:
  • Method Details

    • execute

      void execute(MutableSolutionView<Solution_> solutionView)
      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

      default Move<Solution_> rebase(Rebaser rebaser)
      Rebases a move from an origin ScoreDirector to another destination ScoreDirector which is usually on another Thread. It is necessary for multithreaded solving to function.

      The new move returned by this method translates the entities and problem facts to the destination PlanningSolution of the destination ScoreDirector, That destination PlanningSolution is a deep planning clone (or an even deeper clone) of the origin PlanningSolution that this move has been generated from.

      That new move does the exact same change as this move, resulting in the same PlanningSolution state, presuming that destination PlanningSolution was in the same state as the original PlanningSolution to begin with.

      An implementation of this method typically iterates through every entity and fact instance in this move, translates each one to the destination ScoreDirector with Rebaser.rebase(Object) and creates a new move instance of the same move type, using those translated instances.

      The destination PlanningSolution can be in a different state than the original PlanningSolution. So, rebasing can only depend on the identity of planning entities and problem facts, which are usually declared by a PlanningId on those classes. It must not depend on the state of the planning 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
    • getPlanningEntities

      default Collection<?> getPlanningEntities()
      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 Collection are best avoided. The returned Collection is recommended to be in a stable order. For example, use List or LinkedHashSet, but not HashSet.

      The default implementation throws an UnsupportedOperationException, making tabu search impossible unless the move class implements this method.

      Returns:
      Each entity only once.
    • getPlanningValues

      default Collection<?> getPlanningValues()
      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 Collection are best avoided. The returned Collection is recommended to be in a stable order. For example, use List or LinkedHashSet, but not HashSet.

      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.
    • describe

      default String 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, but it is recommended to stick to ASCII, avoiding whitespace and special characters. Never parse the String returned by this method, it is only intended to be used by the solver.

      Returns:
      Non-empty String that describes the move type.