Record Class LegacyMoveAdapter<Solution_>

java.lang.Object
java.lang.Record
ai.timefold.solver.core.impl.heuristic.move.LegacyMoveAdapter<Solution_>
Type Parameters:
Solution_ -
Record Components:
legacyMove - the move to adapt
All Implemented Interfaces:
Move<Solution_>

@NullMarked public record LegacyMoveAdapter<Solution_>(Move<Solution_> legacyMove) extends Record implements Move<Solution_>
Adapts Move a legacy move) to a new move. Once the move selector framework is removed, this may be removed as well.
  • Constructor Details

    • LegacyMoveAdapter

      public LegacyMoveAdapter(Move<Solution_> legacyMove)
      Creates an instance of a LegacyMoveAdapter record class.
      Parameters:
      legacyMove - the value for the legacyMove record component
  • Method Details

    • isDoable

      public static <Solution_> boolean isDoable(MoveDirector<Solution_,?> moveDirector, Move<Solution_> move)
      Used to determine if a move is doable. A move is only doable if: New moves are doable by default.
      Parameters:
      moveDirector - never null
      move - never null
      Returns:
      true if the move is doable
    • 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.
    • isMoveDoable

      public boolean isMoveDoable(SolutionView<Solution_> solutionView)
    • 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.
    • 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.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in interface Move<Solution_>
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • legacyMove

      public Move<Solution_> legacyMove()
      Returns the value of the legacyMove record component.
      Returns:
      the value of the legacyMove record component