Skip to content

Commit

Permalink
chore: adapt to Move refactor upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
triceo committed Oct 25, 2024
1 parent ca80c22 commit a5ab479
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import ai.timefold.solver.core.impl.localsearch.decider.LocalSearchDecider;
import ai.timefold.solver.core.impl.localsearch.scope.LocalSearchPhaseScope;
import ai.timefold.solver.core.impl.localsearch.scope.LocalSearchStepScope;
import ai.timefold.solver.core.impl.move.director.MoveDirector;
import ai.timefold.solver.core.impl.score.director.InnerScoreDirector;
import ai.timefold.solver.core.impl.score.director.InnerScoreDirectorFactory;
import ai.timefold.solver.core.impl.solver.DefaultSolver;
Expand All @@ -35,6 +36,7 @@ abstract class AbstractProblem<Solution_> implements Problem {
private final InnerScoreDirectorFactory<Solution_, ?> scoreDirectorFactory;
private final Solution_ originalSolution;

private MoveDirector<Solution_> moveDirector;
private InnerScoreDirector<Solution_, ?> scoreDirector;
private MoveSelector<Solution_> moveSelector;
private Iterator<Move<Solution_>> moveIterator;
Expand Down Expand Up @@ -104,6 +106,7 @@ public final void setupIteration() {
scoreDirector.setWorkingSolution(scoreDirector.cloneSolution(originalSolution)); // Use fresh solution again.
scoreDirector.triggerVariableListeners();
scoreDirector.calculateScore();
moveDirector = new MoveDirector<>(scoreDirector);
// Prepare the lifecycle.
var solverScope = new SolverScope<Solution_>();
solverScope.setScoreDirector(scoreDirector);
Expand Down Expand Up @@ -146,10 +149,14 @@ public final void setupInvocation() {
*/
@Override
public final Object runInvocation() {
var scoreDirector = (InnerScoreDirector<Solution_, ?>) moveDirector.getScoreDirector();
if (willUndo) {
move = move.doMove(scoreDirector); // Do the move and prepare undo.
try (var ephemeralMoveDirector = moveDirector.ephemeral()) {
move.doMoveOnly(ephemeralMoveDirector.getScoreDirector());
}
} else {
move.doMoveOnly(scoreDirector); // Do the move without any undo.
}
move.doMoveOnly(scoreDirector); // Run either the original move, or the undo.
return scoreDirector.calculateScore();
}

Expand Down

0 comments on commit a5ab479

Please sign in to comment.