-
Notifications
You must be signed in to change notification settings - Fork 165
feat: add a producer id to BestSolutionChangedEvent #1913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bee9ada
feat: add a producer id to BestSolutionChangedEvent
Christopher-Chianelli c22d043
chore: review comment
Christopher-Chianelli 4e57891
feat: partitioned search support
Christopher-Chianelli ab2f72b
chore: sonar issues
Christopher-Chianelli 2a2abf6
chore: review comments
Christopher-Chianelli 4f87090
fix: flaky tests
Christopher-Chianelli 7b7091e
chore: add back phaseIndex
Christopher-Chianelli bbd3f04
chore: use events in the SolverJob consumers instead of passing the s…
Christopher-Chianelli 68d58b0
Review comments
triceo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
88 changes: 88 additions & 0 deletions
88
core/src/main/java/ai/timefold/solver/core/api/solver/event/EventProducerId.java
This file contains hidden or 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,88 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import java.util.OptionalInt; | ||
|
|
||
| import ai.timefold.solver.core.api.solver.change.ProblemChange; | ||
| import ai.timefold.solver.core.config.solver.SolverConfig; | ||
| import ai.timefold.solver.core.impl.phase.NoChangePhase; | ||
| import ai.timefold.solver.core.impl.phase.PhaseType; | ||
| import ai.timefold.solver.core.impl.phase.event.PhaseEventProducerId; | ||
| import ai.timefold.solver.core.impl.solver.event.SolveEventProducerId; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Identifies the producer of a {@link BestSolutionChangedEvent}. | ||
| */ | ||
| @NullMarked | ||
| public interface EventProducerId { | ||
| /** | ||
| * An unique string identifying what produced the event, either of the form | ||
| * "Event" where "Event" is a string describing the event that cause the update (like "Solving started") | ||
| * or "Phase (index)", where "Phase" is a string identifying the type of phase (like "Construction Heuristics") | ||
| * and index is the index of the phase in the {@link SolverConfig#getPhaseConfigList()}. | ||
| * | ||
| * @return An unique string identifying what produced the event. | ||
| */ | ||
| String producerId(); | ||
|
|
||
| /** | ||
| * A (non-unique) string describing what produced the event. | ||
| * Events from different phases of the same type (for example, | ||
| * when multiple Construction Heuristics are configured) | ||
| * will return the same value. | ||
| * | ||
| * @return A (non-unique) string describing what produced the event. | ||
| */ | ||
| String simpleProducerName(); | ||
|
|
||
| /** | ||
| * If present, the index of the phase that produced the event in the {@link SolverConfig#getPhaseConfigList()}. | ||
| * Is absent when the producer does not correspond to a phase, for instance, | ||
| * an event triggered after {@link ProblemChange} were processed. | ||
| * | ||
| * @return The index of the corresponding phase in {@link SolverConfig#getPhaseConfigList()}, | ||
| * or {@link OptionalInt#empty()} if there is no corresponding phase. | ||
| */ | ||
| OptionalInt phaseIndex(); | ||
|
|
||
| static EventProducerId unknown() { | ||
| return SolveEventProducerId.UNKNOWN; | ||
| } | ||
|
|
||
| static EventProducerId solvingStarted() { | ||
| return SolveEventProducerId.SOLVING_STARTED; | ||
| } | ||
|
|
||
| static EventProducerId problemChange() { | ||
| return SolveEventProducerId.PROBLEM_CHANGE; | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated Deprecated on account of {@link NoChangePhase} having no use. | ||
| */ | ||
| @Deprecated(forRemoval = true, since = "1.28.0") | ||
| static EventProducerId noChange(int phaseIndex) { | ||
| return new PhaseEventProducerId(PhaseType.NO_CHANGE, phaseIndex); | ||
| } | ||
|
|
||
| static EventProducerId constructionHeuristic(int phaseIndex) { | ||
| return new PhaseEventProducerId(PhaseType.CONSTRUCTION_HEURISTIC, phaseIndex); | ||
| } | ||
|
|
||
| static EventProducerId localSearch(int phaseIndex) { | ||
| return new PhaseEventProducerId(PhaseType.LOCAL_SEARCH, phaseIndex); | ||
| } | ||
|
|
||
| static EventProducerId exhaustiveSearch(int phaseIndex) { | ||
| return new PhaseEventProducerId(PhaseType.EXHAUSTIVE_SEARCH, phaseIndex); | ||
| } | ||
|
|
||
| static EventProducerId partitionedSearch(int phaseIndex) { | ||
| return new PhaseEventProducerId(PhaseType.PARTITIONED_SEARCH, phaseIndex); | ||
| } | ||
|
|
||
| static EventProducerId customPhase(int phaseIndex) { | ||
| return new PhaseEventProducerId(PhaseType.CUSTOM_PHASE, phaseIndex); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
core/src/main/java/ai/timefold/solver/core/api/solver/event/FinalBestSolutionEvent.java
This file contains hidden or 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,16 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import ai.timefold.solver.core.api.domain.solution.PlanningSolution; | ||
|
|
||
| /** | ||
| * Delivered in a consumer thread at the end of the solving process and contains the final {@link PlanningSolution best | ||
| * solution} found. | ||
| * | ||
| * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation | ||
| */ | ||
| public interface FinalBestSolutionEvent<Solution_> { | ||
| /** | ||
| * @return the {@link PlanningSolution best solution} found by the solver | ||
| */ | ||
| Solution_ solution(); | ||
| } |
27 changes: 27 additions & 0 deletions
27
...src/main/java/ai/timefold/solver/core/api/solver/event/FirstInitializedSolutionEvent.java
This file contains hidden or 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,27 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import ai.timefold.solver.core.api.domain.solution.PlanningSolution; | ||
|
|
||
| /** | ||
| * Delivered in a consumer thread at the beginning of the actual optimization process. | ||
| * First initialized solution is the solution at the end of the last phase | ||
| * that immediately precedes the first local search phase. | ||
| * | ||
| * @param <Solution_> | ||
| */ | ||
| public interface FirstInitializedSolutionEvent<Solution_> { | ||
| /** | ||
| * @return The {@link PlanningSolution initialized solution} | ||
| */ | ||
| Solution_ solution(); | ||
|
|
||
| /** | ||
| * @return A {@link EventProducerId} identifying what generated the event | ||
| */ | ||
| EventProducerId producerId(); | ||
|
|
||
| /** | ||
| * @return True if the solver was terminated early, false otherwise | ||
| */ | ||
| boolean isTerminatedEarly(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.