Class CompositeMove<Solution_>

java.lang.Object
ai.timefold.solver.core.impl.move.generic.CompositeMove<Solution_>
Type Parameters:
Solution_ - the solution type, the class with the PlanningSolution annotation
All Implemented Interfaces:
Move<Solution_>

@NullMarked public final class CompositeMove<Solution_> extends Object implements Move<Solution_>
A CompositeMove is composed out of multiple other moves.

Warning: each of moves in the moveList must not rely on the effect of a previous move in the moveList to create its undoMove correctly.

See Also:
  • Method Details

    • buildMove

      @SafeVarargs public static <Solution_, Move_ extends Move<Solution_>> Move<Solution_> buildMove(Move_... moves)
      Parameters:
      moves - never null, sometimes empty. Do not modify this argument afterwards or the CompositeMove corrupts.
      Returns:
      never null
    • buildMove

      public static <Solution_, Move_ extends Move<Solution_>> Move<Solution_> buildMove(List<Move_> moveList)
      Parameters:
      moveList - never null, sometimes empty
      Returns:
      never null
    • execute

      public void execute(MutableSolutionView<Solution_> solutionView)
      Description copied from interface: Move
      Runs the move and optionally records the changes done, so that they can be undone later.
      Specified by:
      execute in interface Move<Solution_>
      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

      public Move<Solution_> rebase(Rebaser rebaser)
      Description copied from interface: Move
      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.

      This method is thread-safe.

      Specified by:
      rebase in interface Move<Solution_>
      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

      public Collection<?> extractPlanningEntities()
      Description copied from interface: Move
      Returns 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 Collection are best avoided. The returned Collection is recommended to be in a stable order. For example, use List or LinkedHashSet, but not HashSet.

      Specified by:
      extractPlanningEntities in interface Move<Solution_>
      Returns:
      Each entity only once.
    • extractPlanningValues

      public Collection<?> extractPlanningValues()
      Description copied from interface: Move
      Returns 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 Collection are best avoided. The returned Collection is recommended to be in a stable order. For example, use List or LinkedHashSet, but not HashSet.

      Specified by:
      extractPlanningValues in interface Move<Solution_>
      Returns:
      Each value only once.
    • describe

      public String describe()
      Description copied from interface: Move
      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 String returned by this method.

      Specified by:
      describe in interface Move<Solution_>
      Returns:
      Non-empty String that describes the move type.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Description copied from interface: Move
      The solver will make sure to only call this when the move is actually printed out during debug logging.
      Specified by:
      toString in interface Move<Solution_>
      Overrides:
      toString in class Object
      Returns:
      A description of the move, ideally including the state of the planning entities being changed.