forked from TimefoldAI/timefold-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fail fast when score corruption detected (TimefoldAI#1411)
Also add a whole bunch of unrelated fixes to flaky tests, because with this PR, they started showing up more frequently. Closes TimefoldAI#1402 --------- Co-authored-by: Frederico Gonçalves <[email protected]>
- Loading branch information
Showing
81 changed files
with
1,008 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/main/java/ai/timefold/solver/core/api/solver/phase/PhaseCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ai.timefold.solver.core.api.solver.phase; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
import ai.timefold.solver.core.api.domain.solution.PlanningSolution; | ||
import ai.timefold.solver.core.api.score.Score; | ||
import ai.timefold.solver.core.api.score.director.ScoreDirector; | ||
import ai.timefold.solver.core.api.solver.Solver; | ||
import ai.timefold.solver.core.api.solver.change.ProblemChange; | ||
import ai.timefold.solver.core.impl.phase.Phase; | ||
import ai.timefold.solver.core.impl.score.director.InnerScoreDirector; | ||
|
||
import org.jspecify.annotations.NullMarked; | ||
|
||
/** | ||
* Runs a custom algorithm as a {@link Phase} of the {@link Solver} that changes the planning variables. | ||
* To change problem facts, use {@link Solver#addProblemChange(ProblemChange)} instead. | ||
* <p> | ||
* To add custom properties, configure custom properties and add public setters for them. | ||
* | ||
* @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation | ||
*/ | ||
@NullMarked | ||
public interface PhaseCommand<Solution_> { | ||
|
||
/** | ||
* Changes {@link PlanningSolution working solution} of {@link ScoreDirector#getWorkingSolution()}. | ||
* When the {@link PlanningSolution working solution} is modified, | ||
* the {@link ScoreDirector} must be correctly notified | ||
* (through {@link ScoreDirector#beforeVariableChanged(Object, String)} and | ||
* {@link ScoreDirector#afterVariableChanged(Object, String)}), | ||
* otherwise calculated {@link Score}s will be corrupted. | ||
* <p> | ||
* Don't forget to call {@link ScoreDirector#triggerVariableListeners()} after each set of changes | ||
* (especially before every {@link InnerScoreDirector#calculateScore()} call) | ||
* to ensure all shadow variables are updated. | ||
* | ||
* @param scoreDirector the {@link ScoreDirector} that needs to get notified of the changes. | ||
* @param isPhaseTerminated long-running command implementations should check this periodically | ||
* and terminate early if it returns true. | ||
* Otherwise the terminations configured by the user will have no effect, | ||
* as the solver can only terminate itself when a command has ended. | ||
*/ | ||
void changeWorkingSolution(ScoreDirector<Solution_> scoreDirector, BooleanSupplier isPhaseTerminated); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.