Class MoveDirector<Solution_,Score_ extends Score<Score_>>

java.lang.Object
ai.timefold.solver.core.impl.move.MoveDirector<Solution_,Score_>
All Implemented Interfaces:
InnerMutableSolutionView<Solution_>, MutableSolutionView<Solution_>, Rebaser, SolutionView<Solution_>

@NullMarked public sealed class MoveDirector<Solution_,Score_ extends Score<Score_>> extends Object implements InnerMutableSolutionView<Solution_>, Rebaser
  • Field Details

  • Constructor Details

  • Method Details

    • assignValueAndAdd

      public final <Entity_, Value_> void assignValueAndAdd(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Value_ planningValue, Entity_ destinationEntity, int destinationIndex)
      Description copied from interface: MutableSolutionView
      Puts a given value at a particular index in a given entity's planning list variable. Moves all values at or after the index to the right, much like List.add(int, Object).
      Specified by:
      assignValueAndAdd in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      planningValue - The value to be assigned to a list variable.
      destinationEntity - The entity whose list variable is to be changed.
      destinationIndex - The index in the list variable at which the value is to be assigned, moving the pre-existing value at that index and all subsequent values to the right.
    • assignValueAndSet

      public final <Entity_, Value_> void assignValueAndSet(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Value_ planningValue, Entity_ destinationEntity, int destinationIndex)
      Description copied from interface: MutableSolutionView
      Puts a given value at a particular index in a given entity's planning list variable, much like List.set(int, Object). The original value at that index becomes unassigned. If the destination index is equal to the list size, the value is appended to the end of the list without unassigning any value.
      Specified by:
      assignValueAndSet in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      planningValue - The value to be assigned to a list variable.
      destinationEntity - The entity whose list variable is to be changed.
      destinationIndex - The index in the list variable at which the value is to be assigned, unassigning the pre-existing value at that index.
    • unassignValue

      public <Entity_, Value_> void unassignValue(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Value_ value)
      Description copied from interface: MutableSolutionView
      Removes a given value from the planning list variable that it's part of. Shifts any subsequent values to the left.
      Specified by:
      unassignValue in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      value - The value to be removed from a list variable.
    • unassignValue

      public <Entity_, Value_> Value_ unassignValue(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ entity, int index)
      Description copied from interface: MutableSolutionView
      Removes a value from a given entity's planning list variable at a given index. Shifts any subsequent values to the left.
      Specified by:
      unassignValue in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      entity - The entity whose element is to be removed from a list variable.
      index - The index in entity's list variable which contains the value to be removed; Acceptable values range from zero to one less than list size. All values after the index are shifted to the left.
      Returns:
      the removed value
    • changeVariable

      public final <Entity_, Value_> void changeVariable(PlanningVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ entity, @Nullable Value_ newValue)
      Description copied from interface: MutableSolutionView
      Changes the value of a basic planning variable of a given entity.
      Specified by:
      changeVariable in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      entity - The entity whose variable value is to be changed.
      newValue - maybe null, if unassigning the variable
    • moveValueBetweenLists

      public final <Entity_, Value_> Value_ moveValueBetweenLists(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, Entity_ destinationEntity, int destinationIndex)
      Description copied from interface: MutableSolutionView
      Moves a value from one entity's planning list variable to another. To move values within the same entity, use MutableSolutionView.shiftValue(PlanningListVariableMetaModel, Object, int, int) instead.
      Specified by:
      moveValueBetweenLists in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      sourceEntity - The entity from which the value will be removed.
      sourceIndex - The index in the source entity's list variable which contains the value to be moved; Acceptable values range from zero to one less than list size. All values after the index are shifted to the left.
      destinationEntity - The entity to which the value will be added.
      destinationIndex - The index in the destination entity's list variable to which the value will be moved; Acceptable values range from zero to equal to list size. All values at or after the index are shifted to the right. To append to the end of the list, use the list size as index.
      Returns:
      the value that was moved
    • moveValueInList

      public final <Entity_, Value_> Value_ moveValueInList(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, int destinationIndex)
      Description copied from interface: MutableSolutionView
      Moves a value within one entity's planning list variable. Behaves as if the value is first removed from the source index, shifting all later values to the left, and then inserted at the destination index. This means that, to move the item to the end of the list, the destination index must equal the list size minus one.
      Specified by:
      moveValueInList in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      sourceEntity - The entity whose variable value is to be changed.
      sourceIndex - The index in the source entity's list variable which contains the value to be moved; Acceptable values range from zero to one less than list size. All values after the index are shifted to the left.
      destinationIndex - The index in the source entity's list variable to which the value will be moved; Acceptable values range from zero to one less than list size. All values at or after the index are shifted to the right.
      Returns:
      the value that was moved
      See Also:
    • shiftValue

      public <Entity_, Value_> Value_ shiftValue(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ sourceEntity, int sourceIndex, int offset)
      Description copied from interface: MutableSolutionView
      Moves a value within one entity's planning list variable, by the given offset.
      Specified by:
      shiftValue in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      sourceEntity - The entity whose variable value is to be changed.
      sourceIndex - The index in the source entity's list variable which contains the value to be moved; Acceptable values range from zero to one less than list size.
      offset - By how much to move the value; positive values move to the right, negative values to the left. The offset must not be zero. The offset must not move the value out of bounds.
      Returns:
      the value that was moved
      See Also:
    • swapValuesBetweenLists

      public <Entity_, Value_> void swapValuesBetweenLists(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ leftEntity, int leftIndex, Entity_ rightEntity, int rightIndex)
      Description copied from interface: MutableSolutionView
      Swaps two values between two entities' planning list variable.
      Specified by:
      swapValuesBetweenLists in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      leftEntity - The first entity whose variable value is to be swapped.
      leftIndex - The index in the left entity's list variable which contains the value to be swapped; Acceptable values range from zero to one less than list size.
      rightEntity - The second entity whose variable value is to be swapped.
      rightIndex - The index in the right entity's list variable which contains the other value to be swapped; Acceptable values range from zero to one less than list size.
    • swapValuesInList

      public <Entity_, Value_> void swapValuesInList(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ entity, int leftIndex, int rightIndex)
      Description copied from interface: MutableSolutionView
      Swaps two values within one entity's planning list variable.
      Specified by:
      swapValuesInList in interface MutableSolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable to be changed.
      entity - The entity whose variable values are to be swapped.
      leftIndex - The index in the entity's list variable which contains the value to be swapped; Acceptable values range from zero to one less than list size.
      rightIndex - The index in the entity's list variable which contains the other value to be swapped; Acceptable values range from zero to one less than list size.
    • isValueInRange

      public <Entity_, Value_> boolean isValueInRange(GenuineVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, @Nullable Entity_ entity, @Nullable Value_ value)
      Description copied from interface: SolutionView
      Checks if a given value is present in the value range of a genuine planning variable. If the value range is defined on entity, the entity argument must not be null.
      Specified by:
      isValueInRange in interface SolutionView<Solution_>
      Type Parameters:
      Entity_ - generic type of the entity that the variable is defined on
      Value_ - generic type of the value that the variable can take
      Parameters:
      variableMetaModel - variable in question
      entity - entity that the value would be applied to; must be of a type that the variable is defined on
      value - value to check
      Returns:
      true if the value is acceptable for the variable
    • execute

      public final void execute(Move<Solution_> move)
      Execute a given move and make sure shadow variables are up to date after that.
    • executeTemporary

      public final InnerScore<Score_> executeTemporary(Move<Solution_> move)
    • executeTemporary

      public <Result_> Result_ executeTemporary(Move<Solution_> move, MoveDirector.TemporaryMovePostprocessor<Solution_,Score_,Result_> postprocessor)
    • getValue

      public final <Entity_, Value_> Value_ getValue(PlanningVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ entity)
      Description copied from interface: SolutionView
      Reads the value of a basic planning variable of a given entity.
      Specified by:
      getValue in interface SolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable whose value is to be read.
      entity - The entity whose variable is to be read.
      Returns:
      The value of the variable on the entity.
    • countValues

      public <Entity_, Value_> int countValues(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ entity)
      Description copied from interface: SolutionView
      Reads the value of a list planning variable and returns its length.
      Specified by:
      countValues in interface SolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable whose value is to be read.
      entity - The entity whose variable is to be read.
      Returns:
      The number of values in the list variable.
    • getValueAtIndex

      public final <Entity_, Value_> Value_ getValueAtIndex(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Entity_ entity, int index)
      Description copied from interface: SolutionView
      Reads the value of a list planning variable of a given entity at a specific index.
      Specified by:
      getValueAtIndex in interface SolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable whose value is to be read.
      entity - The entity whose variable is to be read.
      index - >= 0
      Returns:
      The value at the given index in the list variable.
    • getPositionOf

      public <Entity_, Value_> ElementPosition getPositionOf(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, Value_ value)
      Description copied from interface: SolutionView
      Locates a given value in any list planning variable.
      Specified by:
      getPositionOf in interface SolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable whose value is to be read.
      value - The value to locate.
      Returns:
      the location of the value in the variable
    • isPinned

      public <Entity_, Value_> boolean isPinned(PlanningVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, @Nullable Entity_ entity)
      Description copied from interface: SolutionView
      Checks if a PlanningEntity with a basic PlanningVariable is pinned.
      Specified by:
      isPinned in interface SolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable whose value is to be read.
      entity - The entity to check if it is pinned.
      Returns:
      boolean indicating if the value is pinned in the variable
    • isPinned

      public <Value_> boolean isPinned(EntityDescriptor<Solution_> entityDescriptor, @Nullable Value_ entity)
    • getPositionOf

      protected static <Solution_, Entity_, Value_> ElementPosition getPositionOf(InnerScoreDirector<Solution_,?> scoreDirector, PlanningListVariableMetaModel<Solution_,Entity_,Value_> listVariableDescriptor, Value_ value)
    • isPinned

      public <Entity_, Value_> boolean isPinned(PlanningListVariableMetaModel<Solution_,Entity_,Value_> variableMetaModel, @Nullable Value_ value)
      Description copied from interface: SolutionView
      Checking if a PlanningListVariable's value is pinned requires checking: As this is complex, this method is provided as a convenience.
      Specified by:
      isPinned in interface SolutionView<Solution_>
      Parameters:
      variableMetaModel - Describes the variable whose value is to be read.
      value - The value to check if it is pinned; may be null, in which case the method returns false.
      Returns:
      boolean indicating if the value is pinned in the variable
    • isPinned

      public <Value_> boolean isPinned(ListVariableDescriptor<Solution_> listVariableDescriptor, @Nullable Value_ value)
    • rebase

      public final <T> @Nullable T rebase(@Nullable T problemFactOrPlanningEntity)
      Description copied from interface: Rebaser
      Translates an entity or fact instance (often from another Thread) to another ScoreDirector's internal working instance. Useful for move rebasing and in a ProblemChange and for multi-threaded solving.

      Matching is determined by the LookUpStrategyType on PlanningSolution. Matching uses a PlanningId by default.

      Specified by:
      rebase in interface Rebaser
      Parameters:
      problemFactOrPlanningEntity - The fact or entity to rebase.
      Returns:
      null if problemFactOrPlanningEntity is null
    • getScoreDirector

      public final VariableDescriptorAwareScoreDirector<Solution_> getScoreDirector()
      Specified by:
      getScoreDirector in interface InnerMutableSolutionView<Solution_>