-
Notifications
You must be signed in to change notification settings - Fork 164
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 4 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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.OptionalInt; | ||
|
|
||
| import ai.timefold.solver.core.config.solver.SolverConfig; | ||
| import ai.timefold.solver.core.impl.phase.NoChangePhase; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Identifies the producer of a {@link BestSolutionChangedEvent}. | ||
| * Will be an instance of {@link PhaseEventProducerId} if the event is associated | ||
| * with a phase, or a {@link SolveEventProducerId} otherwise. | ||
| */ | ||
| @NullMarked | ||
| public sealed interface EventProducerId extends Serializable permits PhaseEventProducerId, SolveEventProducerId { | ||
| /** | ||
| * 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(); | ||
|
|
||
| /** | ||
| * An optional integer, that if present, identify what index in {@link SolverConfig#getPhaseConfigList()} | ||
| * corresponds to the Phase that produced the event. | ||
| * | ||
| * @return The index of the Phase that produced the event, or {@link OptionalInt#empty()} if the event producer | ||
| * is not associated with a phase. | ||
| */ | ||
| OptionalInt eventPhaseIndex(); | ||
triceo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
core/src/main/java/ai/timefold/solver/core/api/solver/event/PhaseEventProducerId.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,32 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import java.util.OptionalInt; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * {@link EventProducerId} for when a {@link BestSolutionChangedEvent} is | ||
| * caused by a phase. | ||
| */ | ||
| @NullMarked | ||
| public record PhaseEventProducerId(PhaseType phaseType, int phaseIndex) implements EventProducerId { | ||
| @Override | ||
| public String producerId() { | ||
| return "%s (%d)".formatted(phaseType.getPhaseName(), phaseIndex); | ||
| } | ||
|
|
||
| @Override | ||
| public String simpleProducerName() { | ||
| return phaseType.getPhaseName(); | ||
| } | ||
|
|
||
| @Override | ||
| public OptionalInt eventPhaseIndex() { | ||
| return OptionalInt.of(phaseIndex); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return producerId(); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
core/src/main/java/ai/timefold/solver/core/api/solver/event/PhaseType.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,52 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import ai.timefold.solver.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig; | ||
| import ai.timefold.solver.core.config.exhaustivesearch.ExhaustiveSearchPhaseConfig; | ||
| import ai.timefold.solver.core.config.localsearch.LocalSearchPhaseConfig; | ||
| import ai.timefold.solver.core.config.partitionedsearch.PartitionedSearchPhaseConfig; | ||
| import ai.timefold.solver.core.config.phase.NoChangePhaseConfig; | ||
| import ai.timefold.solver.core.config.phase.custom.CustomPhaseConfig; | ||
| import ai.timefold.solver.core.impl.phase.NoChangePhase; | ||
|
|
||
| /** | ||
| * The type of phase (for example, a Construction Heuristic). | ||
| */ | ||
| public enum PhaseType { | ||
| /** | ||
| * The type of phase associated with {@link NoChangePhaseConfig}. | ||
| * | ||
| * @deprecated Deprecated on account of {@link NoChangePhase} having no use. | ||
| */ | ||
| @Deprecated(forRemoval = true, since = "1.28.0") | ||
| NO_CHANGE("No Change"), | ||
| /** | ||
| * The type of phase associated with {@link ConstructionHeuristicPhaseConfig}. | ||
| */ | ||
| CONSTRUCTION_HEURISTIC("Construction Heuristics"), | ||
| /** | ||
| * The type of phase associated with {@link LocalSearchPhaseConfig}. | ||
| */ | ||
| LOCAL_SEARCH("Local Search"), | ||
| /** | ||
| * The type of phase associated with {@link ExhaustiveSearchPhaseConfig}. | ||
| */ | ||
| EXHAUSTIVE_SEARCH("Exhaustive Search"), | ||
| /** | ||
| * The type of phase associated with {@link PartitionedSearchPhaseConfig}. | ||
| */ | ||
| PARTITIONED_SEARCH("Partitioned Search"), | ||
| /** | ||
| * The type of phase associated with {@link CustomPhaseConfig}. | ||
| */ | ||
| CUSTOM_PHASE("Custom Phase"); | ||
|
|
||
| private final String phaseName; | ||
|
|
||
| PhaseType(String phaseName) { | ||
| this.phaseName = phaseName; | ||
| } | ||
|
|
||
| public String getPhaseName() { | ||
| return phaseName; | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
core/src/main/java/ai/timefold/solver/core/api/solver/event/SolveEventProducerId.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,53 @@ | ||
| package ai.timefold.solver.core.api.solver.event; | ||
|
|
||
| import java.util.OptionalInt; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * {@link EventProducerId} for when a {@link BestSolutionChangedEvent} is not | ||
| * caused by a phase. | ||
| */ | ||
| @NullMarked | ||
| public enum SolveEventProducerId implements EventProducerId { | ||
| /** | ||
| * The cause is unknown. This is the {@link EventProducerId} | ||
| * used when one of the deprecated {@link BestSolutionChangedEvent} | ||
| * constructors are used. | ||
| * | ||
| * @deprecated Only used when Users manually construct instances of {@link BestSolutionChangedEvent}. | ||
| */ | ||
| @Deprecated(forRemoval = true, since = "1.28.0") | ||
| UNKNOWN("Unknown"), | ||
|
|
||
| /** | ||
| * The solver was started with an initialized solution. | ||
| */ | ||
| SOLVING_STARTED("Solving started"), | ||
|
|
||
| /** | ||
| * One or more problem changes occured that change the best solution. | ||
| */ | ||
| PROBLEM_CHANGE("Problem change"); | ||
|
|
||
| private final String producerId; | ||
|
|
||
| SolveEventProducerId(String producerId) { | ||
| this.producerId = producerId; | ||
| } | ||
|
|
||
| @Override | ||
| public String producerId() { | ||
| return producerId; | ||
| } | ||
|
|
||
| @Override | ||
| public String simpleProducerName() { | ||
| return producerId; | ||
| } | ||
|
|
||
| @Override | ||
| public OptionalInt eventPhaseIndex() { | ||
| return OptionalInt.empty(); | ||
| } | ||
| } |
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
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.