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 | 1,099 | TimefoldAI | zepfred | @@ -3,22 +3,20 @@
_Planning optimization made easy._
[timefold.ai](https://timefold.ai)
-[](https://pypi.org/project/timefold/)
-[]... | Let's make the "get started" title consistent: `## Get started with Timefold Solver in Python` |
timefold-solver | github_2023 | java | 1,095 | TimefoldAI | zepfred | @@ -0,0 +1,95 @@
+package ai.timefold.solver.core.impl.heuristic.selector.move.generic;
+
+import static ai.timefold.solver.core.impl.testdata.util.PlannerTestUtils.mockRebasingScoreDirector;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.SoftAssertions.assertSoftly;
+imp... | Should we add multithreading tests using the R&R moves? |
timefold-solver | github_2023 | java | 1,084 | TimefoldAI | triceo | @@ -62,6 +65,11 @@ void consumeFirstInitializedSolution(Solution_ firstInitializedSolution) {
scheduleFirstInitializedSolutionConsumption();
}
+ // Called on the solver thread when it starts
+ void triggerStartSolverJob() { | Shouldn't this run on a different thread?
The solver thread cannot be blocked by user code. Have you seen what platform does in the listeners? It's heavy. |
timefold-solver | github_2023 | java | 1,084 | TimefoldAI | triceo | @@ -81,6 +81,14 @@ default SolverJobBuilder<Solution_, ProblemId_> withProblem(Solution_ problem) {
SolverJobBuilder<Solution_, ProblemId_>
withFirstInitializedSolutionConsumer(Consumer<? super Solution_> firstInitializedSolutionConsumer);
+ /**
+ * Sets the runnable action for when the solve... | I'm wondering... how do I find out which job is starting? Maybe we want to replace `Runnable` with something that can give some context? Not sure. |
timefold-solver | github_2023 | java | 1,084 | TimefoldAI | triceo | @@ -306,4 +311,24 @@ public void phaseEnded(AbstractPhaseScope<Solution_> phaseScope) {
}
}
}
+
+ /**
+ * A listener that is triggered once when the solver starts the solving process.
+ */
+ private final class StartSolverJobPhaseLifecycleListener extends PhaseLifecycleListenerA... | `SolverLifecycleListenerAdapter` can listen to `solvingStarted` events. This is what you should listen to, instead of reading the phases. |
timefold-solver | github_2023 | java | 1,084 | TimefoldAI | triceo | @@ -170,10 +175,12 @@ public void terminateEarly(ProblemId_ problemId) {
public void close() {
solverThreadPool.shutdownNow();
problemIdToSolverJobMap.values().forEach(DefaultSolverJob::close);
+ resourcesToRelease.forEach(DefaultSolverJob::close);
}
void unregisterSolverJob(Pr... | This creates a bit of a memory leak for as long as the solver manager is alive.
If we're unregistering the job, why not close it immediately?
We should only remember the jobs that are never unregistered. |
timefold-solver | github_2023 | java | 1,091 | TimefoldAI | zepfred | @@ -297,33 +292,29 @@ protected void setCalculatedScore(Score_ score) {
calculationCount++;
}
+ /**
+ * @deprecated Unused, but kept for backward compatibility.
+ */
+ @Deprecated(forRemoval = true, since = "1.14.0")
@Override
public AbstractScoreDirector<Solution_, Score_, Facto... | Should we update the `upgrade-to-latest-version.adoc` file to include information about this breaking change? |
timefold-solver | github_2023 | java | 1,091 | TimefoldAI | zepfred | @@ -228,17 +230,6 @@ default Score_ doAndProcessMove(Move<Solution_> move, boolean assertMoveScoreFro
*/
SupplyManager getSupplyManager();
- /** | Should we deprecate it before removing it? |
timefold-solver | github_2023 | java | 1,091 | TimefoldAI | zepfred | @@ -81,18 +98,32 @@ public BavetConstraintSession<Score_> buildSession(Solution_ workingSolution, bo
castConstraint.collectActiveConstraintStreams(constraintStreamSet);
constraintWeightMap.put(constraint, constraintWeight);
} else { | ```suggestion
} else if (constraintWeightLoggingEnabled) {
``` |
timefold-solver | github_2023 | python | 1,082 | TimefoldAI | zepfred | @@ -277,6 +277,22 @@ def register_java_class(python_object: Solution_,
return python_object
+def wrap_errors(func): | Is there any test case covering the change? |
timefold-solver | github_2023 | java | 1,067 | TimefoldAI | zepfred | @@ -824,15 +823,33 @@ public int countReinitializableVariables(Object entity) {
return count;
}
- public boolean isMovable(ScoreDirector<Solution_> scoreDirector, Object entity) {
+ public boolean isMovable(Solution_ workingSolution, Object entity) {
return isGenuine() &&
- ... | This class appears to be hidden here, and I think it should be moved to a separate package (e.g., ai.timefold.solver.core.impl.heuristic.selector.common.decorator), and it also deserves better documentation. |
timefold-solver | github_2023 | java | 1,067 | TimefoldAI | zepfred | @@ -22,7 +21,7 @@ public PinEntityFilter(MemberAccessor memberAccessor) {
}
@Override
- public boolean accept(ScoreDirector<Solution_> scoreDirector, Object entity) {
+ public boolean test(Solution_ solution, Object entity) { | I understand your point about using BiPredicate, but I'm wondering if MovableFilter should have a contract consistent with SelectionFilter. For example, it could have a method named accept instead of test. |
timefold-solver | github_2023 | java | 1,067 | TimefoldAI | zepfred | @@ -26,51 +28,51 @@ final class KOptListMoveSelector<Solution_> extends GenericMoveSelector<Solution
private final int[] pickedKDistribution;
private ListVariableStateSupply<Solution_> listVariableStateSupply;
- private EntityIndependentValueSelector<Solution_> effectiveOriginSelector;
- private Entit... | Let's move this method below to the constructor. |
timefold-solver | github_2023 | java | 1,067 | TimefoldAI | zepfred | @@ -41,41 +43,36 @@ public void solvingStarted(SolverScope<Solution_> solverScope) {
var listVariableDescriptor = (ListVariableDescriptor<Solution_>) leftValueSelector.getVariableDescriptor();
var supplyManager = solverScope.getScoreDirector().getSupplyManager();
listVariableStateSupply = sup... | I liked the simplification made with the "effective" selectors, and I noted a pattern where we recreate the selectors when the solver starts. You might have already considered this before making the changes, but would it be possible for the selectors to be inconsistent if we don't recreate them when the solver starts? |
timefold-solver | github_2023 | java | 1,060 | TimefoldAI | triceo | @@ -372,12 +372,19 @@ public static List<Member> getAllMembers(Class<?> baseClass, Class<? extends Ann
.filter(field -> field.isAnnotationPresent(annotationClass) && !field.isSynthetic())
.sorted(alphabeticMemberComparator);
var methodStream = Stream.of(clazz.getDe... | You can filter the entire concated stream at the end, avoiding this duplication. |
timefold-solver | github_2023 | java | 1,060 | TimefoldAI | triceo | @@ -372,12 +372,19 @@ public static List<Member> getAllMembers(Class<?> baseClass, Class<? extends Ann
.filter(field -> field.isAnnotationPresent(annotationClass) && !field.isSynthetic())
.sorted(alphabeticMemberComparator);
var methodStream = Stream.of(clazz.getDe... | Since we're already using stream concatenation, no need to mix normal iteration with it too. Use `flatMap` to achieve the same result. |
timefold-solver | github_2023 | java | 1,060 | TimefoldAI | triceo | @@ -372,12 +372,19 @@ public static List<Member> getAllMembers(Class<?> baseClass, Class<? extends Ann
.filter(field -> field.isAnnotationPresent(annotationClass) && !field.isSynthetic())
.sorted(alphabeticMemberComparator);
var methodStream = Stream.of(clazz.getDe... | Wouldn't it be better to first distinct and then sort? Either way, both can be done at this final stream, and not on the intermediate streams. |
timefold-solver | github_2023 | java | 1,056 | TimefoldAI | triceo | @@ -21,9 +21,9 @@ public ObjectCalculatorBiCollector(BiFunction<? super A, ? super B, ? extends In
@Override
public TriFunction<Calculator_, A, B, Runnable> accumulator() {
return (calculator, a, b) -> {
- final Input_ mapped = mapper.apply(a, b);
- calculator.insert(mapped);
- ... | `final` shouldn't be necessary here. The variable is _effectively final_ without it too. |
timefold-solver | github_2023 | java | 1,056 | TimefoldAI | triceo | @@ -23,9 +23,9 @@ public ObjectCalculatorQuadCollector(QuadFunction<? super A, ? super B, ? super
@Override
public PentaFunction<Calculator_, A, B, C, D, Runnable> accumulator() {
return (calculator, a, b, c, d) -> {
- final Input_ mapped = mapper.apply(a, b, c, d);
- calculator... | Dtto. |
timefold-solver | github_2023 | java | 1,056 | TimefoldAI | triceo | @@ -21,9 +21,9 @@ public ObjectCalculatorTriCollector(TriFunction<? super A, ? super B, ? super C,
@Override
public QuadFunction<Calculator_, A, B, C, Runnable> accumulator() {
return (calculator, a, b, c) -> {
- final Input_ mapped = mapper.apply(a, b, c);
- calculator.insert(m... | Dtto. |
timefold-solver | github_2023 | java | 1,056 | TimefoldAI | triceo | @@ -21,9 +21,9 @@ public ObjectCalculatorUniCollector(Function<? super A, ? extends Input_> mapper
@Override
public BiFunction<Calculator_, A, Runnable> accumulator() {
return (calculator, a) -> {
- final Input_ mapped = mapper.apply(a);
- calculator.insert(mapped);
- ... | Dtto. |
timefold-solver | github_2023 | java | 1,056 | TimefoldAI | triceo | @@ -0,0 +1,137 @@
+package ai.timefold.solver.core.impl.score.stream.collector.connected_ranges;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import ai.timefold.solver.core.api.domain.entity.PlanningEntity;
+import ai.timefold.solver.core.api.domain.lookup.PlanningId;
+import ai.timefold.solver.core.api.do... | Please write a test which tests the collector directly.
I think we have been overdoing it with these integration tests lately. There are several reasons why tests that run the solver should be the exception, rather than the norm:
- They take a relatively long time and if overused, our test suite will take impract... |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -165,19 +175,24 @@ public void solvingError(SolverScope<Solution_> solverScope, Exception exception
decider.solvingError(solverScope, exception);
}
- public static class Builder<Solution_> extends AbstractPhase.Builder<Solution_> {
+ public static class DefaultConstructionHeuristicPhaseBuilder<... | The name `Builder` is used by other builders, e.g., `DefaultLocalSearchPhase`. Is there a reason for changing this one? |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -44,53 +47,65 @@ public DefaultConstructionHeuristicPhaseFactory(ConstructionHeuristicPhaseConfig
super(phaseConfig);
}
- @Override
- public ConstructionHeuristicPhase<Solution_> buildPhase(int phaseIndex, boolean triggerFirstInitializedSolutionEvent,
- HeuristicConfigPolicy<Solution... | I understand using the `DefaultConstructionHeuristicPhaseFactory` class to construct both phases, but I wonder if we can use a different approach. Here are some ideas:
Do we want to allow using `RuinRecreateConstructionHeuristicPhase` as an alternative construction phase to `DefaultConstructionHeuristicPhase`?
If so,... |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,71 @@
+package ai.timefold.solver.core.impl.heuristic.move;
+
+import java.util.Collection;
+import java.util.Objects;
+
+import ai.timefold.solver.core.api.domain.solution.PlanningSolution;
+import ai.timefold.solver.core.api.score.director.ScoreDirector;
+
+/**
+ * Abstract superclass for {@link Move}, sug... | Do we need a text block here? |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,76 @@
+package ai.timefold.solver.core.impl.heuristic.selector.move.generic.list.ruin;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Random;
+
+import ai.timefold.solver.core.impl.domain.variable.ListVariableStateSupply;
+import ai.timefold.solver.core.impl.heuristic.move.Mo... | Should we use an int instead of a long type? |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,52 @@
+package ai.timefold.solver.core.impl.heuristic.selector.move.generic.list.ruin;
+
+import java.util.function.ToLongFunction;
+
+import ai.timefold.solver.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig;
+import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheT... | It looks like we could use a distinct factory class here instead of `DefaultConstructionHeuristicPhaseFactory`. |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,60 @@
+package ai.timefold.solver.core.impl.heuristic.selector.move.generic;
+
+import java.util.List;
+
+import ai.timefold.solver.core.impl.constructionheuristic.ConstructionHeuristicPhase;
+import ai.timefold.solver.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase;
+import ai.timefold.sol... | ```suggestion
public RuinRecreateConstructionHeuristicPhaseBuilder<Solution_> withElementsToRecreate(List<Object> elements) {
``` |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,49 @@
+package ai.timefold.solver.core.impl.heuristic.selector.move.generic;
+
+import java.util.function.ToLongFunction;
+
+import ai.timefold.solver.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig;
+import ai.timefold.solver.core.config.heuristic.selector.common.SelectionCacheType;
+impo... | Same comment as the list variable version. |
timefold-solver | github_2023 | others | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,789 @@
+[#moveSelectorReference]
+= Move Selector reference
+:doctype: book
+:sectnums:
+:icons: font
+
+This chapter describes the move selectors that can be used to select moves for the optimization algorithms.
+For a general introduction to move selectors,
+see xref:optimization-algorithms/overview.adoc#m... | ```suggestion
This coarse-grained move is useful to help the solver to escape from a local optimum.
``` |
timefold-solver | github_2023 | others | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,789 @@
+[#moveSelectorReference]
+= Move Selector reference
+:doctype: book
+:sectnums:
+:icons: font
+
+This chapter describes the move selectors that can be used to select moves for the optimization algorithms.
+For a general introduction to move selectors,
+see xref:optimization-algorithms/overview.adoc#m... | ```suggestion
This coarse-grained move is useful to help the solver to escape from a local optimum.
``` |
timefold-solver | github_2023 | others | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,2134 @@
+[#optimizationAlgorithmsOverview] | The new chapter organization looks better! |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,139 @@
+package ai.timefold.solver.core.config.heuristic.selector.move.generic.list;
+
+import java.util.function.Consumer;
+
+import jakarta.xml.bind.annotation.XmlType;
+
+import ai.timefold.solver.core.config.heuristic.selector.move.MoveSelectorConfig;
+import ai.timefold.solver.core.config.util.ConfigUti... | Just to confirm, the maximum value for `RuinRecreateMoveSelectorConfig` is `20`, and this one is `40`, correct? |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -95,6 +98,10 @@ private void doStep(ConstructionHeuristicStepScope<Solution_> stepScope) {
var step = stepScope.getStep();
step.doMoveOnly(stepScope.getScoreDirector());
predictWorkingStepScore(stepScope, step);
+ processWorkingSolutionDuringStep(stepScope);
+ }
+
+ protected ... | It looks like the new method is not used anywhere else and could be inlined. |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -162,59 +165,47 @@ public static EntityPlacerConfig buildListVariableQueuedValuePlacerConfig(
.withMoveSelectorConfig(listChangeMoveSelectorConfig);
}
- private ConstructionHeuristicDecider<Solution_> buildDecider(HeuristicConfigPolicy<Solution_> configPolicy,
+ protected ConstructionHe... | I couldn't find any other place that updates the decider properties. Please confirm if setting them is still necessary. |
timefold-solver | github_2023 | java | 1,010 | TimefoldAI | zepfred | @@ -0,0 +1,37 @@
+package ai.timefold.solver.core.impl.heuristic.selector.move.generic;
+
+import ai.timefold.solver.core.config.constructionheuristic.ConstructionHeuristicPhaseConfig;
+import ai.timefold.solver.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.DefaultConstructionHeuristicPhaseBuilder;
... | Nice! |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -115,6 +177,25 @@ solution.setConstraintWeightOverrides(constraintWeightOverrides);
...
----
+Python::
++
+[source,python,options="nowrap"]
+----
+...
+
+constraint_weight_overrides = ConstraintWeightOverrides(
+ {
+ "Vehicle capacity": HardSoftScore.of(2, 0), | We don't have `ofHard(...)` in Python? |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -394,23 +491,23 @@ Variants of this `Score` type:
[#scoreCalculationTypes]
=== Score calculation types
-There are several ways to calculate the `Score` of a solution in Java or another JVM language:
+There are several ways to calculate the `Score` of a solution in Java, Python or another JVM language:
* **xre... | Arguably, "Incremental X score calculation" is no longer the correct name. Not only do we have Python, we also have Kotlin. It seems that the name of the language just shouldn't be there at all.
The name of the class is `IncrementalScoreCalculator` - maybe we should just call this "Incremental score calculator"? |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -394,23 +491,23 @@ Variants of this `Score` type:
[#scoreCalculationTypes]
=== Score calculation types
-There are several ways to calculate the `Score` of a solution in Java or another JVM language:
+There are several ways to calculate the `Score` of a solution in Java, Python or another JVM language:
* **xre... | ```suggestion
All score calculation types are object-oriented and can reuse existing Java or Python code.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -113,9 +113,13 @@ In order for constraints to scale well, it is necessary to limit the amount of d
In Constraint Streams, it starts with
xref:constraints-and-score/score-calculation.adoc#constraintStreamsJoin[joins].
Consider a school timetabling problem, where a teacher must not have two overlapping lessons.
-Th... | ```suggestion
This is how the lesson could look:
```
No need to duplicate the language name, which can be seen in the tabs. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -179,35 +222,76 @@ Let's instead remove them from the cross-product entirely.
For the first lesson in the join, also called “left,”
we put the cancellation check before the join like so:
-[source, java]
+[tabs]
+====
+Java::
++
+[source, java, options="nowrap"]
----
constraintFactory.forEach(Lesson.class)
... | Technically, I think the previous example was correct too; the model should ensure there are never two instances which equal. It's a problem fact, those don't need identity. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -5,39 +5,53 @@
:sectnums:
:icons: font
-Using Java's Streams API,
+Using Java's Streams API or Python's generator expressions, | This is another example where maybe talking about a particular language doesn't make sense anymore.
This can be "Let's implement ... using a functional approach:".
Then inside the tab for a particular language, we can add more details specific to that language, if we need to. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -5,39 +5,53 @@
:sectnums:
:icons: font
-Using Java's Streams API,
+Using Java's Streams API or Python's generator expressions,
we could implement an xref:constraints-and-score/score-calculation.adoc#easyJavaScoreCalculation[easy score calculator]
that uses a functional approach:
+[tabs]
+====
+Java::
++
[so... | ```suggestion
Constraint streams are a functional programming form of incremental score calculation
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -5,39 +5,53 @@
:sectnums:
:icons: font
-Using Java's Streams API,
+Using Java's Streams API or Python's generator expressions,
we could implement an xref:constraints-and-score/score-calculation.adoc#easyJavaScoreCalculation[easy score calculator]
that uses a functional approach:
+[tabs]
+====
+Java::
++
[so... | ```suggestion
The Constraint Streams API enables you to write similar code in a language of your choice,
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -72,9 +99,13 @@ image::constraints-and-score/score-calculation/constraintStreamJustification.png
[#constraintStreamsConfiguration]
== Creating a constraint stream
-To use the Constraint Streams API in your project, first write a pure Java `ConstraintProvider` implementation similar
+To use the Constraint Streams... | ```suggestion
To use the Constraint Streams API in your project, first write a `ConstraintProvider` implementation similar
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -666,17 +1052,35 @@ collector.
The following code snippet first groups all visits by the vehicle that will be used,
and averages all the service durations using the `ConstraintCollectors.average(...)` collector.
+[tabs]
+====
+Java::
++
[source,java,options="nowrap"]
----
private Constraint averageServiceDura... | Personally, I'd prefer `HardSoftLongScore` and removing the cast.
Simpler code for the example. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1350,23 +2226,67 @@ The following example uses the Constraint Verifier API to create a simple unit t
}
----
+Python::
++
+[source,python,options="nowrap"]
+----
+from timefold.solver.test import ConstraintVerifier
+from datetime import datetime, date, time, timedelta
+from .constraints import vehicle_routin... | ```suggestion
Constraint Verifier works with testing frameworks popular in your ecosystem, including JUnit and PyTest.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1498,21 +2469,25 @@ public class MyConstraintProviderTest {
Timefold Solver supports two other types of score calculation.
[#easyJavaScoreCalculation]
-=== Easy Java score calculation
+=== Easy Java/Python score calculation
-An easy way to implement your score calculation in Java.
+An easy way to implement yo... | ```suggestion
An easy way to implement your score calculation as imperative code:
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1498,21 +2469,25 @@ public class MyConstraintProviderTest {
Timefold Solver supports two other types of score calculation.
[#easyJavaScoreCalculation]
-=== Easy Java score calculation
+=== Easy Java/Python score calculation | Same comment as above; specifically naming the technology seems unnecessary. The heading, as well as the references, should change. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1498,21 +2469,25 @@ public class MyConstraintProviderTest {
Timefold Solver supports two other types of score calculation.
[#easyJavaScoreCalculation]
-=== Easy Java score calculation
+=== Easy Java/Python score calculation
-An easy way to implement your score calculation in Java.
+An easy way to implement yo... | ```suggestion
** No learning curve; use the language you're already familiar with.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1498,21 +2469,25 @@ public class MyConstraintProviderTest {
Timefold Solver supports two other types of score calculation.
[#easyJavaScoreCalculation]
-=== Easy Java score calculation
+=== Easy Java/Python score calculation
-An easy way to implement your score calculation in Java.
+An easy way to implement yo... | ```suggestion
To start using Easy score calculator, implement the one method of the interface ``EasyScoreCalculator``:
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1547,9 +2534,9 @@ add the `easyScoreCalculatorCustomProperties` element and use xref:using-timefol
[#incrementalJavaScoreCalculation]
-=== Incremental Java score calculation
+=== Incremental Java/Python score calculation | Dtto. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1547,9 +2534,9 @@ add the `easyScoreCalculatorCustomProperties` element and use xref:using-timefol
[#incrementalJavaScoreCalculation]
-=== Incremental Java score calculation
+=== Incremental Java/Python score calculation
-A way to implement your score calculation incrementally in Java.
+A way to implement yo... | ```suggestion
A way to implement your score calculation incrementally in a supported programming language.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1561,9 +2548,13 @@ Why not have <<constraintStreams,constraint streams>> do the hard work for you?
** Hard to read
*** Regular score constraint changes can lead to high maintenance costs.
-To start using Incremental Java score calculation,
+To start using Incremental Java/Python score calculation, | ```suggestion
To start using Incremental score calculator,
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -86,6 +87,40 @@ repositories {
}
----
--
+
+Pyproject.toml:: | I question if we want to do this.
We don't want to push Python to Enterprise users, at least not yet.
Having documentation for it suggests that Timefold will support it; this is not the case. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -122,7 +122,7 @@ by changing the solver configuration in a few lines of code.
== Status of Timefold Solver
Timefold Solver is 100% pure Java^TM^ and runs on Java {java-version} or higher.
-It xref:integration/integration.adoc#integration[integrates very easily] with other Java^TM^ technologies.
+It xref:integrat... | ```suggestion
It xref:integration/integration.adoc#integration[integrates very easily] with other Java^TM^, Python and other technologies.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -66,12 +85,16 @@ These various parts of a configuration are explained further in this manual.
[#solverConfigurationByJavaAPI]
-== Solver configuration by Java API
+== Solver configuration by Java/Python API | ```suggestion
== Solver configuration as code
```
Please also update the ID and all links. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -121,10 +189,10 @@ Timefold Solver needs to be told which classes in your domain model are planning
which properties are planning variables, etc.
There are several ways to deliver this information:
-* Add class annotations and JavaBean property annotations on the domain model (recommended).
+* Add class annotati... | Do we want tabs for this? It's different enough. |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -31,14 +31,18 @@ In xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-tim
To create a good domain model, read the xref:design-patterns/design-patterns.adoc#domainModelingGuide[domain modeling guide].
-*In Timefold Solver, all problem facts and planning entities are plain old JavaBeans (P... | ```suggestion
*In Timefold Solver, all problem facts and planning entities are plain objects.* Load them from a database, an XML file, a data repository, a REST service, a noSQL cloud, ... (see xref:integration/integration.adoc#integration[integration]): it doesn't matter.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -31,14 +31,18 @@ In xref:responding-to-change/responding-to-change.adoc#realTimePlanning[real-tim
To create a good domain model, read the xref:design-patterns/design-patterns.adoc#domainModelingGuide[domain modeling guide].
-*In Timefold Solver, all problem facts and planning entities are plain old JavaBeans (P... | ```suggestion
A problem fact is any object with getters that does not change during planning.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -1121,7 +1583,7 @@ For example, none of the `timeslot` variables of any `Lesson` may be used to det
Use the planning list variable to model problems where the goal is to distribute a number of workload elements among limited resources in a specific order.
This includes, for example, vehicle routing, traveling sale... | ```suggestion
The planning list variable is a successor to the chained planning variable and provides a more intuitive way to express the problem domain.
``` |
timefold-solver | github_2023 | others | 1,047 | TimefoldAI | triceo | @@ -394,23 +491,23 @@ Variants of this `Score` type:
[#scoreCalculationTypes]
=== Score calculation types
-There are several ways to calculate the `Score` of a solution in Java or another JVM language:
+There are several ways to calculate the `Score` of a solution in Java, Python or another JVM language: | ```suggestion
There are several ways to calculate the `Score` of a solution:
``` |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -3,54 +3,24 @@
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
-import ai.timefold.solver.core.api.domain.entity.PlanningEntity... | ```suggestion
* Automatically cascades change events to the subsequent elements of a {@link PlanningListVariable}.
``` |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -3,54 +3,24 @@
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
-import ai.timefold.solver.core.api.domain.entity.PlanningEntity... | ```suggestion
* Specifies that a field may be updated by the target method when any of its variables change, genuine or shadow.
```
Is this correct? |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -3,54 +3,24 @@
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
-import ai.timefold.solver.core.api.domain.entity.PlanningEntity... | The Javadoc should also discuss the differences between this and a shadow variable.
Specifically, that nothing is allowed to depend on it, and that it will always be processed after all other shadow variables have been updated.
Maybe it should discuss what happens if multiple cascading vars on the same entity insta... |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -49,56 +49,62 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) {
private void linkSourceVariableDescriptorToListenerClass(ShadowVariable shadowVariable) {
EntityDescriptor<Solution_> sourceEntityDescriptor;
- Class<?> sourceEntityClass = shadowVariable.sourceEntityClas... | Maybe these new exceptions should explain _why_ that's not the case. What did the user do wrong? From the message, it's not at all clear. |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -33,12 +36,26 @@ public static <Solution_> VariableListenerSupport<Solution_> create(InnerScoreDi
private final NotifiableRegistry<Solution_> notifiableRegistry;
private final Map<Demand<?>, SupplyWithDemandCount> supplyMap = new HashMap<>();
+ private final List<ListVariableEvent> listVariableEventLi... | Afaik `SolutionDescriptor` has a method which can already retrieve the one and only list variable descriptor. |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -33,12 +36,26 @@ public static <Solution_> VariableListenerSupport<Solution_> create(InnerScoreDi
private final NotifiableRegistry<Solution_> notifiableRegistry;
private final Map<Demand<?>, SupplyWithDemandCount> supplyMap = new HashMap<>();
+ private final List<ListVariableEvent> listVariableEventLi... | Please don't use `LinkedList`.
https://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/
I know that it has theoretical benefits in computer science, but in computer reality, they are no longer valid. |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -195,34 +212,69 @@ public void beforeListVariableChanged(ListVariableDescriptor<Solution_> variable
public void afterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex,
int toIndex) {
- Collection<ListVariableListenerNotifiable<Solution_>... | I find it surprising that this is faster than the alternatives discussed.
If there's two events to say `process the entire list`, this will do it twice, even though it's unnecessary. |
timefold-solver | github_2023 | others | 1,020 | TimefoldAI | triceo | @@ -1427,7 +1427,13 @@ A user-defined logic can only change shadow variables.
It must never change a genuine planning variable or a problem fact.
====
-==== Multiple shadow variables
+[WARNING] | ```suggestion
[NOTE]
``` |
timefold-solver | github_2023 | others | 1,020 | TimefoldAI | triceo | @@ -1462,6 +1468,11 @@ It is not allowed to specify the property `shadowEntityClass` in `@PiggybackShad
when the source shadow variable is `@CascadingUpdateShadowVariable`.
====
+[WARNING]
+====
+The user's logic is responsible for defining the order in which each variable is updated. | I don't understand what this is trying to say. Maybe it needs a bit of context?
Not sure if it's a warning. If it has more text explaining why this is bad, then I say it could be a warning. |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -195,34 +207,69 @@ public void beforeListVariableChanged(ListVariableDescriptor<Solution_> variable
public void afterListVariableChanged(ListVariableDescriptor<Solution_> variableDescriptor, Object entity, int fromIndex,
int toIndex) {
- Collection<ListVariableListenerNotifiable<Solution_>... | We don't use `final` for local variables.
Also, arguably this should be standard `camelCase`, unless you want to make it a class-level constant. (Which it probably should be.) |
timefold-solver | github_2023 | others | 1,020 | TimefoldAI | triceo | @@ -1412,98 +1414,23 @@ public class Customer {
The `targetMethodName` refers to the user-defined logic that updates the annotated shadow variable.
The method must be implemented in the defining entity class, be non-static, and not include any parameters.
-The `sourceVariableName` property is the planning variable'... | ```suggestion
the order of their execution is undefined.
``` |
timefold-solver | github_2023 | others | 1,020 | TimefoldAI | triceo | @@ -1412,98 +1414,23 @@ public class Customer {
The `targetMethodName` refers to the user-defined logic that updates the annotated shadow variable.
The method must be implemented in the defining entity class, be non-static, and not include any parameters.
-The `sourceVariableName` property is the planning variable'... | ```suggestion
Changing a genuine planning variable or a problem fact will result in score corruption.
``` |
timefold-solver | github_2023 | others | 1,020 | TimefoldAI | triceo | @@ -1371,8 +1371,10 @@ public class Customer {
=== Updating tail chains
The annotation `@CascadingUpdateShadowVariable` provides a built-in listener that updates a set of connected elements.
-Timefold Solver triggers a user-defined logic whenever the a defined source variable changes.
-Moreover, it automatically pr... | ```suggestion
it automatically propagates changes to the subsequent elements in the list when the value of the related shadow variable changes.
``` |
timefold-solver | github_2023 | java | 1,020 | TimefoldAI | triceo | @@ -4,33 +4,36 @@
import ai.timefold.solver.core.api.domain.variable.CascadingUpdateShadowVariable;
import ai.timefold.solver.core.api.domain.variable.InverseRelationShadowVariable;
import ai.timefold.solver.core.api.domain.variable.NextElementShadowVariable;
+import ai.timefold.solver.core.api.domain.variable.Piggy... | This should be no longer possible, right? |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -38,6 +40,18 @@
*/
String[] sourceVariableNames() default {};
+ /**
+ * The {@link PlanningEntity} class of the source variable.
+ * <p>
+ * Specified if the source variable is on a different {@link Class} than the class that uses this referencing annotation.
+ *
+ * @return {@lin... | ```suggestion
* Defaults to the same {@link Class} as the one that uses this annotation.
``` |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -6,39 +6,51 @@
import ai.timefold.solver.core.api.domain.variable.VariableListener;
import ai.timefold.solver.core.api.score.director.ScoreDirector;
import ai.timefold.solver.core.impl.domain.common.accessor.MemberAccessor;
+import ai.timefold.solver.core.impl.domain.variable.cascade.command.CascadingUpdateComman... | Any chance we could make these protected?
It's a minor issue; I just don't like to expose fields to the outside. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -6,39 +6,51 @@
import ai.timefold.solver.core.api.domain.variable.VariableListener;
import ai.timefold.solver.core.api.score.director.ScoreDirector;
import ai.timefold.solver.core.impl.domain.common.accessor.MemberAccessor;
+import ai.timefold.solver.core.impl.domain.variable.cascade.command.CascadingUpdateComman... | ```suggestion
var isChanged = execute(scoreDirector, entity);
```
Let's stick to this convention in new code, and do it consistently. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -6,39 +6,51 @@
import ai.timefold.solver.core.api.domain.variable.VariableListener;
import ai.timefold.solver.core.api.score.director.ScoreDirector;
import ai.timefold.solver.core.impl.domain.common.accessor.MemberAccessor;
+import ai.timefold.solver.core.impl.domain.variable.cascade.command.CascadingUpdateComman... | `var`; won't mention it anymore, but the PR is full of this. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -110,13 +110,22 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) {
v -> v.getEntityDescriptor().getEntityClass().getSimpleName() + "::" + v.getVariableName())
.collect(joining(", "))));
}
- sourceListVa... | ```suggestion
The entity class (%s) has @%s-annotated properties, but the sources can be either a regular shadow variable or a planning list variable.
``` |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -213,22 +270,21 @@ public boolean hasVariableListener() {
@Override
public Iterable<VariableListenerWithSources<Solution_>> buildVariableListeners(SupplyManager supplyManager) {
AbstractCascadingUpdateShadowVariableListener<Solution_> listener;
- if (nextElementShadowVariableDescriptor != n... | `var` |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -1,33 +1,51 @@
package ai.timefold.solver.core.impl.domain.variable.cascade;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import ai.timefold.solver.core.api.domain.solution.PlanningSolution;
+import ai.timefold.solver.core.api.score.director.ScoreDirector;
import ai.timefold... | Why have the `newValueList`? Can't you just check the value directly, without storing it? The list is never read otherwise. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -0,0 +1,24 @@
+package ai.timefold.solver.core.impl.domain.variable.cascade.command;
+
+import ai.timefold.solver.core.impl.domain.variable.ListVariableStateSupply;
+import ai.timefold.solver.core.impl.heuristic.selector.list.ElementLocation;
+import ai.timefold.solver.core.impl.heuristic.selector.list.LocationInLis... | I'd just return `LocationInList`; let's spare GC some work. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -0,0 +1,24 @@
+package ai.timefold.solver.core.impl.domain.variable.cascade.command;
+
+import ai.timefold.solver.core.impl.domain.variable.ListVariableStateSupply;
+import ai.timefold.solver.core.impl.heuristic.selector.list.ElementLocation;
+import ai.timefold.solver.core.impl.heuristic.selector.list.LocationInLis... | `LocationInList.unassigned()`. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | triceo | @@ -0,0 +1,5 @@
+package ai.timefold.solver.core.impl.domain.variable.cascade.command;
+
+public interface CascadingUpdateCommand<T> { | Not sure why we have this. Isn't this just a `Function<T, Object>`?
Since it seems to only have one implementor, I'd remove it. |
timefold-solver | github_2023 | java | 996 | TimefoldAI | Christopher-Chianelli | @@ -0,0 +1,4 @@
+package ai.timefold.solver.core.impl.domain.variable.cascade.command;
+
+public record Pair<T, U>(T firstValue, U secondValue) { | We already define a Pair record in `ai.timefold.solver.core.impl.util` |
timefold-solver | github_2023 | java | 996 | TimefoldAI | Christopher-Chianelli | @@ -0,0 +1,24 @@
+package ai.timefold.solver.core.impl.domain.variable.cascade.command;
+
+import ai.timefold.solver.core.impl.domain.variable.ListVariableStateSupply;
+import ai.timefold.solver.core.impl.heuristic.selector.list.ElementLocation;
+import ai.timefold.solver.core.impl.heuristic.selector.list.LocationInLis... | Why not use the `LocationInList` record directly? This `Pair` is duplicating an immutable object. |
timefold-solver | github_2023 | python | 996 | TimefoldAI | Christopher-Chianelli | @@ -231,7 +231,7 @@ def __init__(self, *,
super().__init__(JavaPiggybackShadowVariable,
{
'shadowVariableName': PythonClassTranslator.getJavaFieldName(shadow_variable_name),
- 'shadowEntityClass': shadow_entity_class,
+ ... | `get_asm_type` is not needed; remove. |
timefold-solver | github_2023 | python | 996 | TimefoldAI | Christopher-Chianelli | @@ -39,7 +40,11 @@ class Visit:
target_method_name='update_arrival_time')] = field(default=None)
piggyback_arrival_time: Annotated[
Optional[datetime],
- PiggybackShadowVariable(shadow_variable_name='arrival_time')] = field(default=None)
+ PiggybackShad... | Visit is not defined yet (this is inside the Visit class); this code would not run/crash at runtime. Remove the `shadow_entity_class` here. |
timefold-solver | github_2023 | others | 784 | TimefoldAI | rsynek | @@ -37,15 +38,15 @@ jobs:
path: ./timefold-quickstarts
fetch-depth: 0 # Otherwise merge will fail on account of not having history.
- name: Checkout timefold-quickstarts (development) # Checkout the development branch if the PR branch does not exist
- if: steps.checkout-quickstarts.o... | I don't see any `checkout-solver-quickstarts-pr` ID in this file. |
timefold-solver | github_2023 | others | 998 | TimefoldAI | winklerm | @@ -8,8 +8,19 @@ on:
- opened
- reopened
- synchronize
+ - labeled
jobs:
+ safe_for_ci:
+ name: "Ensure that PR is safe for CI"
+ runs-on: ubuntu-latest
+ steps:
+ - name: Fail of not safe | Nitpick: Typo? |
timefold-solver | github_2023 | others | 992 | TimefoldAI | triceo | @@ -1465,6 +1464,28 @@ It calls `updateArrivalTime` whenever a `previousCustomer` or `vehicle` changes.
It then propagates the changes to the subsequent elements,
stopping when the method results in no change to the variable, or when it reaches the tail.
+Another valid approach for defining multiple sources per var... | I wouldn't mention this; at this moment, there's no reason why anyone would want to do it. If we ever implement the variable on a different entity, then we can write a section to describe that aspect. |
timefold-solver | github_2023 | java | 992 | TimefoldAI | triceo | @@ -137,8 +137,39 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) {
MemberAccessorFactory.MemberAccessorType.REGULAR_METHOD, null, descriptorPolicy.getDomainAccessType());
}
- public void linkVariableDescriptorToSource(CascadingUpdateShadowVariable listener) {
- ... | ```suggestion
Maybe update the field "%s" to set only one of the properties ([sourceVariableName, sourceVariableNames])."""
``` |
timefold-solver | github_2023 | java | 992 | TimefoldAI | triceo | @@ -137,8 +137,39 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) {
MemberAccessorFactory.MemberAccessorType.REGULAR_METHOD, null, descriptorPolicy.getDomainAccessType());
}
- public void linkVariableDescriptorToSource(CascadingUpdateShadowVariable listener) {
- ... |
```suggestion
Maybe update the field "%s" and set one of the properties ([sourceVariableName, sourceVariableNames])."""
``` |
timefold-solver | github_2023 | others | 992 | TimefoldAI | triceo | @@ -1451,8 +1451,7 @@ public class Customer {
private Customer previousCustomer;
@NextElementShadowVariable(sourceVariableName = "customers")
private Customer nextCustomer;
- @CascadingUpdateShadowVariable(targetMethodName = "updateArrivalTime", sourceVariableName = "vehicle")
- @CascadingUpdateSha... | Now would be the time to add a section of the documentation that shows how piggybacks interact with cascading variables. |
timefold-solver | github_2023 | java | 992 | TimefoldAI | Christopher-Chianelli | @@ -137,8 +137,39 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) {
MemberAccessorFactory.MemberAccessorType.REGULAR_METHOD, null, descriptorPolicy.getDomainAccessType());
}
- public void linkVariableDescriptorToSource(CascadingUpdateShadowVariable listener) {
- ... | Nitpick: Should be called `nonEmptySources`; `noEmptySources` would be for a boolean, not a list. |
timefold-solver | github_2023 | python | 992 | TimefoldAI | Christopher-Chianelli | @@ -244,13 +244,14 @@ class CascadingUpdateShadowVariable(JavaAnnotation):
Notes
-----
Important: it must only change the shadow variable(s) for which it's configured.
+ It is only possible to define either `sourceVariableName` or `sourceVariableNames`. | ```suggestion
It is only possible to define either `source_variable_name` or `source_variable_names`.
``` |
timefold-solver | github_2023 | python | 992 | TimefoldAI | Christopher-Chianelli | @@ -244,13 +244,14 @@ class CascadingUpdateShadowVariable(JavaAnnotation):
Notes
-----
Important: it must only change the shadow variable(s) for which it's configured.
+ It is only possible to define either `sourceVariableName` or `sourceVariableNames`.
It can be applied to multiple attributes to... | ```
Examples
--------
```
is a standard section used in NumPy formatted docs. Do not change it or add new sections. See https://numpydoc.readthedocs.io/en/latest/format.html .
For this, it would be
```
Examples
--------
Single source
(example here)
Multiple sources
(example here)
``` |
timefold-solver | github_2023 | python | 992 | TimefoldAI | Christopher-Chianelli | @@ -244,13 +244,16 @@ class CascadingUpdateShadowVariable(JavaAnnotation):
Notes
-----
Important: it must only change the shadow variable(s) for which it's configured.
+ It is only possible to define either `source_variable_name` or `source_variable_names`.
It can be applied to multiple attribute... | ```suggestion
Examples
```
```suggestion
Example
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.