repo_name
stringlengths
1
62
dataset
stringclasses
1 value
lang
stringclasses
11 values
pr_id
int64
1
20.1k
owner
stringlengths
2
34
reviewer
stringlengths
2
39
diff_hunk
stringlengths
15
262k
code_review_comment
stringlengths
1
99.6k
timefold-solver
github_2023
others
867
TimefoldAI
zepfred
@@ -75,9 +75,24 @@ $ git clone {quickstarts-clone-url} To complete this guide, you need: +[tabs] +==== +Java / Kotlin:: ++ +-- * https://adoptopenjdk.net/[JDK] {java-version}+ with `JAVA_HOME` configured appropriately * https://maven.apache.org/download.html[Apache Maven] {maven-version}+ or https://gradle.org/install/[Gradle] 7+ * An IDE, such as https://www.jetbrains.com/idea[IntelliJ IDEA], VSCode or Eclipse +-- + +Python:: ++ +-- +* https://adoptopenjdk.net/[JDK] {java-version}+ with `JAVA_HOME` configured appropriately +* https://www.python.org/downloads/[Python] {python-version}+ +* An IDE, such as https://www.jetbrains.com/pycharm/[IntelliJ PyCharm], VSCode or Eclipse
```suggestion * An IDE, such as https://www.jetbrains.com/pycharm/[IntelliJ PyCharm], https://code.visualstudio.com[VSCode] or https://www.eclipse.org[Eclipse] ```
timefold-solver
github_2023
others
841
TimefoldAI
zepfred
@@ -0,0 +1,200 @@ +[#loadBalancingAndFairness] += Load balancing and fairness +:doctype: book +:sectnums: +:icons: font + +Load balancing is a common constraint for many Timefold Solver use cases. +Especially when scheduling employees, the workload needs to be spread out fairly; +there may even be legal requirements to that effect. + +[#fairnessWhatIsFair] +== What is fair
```suggestion == What is fair? ```
timefold-solver
github_2023
java
841
TimefoldAI
Christopher-Chianelli
@@ -0,0 +1,62 @@ +package ai.timefold.solver.core.impl.score.stream.collector; + +import java.math.BigDecimal; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +public final class LoadBalanceCalculator implements ObjectCalculator<Object, BigDecimal> {
So, if I am reading this correctly, this does `sqrt(sum(count^2))`? This has the consequence that a "fair" schedule result increases as the number of shifts increases: Assume two employees, and a perfectly fair schedule, a perfectly fair schedule that is off by one, and a completely unfair schedule. Then these will be the score impact of fairness: - 2 shifts: fair: `sqrt(2)`, slightly unfair: `sqrt(4)` , completely unfair: `sqrt(4)` = 2 (max difference: 0.585786438) - 4 shifts: fair: `sqrt(8)`, slightly unfair: `sqrt(10)` , completely unfair: `sqrt(16)` = 4 (max difference: 1.171572875) - 8 shifts: fair: `sqrt(32)`, slightly unfair: `sqrt(34)` , completely unfair: `sqrt(64)` = 8 (max difference: 2.343145751) This means the "baseline" of a perfectly fair schedule increases, and the maximum difference in score increases linearly with the number of shifts. An alternative formula is "Root of squared deviation from the mean": `sqrt(sum((count - average count)^2))`. For the same dataset: - 2 shifts: fair: 0, slightly unfair: `sqrt(2)` , completely unfair: `sqrt(2)` (max difference: sqrt(2) = 1.414213562) - 4 shifts: fair: 0, slightly unfair: `sqrt(2)` , completely unfair: `sqrt(8)` (max difference: sqrt(8) = 2.828427125) - 8 shifts: fair: 0, slightly unfair: `sqrt(2)` , completely unfair: `sqrt(32)` (max difference: sqrt(32) = 5.656854249) the baseline remains the same, although the max difference still scales linearly.
timefold-solver
github_2023
java
841
TimefoldAI
Christopher-Chianelli
@@ -0,0 +1,62 @@ +package ai.timefold.solver.core.impl.score.stream.collector; + +import java.math.BigDecimal; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +public final class LoadBalanceCalculator implements ObjectCalculator<Object, BigDecimal> { + + private final Map<Object, Long> groupCountMap = new LinkedHashMap<>(); + // the sum of squared deviation from zero + private long squaredSum = 0L; + private BigDecimal result = null; + + @Override + public void insert(Object o) {
How does this handle "load balance by minutes worked"?
timefold-solver
github_2023
java
831
TimefoldAI
triceo
@@ -86,10 +86,6 @@ public final void retractLeft(LeftTuple_ tuple) { return; } TupleState state = outTuple.state; - if (!state.isActive()) { - throw new IllegalStateException("Impossible state: The tuple (" + outTuple.state + ") in node (" + this - + ") is in an unexpected state (" + outTuple.state + ")."); - }
Let's keep the condition, but return from it. Keep a comment explaining the situation where this happens. Dtto. below.
timefold-solver
github_2023
java
830
TimefoldAI
zepfred
@@ -73,11 +71,11 @@ public Result_ result() { if (propertyToItemCountMap.isEmpty()) { return null; } - return isMin ? getFirstKey(propertyToItemCountMap.firstEntry().getValue()) - : getFirstKey(propertyToItemCountMap.lastEntry().getValue()); + var itemCount = isMin ? propertyToItemCountMap.firstEntry().getValue() : propertyToItemCountMap.lastEntry().getValue();
Nice!
timefold-solver
github_2023
java
830
TimefoldAI
zepfred
@@ -1,22 +1,21 @@ package ai.timefold.solver.core.impl.score.stream.collector; import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; import java.util.function.Function; import ai.timefold.solver.core.impl.util.ConstantLambdaUtils; import ai.timefold.solver.core.impl.util.MutableInt; -public final class MinMaxUndoableActionable<Result_, Property_> implements UndoableActionable<Result_, Result_> { +public final class MinMaxUndoableActionable<Result_, Property_>
Do we have tests covering this class?
timefold-solver
github_2023
others
809
TimefoldAI
triceo
@@ -140,6 +140,43 @@ public class Lesson { ---- +==== + +''' + +=== Upgrade from 1.9.0 to 1.10.0
This doesn't belong here, it's already above.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -1955,6 +1957,263 @@ public static <A, ResultContainer_, Result_> UniConstraintCollector<A, ResultCon return InnerQuadConstraintCollectors.toConsecutiveSequences(resultMap, indexMap); } + // ***************************************************************** + // concurrentUsage + // ***************************************************************** + /** + * Creates a constraint collector that returns {@link ConcurrentUsageInfo} about the first fact. + * + * For instance, {@code [Equipment from=2, to=4] [Equipment from=3, to=5] [Equipment from=6, to=7] [Equipment from=7, to=8]} + * returns the following information: + * + * <pre> + * {@code + * ConcurrentUsage: [minConcurrentUsage: 1, maxConcurrentUsage: 2, + * [Equipment from=2, to=4] [Equipment from=3, to=5]], + * [minConcurrentUsage: 1, maxConcurrentUsage: 1, + * [Equipment from=6, to=7] [Equipment from=7, to=8]]
Looking at the example, shouldn't the `to` rather be exclusive? Java APIs concerning ranges typically follow conventions `[min, max)`.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -1,11 +1,15 @@ -package ai.timefold.solver.examples.common.experimental.api; +package ai.timefold.solver.core.api.score.stream.common; -public interface IntervalCluster<Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> +public interface ConcurrentUsage<Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> extends Iterable<Interval_> { int size(); boolean hasOverlap(); + int getMinimumConcurrentUsage(); + + int getMaximumConcurrentUsage();
The first method speak of overlap. The other two methods speak of concurrent usage. We should standardize this; personally, `minimumOverlap` is more self-explanatory to me.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -0,0 +1,16 @@ +package ai.timefold.solver.core.api.score.stream.common; + +public interface ConcurrentUsageInfo<Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> { + + /** + * @return never null, an iterable that iterates through the interval clusters + * contained in the collection in ascending order + */ + Iterable<ConcurrentUsage<Interval_, Point_, Difference_>> getConcurrentUsages();
This, in my opinion, is another place where the new name "concurrent usage" doesn't really work. "get concurrent usages" sounds to me a bit like something a non-native speaker would produce. Overlapping intervals probably wasn't ideal either. How about overlapping ranges?
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -0,0 +1,16 @@ +package ai.timefold.solver.core.api.score.stream.common; + +public interface ConcurrentUsageInfo<Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> { + + /** + * @return never null, an iterable that iterates through the interval clusters + * contained in the collection in ascending order + */ + Iterable<ConcurrentUsage<Interval_, Point_, Difference_>> getConcurrentUsages(); + + /** + * @return never null, an iterable that iterates through the breaks contained in + * the collection in ascending order + */ + Iterable<Break<Point_, Difference_>> getBreaks();
Just out of curiosity... can you think of a term for a "break" inbetween two ranges of numbers? I'm thinking maybe maths has a term for this.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -11,21 +11,21 @@ public interface IntervalBreak<Interval_, Point_ extends Comparable<Point_>, Dif /** * @return never null, the interval cluster leading directly into this */ - IntervalCluster<Interval_, Point_, Difference_> getPreviousIntervalCluster(); + ConcurrentUsage<Interval_, Point_, Difference_> getPreviousConcurrentUsage();
getPreviousRange?
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -11,21 +11,21 @@ public interface IntervalBreak<Interval_, Point_ extends Comparable<Point_>, Dif /** * @return never null, the interval cluster leading directly into this */ - IntervalCluster<Interval_, Point_, Difference_> getPreviousIntervalCluster(); + ConcurrentUsage<Interval_, Point_, Difference_> getPreviousConcurrentUsage(); /** * @return never null, the interval cluster immediately following this */ - IntervalCluster<Interval_, Point_, Difference_> getNextIntervalCluster(); + ConcurrentUsage<Interval_, Point_, Difference_> getNextConcurrentUsage(); /** * Return the end of the sequence before this break. For the * break between 6 and 10, this will return 6. * * @return never null, the item this break is directly after */ - default Point_ getPreviousIntervalClusterEnd() { - return getPreviousIntervalCluster().getEnd(); + default Point_ getPreviousConcurrentUsageEnd() {
If we're changing the difference function to be `[start, end)`, we should consider changing this too.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -0,0 +1,49 @@ +package ai.timefold.solver.core.impl.score.stream.collector.bi; + +import java.util.Objects; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + +import ai.timefold.solver.core.api.score.stream.common.ConcurrentUsageInfo; +import ai.timefold.solver.core.impl.score.stream.collector.ConcurrentUsageCalculator; + +final class ConcurrentUsageBiConstraintCollector<A, B, Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> + extends + ObjectCalculatorBiCollector<A, B, Interval_, ConcurrentUsageInfo<Interval_, Point_, Difference_>, ConcurrentUsageCalculator<Interval_, Point_, Difference_>> { + + private final Function<? super Interval_, ? extends Point_> startMap; + private final Function<? super Interval_, ? extends Point_> endMap; + private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction; + + public ConcurrentUsageBiConstraintCollector(BiFunction<? super A, ? super B, ? extends Interval_> mapper, + Function<? super Interval_, ? extends Point_> startMap, Function<? super Interval_, ? extends Point_> endMap, + BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction) { + super(mapper); + this.startMap = startMap; + this.endMap = endMap; + this.differenceFunction = differenceFunction; + } + + @Override + public Supplier<ConcurrentUsageCalculator<Interval_, Point_, Difference_>> supplier() { + return () -> new ConcurrentUsageCalculator<>(startMap, endMap, differenceFunction); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof ConcurrentUsageBiConstraintCollector<?, ?, ?, ?, ?> that)) + return false; + if (!super.equals(o)) + return false; + return Objects.equals(startMap, that.startMap) && Objects.equals(endMap, + that.endMap) && Objects.equals(differenceFunction, that.differenceFunction);
Let's start learning the "new" equals... return o instanceof ConcurrentUsageBiConstraintCollector<?, ?, ?, ?, ?> that && Objects.equals(startMap, that.startMap) && ... People have started showing that the JVM doesn't really like the way everyone typically does equals.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -1,24 +1,29 @@ -package ai.timefold.solver.examples.common.experimental.impl; +package ai.timefold.solver.core.impl.score.stream.collector.connectedRanges;
I'd go for just `ranges` - we generally don't do camel case in package names.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -1955,6 +1957,263 @@ public static <A, ResultContainer_, Result_> UniConstraintCollector<A, ResultCon return InnerQuadConstraintCollectors.toConsecutiveSequences(resultMap, indexMap); } + // ***************************************************************** + // toConnectedRanges + // ***************************************************************** + /** + * Creates a constraint collector that returns {@link ConnectedRangeChain} about the first fact. + * + * For instance, {@code [Equipment from=2, to=4] [Equipment from=3, to=5] [Equipment from=6, to=7] [Equipment from=7, to=8]} + * returns the following information: + * + * <pre> + * {@code + * ConcurrentUsage: [minConcurrentUsage: 1, maxConcurrentUsage: 2, + * [Equipment from=2, to=4] [Equipment from=3, to=5]], + * [minConcurrentUsage: 1, maxConcurrentUsage: 1, + * [Equipment from=6, to=7] [Equipment from=7, to=8]] + * Breaks: [[Break from=5, to=6, length=1]] + * } + * </pre> + * + * This can be used to ensure a limited resource is not over-assigned. + * + * @param startMap Maps the fact to its start + * @param endMap Maps the fact to its end + * @param differenceFunction Computes the difference between two points. The second argument is always + * larger than the first (ex: {@link Duration#between} + * or {@code (a,b) -> b - a}). + * @param <A> type of the first mapped fact + * @param <PointType_> type of the fact endpoints + * @param <DifferenceType_> type of difference between points + * @return never null + */ + public static <A, PointType_ extends Comparable<PointType_>, DifferenceType_ extends Comparable<DifferenceType_>> + UniConstraintCollector<A, ?, ConnectedRangeChain<A, PointType_, DifferenceType_>> + toConnectedRanges(Function<A, PointType_> startMap, Function<A, PointType_> endMap, + BiFunction<PointType_, PointType_, DifferenceType_> differenceFunction) { + return InnerUniConstraintCollectors.toConnectedRanges(ConstantLambdaUtils.identity(), startMap, endMap, + differenceFunction); + } + + /** + * Specialized version of {@link #toConnectedRanges(Function,Function,BiFunction)} for + * {@link Temporal} types. + * + * @param <A> type of the first mapped fact + * @param <PointType_> temporal type of the endpoints + * @param startMap Maps the fact to its start + * @param endMap Maps the fact to its end + * @return never null + */ + public static <A, PointType_ extends Temporal & Comparable<PointType_>> + UniConstraintCollector<A, ?, ConnectedRangeChain<A, PointType_, Duration>> + toConnectedRangesByTime(Function<A, PointType_> startMap, Function<A, PointType_> endMap) {
```suggestion toConnectedTemporalRanges(Function<A, PointType_> startMap, Function<A, PointType_> endMap) { ``` Reads better to me.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -235,20 +239,39 @@ void removeInterval(Interval<Interval_, Point_> interval) { } @Override - public Iterable<IntervalCluster<Interval_, Point_, Difference_>> getIntervalClusters() { + public Iterable<ConnectedRange<Interval_, Point_, Difference_>> getConnectedRanges() { return (Iterable) clusterStartSplitPointToCluster.values(); } @Override - public Iterable<IntervalBreak<Interval_, Point_, Difference_>> getBreaks() { + public Iterable<RangeGap<Point_, Difference_>> getGaps() { return (Iterable) clusterStartSplitPointToNextBreak.values(); } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof ConnectedRangeChainImpl<?, ?, ?> that)) + return false; + return Objects.equals(clusterStartSplitPointToCluster, + that.clusterStartSplitPointToCluster) + && Objects.equals(splitPointSet, + that.splitPointSet) + && Objects.equals(clusterStartSplitPointToNextBreak, + that.clusterStartSplitPointToNextBreak); + } + + @Override + public int hashCode() { + return Objects.hash(clusterStartSplitPointToCluster, splitPointSet, clusterStartSplitPointToNextBreak); + } + @Override public String toString() { return "Clusters {" + - "intervalClusters=" + getIntervalClusters() + - ", breaks=" + getBreaks() + + "intervalClusters=" + getConnectedRanges() + + ", breaks=" + getGaps() + '}';
Please fix naming. Possibly in the entire PR; speaks of clusters, but there no longer is any such class.
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -0,0 +1,212 @@ +package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges; + +import java.util.Iterator; +import java.util.NavigableSet; +import java.util.Objects; +import java.util.function.BiFunction; + +import ai.timefold.solver.core.api.score.stream.common.ConnectedRange; + +final class ConnectedRangeImpl<Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> + implements ConnectedRange<Interval_, Point_, Difference_> { + + private final NavigableSet<IntervalSplitPoint<Interval_, Point_>> splitPointSet; + private final BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction; + private IntervalSplitPoint<Interval_, Point_> startSplitPoint; + private IntervalSplitPoint<Interval_, Point_> endSplitPoint; + + private int count; + private int minimumOverlap; + private int maximumOverlap; + private boolean hasOverlap; + + ConnectedRangeImpl(NavigableSet<IntervalSplitPoint<Interval_, Point_>> splitPointSet, + BiFunction<? super Point_, ? super Point_, ? extends Difference_> differenceFunction, + IntervalSplitPoint<Interval_, Point_> start) { + if (start == null) { + throw new IllegalArgumentException("start (" + start + ") is null"); + } + if (differenceFunction == null) { + throw new IllegalArgumentException("differenceFunction (" + differenceFunction + ") is null"); + }
For the sake of bravity, I'd prefer this.startSplitPoint = Objects.requireNonNull(start, "start");
timefold-solver
github_2023
java
800
TimefoldAI
triceo
@@ -3,24 +3,24 @@ import ai.timefold.solver.core.api.score.stream.common.ConnectedRange; import ai.timefold.solver.core.api.score.stream.common.RangeGap; -final class RangeGapImpl<Interval_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>> +final class RangeGapImpl<Range_, Point_ extends Comparable<Point_>, Difference_ extends Comparable<Difference_>>
Still clusters throughout this file.
timefold-solver
github_2023
java
786
TimefoldAI
Christopher-Chianelli
@@ -81,17 +38,17 @@ public LookUpStrategyResolver(DescriptorPolicy descriptorPolicy, LookUpStrategyT */ public LookUpStrategy determineLookUpStrategy(Object object) { return decisionCache.computeIfAbsent(object.getClass(), objectClass -> { - if (objectClass.isEnum()) { + if (DeepCloningUtils.isImmutable(objectClass)) {
I think value ranges that return arrays are rare, but probably not impossible. Arrays are mutable though, and may contain reference to mutable values (i.e. PlanningEntities).
timefold-solver
github_2023
java
779
TimefoldAI
zepfred
@@ -28,31 +29,44 @@ * @param <Solution_> the solution type, the class with the {@link PlanningSolution} annotation */ public class SolverScope<Solution_> { - protected Set<SolverMetric> solverMetricSet; - protected Tags monitoringTags; - protected int startingSolverCount; - protected Random workingRandom; - protected InnerScoreDirector<Solution_, ?> scoreDirector; + + private static AtomicLong resetAtomicLongTimeMillis(AtomicLong atomicLong) {
It seems off to have a method before the variable definitions. I suggest to move it after the constructor.
timefold-solver
github_2023
others
772
TimefoldAI
rsynek
@@ -29,22 +29,24 @@ jobs: # Clone timefold-quickstarts # Need to check for stale repo, since Github is not aware of the build chain and therefore doesn't automate it. - - name: Find the proper timefold-quickstarts repo and branch - env: - CHAIN_USER: ${{ github.actor }} - CHAIN_BRANCH: ${{ github.head_ref }} - CHAIN_REPO: "timefold-quickstarts" - CHAIN_DEFAULT_BRANCH: ${{ endsWith(github.head_ref, '.x') && github.head_ref || 'development' }} - shell: bash - run: ./timefold-solver/.github/scripts/check_chain_repo.sh - - name: Checkout timefold-quickstarts + - name: Checkout timefold-quickstarts (PR) # Checkout the PR branch first, if it exists + id: checkout-quickstarts + uses: actions/checkout@v4 + continue-on-error: true + with: + repository: ${{ github.actor }}/timefold-quickstarts + ref: ${{ github.head_ref }} + path: ./timefold-quickstarts + fetch-depth: 0 # Otherwise merge will fail on account of not having history. + - name: Checkout timefold-quickstarts (main) # Checkout the development branch if the PR branch does not exist
Perhaps: ```suggestion - name: Checkout timefold-quickstarts (development) # Checkout the development branch if the PR branch does not exist ```
timefold-solver
github_2023
java
767
TimefoldAI
zepfred
@@ -0,0 +1,180 @@ +package ai.timefold.solver.core.config.heuristic.selector.move; + +import java.util.Random; + +import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; +import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; +import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; + +public final class NearbyUtil { + + public static ChangeMoveSelectorConfig enable(ChangeMoveSelectorConfig changeMoveSelectorConfig, + Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { + var nearbyConfig = changeMoveSelectorConfig.copyConfig(); + var entityConfig = configureEntitySelector(nearbyConfig.getEntitySelectorConfig(), random); + var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), entityConfig.getId(), distanceMeter); + nearbyConfig.withEntitySelectorConfig(entityConfig) + .withValueSelectorConfig(valueConfig); + return nearbyConfig;
```suggestion ```
timefold-solver
github_2023
java
767
TimefoldAI
zepfred
@@ -0,0 +1,180 @@ +package ai.timefold.solver.core.config.heuristic.selector.move; + +import java.util.Random; + +import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; +import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; +import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; + +public final class NearbyUtil { + + public static ChangeMoveSelectorConfig enable(ChangeMoveSelectorConfig changeMoveSelectorConfig, + Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { + var nearbyConfig = changeMoveSelectorConfig.copyConfig(); + var entityConfig = configureEntitySelector(nearbyConfig.getEntitySelectorConfig(), random); + var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), entityConfig.getId(), distanceMeter); + nearbyConfig.withEntitySelectorConfig(entityConfig)
```suggestion return nearbyConfig.withEntitySelectorConfig(entityConfig) ```
timefold-solver
github_2023
java
767
TimefoldAI
zepfred
@@ -0,0 +1,180 @@ +package ai.timefold.solver.core.config.heuristic.selector.move; + +import java.util.Random; + +import ai.timefold.solver.core.config.heuristic.selector.common.nearby.NearbySelectionConfig; +import ai.timefold.solver.core.config.heuristic.selector.entity.EntitySelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.list.DestinationSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.ChangeMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.chained.TailChainSwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListChangeMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.ListSwapMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.move.generic.list.kopt.KOptListMoveSelectorConfig; +import ai.timefold.solver.core.config.heuristic.selector.value.ValueSelectorConfig; +import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; + +public final class NearbyUtil { + + public static ChangeMoveSelectorConfig enable(ChangeMoveSelectorConfig changeMoveSelectorConfig, + Class<? extends NearbyDistanceMeter<?, ?>> distanceMeter, Random random) { + var nearbyConfig = changeMoveSelectorConfig.copyConfig(); + var entityConfig = configureEntitySelector(nearbyConfig.getEntitySelectorConfig(), random); + var valueConfig = configureValueSelector(nearbyConfig.getValueSelectorConfig(), entityConfig.getId(), distanceMeter); + nearbyConfig.withEntitySelectorConfig(entityConfig) + .withValueSelectorConfig(valueConfig); + return nearbyConfig; + } + + private static EntitySelectorConfig configureEntitySelector(EntitySelectorConfig entitySelectorConfig, Random random) { + if (entitySelectorConfig == null) { + entitySelectorConfig = new EntitySelectorConfig(); + } + var entitySelectorId = addRandomSuffix("entitySelector", random); + entitySelectorConfig.withId(entitySelectorId);
Let's inline the returning operation for the existing methods.
timefold-solver
github_2023
java
767
TimefoldAI
zepfred
@@ -0,0 +1,19 @@ +package ai.timefold.solver.core.config.heuristic.selector.move; + +import java.util.Random; + +import ai.timefold.solver.core.impl.heuristic.selector.common.nearby.NearbyDistanceMeter; + +/** + * General superclass for move selectors that support Nearby Selection autoconfiguration in construction heuristics. + */ +public abstract class NearbyConstructionHeuristicAutoConfigurationMoveSelectorConfig<Config_ extends MoveSelectorConfig<Config_>>
I'm unsure if it is a good idea for this interface to extend `NearbyAutoConfigurationMoveSelectorConfig`. I am aware that multiple inheritance is not supported, so I suggest converting the classes `NearbyConstructionHeuristicAutoConfigurationMoveSelectorConfig` and `NearbyAutoConfigurationMoveSelectorConfig` into interfaces and making `ListChangeMoveSelectorConfig` and `ChangeMoveSelectorConfig` implement both contracts. I believe this will improve the readability, and `NearbyConstructionHeuristicAutoConfigurationMoveSelectorConfig` won't directly result in automatically enabling nearby for the local search moves. Maybe it makes sense to rename `NearbyAutoConfigurationMoveSelectorConfig` to `NearbyLocalSearchAutoConfigurationMoveSelectorConfig`.
timefold-solver
github_2023
java
767
TimefoldAI
zepfred
@@ -56,6 +56,13 @@ public ConstructionHeuristicPhase<Solution_> buildPhase(int phaseIndex, Heuristi ValueSorterManner valueSorterManner = Objects.requireNonNullElse(
Maybe remove valueSorterManner from your construction heuristics settings?
timefold-solver
github_2023
java
766
TimefoldAI
triceo
@@ -330,6 +331,21 @@ Some solver configs (%s) don't specify a %s class, yet there are multiple availa assertTargetClasses(targetList, DotNames.PLANNING_SOLUTION); } + private void assertNodeSharingDisabled(Map<String, SolverConfig> solverConfigMap) { + for (var entry : solverConfigMap.entrySet()) { + var solverConfig = entry.getValue(); + if (solverConfig.getScoreDirectorFactoryConfig() != null && + Boolean.TRUE + .equals(solverConfig.getScoreDirectorFactoryConfig().getConstraintStreamAutomaticNodeSharing())) { + throw new IllegalStateException( + ("SolverConfig %s enabled automatic node sharing via SolverConfig, which is not allowed." + + " Enable automatic node sharing with the property %s instead.")
You probably wanted to get the string on a single line, but I don't think it's necessary. In fact, the suggestion typically follows on the second line; in which case, you can use the raw string and can avoid the parens and the concat.
timefold-solver
github_2023
java
758
TimefoldAI
triceo
@@ -176,28 +189,28 @@ private void assertJustification(String message, ConstraintJustification... just throw new AssertionError(assertionMessage); } - List<Object> noneMatchedList = new LinkedList<>(); - List<Object> invalidMatchList = new LinkedList<>(); + List<Object> expectedNotFound = new LinkedList<>();
Let's use `ArrayList` exclusively. `LinkedList` theoretically has some advantages, but practically, it has none. This doesn't exactly match our use case, but it does a good job of explaining why the reasons people like LinkedList are actually kinda false: https://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/
timefold-solver
github_2023
java
761
TimefoldAI
triceo
@@ -204,6 +204,20 @@ public static <T> List<T> inheritMergeableListProperty(List<T> originalList, Lis } } + public static <T> List<T> inheritUniqueMergeableListProperty(List<T> originalList, List<T> inheritedList) { + if (inheritedList == null) { + return originalList; + } else if (originalList == null) { + // Shallow clone due to modifications after calling inherit + return new ArrayList<>(inheritedList); + } else { + // The inheritedList should be before the originalList + List<T> mergedList = new ArrayList<>(inheritedList); + mergedList.addAll(originalList.stream().filter(v -> !mergedList.contains(v)).toList()); + return mergedList;
I think it'd read easier if it were instead: Set<T> mergedSet = new LinkedHashSet<>(originalList); mergedSet.addAll(inheritedList); return new ArrayList<>(mergedSet); Maintains insertion order, doesn't need to use any streams, and absolute efficiency is not required here.
timefold-solver
github_2023
java
759
TimefoldAI
zepfred
@@ -52,39 +52,45 @@ public boolean isEntityIndependent() { @Override public ValueRange<?> extractValueRange(Solution_ solution, Object entity) { - List<CountableValueRange<?>> childValueRangeList = new ArrayList<>(childValueRangeDescriptorList.size()); - for (ValueRangeDescriptor<Solution_> valueRangeDescriptor : childValueRangeDescriptorList) { - childValueRangeList.add((CountableValueRange) valueRangeDescriptor.extractValueRange(solution, entity)); + return innerExtractValueRange(solution, entity);
Do we have tests to validate the changes?
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,14 +30,35 @@ public abstract class AbstractPhaseScope<Solution_> { protected int bestSolutionStepIndex; - public AbstractPhaseScope(SolverScope<Solution_> solverScope) { + /** + * As defined by #AbstractPhaseScope(SolverScope, boolean), + * with the phaseSendsBestSolutionEvents parameter set to true. + */ + protected AbstractPhaseScope(SolverScope<Solution_> solverScope) { + this(solverScope, true); + } + + /** + * + * @param solverScope never null + * @param phaseSendsBestSolutionEvents set to false if the phase only sends one best solution event at the end, + * or none at all; + * this is typical for construction heuristics, + * whose result only matters when it reached its natural end. + */ + protected AbstractPhaseScope(SolverScope<Solution_> solverScope, boolean phaseSendsBestSolutionEvents) { this.solverScope = solverScope; + this.phaseSendsBestSolutionEvents = phaseSendsBestSolutionEvents; } public SolverScope<Solution_> getSolverScope() { return solverScope; } + public boolean phaseSendsBestSolutionEvents() {
Should we use the default nomenclature `isPhaseSendsBestSolutionEvents`?
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -8,20 +8,19 @@ import ai.timefold.solver.core.impl.solver.scope.SolverScope; import ai.timefold.solver.core.impl.solver.thread.ChildThreadType; -public class BestScoreFeasibleTermination<Solution_> extends AbstractTermination<Solution_> { +public final class BestScoreFeasibleTermination<Solution_> extends AbstractTermination<Solution_> { private final int feasibleLevelsSize; private final double[] timeGradientWeightFeasibleNumbers; - public BestScoreFeasibleTermination(ScoreDefinition scoreDefinition, double[] timeGradientWeightFeasibleNumbers) { - feasibleLevelsSize = scoreDefinition.getFeasibleLevelsSize(); + public BestScoreFeasibleTermination(ScoreDefinition<?> scoreDefinition, double[] timeGradientWeightFeasibleNumbers) { + this.feasibleLevelsSize = scoreDefinition.getFeasibleLevelsSize(); this.timeGradientWeightFeasibleNumbers = timeGradientWeightFeasibleNumbers; - if (timeGradientWeightFeasibleNumbers.length != feasibleLevelsSize - 1) { + if (timeGradientWeightFeasibleNumbers.length != this.feasibleLevelsSize - 1) { throw new IllegalStateException( - "The timeGradientWeightNumbers (" + Arrays.toString(timeGradientWeightFeasibleNumbers) - + ")'s length (" + timeGradientWeightFeasibleNumbers.length - + ") is not 1 less than the feasibleLevelsSize (" + scoreDefinition.getFeasibleLevelsSize() - + ")."); + "The timeGradientWeightNumbers (%s)'s length (%d) is not 1 less than the feasibleLevelsSize (%s)."
```suggestion "The timeGradientWeightNumbers (%s)'s length (%d) is not 1 less than the feasibleLevelsSize (%d)." ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -56,7 +56,7 @@ public double calculatePhaseTimeGradient(AbstractPhaseScope<Solution_> phaseScop return calculateTimeGradient(phaseTimeMillisSpent); } - protected double calculateTimeGradient(long timeMillisSpent) { + private double calculateTimeGradient(long timeMillisSpent) {
Let's use the `var` keyword as we did in other classes.
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -36,7 +32,7 @@ public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { return unimprovedStepCount >= unimprovedStepCountLimit; } - protected int calculateUnimprovedStepCount(AbstractPhaseScope<Solution_> phaseScope) { + private static int calculateUnimprovedStepCount(AbstractPhaseScope<?> phaseScope) {
Let's use the `var` keyword as we did in other classes.
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -127,18 +139,24 @@ protected boolean isTerminated(long safeTimeMillis) { @Override public double calculateSolverTimeGradient(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return 0.0; + } return calculateTimeGradient(solverSafeTimeMillis); } @Override public double calculatePhaseTimeGradient(AbstractPhaseScope<Solution_> phaseScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return 0.0; + } return calculateTimeGradient(phaseSafeTimeMillis); } - protected double calculateTimeGradient(long safeTimeMillis) { - long now = clock.millis(); - long unimprovedTimeMillisSpent = now - (safeTimeMillis - unimprovedTimeMillisSpentLimit); - double timeGradient = unimprovedTimeMillisSpent / ((double) unimprovedTimeMillisSpentLimit); + private double calculateTimeGradient(long safeTimeMillis) {
```suggestion private double calculateTimeGradient(long safeTimeMillis) { if (!currentPhaseSendsBestSolutionEvents) { return 0.0; } ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -127,18 +139,24 @@ protected boolean isTerminated(long safeTimeMillis) { @Override public double calculateSolverTimeGradient(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) {
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -127,18 +139,24 @@ protected boolean isTerminated(long safeTimeMillis) { @Override public double calculateSolverTimeGradient(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return 0.0; + } return calculateTimeGradient(solverSafeTimeMillis); } @Override public double calculatePhaseTimeGradient(AbstractPhaseScope<Solution_> phaseScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return 0.0; + }
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -127,18 +139,24 @@ protected boolean isTerminated(long safeTimeMillis) { @Override public double calculateSolverTimeGradient(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return 0.0;
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -127,18 +139,24 @@ protected boolean isTerminated(long safeTimeMillis) { @Override public double calculateSolverTimeGradient(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return 0.0; + }
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } long bestSolutionTimeMillis = solverScope.getBestSolutionTimeMillis(); return isTerminated(bestSolutionTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { - long bestSolutionTimeMillis = phaseScope.getPhaseBestSolutionTimeMillis(); + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } + var bestSolutionTimeMillis = phaseScope.getPhaseBestSolutionTimeMillis(); return isTerminated(bestSolutionTimeMillis); } - protected boolean isTerminated(long bestSolutionTimeMillis) { - long now = clock.millis(); - long unimprovedTimeMillisSpent = now - bestSolutionTimeMillis; - return unimprovedTimeMillisSpent >= unimprovedTimeMillisSpentLimit; + private boolean isTerminated(long bestSolutionTimeMillis) { + return getUnimprovedTimeMillisSpent(bestSolutionTimeMillis) >= unimprovedTimeMillisSpentLimit;
```suggestion if (!currentPhaseSendsBestSolutionEvents) { return false; } return getUnimprovedTimeMillisSpent(bestSolutionTimeMillis) >= unimprovedTimeMillisSpentLimit; ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) {
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false;
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + }
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } long bestSolutionTimeMillis = solverScope.getBestSolutionTimeMillis(); return isTerminated(bestSolutionTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { - long bestSolutionTimeMillis = phaseScope.getPhaseBestSolutionTimeMillis(); + if (!currentPhaseSendsBestSolutionEvents) { + return false; + }
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } long bestSolutionTimeMillis = solverScope.getBestSolutionTimeMillis(); return isTerminated(bestSolutionTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { - long bestSolutionTimeMillis = phaseScope.getPhaseBestSolutionTimeMillis(); + if (!currentPhaseSendsBestSolutionEvents) { + return false;
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -29,26 +31,50 @@ public long getUnimprovedTimeMillisSpentLimit() { return unimprovedTimeMillisSpentLimit; } + @Override + public void phaseStarted(AbstractPhaseScope<Solution_> phaseScope) { + /* + * Construction heuristics and similar phases only trigger best solution events at the end. + * This means that these phases only provide a meaningful result at their end. + * Unimproved time spent termination is not useful for these phases, + * as it would terminate the solver prematurely, + * skipping any useful phases that follow it, such as local search. + * We avoid that by never terminating during these phases, + * and resetting the counter to zero when the next phase starts. + */ + currentPhaseSendsBestSolutionEvents = phaseScope.phaseSendsBestSolutionEvents(); + phaseStartedTimeMillis = clock.millis(); + } + // ************************************************************************ // Terminated methods // ************************************************************************ @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } long bestSolutionTimeMillis = solverScope.getBestSolutionTimeMillis(); return isTerminated(bestSolutionTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { - long bestSolutionTimeMillis = phaseScope.getPhaseBestSolutionTimeMillis(); + if (!currentPhaseSendsBestSolutionEvents) {
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } return isTerminated(solverSafeTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } return isTerminated(phaseSafeTimeMillis); } - protected boolean isTerminated(long safeTimeMillis) { + private boolean isTerminated(long safeTimeMillis) { // It's possible that there is already an improving move in the forager // that will end up pushing the safeTimeMillis further // but that doesn't change the fact that the best score didn't improve enough in the specified time interval. // It just looks weird because it terminates even though the final step is a high enough score improvement. - long now = clock.millis(); + var now = clock.millis();
```suggestion if (!currentPhaseSendsBestSolutionEvents) { return false; } var now = clock.millis(); ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) {
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false;
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + }
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } return isTerminated(solverSafeTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { + if (!currentPhaseSendsBestSolutionEvents) {
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } return isTerminated(solverSafeTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false;
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -104,20 +110,26 @@ public void stepEnded(AbstractStepScope<Solution_> stepScope) { @Override public boolean isSolverTerminated(SolverScope<Solution_> solverScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + } return isTerminated(solverSafeTimeMillis); } @Override public boolean isPhaseTerminated(AbstractPhaseScope<Solution_> phaseScope) { + if (!currentPhaseSendsBestSolutionEvents) { + return false; + }
```suggestion ```
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -130,13 +120,124 @@ void scoreImprovesTooLate_terminates() { assertThat(termination.calculateSolverTimeGradient(solverScope)).isEqualTo(1.0, withPrecision(0.0)); // third step - score has improved beyond the threshold, but too late - when(clock.millis()).thenReturn(START_TIME_MILLIS + 1001L); - when(solverScope.getBestSolutionTimeMillis()).thenReturn(START_TIME_MILLIS + 1001L); - when(stepScope.getBestScoreImproved()).thenReturn(Boolean.TRUE); - when(solverScope.getBestScore()).thenReturn(SimpleScore.of(10)); + doReturn(START_TIME_MILLIS + 1001).when(clock).millis(); + doReturn(START_TIME_MILLIS + 1001).when(solverScope).getBestSolutionTimeMillis(); + doReturn(SimpleScore.of(10)).when(solverScope).getBestScore(); termination.stepEnded(stepScope); assertThat(termination.isPhaseTerminated(phaseScope)).isTrue(); assertThat(termination.isSolverTerminated(solverScope)).isTrue(); + + termination.phaseEnded(phaseScope); + termination.solvingEnded(solverScope); + } + + @Test + void withConstructionHeuristic() { // CH ignores unimproved time spent termination. + var solverScope = spy(new SolverScope<TestdataSolution>()); + var phaseScope = spy(new ConstructionHeuristicPhaseScope<>(solverScope)); + var stepScope = spy(new ConstructionHeuristicStepScope<>(phaseScope)); + var clock = mock(Clock.class); + + var termination = new UnimprovedTimeMillisSpentScoreDifferenceThresholdTermination<TestdataSolution>(1000L, + SimpleScore.of(7), clock); + + doReturn(START_TIME_MILLIS).when(clock).millis(); + doReturn(0L).when(phaseScope).getStartingSystemTimeMillis(); + doReturn(0L).when(solverScope).getBestSolutionTimeMillis(); + + termination.solvingStarted(solverScope); + termination.phaseStarted(phaseScope); + termination.stepEnded(stepScope); + + // time has not yet run out
Let's also check the condition the time runs out
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -130,13 +120,124 @@ void scoreImprovesTooLate_terminates() { assertThat(termination.calculateSolverTimeGradient(solverScope)).isEqualTo(1.0, withPrecision(0.0)); // third step - score has improved beyond the threshold, but too late - when(clock.millis()).thenReturn(START_TIME_MILLIS + 1001L); - when(solverScope.getBestSolutionTimeMillis()).thenReturn(START_TIME_MILLIS + 1001L); - when(stepScope.getBestScoreImproved()).thenReturn(Boolean.TRUE); - when(solverScope.getBestScore()).thenReturn(SimpleScore.of(10)); + doReturn(START_TIME_MILLIS + 1001).when(clock).millis(); + doReturn(START_TIME_MILLIS + 1001).when(solverScope).getBestSolutionTimeMillis(); + doReturn(SimpleScore.of(10)).when(solverScope).getBestScore(); termination.stepEnded(stepScope); assertThat(termination.isPhaseTerminated(phaseScope)).isTrue(); assertThat(termination.isSolverTerminated(solverScope)).isTrue(); + + termination.phaseEnded(phaseScope); + termination.solvingEnded(solverScope); + } + + @Test + void withConstructionHeuristic() { // CH ignores unimproved time spent termination. + var solverScope = spy(new SolverScope<TestdataSolution>()); + var phaseScope = spy(new ConstructionHeuristicPhaseScope<>(solverScope)); + var stepScope = spy(new ConstructionHeuristicStepScope<>(phaseScope)); + var clock = mock(Clock.class); + + var termination = new UnimprovedTimeMillisSpentScoreDifferenceThresholdTermination<TestdataSolution>(1000L, + SimpleScore.of(7), clock); + + doReturn(START_TIME_MILLIS).when(clock).millis(); + doReturn(0L).when(phaseScope).getStartingSystemTimeMillis(); + doReturn(0L).when(solverScope).getBestSolutionTimeMillis(); + + termination.solvingStarted(solverScope); + termination.phaseStarted(phaseScope); + termination.stepEnded(stepScope); + + // time has not yet run out + doReturn(START_TIME_MILLIS + 500).when(clock).millis(); + assertThat(termination.isPhaseTerminated(phaseScope)).isFalse(); + assertThat(termination.calculatePhaseTimeGradient(phaseScope)).isEqualTo(0.0, withPrecision(0.0)); + assertThat(termination.isSolverTerminated(solverScope)).isFalse(); + assertThat(termination.calculateSolverTimeGradient(solverScope)).isEqualTo(0.0, withPrecision(0.0)); + + termination.phaseEnded(phaseScope); + termination.solvingEnded(solverScope); + } + + @Test + void withConstructionHeuristicAndLocalSearch() { // CH ignores unimproved time spent termination. + var solverScope = spy(new SolverScope<TestdataSolution>()); + var phaseScope = spy(new ConstructionHeuristicPhaseScope<>(solverScope)); + var stepScope = spy(new ConstructionHeuristicStepScope<>(phaseScope)); + var clock = mock(Clock.class); + + var termination = new UnimprovedTimeMillisSpentScoreDifferenceThresholdTermination<TestdataSolution>(1000L, + SimpleScore.of(7), clock); + + doReturn(START_TIME_MILLIS).when(clock).millis(); + doReturn(0L).when(phaseScope).getStartingSystemTimeMillis(); + doReturn(0L).when(solverScope).getBestSolutionTimeMillis(); + + termination.solvingStarted(solverScope); + termination.phaseStarted(phaseScope); + termination.stepEnded(stepScope); + + // time has not yet run out
Same as above
timefold-solver
github_2023
java
755
TimefoldAI
zepfred
@@ -25,37 +28,107 @@ void forNegativeUnimprovedTimeMillis_exceptionIsThrown() { @Test void solverTermination() { - SolverScope<TestdataSolution> solverScope = mock(SolverScope.class); + SolverScope<TestdataSolution> solverScope = spy(new SolverScope<>()); + AbstractPhaseScope<TestdataSolution> phaseScope = new LocalSearchPhaseScope<>(solverScope); Clock clock = mock(Clock.class); Termination<TestdataSolution> termination = new UnimprovedTimeMillisSpentTermination<>(1000L, clock); + termination.solvingStarted(solverScope); + termination.phaseStarted(phaseScope); - when(clock.millis()).thenReturn(1000L); - when(solverScope.getBestSolutionTimeMillis()).thenReturn(500L); + doReturn(1000L).when(clock).millis(); + doReturn(500L).when(solverScope).getBestSolutionTimeMillis(); assertThat(termination.isSolverTerminated(solverScope)).isFalse(); assertThat(termination.calculateSolverTimeGradient(solverScope)).isEqualTo(0.5, withPrecision(0.0)); - when(clock.millis()).thenReturn(2000L); - when(solverScope.getBestSolutionTimeMillis()).thenReturn(1000L); + doReturn(2000L).when(clock).millis(); + doReturn(1000L).when(solverScope).getBestSolutionTimeMillis(); assertThat(termination.isSolverTerminated(solverScope)).isTrue(); assertThat(termination.calculateSolverTimeGradient(solverScope)).isEqualTo(1.0, withPrecision(0.0)); } @Test void phaseTermination() { - AbstractPhaseScope<TestdataSolution> phaseScope = mock(AbstractPhaseScope.class); + SolverScope<TestdataSolution> solverScope = new SolverScope<>(); + AbstractPhaseScope<TestdataSolution> phaseScope = spy(new LocalSearchPhaseScope<>(solverScope)); Clock clock = mock(Clock.class); Termination<TestdataSolution> termination = new UnimprovedTimeMillisSpentTermination<>(1000L, clock); + termination.solvingStarted(solverScope); + termination.phaseStarted(phaseScope); - when(clock.millis()).thenReturn(1000L); - when(phaseScope.getPhaseBestSolutionTimeMillis()).thenReturn(500L); + doReturn(1000L).when(clock).millis(); + doReturn(500L).when(phaseScope).getPhaseBestSolutionTimeMillis(); assertThat(termination.isPhaseTerminated(phaseScope)).isFalse(); assertThat(termination.calculatePhaseTimeGradient(phaseScope)).isEqualTo(0.5, withPrecision(0.0)); - when(clock.millis()).thenReturn(2000L); - when(phaseScope.getPhaseBestSolutionTimeMillis()).thenReturn(1000L); + doReturn(2000L).when(clock).millis(); + doReturn(1000L).when(phaseScope).getPhaseBestSolutionTimeMillis(); assertThat(termination.isPhaseTerminated(phaseScope)).isTrue(); assertThat(termination.calculatePhaseTimeGradient(phaseScope)).isEqualTo(1.0, withPrecision(0.0)); } + + @Test
Nice tests!
timefold-solver
github_2023
others
755
TimefoldAI
zepfred
@@ -459,6 +459,13 @@ Just like <<timeMillisSpentTermination,time spent termination>>, combinations ar It is preffered to configure this termination on a specific `Phase` (such as ``<localSearch>``) instead of on the `Solver` itself. +Several phases, such as construction heuristics, do not count towards this termination because +they only trigger new best solution events when they are done. +If such a phase is encountered, the termination is disabled and when the next phase is encountered,
```suggestion If such a phase is encountered, the termination is disabled and when the next phase is started, ```
timefold-solver
github_2023
java
714
TimefoldAI
triceo
@@ -173,7 +187,7 @@ public void writeToFile(Path parentFolder) { } public static final class Builder<X extends Number & Comparable<X>, Y extends Number & Comparable<Y>> { - + private static final int MAX_CHART_WIDTH = 1280;
Seems low, no? I'd increase it up to 4K width, which is 3840.
timefold-solver
github_2023
java
714
TimefoldAI
triceo
@@ -209,25 +223,35 @@ public LineChart<X, Y> build(String fileName, String title, String xLabel, Strin * This allows Chart.js to only draw the absolute minimum necessary points. */ data.values().forEach(map -> { - List<Map.Entry<X, Y>> entries = map.entrySet().stream().toList(); + List<Entry<X, Y>> entries = map.entrySet().stream().toList();
I'd really like us to start using `var` for these generic-heavy things. The declaration brings no additional context here. You already know it's a list (`toList()`) and you already know it is an entry (`entrySet()`).
timefold-solver
github_2023
java
714
TimefoldAI
triceo
@@ -209,25 +223,35 @@ public LineChart<X, Y> build(String fileName, String title, String xLabel, Strin * This allows Chart.js to only draw the absolute minimum necessary points. */ data.values().forEach(map -> { - List<Map.Entry<X, Y>> entries = map.entrySet().stream().toList(); + List<Entry<X, Y>> entries = map.entrySet().stream().toList(); if (entries.size() < 3) { return; } for (int i = 0; i < entries.size() - 2; i++) { - Map.Entry<X, Y> entry1 = entries.get(i); - Map.Entry<X, Y> entry2 = entries.get(i + 1); + Entry<X, Y> entry1 = entries.get(i); + Entry<X, Y> entry2 = entries.get(i + 1); if (!entry1.getValue().equals(entry2.getValue())) { continue; } - Map.Entry<X, Y> entry3 = entries.get(i + 2); + Entry<X, Y> entry3 = entries.get(i + 2); if (entry2.getValue().equals(entry3.getValue())) { map.remove(entry2.getKey()); } } }); - // Then find all points on the X axis across all data sets. + /* + * Sometimes, when the dataset size is large, it can cause the browser to freeze or use excessive memory + * while rendering the line chart. To solve the issue of a large volume of data points, we use the + * Largest-Triangle-Three-Buckets algorithm to down-sample the data. + */ + Map<String, Map<X, Y>> datasetMap = new LinkedHashMap<>(data.size()); + for (Entry<String, NavigableMap<X, Y>> entry : data.entrySet()) {
Another great place for `var`. Makes the code much more readable. In fact, I'd go as far as saying that we should make `var` the default, and use the full type if we have a reason to do that.
timefold-solver
github_2023
others
714
TimefoldAI
triceo
@@ -34,7 +31,7 @@ var ${chartId} = new Chart(document.getElementById('${chartId}'), { borderWidth: 1 </#if>, data: [ - <#list dataset.data() as datum><#if datum??>${datum?cn}</#if><#sep>, </#sep></#list> + <#list chart.points(dataset.label()) as datum>{x: ${datum.key()?cn}, y: ${datum.value()?cn}}<#sep>, </#sep></#list>
If I may recommend - don't touch the format of JS files. I spent days tweaking chart.js to avoid all of its bugs and quirks. Sometimes it required weird choices in data set format. Unless you want to manually check every single supported chart, including tooltips, scaling and different browsers, I recommend not touching the data format.
timefold-solver
github_2023
others
714
TimefoldAI
triceo
@@ -0,0 +1 @@ +18479.00/-529067.00,18751.00/-528929.00,19215.00/-528612.00,19303.00/-528321.00,19953.00/-527645.00,20260.00/-527138.00,20713.00/-525693.00,21012.00/-525142.00,21256.00/-524264.00,21775.00/-523486.00,22214.00/-523138.00,22572.00/-522136.00,23041.00/-521110.00,23762.00/-519091.00,24210.00/-518093.00,24754.00/-516018.00,25205.00/-515543.00,25601.00/-514578.00,26474.00/-513226.00,26596.00/-512842.00,27024.00/-512190.00,27471.00/-511174.00,28257.00/-509846.00,28463.00/-509148.00,28836.00/-508302.00,29931.00/-506311.00,30292.00/-504916.00,30884.00/-503892.00,31384.00/-501730.00,31711.00/-500864.00,32312.00/-499757.00,32816.00/-499159.00,33060.00/-498785.00,33635.00/-497005.00,34118.00/-495857.00,34510.00/-495355.00,35340.00/-494519.00,35737.00/-493897.00,36400.00/-492131.00,36627.00/-491628.00,37286.00/-490753.00,37396.00/-490137.00,38161.00/-489028.00,38398.00/-488387.00,38755.00/-488066.00,39182.00/-487081.00,39798.00/-486373.00,40630.00/-484773.00,40946.00/-484453.00,41129.00/-484094.00,41674.00/-483394.00,42317.00/-482023.00,42706.00/-481751.00,43187.00/-480634.00,43850.00/-479786.00,44166.00/-478833.00,44809.00/-477802.00,45026.00/-477081.00,45575.00/-476241.00,46291.00/-474560.00,46833.00/-473929.00,47206.00/-472984.00,47634.00/-472395.00,48172.00/-471258.00,48379.00/-470968.00,48878.00/-470049.00,49362.00/-469493.00,49854.00/-468667.00,50504.00/-468022.00,51042.00/-467043.00,51387.00/-466779.00,52120.00/-466075.00,52705.00/-464807.00,53540.00/-463413.00,53661.00/-463363.00,54621.00/-462317.00,54739.00/-462175.00,55243.00/-461196.00,55779.00/-460319.00,56033.00/-460142.00,56717.00/-459216.00,56894.00/-458685.00,57313.00/-458252.00,58021.00/-457263.00,58503.00/-456354.00,59268.00/-455356.00,59645.00/-454497.00,59870.00/-454334.00,60305.00/-453390.00,61354.00/-451914.00,61798.00/-450715.00,62016.00/-450599.00,62811.00/-449313.00,63047.00/-448714.00,63422.00/-448364.00,64042.00/-447494.00,64841.00/-446596.00,65284.00/-445887.00,65391.00/-445782.00,65861.00/-444577.00,66486.00/-444150.00,66805.00/-443729.00,67256.00/-442819.00,67856.00/-442295.00,68199.00/-441892.00,68984.00/-440546.00,69513.00/-439882.00,69758.00/-439370.00,70181.00/-438460.00,70665.00/-438122.00,70962.00/-437465.00,71704.00/-436483.00,71978.00/-436369.00,72653.00/-435970.00,73054.00/-434941.00,73707.00/-434363.00,74107.00/-433617.00,74421.00/-433334.00,75032.00/-432563.00,75450.00/-432175.00,75896.00/-431639.00,76663.00/-430735.00,77215.00/-430463.00,77464.00/-430109.00,77861.00/-429864.00,78399.00/-429116.00,79048.00/-428515.00,79499.00/-428350.00,80022.00/-427705.00,80645.00/-427351.00,81218.00/-426530.00,81922.00/-426073.00,82753.00/-425479.00,83261.00/-424643.00,83766.00/-424249.00,84166.00/-423658.00,84675.00/-423412.00,85307.00/-422554.00,85737.00/-422051.00,86314.00/-421707.00,86429.00/-421534.00,87213.00/-420578.00,87413.00/-420535.00,88154.00/-419606.00,88603.00/-419154.00,88998.00/-418447.00,89191.00/-418344.00,89884.00/-417559.00,90196.00/-416601.00,90798.00/-416069.00,91275.00/-415349.00,91649.00/-415102.00,91920.00/-414709.00,92450.00/-414297.00,92779.00/-414014.00,93091.00/-413365.00,93621.00/-413064.00,93999.00/-412361.00,94334.00/-412180.00,95044.00/-411246.00,95640.00/-410629.00,95867.00/-410566.00,96300.00/-410119.00,97334.00/-409705.00,97463.00/-409472.00,98286.00/-409156.00,98495.00/-409026.00,99130.00/-408214.00,99748.00/-407973.00,100126.00/-407349.00,100350.00/-407189.00,100827.00/-406636.00,101368.00/-406252.00,101861.00/-405664.00,102473.00/-405362.00,102792.00/-404839.00,103320.00/-404375.00,103645.00/-404236.00,104066.00/-403852.00,104545.00/-403598.00,105099.00/-403091.00,105425.00/-402442.00,105898.00/-402213.00,106773.00/-401400.00,107620.00/-400780.00,108091.00/-400546.00,108544.00/-400043.00,108736.00/-399981.00,109296.00/-399525.00,109870.00/-399252.00,110140.00/-398887.00,110461.00/-398754.00,111042.00/-398124.00,111399.00/-397211.00,111727.00/-396826.00,112230.00/-396517.00,112852.00/-396082.00,113163.00/-395609.00,113755.00/-395247.00,114179.00/-394596.00,114781.00/-394315.00,115251.00/-393862.00,115479.00/-393779.00,115747.00/-393462.00,116162.00/-393270.00,116894.00/-392796.00,117360.00/-392083.00,117627.00/-391950.00,118602.00/-390334.00,118843.00/-390202.00,119468.00/-389795.00,119810.00/-389229.00,120350.00/-388540.00,120844.00/-388178.00,121370.00/-387652.00,121886.00/-387260.00,122818.00/-386374.00,123283.00/-386163.00,123705.00/-385734.00,124068.00/-385176.00,124576.00/-384602.00,125017.00/-384494.00,125526.00/-384233.00,125932.00/-383940.00,126144.00/-383676.00,126453.00/-383547.00,127077.00/-383123.00,127405.00/-382777.00,128201.00/-382420.00,128776.00/-381800.00,129198.00/-381664.00,129470.00/-381576.00,130199.00/-381179.00,130639.00/-381121.00,130862.00/-380846.00,131200.00/-380591.00,131884.00/-380380.00,132098.00/-380279.00,132642.00/-379721.00,133303.00/-379298.00,133492.00/-378699.00,134016.00/-378553.00,134555.00/-377859.00,135231.00/-377500.00,135616.00/-377313.00,135856.00/-376399.00,136656.00/-375429.00,136855.00/-374830.00,137586.00/-374589.00,138066.00/-373761.00,138546.00/-373437.00,138753.00/-373306.00,139366.00/-372251.00,139727.00/-372139.00,140047.00/-371680.00,140601.00/-371214.00,140810.00/-371162.00,141457.00/-370446.00,141858.00/-370204.00,142307.00/-370086.00,142797.00/-369673.00,143175.00/-369212.00,144018.00/-368548.00,144495.00/-368433.00,145025.00/-368175.00,145242.00/-367817.00,146117.00/-367465.00,146304.00/-367296.00,146705.00/-367186.00,147303.00/-366702.00,147862.00/-366513.00,148189.00/-366185.00,149171.00/-365791.00,149532.00/-365403.00,150172.00/-365147.00,150382.00/-364898.00,150777.00/-364623.00,151558.00/-364337.00,151906.00/-363941.00,152247.00/-363358.00,152966.00/-362997.00,153406.00/-362546.00,154027.00/-362079.00,154624.00/-361188.00,155076.00/-361071.00,155641.00/-360694.00,155849.00/-360526.00,156256.00/-359966.00,156699.00/-359831.00,157438.00/-359546.00,157947.00/-359147.00,158449.00/-358717.00,158770.00/-358214.00,159287.00/-357911.00,159471.00/-357647.00,160118.00/-357359.00,160739.00/-356739.00,160952.00/-356612.00,161360.00/-356531.00,162337.00/-356017.00,162735.00/-355660.00,163111.00/-355556.00,163465.00/-355159.00,164036.00/-355022.00,164704.00/-354631.00,165475.00/-354292.00,165803.00/-353803.00,166532.00/-353411.00,166636.00/-353219.00,167190.00/-352920.00,167955.00/-352270.00,168200.00/-352207.00,169135.00/-351633.00,169654.00/-350846.00,169890.00/-350696.00,170352.00/-350248.00,170866.00/-349839.00,171165.00/-349768.00,171907.00/-349361.00,172036.00/-349105.00,172767.00/-348719.00,173135.00/-348325.00,173609.00/-347846.00,174333.00/-347627.00,174906.00/-347548.00,175546.00/-347233.00,175648.00/-346848.00,176080.00/-346516.00,176913.00/-346304.00,177253.00/-345996.00,177574.00/-345824.00,178418.00/-345579.00,178747.00/-345340.00,179306.00/-345225.00,179770.00/-344925.00,180281.00/-344463.00,180783.00/-344183.00,181025.00/-343791.00,181924.00/-343174.00,182444.00/-343131.00,182797.00/-342797.00,183392.00/-342538.00,183930.00/-342132.00,184247.00/-341941.00,184749.00/-341752.00,185567.00/-341279.00,185981.00/-341205.00,186242.00/-340813.00,186881.00/-340587.00,187188.00/-340426.00,187957.00/-339777.00,188064.00/-339328.00,188474.00/-338997.00,189331.00/-338336.00,189711.00/-338241.00,190120.00/-337795.00,190506.00/-337547.00,190953.00/-337228.00,191467.00/-337146.00,192143.00/-336897.00,192358.00/-336721.00,193108.00/-336401.00,193749.00/-336026.00,193948.00/-335805.00,194302.00/-335528.00,194702.00/-335337.00,195266.00/-334840.00,195653.00/-334752.00,196460.00/-334250.00,196646.00/-333902.00,197451.00/-333550.00,197662.00/-333350.00,198148.00/-333210.00,198883.00/-332408.00,199264.00/-332313.00,200010.00/-331794.00,200196.00/-331581.00,200591.00/-331391.00,200886.00/-331214.00,201547.00/-330493.00,201989.00/-330247.00,202432.00/-329623.00,202809.00/-329385.00,203373.00/-329276.00,203850.00/-328912.00,204057.00/-328859.00,204869.00/-328432.00,205111.00/-328178.00,205823.00/-327730.00,206037.00/-327310.00,206444.00/-326873.00,207195.00/-326190.00,207617.00/-326032.00,207735.00/-325872.00,208208.00/-325603.00,209146.00/-324851.00,209629.00/-324771.00,209946.00/-324211.00,210314.00/-324085.00,211095.00/-323707.00,211210.00/-323490.00,211966.00/-323163.00,212193.00/-322858.00,213068.00/-322371.00,213351.00/-322109.00,213739.00/-321648.00,214222.00/-321431.00,214652.00/-321134.00,214831.00/-320889.00,215403.00/-320700.00,215824.00/-320165.00,216037.00/-320051.00,216638.00/-319504.00,216957.00/-319386.00,217276.00/-319128.00,218084.00/-318836.00,218432.00/-318507.00,218945.00/-318229.00,219320.00/-317836.00,219834.00/-317523.00,220186.00/-317300.00,220785.00/-316746.00,221218.00/-316606.00,221678.00/-316353.00,221903.00/-316057.00,222425.00/-315810.00,222963.00/-315669.00,223558.00/-315419.00,223960.00/-315164.00,224332.00/-314490.00,224523.00/-314413.00,224899.00/-313979.00,225673.00/-313257.00,226075.00/-313167.00,226555.00/-312828.00,226871.00/-312765.00,227398.00/-312402.00,228115.00/-311894.00,228562.00/-311301.00,228908.00/-311189.00,229621.00/-310841.00,229749.00/-310799.00,230408.00/-310138.00,230847.00/-310005.00,231473.00/-309629.00,231778.00/-309336.00,232196.00/-309151.00,232576.00/-308885.00,233188.00/-308624.00,233395.00/-308376.00,233812.00/-308152.00,234461.00/-307539.00,235134.00/-307191.00,235808.00/-307047.00,236114.00/-306402.00,236744.00/-306184.00,237146.00/-305718.00,237415.00/-305551.00,237773.00/-305484.00,238320.00/-305166.00,238552.00/-304930.00,239356.00/-304532.00,239645.00/-304079.00,239953.00/-303963.00,240386.00/-303371.00,240703.00/-303280.00,241588.00/-302605.00,241801.00/-302364.00,242377.00/-301992.00,242715.00/-301654.00,243095.00/-301500.00,243591.00/-301071.00,244155.00/-300812.00,244588.00/-300736.00,245242.00/-300402.00,245771.00/-300267.00,246062.00/-300052.00,246279.00/-300011.00,247136.00/-299570.00,247350.00/-299320.00,247844.00/-299189.00,248440.00/-298709.00,248772.00/-298456.00,249483.00/-298105.00,249683.00/-297848.00,250070.00/-297640.00,250528.00/-297267.00,251161.00/-297027.00,251900.00/-296689.00,252003.00/-296488.00,252815.00/-295923.00,253217.00/-295525.00,253553.00/-295447.00,254117.00/-294968.00,254484.00/-294693.00,255072.00/-294450.00,255793.00/-293970.00,256264.00/-293783.00,256840.00/-293425.00,257159.00/-293379.00,257600.00/-293195.00,258227.00/-293017.00,258321.00/-292913.00,259208.00/-292661.00,259605.00/-292351.00,260262.00/-292112.00,260357.00/-292022.00,260861.00/-291860.00,261368.00/-291368.00,262120.00/-290942.00,262576.00/-290797.00,262780.00/-290662.00,263324.00/-290565.00,263827.00/-289690.00,264456.00/-289481.00,264839.00/-289272.00,265307.00/-288313.00,265509.00/-288256.00,265979.00/-287903.00,266561.00/-287538.00,267174.00/-287237.00,267382.00/-287054.00,267681.00/-286932.00,268432.00/-286284.00,268836.00/-286026.00,269167.00/-286005.00,269854.00/-285738.00,270147.00/-285507.00,270660.00/-285317.00,271107.00/-284910.00,271788.00/-284736.00,272247.00/-284624.00,272849.00/-284121.00,273118.00/-284088.00,273831.00/-283813.00,274060.00/-283519.00,274722.00/-283298.00,275300.00/-283155.00,275401.00/-283086.00,275826.00/-282888.00,276666.00/-282151.00,276866.00/-282061.00,277541.00/-281805.00,277836.00/-281496.00,278574.00/-281408.00,279107.00/-281096.00,279575.00/-280968.00,280002.00/-280761.00,280579.00/-280170.00,280792.00/-280104.00,281662.00/-279977.00,281870.00/-279911.00,282198.00/-279243.00,282912.00/-278873.00,283321.00/-278748.00,283620.00/-278620.00,284052.00/-278184.00,284659.00/-278063.00,284960.00/-277879.00,285776.00/-277670.00,286014.00/-277619.00,286754.00/-277157.00,287344.00/-276550.00,287623.00/-276480.00,287835.00/-276365.00,288636.00/-276192.00,289368.00/-275667.00,289490.00/-275582.00,290154.00/-275288.00,290627.00/-275093.00,291066.00/-274947.00,291871.00/-274773.00,292235.00/-274280.00,292717.00/-274191.00,293158.00/-273962.00,293760.00/-273808.00,294059.00/-273678.00,294269.00/-273502.00,295048.00/-273186.00,295532.00/-273113.00,296070.00/-272760.00,296496.00/-272620.00,296919.00/-272216.00,297408.00/-271849.00,297501.00/-271687.00,298055.00/-271526.00,298596.00/-271218.00,299251.00/-271067.00,299497.00/-270996.00,299842.00/-270721.00,300289.00/-270596.00,301113.00/-270154.00,301712.00/-269977.00,301891.00/-269787.00,302376.00/-269496.00,303164.00/-269233.00,303473.00/-268963.00,303880.00/-268893.00,304476.00/-268630.00,304589.00/-268426.00,305145.00/-268020.00,305507.00/-267879.00,306313.00/-267571.00,306550.00/-267312.00,306966.00/-267131.00,307721.00/-266914.00,307887.00/-266808.00,308670.00/-266453.00,308858.00/-266423.00,309439.00/-266237.00,310075.00/-266145.00,310431.00/-265907.00,311521.00/-265760.00,312159.00/-265560.00,312532.00/-264992.00,313217.00/-264589.00,313542.00/-264538.00,313810.00/-264441.00,314337.00/-264375.00,315287.00/-264132.00,315651.00/-263490.00,315862.00/-263455.00,316595.00/-263177.00,316801.00/-262853.00,317426.00/-262465.00,318101.00/-262262.00,318557.00/-261902.00,319142.00/-261718.00,319252.00/-261584.00,319763.00/-261388.00,320049.00/-261159.00,320746.00/-261091.00,321230.00/-260916.00,321523.00/-260747.00,321928.00/-260557.00,322321.00/-260549.00,323311.00/-260335.00,323410.00/-260236.00,324225.00/-259998.00,324563.00/-259707.00,325063.00/-259686.00,325676.00/-259476.00,326064.00/-259319.00,326251.00/-259150.00,326648.00/-259121.00,327609.00/-258900.00,328106.00/-258567.00,328366.00/-258297.00,328799.00/-258216.00,329184.00/-258002.00,329668.00/-257448.00,330022.00/-257229.00,331185.00/-256870.00,331356.00/-256599.00,332013.00/-256390.00,332479.00/-256016.00,332939.00/-255932.00,333482.00/-255612.00,333774.00/-255545.00,334122.00/-255372.00,334864.00/-255166.00,335442.00/-254938.00,335959.00/-254631.00,336324.00/-254496.00,336814.00/-254401.00,337279.00/-254221.00,337989.00/-254092.00,338662.00/-253877.00,338884.00/-253764.00,339678.00/-253424.00,339907.00/-253402.00,340320.00/-253315.00,340884.00/-253171.00,341118.00/-252971.00,342057.00/-252705.00,342594.00/-252398.00,342945.00/-252329.00,343207.00/-252098.00,344266.00/-251744.00,345033.00/-251729.00,345701.00/-251428.00,346570.00/-251313.00,347143.00/-251191.00,347497.00/-250941.00,348234.00/-250695.00,349187.00/-250484.00,349529.00/-250170.00,350260.00/-249992.00,350645.00/-249836.00,350843.00/-249750.00,351415.00/-249588.00,351812.00/-249548.00,352664.00/-249368.00,352844.00/-249258.00,353624.00/-249117.00,353739.00/-248713.00,354227.00/-248472.00,354530.00/-248341.00,355469.00/-247992.00,355827.00/-247885.00,357258.00/-247842.00,358088.00/-247507.00,358332.00/-247491.00,359353.00/-247220.00,359647.00/-246942.00,360026.00/-246861.00,360626.00/-246452.00,360872.00/-246410.00,361446.00/-246230.00,361985.00/-245974.00,362418.00/-245813.00,363215.00/-245682.00,363688.00/-245372.00,363893.00/-245293.00,364892.00/-245078.00,365314.00/-244863.00,365536.00/-244853.00,366148.00/-244662.00,366523.00/-244334.00,366958.00/-244193.00,367184.00/-243661.00,367677.00/-243394.00,368701.00/-243302.00,369142.00/-243177.00,369936.00/-243102.00,370203.00/-242873.00,370753.00/-242669.00,371298.00/-242553.00,372346.00/-242417.00,372819.00/-242248.00,373809.00/-242110.00,374413.00/-241944.00,374888.00/-241612.00,375141.00/-241572.00,375602.00/-241345.00,375878.00/-241337.00,376911.00/-241147.00,377438.00/-241040.00,377714.00/-240853.00,378361.00/-240787.00,379126.00/-240559.00,379356.00/-240347.00,379767.00/-240242.00,380309.00/-239866.00,380652.00/-239703.00,381860.00/-239611.00,382417.00/-239503.00,382761.00/-239251.00,383442.00/-238971.00,383526.00/-238938.00,384388.00/-238834.00,385277.00/-238335.00,385576.00/-238306.00,386175.00/-238126.00,386819.00/-237999.00,387334.00/-237865.00,387837.00/-237570.00,389815.00/-237507.00,390540.00/-237367.00,390907.00/-237225.00,391277.00/-237092.00,391925.00/-237052.00,392195.00/-236832.00,392754.00/-236551.00,393208.00/-236486.00,393713.00/-236238.00,394265.00/-236119.00,395241.00/-236027.00,395695.00/-235897.00,396115.00/-235616.00,396638.00/-235507.00,397184.00/-235373.00,397939.00/-235070.00,400707.00/-235004.00,400984.00/-234784.00,401709.00/-234538.00,402068.00/-234503.00,402633.00/-234394.00,402807.00/-234178.00,403805.00/-234025.00,404119.00/-233881.00,404529.00/-233749.00,404973.00/-233710.00,405455.00/-233531.00,406111.00/-233408.00,406327.00/-233240.00,407184.00/-233142.00,407636.00/-233001.00,408370.00/-232824.00,408482.00/-232735.00,410921.00/-232596.00,411513.00/-232326.00,412057.00/-232244.00,412611.00/-231964.00,413371.00/-231755.00,414126.00/-231680.00,414570.00/-231554.00,415244.00/-231452.00,415845.00/-231114.00,416315.00/-231013.00,417168.00/-230961.00,417374.00/-230824.00,418197.00/-230719.00,418980.00/-230548.00,419478.00/-230487.00,419739.00/-230460.00,420288.00/-230219.00,420785.00/-230105.00,421138.00/-229884.00,421765.00/-229834.00,422340.00/-229661.00,423068.00/-229548.00,423678.00/-229138.00,424546.00/-228978.00,424812.00/-228811.00,425678.00/-228676.00,426657.00/-228394.00,426997.00/-228381.00,427496.00/-228241.00,428327.00/-228091.00,428883.00/-228019.00,429442.00/-227878.00,430190.00/-227792.00,431141.00/-227487.00,431588.00/-227460.00,432359.00/-227353.00,432876.00/-227279.00,433806.00/-226894.00,434237.00/-226810.00,434473.00/-226771.00,435088.00/-226343.00,436048.00/-226283.00,436721.00/-225800.00,437505.00/-225744.00,438062.00/-225630.00,438410.00/-225598.00,439166.00/-225482.00,439624.00/-225350.00,440309.00/-225072.00,440790.00/-224894.00,441533.00/-224840.00,441748.00/-224805.00,442359.00/-224429.00,442636.00/-224355.00,443302.00/-224267.00,443716.00/-224161.00,444224.00/-224103.00,445057.00/-223955.00,445634.00/-223797.00,446009.00/-223764.00,446413.00/-223593.00,447463.00/-223391.00,447810.00/-223202.00,448926.00/-223101.00,449439.00/-222996.00,449752.00/-222910.00,450297.00/-222680.00,450902.00/-222548.00,451005.00/-222509.00,452280.00/-222422.00,452865.00/-222190.00,453704.00/-222129.00,454267.00/-221959.00,454728.00/-221704.00,455677.00/-221469.00,456727.00/-221280.00,457140.00/-220971.00,457330.00/-220874.00,457616.00/-220743.00,458603.00/-220625.00,458911.00/-220458.00,459679.00/-220365.00,460453.00/-220180.00,461016.00/-220168.00,461513.00/-220133.00,463467.00/-219795.00,474905.00/-219675.00,475584.00/-219348.00,477210.00/-219221.00,477741.00/-219010.00,478386.00/-218952.00,478996.00/-218851.00,479196.00/-218721.00,480145.00/-218456.00,480253.00/-218451.00,481050.00/-218254.00,481593.00/-218205.00,482006.00/-218084.00,482924.00/-218021.00,483338.00/-217920.00,483733.00/-217904.00,484458.00/-217792.00,484875.00/-217666.00,485859.00/-217578.00,486302.00/-217446.00,486966.00/-217354.00,487303.00/-217230.00,487952.00/-217148.00,488271.00/-216998.00,489043.00/-216808.00,489403.00/-216553.00,489683.00/-216474.00,490319.00/-216405.00,490935.00/-216277.00,491129.00/-216248.00,491707.00/-215890.00,491948.00/-215867.00,492670.00/-215738.00,493169.00/-215611.00,494383.00/-215387.00,495104.00/-215344.00,496726.00/-215183.00,497150.00/-215043.00,498056.00/-215006.00,499183.00/-214783.00,499551.00/-214627.00,500689.00/-214473.00,501236.00/-214322.00,503858.00/-214297.00,504710.00/-214023.00,505006.00/-213658.00,506105.00/-213617.00,507373.00/-213383.00,523662.00/-213348.00,525208.00/-213144.00,533551.00/-212972.00,534072.00/-212828.00,534855.00/-212740.00,535267.00/-212381.00,535588.00/-212298.00,536103.00/-211803.00,538223.00/-211751.00,538534.00/-211670.00,539005.00/-211621.00,539972.00/-211431.00,540410.00/-211420.00,541174.00/-211291.00,541280.00/-211249.00,543354.00/-211221.00,544516.00/-211061.00,544634.00/-210941.00,545358.00/-210869.00,546036.00/-210800.00,546465.00/-210721.00,546778.00/-210511.00,547511.00/-210426.00,548503.00/-210190.00,549106.00/-210181.00,549707.00/-210052.00,550889.00/-210018.00,551393.00/-209797.00,552508.00/-209571.00,554388.00/-209495.00,555151.00/-209353.00,555482.00/-209187.00,555811.00/-209148.00,556503.00/-208940.00,556915.00/-208860.00,557559.00/-208829.00,558528.00/-208707.00,559168.00/-208437.00,559896.00/-208346.00,560238.00/-208236.00,560629.00/-208211.00,561095.00/-208094.00,561874.00/-207884.00,563411.00/-207753.00,564366.00/-207629.00,582631.00/-207508.00,583460.00/-207315.00,583551.00/-207244.00,585067.00/-207070.00,585445.00/-206939.00,585966.00/-206857.00,586498.00/-206722.00,586713.00/-206566.00,587212.00/-206502.00,587604.00/-206390.00,588089.00/-206372.00,588761.00/-206177.00,589275.00/-206007.00,589562.00/-205787.00,590370.00/-205701.00,590702.00/-205628.00,591427.00/-205394.00,592241.00/-205316.00,592609.00/-205231.00,592913.00/-205013.00,593328.00/-204967.00,594455.00/-204701.00,594750.00/-204455.00,595252.00/-204304.00,600340.00/-204281.00,603925.00/-204073.00,604930.00/-203910.00,605546.00/-203696.00,607348.00/-203610.00,607800.00/-203498.00,608719.00/-203396.00,610881.00/-203372.00,611892.00/-203191.00,613566.00/-203147.00,614172.00/-202977.00,614692.00/-202918.00,615726.00/-202869.00,617021.00/-202739.00,617229.00/-202735.00,617623.00/-202500.00,618328.00/-202296.00,619032.00/-202205.00,619535.00/-202198.00,620272.00/-202161.00,620881.00/-201998.00,622447.00/-201952.00,623409.00/-201880.00,623773.00/-201735.00,625192.00/-201621.00,625663.00/-201456.00,628185.00/-201379.00,628800.00/-201309.00,631014.00/-201205.00,631647.00/-200942.00,633381.00/-200820.00,633954.00/-200744.00,634223.00/-200587.00,634865.00/-200423.00,635288.00/-200370.00,636883.00/-200346.00,637721.00/-200242.00,639047.00/-200218.00,639638.00/-200150.00,640214.00/-200035.00,640833.00/-199823.00,640922.00/-199756.00,652752.00/-199647.00,654106.00/-199546.00,655061.00/-199323.00,655453.00/-199292.00,655657.00/-199226.00,656948.00/-199091.00,658978.00/-199031.00,659199.00/-198949.00,659727.00/-198881.00,661058.00/-198534.00,672318.00/-198507.00,673285.00/-198405.00,673879.00/-198264.00,673986.00/-198194.00,677154.00/-198090.00,677456.00/-197906.00,678376.00/-197822.00,679262.00/-197483.00,681015.00/-197399.00,681971.00/-197114.00,682771.00/-196910.00,695927.00/-196833.00,696332.00/-196580.00,697155.00/-196532.00,697835.00/-196391.00,698440.00/-196099.00,698911.00/-196078.00,699126.00/-196005.00,699764.00/-195897.00,700697.00/-195800.00,700800.00/-195743.00,703029.00/-195689.00,704183.00/-195502.00,705870.00/-195440.00,706587.00/-195353.00,707354.00/-195101.00,707749.00/-195078.00,708446.00/-194978.00,708965.00/-194853.00,709901.00/-194845.00,710369.00/-194749.00,711341.00/-194669.00,713507.00/-194607.00,713624.00/-194523.00,715264.00/-194457.00,716624.00/-194284.00,716848.00/-194213.00,717757.00/-194075.00,718426.00/-193873.00,718896.00/-193811.00,719826.00/-193723.00,721908.00/-193655.00,722635.00/-193424.00,723060.00/-193226.00,855156.00/-193174.00,856631.00/-193077.00,856988.00/-193026.00,857639.00/-192836.00,858740.00/-192743.00,860103.00/-192678.00,860419.00/-192541.00,861069.00/-192417.00,861376.00/-192260.00,861910.00/-192223.00,862652.00/-191968.00,864565.00/-191868.00,865513.00/-191725.00,947471.00/-191706.00,948118.00/-191603.00,952189.00/-191415.00,952818.00/-191219.00,958368.00/-191186.00,958572.00/-191065.00,958908.00/-191012.00,959481.00/-190752.00,960045.00/-190709.00,960390.00/-190574.00,961009.00/-190372.00,961434.00/-190338.00,961775.00/-190113.00,962630.00/-189884.00,966422.00/-189821.00,967290.00/-189763.00,967766.00/-189563.00,968096.00/-189539.00,968542.00/-189438.00,972485.00/-189350.00,973441.00/-189321.00,974288.00/-189054.00,977880.00/-188973.00,978828.00/-188730.00,980541.00/-188671.00,981003.00/-188576.00,981788.00/-188451.00,984893.00/-188396.00,985664.00/-188271.00,986406.00/-188254.00,987228.00/-188002.00,988197.00/-187911.00,988741.00/-187767.00,989252.00/-187553.00,989343.00/-187498.00,989847.00/-187452.00,990225.00/-187339.00,991163.00/-187249.00,991494.00/-187153.00,992505.00/-187095.00,992713.00/-187080.00,993061.00/-186920.00,994476.00/-186765.00,994906.00/-186760.00,995481.00/-186513.00,996561.00/-186459.00,997387.00/-186322.00,998911.00/-186238.00,999342.00/-186164.00,1000197.00/-186075.00,1014551.00/-186051.00,1015368.00/-185786.00,1016573.00/-185700.00,1017752.00/-185431.00,1018119.00/-185368.00,1020555.00/-185276.00,1021059.00/-185199.00,1021924.00/-185178.00,1022704.00/-185099.00,1023452.00/-184918.00,1023766.00/-184791.00,1025521.00/-184675.00,1026062.00/-184517.00,1027215.00/-184424.00,1028463.00/-184310.00,1029122.00/-184242.00,1095809.00/-184209.00,1097494.00/-184047.00,1097893.00/-184011.00,1100470.00/-183950.00,1100836.00/-183858.00,1102317.00/-183776.00,1102995.00/-183634.00,1104455.00/-183593.00,1104663.00/-183537.00,1105256.00/-183488.00,1105822.00/-183312.00,1106472.00/-183248.00,1107239.00/-183057.00,1164959.00/-183005.00,1165585.00/-182686.00,1168667.00/-182580.00,1209749.00/-182403.00,1210404.00/-182193.00,1210630.00/-182105.00,1213936.00/-182034.00,1214493.00/-181889.00,1215534.00/-181775.00,1216248.00/-181532.00,1216447.00/-181383.00,1221144.00/-181340.00,1221897.00/-181104.00,1222589.00/-181013.00,1225922.00/-180953.00,1226369.00/-180889.00,1227384.00/-180612.00,1227700.00/-180534.00,1272221.00/-180499.00,1273385.00/-180368.00,1854419.00/-180270.00,1855112.00/-180138.00,1855497.00/-179917.00,1856308.00/-179734.00,1858102.00/-179716.00,1858741.00/-179660.00,1859651.00/-179414.00,1859734.00/-179409.00,1860364.00/-179322.00,1862928.00/-179288.00,1863888.00/-179155.00,1864927.00/-179077.00,1865504.00/-178962.00,1866850.00/-178800.00,1875767.00/-178732.00,1876119.00/-178549.00,1876500.00/-178364.00,1876859.00/-178326.00,1877477.00/-178107.00,1878371.00/-178016.00,1880603.00/-177909.00,1881055.00/-177839.00,1981547.00/-177752.00,1982084.00/-177685.00,1983260.00/-177538.00,1983719.00/-177368.00,1984698.00/-177307.00,1985432.00/-177240.00,1985684.00/-177176.00,1985932.00/-177097.00,1986561.00/-177075.00,1987304.00/-176939.00,1989111.00/-176869.00,1990041.00/-176703.00,1990258.00/-176613.00,1991035.00/-176487.00,1992117.00/-176389.00,2523485.00/-176360.00,2597077.00/-176217.00,2597595.00/-176096.00,2600931.00/-176005.00,2601430.00/-175817.00,2604282.00/-175755.00,2604596.00/-175664.00,2604935.00/-175576.00,2605731.00/-175450.00,2606843.00/-175412.00,2607241.00/-175379.00,2607902.00/-175290.00,2610423.00/-175145.00,2868654.00/-174996.00,2868848.00/-174878.00,2869944.00/-174636.00,2871747.00/-174568.00,2872171.00/-174510.00,2873069.00/-174246.00,2873352.00/-174097.00,2874196.00/-174067.00,2875034.00/-174014.00,2875714.00/-173917.00,2876790.00/-173857.00,2878191.00/-173748.00,2878412.00/-173669.00,2883184.00/-173600.00,2885176.00/-173568.00,2885601.00/-173501.00,2886618.00/-173390.00,2887661.00/-173351.00,2888256.00/-173279.00,2889078.00/-173135.00,2889566.00/-172886.00,2889891.00/-172796.00,2890498.00/-172623.00,2896148.00/-172536.00,2896411.00/-172515.00,2896817.00/-172423.00,2897498.00/-172287.00,2897693.00/-172191.00,3589914.00/-172070.00,3600000.00/-172046.00,
Ideally this file would have the same format as the input files. And all those input files would be called not `.txt`, but `.csv`, because that is what they are - comma-separated values.
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,18 +198,112 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("changeMoveSelector")) + .withDestinationSelectorConfig(new DestinationSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("changeMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new ListSwapMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("swapMoveSelector")) + .withSecondaryValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("swapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new KOptListMoveSelectorConfig()
I'm asking myself... if we're adding this move, why only for nearby? Does it make sense to add it for both?
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,18 +198,112 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("changeMoveSelector")) + .withDestinationSelectorConfig(new DestinationSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("changeMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new ListSwapMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("swapMoveSelector")) + .withSecondaryValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("swapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new KOptListMoveSelectorConfig() + .withOriginSelectorConfig(new ValueSelectorConfig() + .withId("koptMoveSelector")) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("koptMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } } else if (listVariableDescriptor == null) { // We only have basic variables. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + } else { + if (hasChainedVariable) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), + new SwapMoveSelectorConfig(), + new ChangeMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig().withId("changeMoveSelector")) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("changeMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new SwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId("swapMoveSelector")) + .withSecondaryEntitySelectorConfig(new EntitySelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("swapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new TailChainSwapMoveSelectorConfig()
Same question here.
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,18 +198,112 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("changeMoveSelector")) + .withDestinationSelectorConfig(new DestinationSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("changeMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new ListSwapMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("swapMoveSelector")) + .withSecondaryValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("swapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new KOptListMoveSelectorConfig() + .withOriginSelectorConfig(new ValueSelectorConfig() + .withId("koptMoveSelector")) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef("koptMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } } else if (listVariableDescriptor == null) { // We only have basic variables. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + } else { + if (hasChainedVariable) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), + new SwapMoveSelectorConfig(), + new ChangeMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig().withId("changeMoveSelector")) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("changeMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new SwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId("swapMoveSelector")) + .withSecondaryEntitySelectorConfig(new EntitySelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("swapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new TailChainSwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId("tailChainSwapMoveSelector")) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("tailChainSwapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), + new SwapMoveSelectorConfig(), + new ChangeMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig().withId("changeMoveSelector")) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("changeMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new SwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId("swapMoveSelector")) + .withSecondaryEntitySelectorConfig(new EntitySelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef("swapMoveSelector")) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } + } } else { /* * We have a mix of basic and list variables. * The "old" move selector configs handle this situation correctly but they complain of it being deprecated. * + * Combining essential variables with list variables in a single entity is not supported. Therefore,
How can this even happen? List and basic vars are mutually incompatible - so shouldn't this `else` branch fail fast instead? Or is there a place where this actually works?
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,18 +198,112 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId("changeMoveSelector"))
I'm thinking... I don't remember the specific behavior, but aren't these supposed to be unique? Maybe we want to generate the selector names with some randomness? `changeMoveSelector-f4edab` or something like that.
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,21 +199,137 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig(), + new KOptListMoveSelectorConfig()); + } else { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String swapSelectorName = "swapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String koptSelectorName = "koptMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId(changeSelectorName)) + .withDestinationSelectorConfig(new DestinationSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(changeSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new ListSwapMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId(swapSelectorName)) + .withSecondaryValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(swapSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new KOptListMoveSelectorConfig() + .withOriginSelectorConfig(new ValueSelectorConfig() + .withId(koptSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(koptSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } } else if (listVariableDescriptor == null) { // We only have basic variables. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + if (hasChainedVariable) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig(), + new TailChainSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + } + } else { + if (hasChainedVariable) { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String swapSelectorName = "swapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String tailChainSelectorName = + "tailChainSwapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), + new SwapMoveSelectorConfig(), + new ChangeMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig().withId(changeSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(changeSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new SwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId(swapSelectorName)) + .withSecondaryEntitySelectorConfig(new EntitySelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(swapSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new TailChainSwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId(tailChainSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(tailChainSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } else { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String swapSelectorName = "swapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), + new SwapMoveSelectorConfig(), + new ChangeMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig().withId(changeSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(changeSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new SwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId(swapSelectorName)) + .withSecondaryEntitySelectorConfig(new EntitySelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(swapSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } + } } else { /* * We have a mix of basic and list variables. * The "old" move selector configs handle this situation correctly but they complain of it being deprecated. * + * Combining essential variables with list variables in a single entity is not supported. Therefore, + * default selectors do not support enabling Nearby Selection with multiple entities. + * * TODO Improve so that list variables get list variable selectors directly. * TODO PLANNER-2755 Support coexistence of basic and list variables on the same entity. */ + if (configPolicy.getNearbyDistanceMeterClass() != null) { + throw new IllegalArgumentException( + "The configuration contains basic and list variables that are incompatible with using the nearbyDistanceMeterClass (%s)."
```suggestion """ The configuration contains both basic and list variables, which makes it incompatible with using a top-level nearbyDistanceMeterClass (%s). Specify move selectors manually or remove the top-level nearbyDistanceMeterClass from your solver config.""" ```
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,21 +199,137 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig(), + new KOptListMoveSelectorConfig()); + } else { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String swapSelectorName = "swapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String koptSelectorName = "koptMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId(changeSelectorName)) + .withDestinationSelectorConfig(new DestinationSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(changeSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new ListSwapMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId(swapSelectorName)) + .withSecondaryValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(swapSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new KOptListMoveSelectorConfig() + .withOriginSelectorConfig(new ValueSelectorConfig() + .withId(koptSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(koptSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } } else if (listVariableDescriptor == null) { // We only have basic variables. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + if (hasChainedVariable) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig(), + new TailChainSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + } + } else { + if (hasChainedVariable) { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String swapSelectorName = "swapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String tailChainSelectorName = + "tailChainSwapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), + new SwapMoveSelectorConfig(), + new ChangeMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig().withId(changeSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(changeSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new SwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId(swapSelectorName)) + .withSecondaryEntitySelectorConfig(new EntitySelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(swapSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new TailChainSwapMoveSelectorConfig() + .withEntitySelectorConfig(new EntitySelectorConfig() + .withId(tailChainSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginEntitySelectorConfig(new EntitySelectorConfig() + .withMimicSelectorRef(tailChainSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } else { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8));
I recommend turning the code for randomness into its own method - it is repeated far too often. Something like `addRandomSuffix(...)`. Also, any chance we could make this randomness deterministic, sharing a pre-determined random seed across all the invocations?
timefold-solver
github_2023
java
673
TimefoldAI
triceo
@@ -191,21 +199,137 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf .filter(variableDescriptor -> !variableDescriptor.isListVariable()) .distinct() .toList(); + var hasChainedVariable = basicVariableDescriptorList.stream() + .filter(v -> v instanceof BasicVariableDescriptor<Solution_>) + .anyMatch(v -> ((BasicVariableDescriptor<?>) v).isChained()); var listVariableDescriptor = solutionDescriptor.getListVariableDescriptor(); if (basicVariableDescriptorList.isEmpty()) { // We only have the one list variable. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig(), + new KOptListMoveSelectorConfig()); + } else { + String changeSelectorName = "changeMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String swapSelectorName = "swapMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + String koptSelectorName = "koptMoveSelector-%s".formatted(UUID.randomUUID().toString().substring(0, 8)); + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ListChangeMoveSelectorConfig(), + new ListSwapMoveSelectorConfig(), + new ListChangeMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId(changeSelectorName)) + .withDestinationSelectorConfig(new DestinationSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(changeSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new ListSwapMoveSelectorConfig() + .withValueSelectorConfig(new ValueSelectorConfig() + .withId(swapSelectorName)) + .withSecondaryValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(swapSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass()))), + new KOptListMoveSelectorConfig() + .withOriginSelectorConfig(new ValueSelectorConfig() + .withId(koptSelectorName)) + .withValueSelectorConfig(new ValueSelectorConfig() + .withNearbySelectionConfig(new NearbySelectionConfig() + .withOriginValueSelectorConfig(new ValueSelectorConfig() + .withMimicSelectorRef(koptSelectorName)) + .withNearbyDistanceMeterClass( + configPolicy.getNearbyDistanceMeterClass())))); + } } else if (listVariableDescriptor == null) { // We only have basic variables. - return new UnionMoveSelectorConfig() - .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + if (configPolicy.getNearbyDistanceMeterClass() == null) { + if (hasChainedVariable) { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig(), + new TailChainSwapMoveSelectorConfig()); + } else { + return new UnionMoveSelectorConfig() + .withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig()); + } + } else {
The method is getting crazy long. I suggest we split it into parts - perhaps each of these inner-most branches gets its own method?
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties.
Good idea. One thing that's not entirely obvious to me is the `<solverName>` part. You explain it in another section, and that is fine. But do you ever mention that this is optional? That `<solverName>` can be exluded if you only ever inject one thing? I think this needs to be described in more detail, to give more clarity.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional.
What do you mean "optional"? If the property is not specified, but the file `solverConfig.xml` is still found, will it be used? And if the file is not found/not used, where do the defaults come frome? (I'm not saying we should _change_ existing behavior, but we should _describe_ it.)
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional. + +{property_prefix}timefold.solver.<solverName>.environment-mode:: +Enable runtime assertions to detect common bugs in your implementation during development.
Could use a link to the chapter discussing those.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML.
Add a link to a chapter on solver configuration.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional. + +{property_prefix}timefold.solver.<solverName>.environment-mode:: +Enable runtime assertions to detect common bugs in your implementation during development. + +{property_prefix}timefold.solver.<solverName>.daemon:: +Enable xref:responding-to-change/responding-to-change.adoc#daemon[daemon mode]. +In daemon mode, non-early termination pauses the solver instead of stopping it, until the next problem fact change arrives. +This is often useful for xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-time planning]. +Defaults to `false`. + +{property_prefix}timefold.solver.<solverName>.move-thread-count:: +Enable multi-threaded solving for a single problem, which increases CPU consumption. +Defaults to `NONE`. +Note that this is a feature of the xref:enterprise-edition/enterprise-edition.adoc[Enterprise edition], +which is Timefold's commercial offering. +See xref:enterprise-edition/enterprise-edition.adoc#multithreadedIncrementalSolving[multithreaded incremental solving]. + +{property_prefix}timefold.solver.<solverName>.domain-access-type:: +How Timefold Solver should access the domain model. +See xref:using-timefold-solver/configuration.adoc#domainAccess[the domain access section] for more details. +ifeval::["{property_prefix}" == "quarkus."] +Defaults to `GIZMO`. +The other possible value is `REFLECTION`. +endif::[] +ifeval::["{property_prefix}" == ""] +Defaults to `REFLECTION`. +The other possible value is `GIZMO`.
Since this is for Spring Boot, I recommend adding a note on Gizmo limitations outside of Quarkus. If we have this in the docs already, a link will be enough. Otherwise we really should explain how GIZMO - for some minor performance benefits - requires you to open your domain model, making fields public.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional. + +{property_prefix}timefold.solver.<solverName>.environment-mode:: +Enable runtime assertions to detect common bugs in your implementation during development. + +{property_prefix}timefold.solver.<solverName>.daemon:: +Enable xref:responding-to-change/responding-to-change.adoc#daemon[daemon mode]. +In daemon mode, non-early termination pauses the solver instead of stopping it, until the next problem fact change arrives. +This is often useful for xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-time planning]. +Defaults to `false`. + +{property_prefix}timefold.solver.<solverName>.move-thread-count:: +Enable multi-threaded solving for a single problem, which increases CPU consumption. +Defaults to `NONE`. +Note that this is a feature of the xref:enterprise-edition/enterprise-edition.adoc[Enterprise edition], +which is Timefold's commercial offering. +See xref:enterprise-edition/enterprise-edition.adoc#multithreadedIncrementalSolving[multithreaded incremental solving]. + +{property_prefix}timefold.solver.<solverName>.domain-access-type:: +How Timefold Solver should access the domain model. +See xref:using-timefold-solver/configuration.adoc#domainAccess[the domain access section] for more details. +ifeval::["{property_prefix}" == "quarkus."] +Defaults to `GIZMO`. +The other possible value is `REFLECTION`. +endif::[] +ifeval::["{property_prefix}" == ""] +Defaults to `REFLECTION`. +The other possible value is `GIZMO`. +endif::[] + +{property_prefix}timefold.solver.<solverName>.termination.spent-limit:: +How long the solver can run. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day.
I am not entirely sure, but don't we support the ISO duration format [1] here? If so, we might as well provide a link. [1] https://www.digi.com/resources/documentation/digidocs/90001488-13/reference/r_iso_8601_duration_format.htm
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional. + +{property_prefix}timefold.solver.<solverName>.environment-mode:: +Enable runtime assertions to detect common bugs in your implementation during development. + +{property_prefix}timefold.solver.<solverName>.daemon:: +Enable xref:responding-to-change/responding-to-change.adoc#daemon[daemon mode]. +In daemon mode, non-early termination pauses the solver instead of stopping it, until the next problem fact change arrives. +This is often useful for xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-time planning]. +Defaults to `false`. + +{property_prefix}timefold.solver.<solverName>.move-thread-count:: +Enable multi-threaded solving for a single problem, which increases CPU consumption. +Defaults to `NONE`. +Note that this is a feature of the xref:enterprise-edition/enterprise-edition.adoc[Enterprise edition], +which is Timefold's commercial offering. +See xref:enterprise-edition/enterprise-edition.adoc#multithreadedIncrementalSolving[multithreaded incremental solving]. + +{property_prefix}timefold.solver.<solverName>.domain-access-type:: +How Timefold Solver should access the domain model. +See xref:using-timefold-solver/configuration.adoc#domainAccess[the domain access section] for more details. +ifeval::["{property_prefix}" == "quarkus."] +Defaults to `GIZMO`. +The other possible value is `REFLECTION`. +endif::[] +ifeval::["{property_prefix}" == ""] +Defaults to `REFLECTION`. +The other possible value is `GIZMO`. +endif::[] + +{property_prefix}timefold.solver.<solverName>.termination.spent-limit:: +How long the solver can run. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day. + +{property_prefix}timefold.solver.<solverName>.termination.unimproved-spent-limit:: +How long the solver can run without finding a new best solution after finding a new best solution. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day.
Dtto.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional. + +{property_prefix}timefold.solver.<solverName>.environment-mode:: +Enable runtime assertions to detect common bugs in your implementation during development. + +{property_prefix}timefold.solver.<solverName>.daemon:: +Enable xref:responding-to-change/responding-to-change.adoc#daemon[daemon mode]. +In daemon mode, non-early termination pauses the solver instead of stopping it, until the next problem fact change arrives. +This is often useful for xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-time planning]. +Defaults to `false`. + +{property_prefix}timefold.solver.<solverName>.move-thread-count:: +Enable multi-threaded solving for a single problem, which increases CPU consumption. +Defaults to `NONE`. +Note that this is a feature of the xref:enterprise-edition/enterprise-edition.adoc[Enterprise edition], +which is Timefold's commercial offering. +See xref:enterprise-edition/enterprise-edition.adoc#multithreadedIncrementalSolving[multithreaded incremental solving]. + +{property_prefix}timefold.solver.<solverName>.domain-access-type:: +How Timefold Solver should access the domain model. +See xref:using-timefold-solver/configuration.adoc#domainAccess[the domain access section] for more details. +ifeval::["{property_prefix}" == "quarkus."] +Defaults to `GIZMO`. +The other possible value is `REFLECTION`. +endif::[] +ifeval::["{property_prefix}" == ""] +Defaults to `REFLECTION`. +The other possible value is `GIZMO`. +endif::[] + +{property_prefix}timefold.solver.<solverName>.termination.spent-limit:: +How long the solver can run. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day. + +{property_prefix}timefold.solver.<solverName>.termination.unimproved-spent-limit:: +How long the solver can run without finding a new best solution after finding a new best solution. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day. + +{property_prefix}timefold.solver.<solverName>.termination.best-score-limit:: +Terminates the solver when a specific or higher score has been reached.
I'd say "when a specific score (or better) has been reached".
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,52 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml:: +A classpath resource to read the solver configuration XML. +Defaults to `solverConfig.xml`. +If this property isn't specified, that file is optional. + +{property_prefix}timefold.solver.<solverName>.environment-mode:: +Enable runtime assertions to detect common bugs in your implementation during development. + +{property_prefix}timefold.solver.<solverName>.daemon:: +Enable xref:responding-to-change/responding-to-change.adoc#daemon[daemon mode]. +In daemon mode, non-early termination pauses the solver instead of stopping it, until the next problem fact change arrives. +This is often useful for xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-time planning]. +Defaults to `false`. + +{property_prefix}timefold.solver.<solverName>.move-thread-count:: +Enable multi-threaded solving for a single problem, which increases CPU consumption. +Defaults to `NONE`. +Note that this is a feature of the xref:enterprise-edition/enterprise-edition.adoc[Enterprise edition], +which is Timefold's commercial offering. +See xref:enterprise-edition/enterprise-edition.adoc#multithreadedIncrementalSolving[multithreaded incremental solving]. + +{property_prefix}timefold.solver.<solverName>.domain-access-type:: +How Timefold Solver should access the domain model. +See xref:using-timefold-solver/configuration.adoc#domainAccess[the domain access section] for more details. +ifeval::["{property_prefix}" == "quarkus."] +Defaults to `GIZMO`. +The other possible value is `REFLECTION`. +endif::[] +ifeval::["{property_prefix}" == ""] +Defaults to `REFLECTION`. +The other possible value is `GIZMO`. +endif::[] + +{property_prefix}timefold.solver.<solverName>.termination.spent-limit:: +How long the solver can run. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day. + +{property_prefix}timefold.solver.<solverName>.termination.unimproved-spent-limit:: +How long the solver can run without finding a new best solution after finding a new best solution. +For example: `30s` is 30 seconds. `5m` is 5 minutes. `2h` is 2 hours. `1d` is 1 day. + +{property_prefix}timefold.solver.<solverName>.termination.best-score-limit:: +Terminates the solver when a specific or higher score has been reached. +For example: `0hard/-1000soft` terminates when the best score changes from `0hard/-1200soft` to `0hard/-900soft`. +Wildcards are supported to replace numbers.
Is this true? Wow, I didn't know. Cool.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources
I'd call this "injecting managed resources".
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (spent-limit, domain-access-type, etc) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`.
Don't we have a list of score types elsewhere in the docs? If so, I'd just reference that. No point in duplicating content.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (spent-limit, domain-access-type, etc) for the
```suggestion (solution, entities, and constraint classes) and customized properties (`spent-limit`, `domain-access-type` etc.) for the ```
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (spent-limit, domain-access-type, etc) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + @Inject + var solverConfig:SolverConfig? + + @Inject + var solverFactory:SolverFactory<Timetable>? + + @Inject + var solverManager:SolverManager<Timetable, String>? + + @Inject + var simpleSolutionManager:SolutionManager<Timetable, SimpleScore>? // <1> + + @Inject + var simpleScoreManager:ScoreManager<Timetable, SimpleScore>? // <1> + + @Inject + var constraintVerifier:ConstraintVerifier<TimetableConstraintProvider, Timetable>? = null + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +==== + +Timefold provides all the necessary resources for problem-solving and analysis. However, it is still possible to manually create and override the default managed resources. To create a custom `SolverManager`, use the `SolverFactory` resource. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +package org.acme.employeescheduling.rest; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Default; +import jakarta.ws.rs.Produces; + +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.SolverManagerConfig; + +import org.acme.employeescheduling.domain.EmployeeSchedule; + +@ApplicationScoped +public class BeanProducer { + + @Produces + @Default + public SolverManager<Timetable, String> overrideSolverManager(SolverFactory<Timetable> solverFactory) { + SolverManagerConfig solverManagerConfig = new SolverManagerConfig(); + return SolverManager.create(solverFactory, solverManagerConfig); + } +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +package org.acme.employeescheduling.rest + +import ai.timefold.solver.core.api.solver.SolverFactory +import ai.timefold.solver.core.api.solver.SolverManager +import ai.timefold.solver.core.config.solver.SolverManagerConfig +import jakarta.enterprise.context.ApplicationScoped +import jakarta.enterprise.inject.Default +import jakarta.ws.rs.Produces +import org.acme.kotlin.schooltimetabling.domain.Timetable + +@ApplicationScoped +class BeanProducer { + + @Produces + @Default + fun overrideSolverManager(solverFactory: SolverFactory<Timetable>?): SolverManager<Timetable, String> { + val solverManagerConfig = SolverManagerConfig() + return SolverManager.create(solverFactory, solverManagerConfig) + } +} +---- +-- +==== + +[NOTE] +==== +Consider using xref:#integrationWithQuarkusMultiStage[Multi-stage planning] for multiple solver configurations instead of manually creating resources. +==== + +[#integrationWithQuarkusMultiStage] +=== Multi-stage planning
I am not entirely sure why we're selling this as multi-stage planning. This feature can be used for other uses as well. It is a generic feature. Personally, I'd remove references to multi-stage, turn it into a generic chapter on injecting multiple instances of `SolverManager`, and maybe mention in a note that this feature could be used for multi-stage planning.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (spent-limit, domain-access-type, etc) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + @Inject + var solverConfig:SolverConfig? + + @Inject + var solverFactory:SolverFactory<Timetable>? + + @Inject + var solverManager:SolverManager<Timetable, String>? + + @Inject + var simpleSolutionManager:SolutionManager<Timetable, SimpleScore>? // <1> + + @Inject + var simpleScoreManager:ScoreManager<Timetable, SimpleScore>? // <1> + + @Inject + var constraintVerifier:ConstraintVerifier<TimetableConstraintProvider, Timetable>? = null + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +==== + +Timefold provides all the necessary resources for problem-solving and analysis. However, it is still possible to manually create and override the default managed resources. To create a custom `SolverManager`, use the `SolverFactory` resource. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +package org.acme.employeescheduling.rest; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Default; +import jakarta.ws.rs.Produces; + +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.SolverManagerConfig; + +import org.acme.employeescheduling.domain.EmployeeSchedule; + +@ApplicationScoped +public class BeanProducer { + + @Produces + @Default + public SolverManager<Timetable, String> overrideSolverManager(SolverFactory<Timetable> solverFactory) { + SolverManagerConfig solverManagerConfig = new SolverManagerConfig(); + return SolverManager.create(solverFactory, solverManagerConfig); + } +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +package org.acme.employeescheduling.rest + +import ai.timefold.solver.core.api.solver.SolverFactory +import ai.timefold.solver.core.api.solver.SolverManager +import ai.timefold.solver.core.config.solver.SolverManagerConfig +import jakarta.enterprise.context.ApplicationScoped +import jakarta.enterprise.inject.Default +import jakarta.ws.rs.Produces +import org.acme.kotlin.schooltimetabling.domain.Timetable + +@ApplicationScoped +class BeanProducer { + + @Produces + @Default + fun overrideSolverManager(solverFactory: SolverFactory<Timetable>?): SolverManager<Timetable, String> { + val solverManagerConfig = SolverManagerConfig() + return SolverManager.create(solverFactory, solverManagerConfig) + } +} +---- +-- +==== + +[NOTE] +==== +Consider using xref:#integrationWithQuarkusMultiStage[Multi-stage planning] for multiple solver configurations instead of manually creating resources. +==== + +[#integrationWithQuarkusMultiStage] +=== Multi-stage planning + +Quarkus multi-stage planning allows for defining different solver settings or even wholly distinct planning problems in the same +application. Timefold identifies each setting and provides a specific managed resource, `SolverManager`. + +==== Solver configuration properties + +Following properties are supported per each solver: + +:property_prefix: quarkus. +include::config-solver-properties.adoc[] + +==== Working with multiple Solvers + +The different solver settings are configured in the `application.properties` file. For example, two different time +settings for spent-limit are defined as follows:
```suggestion The different solver settings are configured in the `application.properties` file. For example, two different time settings for `spent-limit` are defined as follows: ```
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties
```suggestion === Available configuration properties ``` This is the Timefold documentation. No need to repeat the name over and over; and even if that were necessary, it'd be `Timefold Solver`, not `Timefold`.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (spent-limit, domain-access-type, etc) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + @Inject + var solverConfig:SolverConfig? + + @Inject + var solverFactory:SolverFactory<Timetable>? + + @Inject + var solverManager:SolverManager<Timetable, String>? + + @Inject + var simpleSolutionManager:SolutionManager<Timetable, SimpleScore>? // <1> + + @Inject + var simpleScoreManager:ScoreManager<Timetable, SimpleScore>? // <1> + + @Inject + var constraintVerifier:ConstraintVerifier<TimetableConstraintProvider, Timetable>? = null + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +==== + +Timefold provides all the necessary resources for problem-solving and analysis. However, it is still possible to manually create and override the default managed resources. To create a custom `SolverManager`, use the `SolverFactory` resource. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +package org.acme.employeescheduling.rest; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Default; +import jakarta.ws.rs.Produces; + +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.SolverManagerConfig; + +import org.acme.employeescheduling.domain.EmployeeSchedule; + +@ApplicationScoped +public class BeanProducer { + + @Produces + @Default + public SolverManager<Timetable, String> overrideSolverManager(SolverFactory<Timetable> solverFactory) { + SolverManagerConfig solverManagerConfig = new SolverManagerConfig(); + return SolverManager.create(solverFactory, solverManagerConfig); + } +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +package org.acme.employeescheduling.rest + +import ai.timefold.solver.core.api.solver.SolverFactory +import ai.timefold.solver.core.api.solver.SolverManager +import ai.timefold.solver.core.config.solver.SolverManagerConfig +import jakarta.enterprise.context.ApplicationScoped +import jakarta.enterprise.inject.Default +import jakarta.ws.rs.Produces +import org.acme.kotlin.schooltimetabling.domain.Timetable + +@ApplicationScoped +class BeanProducer { + + @Produces + @Default + fun overrideSolverManager(solverFactory: SolverFactory<Timetable>?): SolverManager<Timetable, String> { + val solverManagerConfig = SolverManagerConfig() + return SolverManager.create(solverFactory, solverManagerConfig) + } +} +---- +-- +==== + +[NOTE] +==== +Consider using xref:#integrationWithQuarkusMultiStage[Multi-stage planning] for multiple solver configurations instead of manually creating resources. +==== + +[#integrationWithQuarkusMultiStage] +=== Multi-stage planning + +Quarkus multi-stage planning allows for defining different solver settings or even wholly distinct planning problems in the same +application. Timefold identifies each setting and provides a specific managed resource, `SolverManager`. + +==== Solver configuration properties + +Following properties are supported per each solver: + +:property_prefix: quarkus. +include::config-solver-properties.adoc[] + +==== Working with multiple Solvers + +The different solver settings are configured in the `application.properties` file. For example, two different time +settings for spent-limit are defined as follows: + +[source,properties] +---- +# The solver "fastSolver" runs only for 5 seconds, and "regularSolver" runs for 10s +quarkus.timefold.solver."fastSolver".termination.spent-limit=5s // <1> +quarkus.timefold.solver."regularSolver".termination.spent-limit=10s // <2> +---- +<1> Define a solver config named *fastSolver*. +<2> Define a solver config named *regularSolver*. + +To inject a specific `SolverManager`, use the `@Named` annotation along with the solver configuration name, e.g., fastSolver. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Named("fastSolver") + SolverManager<...> fastSolver; + + @Named("regularSolver") + SolverManager<...> regularSolver; + + ... +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + private final var fastSolver: SolverManager<...>? + private final var regularSolver: SolverManager<...>? + + @Inject + constructor( + @Named("fastSolver") fastSolver: SolverManager<Timetable, String>, + @Named("regularSolver") fastSolver: SolverManager<Timetable, String> + ) { + this.fastSolver = fastSolver + this.regularSolver = regularSolver + } + + ... +} +---- +-- +==== + +[NOTE] +==== +When implementing multi-stage planning, it's important to note that only the `SolverManager` resource can be injected.
This is what I mean with the multi-stage planning. It's irrelevant to this comment - no matter if you use multi-stage or not, when injecting multiple `@Named` instances, you can only use the `SolverManager`.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,743 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +=== Timefold configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Auto-managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (spent-limit, domain-access-type, etc) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + @Inject + var solverConfig:SolverConfig? + + @Inject + var solverFactory:SolverFactory<Timetable>? + + @Inject + var solverManager:SolverManager<Timetable, String>? + + @Inject + var simpleSolutionManager:SolutionManager<Timetable, SimpleScore>? // <1> + + @Inject + var simpleScoreManager:ScoreManager<Timetable, SimpleScore>? // <1> + + @Inject + var constraintVerifier:ConstraintVerifier<TimetableConstraintProvider, Timetable>? = null + + ... +} +---- +<1> The following score types are available: `SimpleScore`, `SimpleLongScore`, `SimpleBigDecimalScore`, `HardSoftScore`, `HardSoftLongScore`, `HardSoftBigDecimalScore`, `HardMediumSoftScore`, `HardMediumSoftLongScore`, `HardMediumSoftBigDecimalScore`, `BendableScore`, `BendableLongScore`, and `BendableBigDecimalScore`. +-- +==== + +Timefold provides all the necessary resources for problem-solving and analysis. However, it is still possible to manually create and override the default managed resources. To create a custom `SolverManager`, use the `SolverFactory` resource. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +package org.acme.employeescheduling.rest; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Default; +import jakarta.ws.rs.Produces; + +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.SolverManagerConfig; + +import org.acme.employeescheduling.domain.EmployeeSchedule; + +@ApplicationScoped +public class BeanProducer { + + @Produces + @Default + public SolverManager<Timetable, String> overrideSolverManager(SolverFactory<Timetable> solverFactory) { + SolverManagerConfig solverManagerConfig = new SolverManagerConfig(); + return SolverManager.create(solverFactory, solverManagerConfig); + } +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +package org.acme.employeescheduling.rest + +import ai.timefold.solver.core.api.solver.SolverFactory +import ai.timefold.solver.core.api.solver.SolverManager +import ai.timefold.solver.core.config.solver.SolverManagerConfig +import jakarta.enterprise.context.ApplicationScoped +import jakarta.enterprise.inject.Default +import jakarta.ws.rs.Produces +import org.acme.kotlin.schooltimetabling.domain.Timetable + +@ApplicationScoped +class BeanProducer { + + @Produces + @Default + fun overrideSolverManager(solverFactory: SolverFactory<Timetable>?): SolverManager<Timetable, String> { + val solverManagerConfig = SolverManagerConfig() + return SolverManager.create(solverFactory, solverManagerConfig) + } +} +---- +-- +==== + +[NOTE] +==== +Consider using xref:#integrationWithQuarkusMultiStage[Multi-stage planning] for multiple solver configurations instead of manually creating resources. +==== + +[#integrationWithQuarkusMultiStage] +=== Multi-stage planning + +Quarkus multi-stage planning allows for defining different solver settings or even wholly distinct planning problems in the same +application. Timefold identifies each setting and provides a specific managed resource, `SolverManager`. + +==== Solver configuration properties + +Following properties are supported per each solver: + +:property_prefix: quarkus. +include::config-solver-properties.adoc[] + +==== Working with multiple Solvers + +The different solver settings are configured in the `application.properties` file. For example, two different time +settings for spent-limit are defined as follows: + +[source,properties] +---- +# The solver "fastSolver" runs only for 5 seconds, and "regularSolver" runs for 10s +quarkus.timefold.solver."fastSolver".termination.spent-limit=5s // <1> +quarkus.timefold.solver."regularSolver".termination.spent-limit=10s // <2> +---- +<1> Define a solver config named *fastSolver*. +<2> Define a solver config named *regularSolver*. + +To inject a specific `SolverManager`, use the `@Named` annotation along with the solver configuration name, e.g., fastSolver. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Named("fastSolver") + SolverManager<...> fastSolver; + + @Named("regularSolver") + SolverManager<...> regularSolver; + + ... +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + private final var fastSolver: SolverManager<...>? + private final var regularSolver: SolverManager<...>? + + @Inject + constructor( + @Named("fastSolver") fastSolver: SolverManager<Timetable, String>, + @Named("regularSolver") fastSolver: SolverManager<Timetable, String> + ) { + this.fastSolver = fastSolver + this.regularSolver = regularSolver + } + + ... +} +---- +-- +==== + +[NOTE] +==== +When implementing multi-stage planning, it's important to note that only the `SolverManager` resource can be injected. +==== + +For a more advanced example, let's imagine two different steps for optimizing the school timetabling problem: + +1. Initially, a specific group of teachers is designated to teach the available lessons. +2. The next step involves assigning lessons to the rooms.
I think you brought in the multi-stage planning because you needed a good use case for this feature. However, I think the example you ended up with may cause more confusion. I don't think we should be telling people to have two constraint providers, one for every part of a problem. (Even though a minority of users will probably need that.) Instead, I'd simply mention that you can provide two different solver configs to solve two different problems, and not complicate it any further.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,708 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +[#integrationWithQuarkusProperties] +=== Available configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Injecting managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (`spent-limit`, `domain-access-type`, etc.) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> You can find all the available score types in the xref:constraints-and-score/overview.adoc#scoreType[Constraints and Score] page. +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + @Inject + var solverConfig:SolverConfig? + + @Inject + var solverFactory:SolverFactory<Timetable>? + + @Inject + var solverManager:SolverManager<Timetable, String>? + + @Inject + var simpleSolutionManager:SolutionManager<Timetable, SimpleScore>? // <1> + + @Inject + var simpleScoreManager:ScoreManager<Timetable, SimpleScore>? // <1> + + @Inject + var constraintVerifier:ConstraintVerifier<TimetableConstraintProvider, Timetable>? = null + + ... +} +---- +<1> You can find all the available score types in the xref:constraints-and-score/overview.adoc#scoreType[Constraints and Score] page. +-- +==== + +Timefold provides all the necessary resources for problem-solving and analysis. However, it is still possible to manually create and override the default managed resources. To create a custom `SolverManager`, use the `SolverFactory` resource. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +package org.acme.employeescheduling.rest; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Default; +import jakarta.ws.rs.Produces; + +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.SolverManagerConfig; + +import org.acme.employeescheduling.domain.EmployeeSchedule; + +@ApplicationScoped +public class BeanProducer { + + @Produces + @Default + public SolverManager<Timetable, String> overrideSolverManager(SolverFactory<Timetable> solverFactory) { + SolverManagerConfig solverManagerConfig = new SolverManagerConfig(); + return SolverManager.create(solverFactory, solverManagerConfig); + } +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +package org.acme.employeescheduling.rest + +import ai.timefold.solver.core.api.solver.SolverFactory +import ai.timefold.solver.core.api.solver.SolverManager +import ai.timefold.solver.core.config.solver.SolverManagerConfig +import jakarta.enterprise.context.ApplicationScoped +import jakarta.enterprise.inject.Default +import jakarta.ws.rs.Produces +import org.acme.kotlin.schooltimetabling.domain.Timetable + +@ApplicationScoped +class BeanProducer { + + @Produces + @Default + fun overrideSolverManager(solverFactory: SolverFactory<Timetable>?): SolverManager<Timetable, String> { + val solverManagerConfig = SolverManagerConfig() + return SolverManager.create(solverFactory, solverManagerConfig) + } +} +---- +-- +==== + +[NOTE] +==== +Consider using xref:#integrationWithQuarkusMultiStage[multiple solver configurations] instead of manually creating resources. +==== + +[#integrationWithQuarkusMultiStage]
Please change the ref to match the title.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -0,0 +1,61 @@ +//// +Quarkus and Spring Boot support the same configuration properties. +All the properties are in this file, which can then be included multiple times. +The {property_prefix} attribute is used for Quarkus properties. +//// + +{property_prefix}timefold.solver.<solverName>.solver-config-xml::
I'm thinking... this is content duplication with the `config-properties.adoc` file. Can we somehow define a property (just like we do `property_prefix`) which will only inject `<solverName>.` when necessary by the context? That way, we'll be able to use the same file for all three places where it's used.
timefold-solver
github_2023
others
596
TimefoldAI
triceo
@@ -271,22 +271,708 @@ To use Timefold Solver with Quarkus, read the xref:quickstart/quarkus/quarkus-qu If you are starting a new project, visit the https://code.quarkus.io/[code.quarkus.io] and select the _Timefold AI constraint solver_ extension before generating your application. +[#integrationWithQuarkusProperties] +=== Available configuration properties + Following properties are supported in the Quarkus `application.properties`: :property_prefix: quarkus. include::config-properties.adoc[] +[#integrationWithQuarkusManagedResources] +=== Injecting managed resources + +The Quarkus integration allows the injection of several managed resources, including `SolverConfig`, `SolverFactory`, +`SolverManager`, `SolutionManager`, `ScoreManager`, and `ConstraintVerifier`. + +The `SolverConfig` resource is constructed by reading the `application.properties` file and classpath. Therefore, Domain entities +(solution, entities, and constraint classes) and customized properties (`spent-limit`, `domain-access-type`, etc.) for the +planning problem are identified and loaded into the solver configuration. + +The available resouses can be injected as follows: + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Inject + SolverConfig solverConfig; + + @Inject + SolverFactory<Timetable> solverFactory; + + @Inject + SolverManager<Timetable, String> solverManager; + + @Inject + SolutionManager<Timetable, SimpleScore> simpleSolutionManager; // <1> + + @Inject + ScoreManager<Timetable, SimpleScore> simpleScoreManager; // <1> + + @Inject + ConstraintVerifier<TimetableConstraintProvider, Timetable> constraintVerifier; + + ... +} +---- +<1> You can find all the available score types in the xref:constraints-and-score/overview.adoc#scoreType[Constraints and Score] page. +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + @Inject + var solverConfig:SolverConfig? + + @Inject + var solverFactory:SolverFactory<Timetable>? + + @Inject + var solverManager:SolverManager<Timetable, String>? + + @Inject + var simpleSolutionManager:SolutionManager<Timetable, SimpleScore>? // <1> + + @Inject + var simpleScoreManager:ScoreManager<Timetable, SimpleScore>? // <1> + + @Inject + var constraintVerifier:ConstraintVerifier<TimetableConstraintProvider, Timetable>? = null + + ... +} +---- +<1> You can find all the available score types in the xref:constraints-and-score/overview.adoc#scoreType[Constraints and Score] page. +-- +==== + +Timefold provides all the necessary resources for problem-solving and analysis. However, it is still possible to manually create and override the default managed resources. To create a custom `SolverManager`, use the `SolverFactory` resource. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +package org.acme.employeescheduling.rest; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Default; +import jakarta.ws.rs.Produces; + +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.SolverManagerConfig; + +import org.acme.employeescheduling.domain.EmployeeSchedule; + +@ApplicationScoped +public class BeanProducer { + + @Produces + @Default + public SolverManager<Timetable, String> overrideSolverManager(SolverFactory<Timetable> solverFactory) { + SolverManagerConfig solverManagerConfig = new SolverManagerConfig(); + return SolverManager.create(solverFactory, solverManagerConfig); + } +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +package org.acme.employeescheduling.rest + +import ai.timefold.solver.core.api.solver.SolverFactory +import ai.timefold.solver.core.api.solver.SolverManager +import ai.timefold.solver.core.config.solver.SolverManagerConfig +import jakarta.enterprise.context.ApplicationScoped +import jakarta.enterprise.inject.Default +import jakarta.ws.rs.Produces +import org.acme.kotlin.schooltimetabling.domain.Timetable + +@ApplicationScoped +class BeanProducer { + + @Produces + @Default + fun overrideSolverManager(solverFactory: SolverFactory<Timetable>?): SolverManager<Timetable, String> { + val solverManagerConfig = SolverManagerConfig() + return SolverManager.create(solverFactory, solverManagerConfig) + } +} +---- +-- +==== + +[NOTE] +==== +Consider using xref:#integrationWithQuarkusMultiStage[multiple solver configurations] instead of manually creating resources. +==== + +[#integrationWithQuarkusMultiStage] +=== Injecting multiple instances of `SolverManager` + +Quarkus extension allows for defining different solver settings or even wholly distinct planning problems in the same +application. Timefold identifies each setting and provides a specific managed resource, `SolverManager`. + +==== Solver configuration properties + +The configuration properties for multiple solvers are defined using the namespace `quarkus.timefold.solver.<solverName>`, +where `<solverName>` is the name of the related solver. The `<solverName>` property is only necessary when using multiple +solvers. For defining a single solver, refer to the xref:#integrationWithQuarkusProperties[Timefold configuration properties section]. +Following properties are supported: + +:property_prefix: quarkus. +include::config-solver-properties.adoc[] + +==== Working with multiple Solvers + +The different solver settings are configured in the `application.properties` file. For example, two different time +settings for `spent-limit` are defined as follows: + +[source,properties] +---- +# The solver "fastSolver" runs only for 5 seconds, and "regularSolver" runs for 10s +quarkus.timefold.solver."fastSolver".termination.spent-limit=5s // <1> +quarkus.timefold.solver."regularSolver".termination.spent-limit=10s // <2> +---- +<1> Define a solver config named *fastSolver*. +<2> Define a solver config named *regularSolver*. + +To inject a specific `SolverManager`, use the `@Named` annotation along with the solver configuration name, e.g., fastSolver. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@Path("/path") +public class Resource { + + @Named("fastSolver") + SolverManager<...> fastSolver; + + @Named("regularSolver") + SolverManager<...> regularSolver; + + ... +} +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- +@Path("path") +class Resource { + + private final var fastSolver: SolverManager<...>? + private final var regularSolver: SolverManager<...>? + + @Inject + constructor( + @Named("fastSolver") fastSolver: SolverManager<Timetable, String>, + @Named("regularSolver") fastSolver: SolverManager<Timetable, String> + ) { + this.fastSolver = fastSolver + this.regularSolver = regularSolver + } + + ... +} +---- +-- +==== + +For a more advanced example, let's imagine two different steps for optimizing the school timetabling problem: + +1. Initially, a specific group of teachers is designated to teach the available lessons. +2. The next step involves assigning lessons to the rooms. + +To configure two different problems, add two XML files containing related planning configurations. + +[tabs] +==== +teachersSolverConfig.xml:: ++ +[source,xml,options="nowrap"] +---- +<solver xmlns="https://timefold.ai/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://timefold.ai/xsd/solver https://timefold.ai/xsd/solver/solver.xsd"> + <solutionClass>org.acme.schooltimetabling.domain.TeacherToLessonSchedule</solutionClass> + <entityClass>org.acme.schooltimetabling.domain.Teacher</entityClass> +</solver> +---- +roomsSolverConfig.xml:: ++ +[source,xml,options="nowrap"] +---- +<solver xmlns="https://timefold.ai/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://timefold.ai/xsd/solver https://timefold.ai/xsd/solver/solver.xsd"> + <solutionClass>org.acme.schooltimetabling.domain.Timetable</solutionClass> + <entityClass>org.acme.schooltimetabling.domain.Lesson</entityClass> +</solver> +---- +==== + +Set the solvers with the specific XML files in the `application.properties` file: + +[source,properties] +---- +quarkus.timefold.solver."teacherSolver".solver-config-xml=teachersSolverConfig.xml // <1> +quarkus.timefold.solver."roomSolver".solver-config-xml=roomsSolverConfig.xml // <2> +---- +<1> Define a solver config named *teacherSolver*. +<2> Define a solver config named *roomSolver*. + +Now let's inject both solvers. + +[tabs] +==== +Java:: ++ +-- +[source,java] +---- +@PlanningSolution +public class TeacherToLessonSchedule { + ... +} + +@PlanningEntity +public class Teacher { + ... +} + +@Path("/path") +public class Resource { + + @Named("teacherSolver") + SolverManager<TeacherToLessonSchedule, String> teacherToLessonScheduleSolverManager; + + @Named("roomSolver") + SolverManager<Timetable, String> lessonToRoomTimeslotSolverManager; + + ... +} + + +---- +-- +Kotlin:: ++ +-- +[source,kotlin] +---- + +@PlanningSolution +class TeacherToLessonSchedule { + ... +} + +@PlanningEntity +class Teacher { + ... +} + +@Path("path") +class Resource { + + private final var teacherToLessonScheduleSolverManager: SolverManager<TeacherToLessonSchedule, String>? + private final var lessonToRoomTimeslotSolverManager: SolverManager<Timetable, String>? + + @Inject + constructor( + @Named("teacherSolver") teacherToLessonScheduleSolverManager: SolverManager<TeacherToLessonSchedule, String>, + @Named("roomSolver") lessonToRoomTimeslotSolverManager: SolverManager<Timetable, String> + ) { + this.teacherToLessonScheduleSolverManager = teacherToLessonScheduleSolverManager + this.lessonToRoomTimeslotSolverManager = lessonToRoomTimeslotSolverManager + } + + ... +} +---- +-- +==== + +It is worth noting that **multi-stage** planning can be accomplished by using a separate solver configuration for each optimization stage.
```suggestion Multi-stage planning can also be accomplished by using a separate solver configuration for each optimization stage. ```
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -0,0 +1,312 @@ +package ai.timefold.solver.quarkus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.Duration; + +import jakarta.inject.Inject; +import jakarta.inject.Named; + +import ai.timefold.solver.core.api.domain.common.DomainAccessType; +import ai.timefold.solver.core.api.score.ScoreManager; +import ai.timefold.solver.core.api.score.buildin.bendable.BendableScore; +import ai.timefold.solver.core.api.score.buildin.bendablebigdecimal.BendableBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.bendablelong.BendableLongScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoftbigdecimal.HardMediumSoftBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScore; +import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore; +import ai.timefold.solver.core.api.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.hardsoftlong.HardSoftLongScore; +import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore; +import ai.timefold.solver.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.simplelong.SimpleLongScore; +import ai.timefold.solver.core.api.solver.SolutionManager; +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.EnvironmentMode; +import ai.timefold.solver.core.config.solver.SolverConfig; +import ai.timefold.solver.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider; +import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusEntity; +import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusSolution; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +class TimefoldProcessorMultipleSolverPropertiesTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".environment-mode", "FULL_ASSERT") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".daemon", "true") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".domain-access-type", "REFLECTION") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".termination.spent-limit", "4h") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".termination.unimproved-spent-limit", "5h") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".termination.best-score-limit", "0") + .overrideConfigKey("quarkus.timefold.solver.\"solver2\".daemon", "false") + .overrideConfigKey("quarkus.timefold.solver.\"solver2\".domain-access-type", "REFLECTION") + .overrideConfigKey("quarkus.timefold.solver.\"solver2\".termination.spent-limit", "1h") + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClasses(TestdataQuarkusEntity.class, TestdataQuarkusSolution.class, + TestdataQuarkusConstraintProvider.class)); + + @Inject + @Named("solver1Config") + SolverConfig solverConfig; + @Inject + @Named("solver1Factory") + SolverFactory<TestdataQuarkusSolution> solver1Factory; + @Inject + @Named("solver1Manager") + SolverManager<TestdataQuarkusSolution, String> solver1Manager; + + // ScoreManager per score type + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, SimpleScore> simpleScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, SimpleLongScore> simpleLongScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, SimpleBigDecimalScore> simpleBigDecimalScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, HardSoftScore> hardSoftScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, HardSoftLongScore> hardSoftLongScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, HardSoftBigDecimalScore> hardSoftBigDecimalScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, HardMediumSoftScore> hardMediumSoftScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, HardMediumSoftLongScore> hardMediumSoftLongScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, HardMediumSoftBigDecimalScore> hardMediumSoftBigDecimalScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, BendableScore> bendableScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, BendableLongScore> bendableLongScoreManager1; + @Inject + @Named("solver1ScoreManager") + ScoreManager<TestdataQuarkusSolution, BendableBigDecimalScore> bendableBigDecimalScoreManager1;
`ScoreManager` is deprecated. We need not and should not support it in this new feature. Also, aren't we missing the `SolverManager` here?
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -0,0 +1,312 @@ +package ai.timefold.solver.quarkus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.Duration; + +import jakarta.inject.Inject; +import jakarta.inject.Named; + +import ai.timefold.solver.core.api.domain.common.DomainAccessType; +import ai.timefold.solver.core.api.score.ScoreManager; +import ai.timefold.solver.core.api.score.buildin.bendable.BendableScore; +import ai.timefold.solver.core.api.score.buildin.bendablebigdecimal.BendableBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.bendablelong.BendableLongScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoftbigdecimal.HardMediumSoftBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScore; +import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore; +import ai.timefold.solver.core.api.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.hardsoftlong.HardSoftLongScore; +import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore; +import ai.timefold.solver.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.simplelong.SimpleLongScore; +import ai.timefold.solver.core.api.solver.SolutionManager; +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.EnvironmentMode; +import ai.timefold.solver.core.config.solver.SolverConfig; +import ai.timefold.solver.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider; +import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusEntity; +import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusSolution; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +class TimefoldProcessorMultipleSolverPropertiesTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".environment-mode", "FULL_ASSERT") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".daemon", "true") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".domain-access-type", "REFLECTION") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".termination.spent-limit", "4h") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".termination.unimproved-spent-limit", "5h") + .overrideConfigKey("quarkus.timefold.solver.\"solver1\".termination.best-score-limit", "0") + .overrideConfigKey("quarkus.timefold.solver.\"solver2\".daemon", "false") + .overrideConfigKey("quarkus.timefold.solver.\"solver2\".domain-access-type", "REFLECTION") + .overrideConfigKey("quarkus.timefold.solver.\"solver2\".termination.spent-limit", "1h") + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addClasses(TestdataQuarkusEntity.class, TestdataQuarkusSolution.class, + TestdataQuarkusConstraintProvider.class)); + + @Inject + @Named("solver1Config")
Are the `Config`/`Factory`/`Manager` suffixes necessary? They are boilerplate; we need to find a way for this to work with simple names and no such restrictive rules.
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -66,11 +63,35 @@ void registerAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBe } else { benchmarkConfig = null; } - syntheticBeans.produce(SyntheticBeanBuildItem.configure(PlannerBenchmarkConfig.class) - .supplier(recorder.benchmarkConfigSupplier(benchmarkConfig)) - .done()); additionalBeans.produce(new AdditionalBeanBuildItem(TimefoldBenchmarkBeanProvider.class)); unremovableBeans.produce(UnremovableBeanBuildItem.beanTypes(TimefoldBenchmarkRuntimeConfig.class)); unremovableBeans.produce(UnremovableBeanBuildItem.beanTypes(SolverConfig.class)); + return new BenchmarkConfigBuildItem(benchmarkConfig); + } + + /** + * The build step executes at runtime to fetch an updated instance of properties from + * {@link ai.timefold.solver.quarkus.config.TimefoldRuntimeConfig}. + * <p> + * The reason we need to register the managed beans at runtime is because {@code Arc.container().instance()} does + * not return an instance of {@link ai.timefold.solver.quarkus.config.TimefoldRuntimeConfig} when using interfaces + * instead of classes. Defining configuration properties as interfaces is the only way to use {@code @WithUnnamedKey}. + * This is the default approach documented in both Quarkus and Smallrye pages. + * <p> + * Finally, recording the bean at runtime is necessary to use updated instances of configuration properties, and + * annotating {@link ai.timefold.solver.quarkus.config.TimefoldRuntimeConfig} with {@code @StaticInitSafe} has no effect. + */
This seems like a defensive comment. You're justifying why you did it like this, as if someone was going to say you've done it wrong. In my opinion, after this code is merged, this comment no longer has any value. We should remove it.
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -18,37 +17,40 @@ * See also {@link SolverRuntimeConfig} */ @ConfigGroup -public class SolverBuildTimeConfig { +public interface SolverBuildTimeConfig {
Have you made sure none of the pre-existing behavior have changed? (In other words: is this 100 % backwards compatible?) Have you ensured that for the single instance, the config is still properly overriden when using the config XML as well as these properties? Have you ensured the same with the benchmark config?
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -1,24 +1,39 @@ package ai.timefold.solver.quarkus.config; +import java.util.Map; +import java.util.Optional; + import ai.timefold.solver.core.config.solver.SolverConfig; import ai.timefold.solver.core.config.solver.SolverManagerConfig; -import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.quarkus.runtime.annotations.StaticInitSafe; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithDefaults; +import io.smallrye.config.WithUnnamedKey; + +@ConfigMapping(prefix = "quarkus.timefold") +@ConfigRoot(phase = ConfigPhase.RUN_TIME) +@StaticInitSafe +public interface TimefoldRuntimeConfig { + + String DEFAULT_SOLVER_NAME = "default"; -@ConfigRoot(name = "timefold", phase = ConfigPhase.RUN_TIME) -public class TimefoldRuntimeConfig { /** - * During run time, this is translated into Timefold's {@link SolverConfig} - * runtime properties. + * During run time, this is translated into Timefold's {@link SolverConfig} runtime properties per solver. If a solver + * name is not explicitly specified, the solver name will default to {@link #DEFAULT_SOLVER_NAME}.
```suggestion * During run time, this is translated into Timefold's {@link SolverConfig} runtime properties per solver. * If a solver name is not explicitly specified, the solver name will default to {@link #DEFAULT_SOLVER_NAME}. ```
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -40,16 +40,20 @@ HotDeploymentWatchedFileBuildItem watchSolverBenchmarkConfigXml() { } @BuildStep - @Record(ExecutionTime.STATIC_INIT) - void registerAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans, - BuildProducer<SyntheticBeanBuildItem> syntheticBeans, + BenchmarkConfigBuildItem registerAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<UnremovableBeanBuildItem> unremovableBeans, - SolverConfigBuildItem solverConfigBuildItem, - TimefoldBenchmarkRecorder recorder) { - if (solverConfigBuildItem.getSolverConfig() == null) { + SolverConfigBuildItem solverConfigBuildItem) { + // We don't support benchmarking for multiple solvers + if (solverConfigBuildItem.getAllSolverConfigurations().size() > 1) { + throw new ConfigurationException("When defining multiple solvers, the benchmark feature is not enabled. " + + "Consider using separate <solverBenchmark> instances for evaluating different solver configurations. " + + "You can find additional information by visiting the Timefold documentation page and navigating to the " + + "\"Benchmarking and tweaking\" section.");
```suggestion throw new ConfigurationException("When defining multiple solvers, the benchmark feature is not enabled. " + "Consider using separate <solverBenchmark> instances for evaluating different solver configurations."); ``` I wouldn't go so far as to recommend specific sections of the documentation. Documentation changes, sections move around, titles are renamed... these comments very quickly get obsolete. Also, please use raw string (`"""`) and put each sentence on its own line. That way, you get to avoid the ugly string contatenation where it's not necessary.
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -18,37 +19,53 @@ * See also {@link SolverRuntimeConfig} */ @ConfigGroup -public class SolverBuildTimeConfig { +public interface SolverBuildTimeConfig { + + /** + * A classpath resource to read the specific solver configuration XML. + * + * If this property isn't specified, that solverConfig.xml is optional. + */ + Optional<String> solverConfigXml(); /** * Enable runtime assertions to detect common bugs in your implementation during development. * Defaults to {@link EnvironmentMode#REPRODUCIBLE}. */ - @ConfigItem - public Optional<EnvironmentMode> environmentMode; + Optional<EnvironmentMode> environmentMode(); /** * Enable daemon mode. In daemon mode, non-early termination pauses the solver instead of stopping it, * until the next problem fact change arrives. This is often useful for real-time planning. * Defaults to "false". */ - @ConfigItem - public Optional<Boolean> daemon; + Optional<Boolean> daemon(); /** * Determines how to access the fields and methods of domain classes. * Defaults to {@link DomainAccessType#GIZMO}. */ - @ConfigItem - public Optional<DomainAccessType> domainAccessType; + Optional<DomainAccessType> domainAccessType(); + + /** + * Enable multithreaded solving for a single problem, which increases CPU consumption. + * Defaults to {@value SolverConfig#MOVE_THREAD_COUNT_NONE}. + * Other options include {@value SolverConfig#MOVE_THREAD_COUNT_AUTO}, a number + * or formula based on the available processor count. + */ + Optional<String> moveThreadCount(); + + /** + * Configuration properties regarding Timefold's {@link TerminationConfig}. + */ + TerminationRuntimeConfig termination(); /** * What constraint stream implementation to use. Defaults to {@link ConstraintStreamImplType#BAVET}. * * @deprecated Not used anymore. */ - @ConfigItem @Deprecated(forRemoval = true, since = "1.4.0") - public Optional<ConstraintStreamImplType> constraintStreamImplType; + Optional<ConstraintStreamImplType> constraintStreamImplType();
Any chance to not include the deprecated field for the new config, only keep it for the old way? (If it's too hard to split the two, or requires code duplication, forget about it.)
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -1,32 +1,47 @@ package ai.timefold.solver.quarkus.deployment.config; +import java.util.Map; import java.util.Optional; import ai.timefold.solver.core.config.solver.SolverConfig; -import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; +import io.smallrye.config.ConfigMapping; +import io.smallrye.config.WithUnnamedKey; /** * During build time, this is translated into Timefold's Config classes. */ -@ConfigRoot(name = "timefold") -public class TimefoldBuildTimeConfig { +@ConfigMapping(prefix = "quarkus.timefold") +@ConfigRoot(phase = ConfigPhase.BUILD_TIME) +public interface TimefoldBuildTimeConfig { - public static final String DEFAULT_SOLVER_CONFIG_URL = "solverConfig.xml"; + String DEFAULT_SOLVER_CONFIG_URL = "solverConfig.xml"; + String DEFAULT_SOLVER_NAME = "default"; /** * A classpath resource to read the solver configuration XML. * Defaults to {@value DEFAULT_SOLVER_CONFIG_URL}. * If this property isn't specified, that solverConfig.xml is optional. */ - @ConfigItem - public Optional<String> solverConfigXml; + Optional<String> solverConfigXml(); /** - * Configuration properties that overwrite Timefold's {@link SolverConfig}. + * Configuration properties that overwrite Timefold's {@link SolverConfig} per Solver. If a solver name is not + * explicitly specified, the solver name will default to {@link #DEFAULT_SOLVER_NAME}.
```suggestion * Configuration properties that overwrite the {@link SolverConfig} per Solver. * If a solver name is not explicitly specified, the solver name will default to {@link #DEFAULT_SOLVER_NAME}. ``` When writing about Timefold, please remember: - Timefold is the company. - Timefold Solver is the project. In this case, no need to mention Timefold at all; everyone knows that it's inside the Timefold Solver code.
timefold-solver
github_2023
java
564
TimefoldAI
triceo
@@ -0,0 +1,115 @@ +package ai.timefold.solver.quarkus; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.time.Duration; + +import jakarta.inject.Inject; + +import ai.timefold.solver.core.api.domain.common.DomainAccessType; +import ai.timefold.solver.core.api.score.buildin.bendable.BendableScore; +import ai.timefold.solver.core.api.score.buildin.bendablebigdecimal.BendableBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.bendablelong.BendableLongScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoftbigdecimal.HardMediumSoftBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScore; +import ai.timefold.solver.core.api.score.buildin.hardsoft.HardSoftScore; +import ai.timefold.solver.core.api.score.buildin.hardsoftbigdecimal.HardSoftBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.hardsoftlong.HardSoftLongScore; +import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore; +import ai.timefold.solver.core.api.score.buildin.simplebigdecimal.SimpleBigDecimalScore; +import ai.timefold.solver.core.api.score.buildin.simplelong.SimpleLongScore; +import ai.timefold.solver.core.api.solver.SolutionManager; +import ai.timefold.solver.core.api.solver.SolverFactory; +import ai.timefold.solver.core.api.solver.SolverManager; +import ai.timefold.solver.core.config.solver.EnvironmentMode; +import ai.timefold.solver.core.config.solver.SolverConfig; +import ai.timefold.solver.quarkus.testdata.normal.constraints.TestdataQuarkusConstraintProvider; +import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusEntity; +import ai.timefold.solver.quarkus.testdata.normal.domain.TestdataQuarkusSolution; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +class TimefoldProcessorSingleDefaultSolverPropertiesTest {
This test - a test for the old behavior - should still test the deprecated `ScoreManager`. It's only the new `@Named` behavior where we don't support it.