-
Notifications
You must be signed in to change notification settings - Fork 207
refactor: introduce incremental constraint collectors for improved performance #2270
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 all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3eeb4e1
refactor to put all update logic in one place
triceo d7107e2
introduce the new API
triceo efd3881
incorporate the new API into the group node
triceo 86c5323
further improve the collector API
triceo b1d32f4
update the nodes to the new API
triceo 8e01c6f
Revert the changes to propagation, as it can't be done safely
triceo 0796860
Convert the easy collectors
triceo 624b483
Clarify the APIs
triceo 9d16c69
Second wave of incrementality
triceo a2e813d
Third wave of incrementality
triceo a890555
Another wave
triceo 7286f01
Smaller optimizations
triceo 4b576a2
More refactors
triceo 33cbe56
Formatting
triceo 4770416
Review
triceo b0eaa00
Some simplifications from review
triceo ae6af3c
Naming
triceo b145437
More naming
triceo ed165d7
Naming
triceo 9ff7122
refactor: remove isIncremental/incrementalAccumulator switch from *Co…
triceo 99d09dd
Add docs
triceo 75900d5
review
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
33 changes: 33 additions & 0 deletions
33
...in/java/ai/timefold/solver/core/api/score/stream/bi/BiConstraintCollectorAccumulator.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,33 @@ | ||
| package ai.timefold.solver.core.api.score.stream.bi; | ||
|
|
||
| import ai.timefold.solver.core.api.function.TriFunction; | ||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollectorAccumulator; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorAccumulator}, | ||
| * only for {@link BiConstraintCollector}. | ||
| */ | ||
| @NullMarked | ||
| @FunctionalInterface | ||
| public interface BiConstraintCollectorAccumulator<ResultContainer_, A, B> | ||
| extends TriFunction<ResultContainer_, A, B, Runnable> { | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorAccumulator#intoGroup(Object)}, | ||
| * only for {@link BiConstraintCollector}. | ||
| */ | ||
| BiConstraintCollectorValueHandle<A, B> intoGroup(ResultContainer_ resultContainer); | ||
|
|
||
| /** | ||
| * @deprecated Use {@link #intoGroup(Object)} instead. | ||
| * @throws UnsupportedOperationException always | ||
| */ | ||
| @Deprecated(since = "2.2.0", forRemoval = true) | ||
| @Override | ||
| default Runnable apply(ResultContainer_ resultContainer, A a, B b) { | ||
| throw new UnsupportedOperationException("Use intoGroup() instead."); | ||
| } | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
...in/java/ai/timefold/solver/core/api/score/stream/bi/BiConstraintCollectorValueHandle.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,36 @@ | ||
| package ai.timefold.solver.core.api.score.stream.bi; | ||
|
|
||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollectorValueHandle; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle}, | ||
| * only for {@link BiConstraintCollector}. | ||
| */ | ||
| @NullMarked | ||
| public interface BiConstraintCollectorValueHandle<A, B> { | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#add(Object)}, | ||
| * only for {@link BiConstraintCollector} | ||
| */ | ||
| void add(@Nullable A a, @Nullable B b); | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#replaceWith(Object)}, | ||
| * only for {@link BiConstraintCollector} | ||
| */ | ||
| default void replaceWith(@Nullable A a, @Nullable B b) { | ||
| remove(); | ||
| add(a, b); | ||
| } | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#remove()}, | ||
| * only for {@link BiConstraintCollector} | ||
| */ | ||
| void remove(); | ||
|
|
||
| } |
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
33 changes: 33 additions & 0 deletions
33
...ava/ai/timefold/solver/core/api/score/stream/quad/QuadConstraintCollectorAccumulator.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,33 @@ | ||
| package ai.timefold.solver.core.api.score.stream.quad; | ||
|
|
||
| import ai.timefold.solver.core.api.function.PentaFunction; | ||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollectorAccumulator; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorAccumulator}, | ||
| * only for {@link QuadConstraintCollector}. | ||
| */ | ||
| @NullMarked | ||
| @FunctionalInterface | ||
| public interface QuadConstraintCollectorAccumulator<ResultContainer_, A, B, C, D> | ||
| extends PentaFunction<ResultContainer_, A, B, C, D, Runnable> { | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorAccumulator#intoGroup(Object)}, | ||
| * only for {@link QuadConstraintCollector}. | ||
| */ | ||
| QuadConstraintCollectorValueHandle<A, B, C, D> intoGroup(ResultContainer_ resultContainer); | ||
|
|
||
| /** | ||
| * @deprecated Use {@link #intoGroup(Object)} instead. | ||
| * @throws UnsupportedOperationException always | ||
| */ | ||
| @Deprecated(since = "2.2.0", forRemoval = true) | ||
| @Override | ||
| default Runnable apply(ResultContainer_ resultContainer, A a, B b, C c, D d) { | ||
| throw new UnsupportedOperationException("Use intoGroup() instead."); | ||
| } | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
...ava/ai/timefold/solver/core/api/score/stream/quad/QuadConstraintCollectorValueHandle.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,36 @@ | ||
| package ai.timefold.solver.core.api.score.stream.quad; | ||
|
|
||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollectorValueHandle; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle}, | ||
| * only for {@link QuadConstraintCollector}. | ||
| */ | ||
| @NullMarked | ||
| public interface QuadConstraintCollectorValueHandle<A, B, C, D> { | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#add(Object)}, | ||
| * only for {@link QuadConstraintCollector} | ||
| */ | ||
| void add(@Nullable A a, @Nullable B b, @Nullable C c, @Nullable D d); | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#replaceWith(Object)}, | ||
| * only for {@link QuadConstraintCollector} | ||
| */ | ||
| default void replaceWith(@Nullable A a, @Nullable B b, @Nullable C c, @Nullable D d) { | ||
| remove(); | ||
| add(a, b, c, d); | ||
| } | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#remove()}, | ||
| * only for {@link QuadConstraintCollector} | ||
| */ | ||
| void remove(); | ||
|
|
||
| } |
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
33 changes: 33 additions & 0 deletions
33
.../java/ai/timefold/solver/core/api/score/stream/tri/TriConstraintCollectorAccumulator.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,33 @@ | ||
| package ai.timefold.solver.core.api.score.stream.tri; | ||
|
|
||
| import ai.timefold.solver.core.api.function.QuadFunction; | ||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollectorAccumulator; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorAccumulator}, | ||
| * only for {@link TriConstraintCollector}. | ||
| */ | ||
| @NullMarked | ||
| @FunctionalInterface | ||
| public interface TriConstraintCollectorAccumulator<ResultContainer_, A, B, C> | ||
| extends QuadFunction<ResultContainer_, A, B, C, Runnable> { | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorAccumulator#intoGroup(Object)}, | ||
| * only for {@link TriConstraintCollector}. | ||
| */ | ||
| TriConstraintCollectorValueHandle<A, B, C> intoGroup(ResultContainer_ resultContainer); | ||
|
|
||
| /** | ||
| * @deprecated Use {@link #intoGroup(Object)} instead. | ||
| * @throws UnsupportedOperationException always | ||
| */ | ||
| @Deprecated(since = "2.2.0", forRemoval = true) | ||
| @Override | ||
| default Runnable apply(ResultContainer_ resultContainer, A a, B b, C c) { | ||
| throw new UnsupportedOperationException("Use intoGroup() instead."); | ||
| } | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
.../java/ai/timefold/solver/core/api/score/stream/tri/TriConstraintCollectorValueHandle.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,36 @@ | ||
| package ai.timefold.solver.core.api.score.stream.tri; | ||
|
|
||
| import ai.timefold.solver.core.api.score.stream.uni.UniConstraintCollectorValueHandle; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle}, | ||
| * only for {@link TriConstraintCollector}. | ||
| */ | ||
| @NullMarked | ||
| public interface TriConstraintCollectorValueHandle<A, B, C> { | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#add(Object)}, | ||
| * only for {@link TriConstraintCollector} | ||
| */ | ||
| void add(@Nullable A a, @Nullable B b, @Nullable C c); | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#replaceWith(Object)}, | ||
| * only for {@link TriConstraintCollector} | ||
| */ | ||
| default void replaceWith(@Nullable A a, @Nullable B b, @Nullable C c) { | ||
| remove(); | ||
| add(a, b, c); | ||
| } | ||
|
|
||
| /** | ||
| * As defined by {@link UniConstraintCollectorValueHandle#remove()}, | ||
| * only for {@link TriConstraintCollector} | ||
| */ | ||
| void remove(); | ||
|
|
||
| } |
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.