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
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 -------- ```
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 >>> from timefold.solver.domain import CascadingUpdateShadowVariable, PreviousElementShadowVariable, planning_entity ```
timefold-solver
github_2023
python
992
TimefoldAI
Christopher-Chianelli
@@ -268,10 +271,31 @@ class CascadingUpdateShadowVariable(JavaAnnotation): ... ... def update_arrival_time(self): ... self.arrival_time = previous.arrival_time + timedelta(hours=1) + Multiple sources
```suggestion Multiple sources ```
timefold-solver
github_2023
java
990
TimefoldAI
Christopher-Chianelli
@@ -118,20 +118,24 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) { .orElse(null); var targetMethodName = getTargetMethodName(); - var sourceMethodMember = ConfigUtils.getDeclaredMembers(entityDescriptor.getEntityClass()) + var sourceMethodMembers = C...
Might want to filter out fields here; using a field as a "cascade update method" makes no sense. i.e. we want this to fail: ```java @PlanningEntity class A { Runnable update; @CascadingUpdateShadowVariable(targetMethodName = "update", sourceVariableName = "entity")) Integer variable; } ``` If...
timefold-solver
github_2023
java
990
TimefoldAI
Christopher-Chianelli
@@ -118,20 +119,24 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) { .orElse(null); var targetMethodName = getTargetMethodName(); - var sourceMethodMember = ConfigUtils.getDeclaredMembers(entityDescriptor.getEntityClass()) + var sourceMethodMembers = C...
I would honestly do it like this: ```java var sourceMethodMembers = ConfigUtils.getDeclaredMembers(entityDescriptor.getEntityClass()) .stream() .filter(member -> member instanceof Method method && method.getName().equals(targetMethod) && ...
timefold-solver
github_2023
java
990
TimefoldAI
Christopher-Chianelli
@@ -119,24 +119,28 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) { .orElse(null); var targetMethodName = getTargetMethodName(); - var sourceMethodMembers = ConfigUtils.getDeclaredMembers(entityDescriptor.getEntityClass()) + var allSourceMethodMembers...
This line should be ``` member -> member instanceof Method method && member.getName().equals(targetMethodName) && method.getParameterCount() == 0 ```
timefold-solver
github_2023
java
990
TimefoldAI
Christopher-Chianelli
@@ -119,24 +119,28 @@ public void linkVariableDescriptors(DescriptorPolicy descriptorPolicy) { .orElse(null); var targetMethodName = getTargetMethodName(); - var sourceMethodMembers = ConfigUtils.getDeclaredMembers(entityDescriptor.getEntityClass()) + var allSourceMethodMembers...
Should be done on `allSourceMethodMembers`
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,32 @@ +package ai.timefold.solver.core.api.domain.variable; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * A listener automatically sourced on a {@l...
TODO: Naming.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,32 @@ +package ai.timefold.solver.core.api.domain.variable; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * A listener automatically sourced on a {@l...
```suggestion * Important: it must only change the shadow variable(s) for which it's configured. ``` We generally don't shout at people. :-)
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -19,6 +19,10 @@ public final class ReflectionMethodMemberAccessor extends AbstractMemberAccessor private final MethodHandle methodHandle; public ReflectionMethodMemberAccessor(Method readMethod) { + this(readMethod, true); + } + + public ReflectionMethodMemberAccessor(Method readMethod, bool...
I think `returnTypeRequired` makes it more obvious that it's a `boolean`. Please apply consistently throughout the codebase.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -161,12 +162,17 @@ private static void createConstructor(ClassCreator classCreator, GizmoMemberInfo Method.class, String.class, Class[].class), declaringClass, name, methodCreator.newArray(Class.class, 0)); - ResultHandle type = - ...
```suggestion // We create a field to store the result, only if the called method has a return type. // Otherwise, we will only execute it. ``` It reads better if the lines are split by sentence, if possible. (The IntelliJ Grazie Pro plugin helps with writing a lot.)
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -246,9 +254,8 @@ private static void createGetName(ClassCreator classCreator, GizmoMemberInfo mem // If it is a method, assert that it has the required // properties - memberInfo.getDescriptor().whenIsMethod(method -> { - assertIsGoodMethod(method, memberInfo.getAnnotationClass(...
It's a race to the finish line now. :-) We're going to have conflicts, you and I. Nevermind, we'll figure it out when the time comes.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,135 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import ai.timefold.solver.core.api.domain.variable.AbstractVariableListener; +import ai.timefold.solver.core.api.domain....
I wonder if this is necessary. If the inverse is not defined, can we not use a supply? List variable works even without defining these, so the code to support that is already in there.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,135 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import ai.timefold.solver.core.api.domain.variable.AbstractVariableListener; +import ai.timefold.solver.core.api.domain....
Dtto.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,135 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import ai.timefold.solver.core.api.domain.variable.AbstractVariableListener; +import ai.timefold.solver.core.api.domain....
Dtto.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,168 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; + +import java.util.Arrays; +import java.util.List; + +import ai.timefold.solver.core.api.score...
Maybe we should also test the case where two listeners point to the same method?
timefold-solver
github_2023
others
954
TimefoldAI
triceo
@@ -1367,6 +1367,91 @@ public class Customer { public void setNextCustomer(Customer nextCustomer) {...} ---- +[#cascadeUpdateVariable] +==== Cascade element update shadow variable + +The annotation `@CascadeUpdateElementShadowVariable` provides a built-in listener that updates a set of connected elements. +Time...
Isn't it rather the `targetMethodName`? The relationship is inversed here.
timefold-solver
github_2023
others
954
TimefoldAI
triceo
@@ -1367,6 +1367,91 @@ public class Customer { public void setNextCustomer(Customer nextCustomer) {...} ---- +[#cascadeUpdateVariable] +==== Cascade element update shadow variable
This documentation is correct, but I've been wondering... Should we rather (or maybe in addition) write a short section on "updating tail chains"? And maybe we don't hide it deep in a subsection on variable listeners. Because as a user, that's what I will look for - not "cascade element update shadow variable".
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -127,9 +152,21 @@ public Demand<?> getProvidedDemand() { @Override public Iterable<VariableListenerWithSources<Solution_>> buildVariableListeners(SupplyManager supplyManager) { - return List.of(new VariableListenerWithSources<>( - new CascadeUpdateVariableListener<>(sourceShadowVari...
```suggestion // There are use cases where the shadow variable is applied to different fields // and relies on the same method to update their values. // Therefore, only one listener will be generated when multiple descriptors use the same method, // and the notifiable flag won't ...
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -33,12 +35,25 @@ public void beforeVariableChanged(ScoreDirector<Solution_> scoreDirector, Object public void afterVariableChanged(ScoreDirector<Solution_> scoreDirector, Object entity) { var currentEntity = entity; while (currentEntity != null) { - scoreDirector.beforeVariableChang...
Arguably you can make this check when you're reading the new value, completely avoiding this loop and improving performance.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -33,12 +35,25 @@ public void beforeVariableChanged(ScoreDirector<Solution_> scoreDirector, Object public void afterVariableChanged(ScoreDirector<Solution_> scoreDirector, Object entity) { var currentEntity = entity; while (currentEntity != null) { - scoreDirector.beforeVariableChang...
Personally, I'd introduce two methods for this - one which only has 1 var, and another which handles 2+ vars. The 1-var path will be significantly faster, avoiding the list and the iterations. It is also the most frequent use case, so it makes sense to have a path handling it.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,49 @@ +package ai.timefold.solver.core.api.domain.variable; + +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; + +/** + * ...
I'd put this first, as it is for other listeners.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -320,7 +327,13 @@ private static void createGetGenericType(ClassCreator classCreator) { private static void createExecuteGetter(ClassCreator classCreator, GizmoMemberInfo memberInfo) { MethodCreator methodCreator = getMethodCreator(classCreator, Object.class, "executeGetter", Object.class); Re...
Arguably the Javadoc should change, as the method now does something different than what it says.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -5,16 +5,23 @@ public final class GizmoMemberInfo {
If I remember correctly, in my previous changes, I turned this into a record. Are you sure you resolved all conflicts with the main branch?
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -85,7 +88,9 @@ public class EntityDescriptor<Solution_> { ShadowVariable.class, ShadowVariable.List.class, PiggybackShadowVariable.class, - CustomShadowVariable.class }; + CustomShadowVariable.class, + CascadingUpdateListener.class, + ...
Now that I see it written like this... maybe it should be `CascadingUpdateShadowVariable`?
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -350,6 +359,21 @@ The entityClass (%s) has a @%s annotated member (%s) that has an unsupported typ || variableAnnotationClass.equals(ShadowVariable.List.class)) { var variableDescriptor = new CustomShadowVariableDescriptor<>(nextVariableDescriptorOrdinal, this, memberAccessor); ...
Maybe also explain _why_? What's the point?
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,49 @@ +package ai.timefold.solver.core.api.domain.variable; + +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; + +/** + * ...
We should describe the method. What are the arguments? What is the return value and what does it mean? Is it allowed to be static? What is the expected visibility?
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,116 @@ +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.domain.variable.VariableListener; +import ai.time...
Personally, I'd have two listeners for this. One that only accepts the descriptor, and another that only accepts the supply. That way, it's clear what the code path intends to do.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,116 @@ +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.domain.variable.VariableListener; +import ai.time...
I'd consider having two separate impl classes with the same abstract parent. Otherwise you'll be paying the penalty for this condition on every call of this method, which is a lot. (Conditions = branch predictions = CPU cache misses.)
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,116 @@ +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.domain.variable.VariableListener; +import ai.time...
Arguably, you can turn this into a lambda in the constructor, avoiding a condition at all. If you know the descriptor is null, simply provide a lambda to access the supply, and vice versa.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,194 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import static java.util.stream.Collectors.joining; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.uti...
Let's use `var` consistently in new code. IDE can help you replace all.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,134 @@ +package ai.timefold.solver.core.impl.domain.variable.nextprev; + +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + +import ai.timefold.solver.core.api.domain.variable.VariableListener; +import ai.timefold.solver.core.api.score.director.ScoreDirector; +import ai.timef...
I've been wondering... not sure here... should this be part of the externalized list variable state supply? That's one place where I've been putting logic related to list variable.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,93 @@ +package ai.timefold.solver.core.impl.util; + +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.function.Consumer; +import java.util.function.UnaryOperator; + +/** + * This data structure differs from {@link ElementAwareList} because it provides a find operation in O(H). ...
The point of `ElementAwareList` is to avoid hash lookups, and it replaced various uses of maps and sets. That's it's main benefit. Since you've introduced `IdentityHashMap` in there, you are effectively turning this into a `Map` again. You might as well use `new IdentityHashMap<>()` directly and avoid this entire new ...
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -67,6 +68,8 @@ public final class DotNames { static final DotName PIGGYBACK_SHADOW_VARIABLE = DotName.createSimple(PiggybackShadowVariable.class.getName()); static final DotName PREVIOUS_ELEMENT_SHADOW_VARIABLE = DotName.createSimple(PreviousElementShadowVariable.class.getName()); static final DotName...
No list?
timefold-solver
github_2023
others
954
TimefoldAI
triceo
@@ -1367,6 +1367,121 @@ public class Customer { public void setNextCustomer(Customer nextCustomer) {...} ---- +[#tailChainVariable] +=== Updating tail chains + +The annotation `@CascadingUpdateListener` provides a built-in listener that updates a set of connected elements. +Timefold Solver triggers a user-defin...
The very first example shouldn't be this complicated. Reduce it to the bare minimum code. You can explain the extra features later.
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,206 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import static java.util.stream.Collectors.joining; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.uti...
```suggestion "The entityClass (%s) has an @%s annotated property (%s), but the method \"%s\" cannot be found." ```
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,206 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import static java.util.stream.Collectors.joining; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.uti...
```suggestion The entityClass (%s) has an @%s annotated property (%s), but the shadow variable "%s" cannot be found. ```
timefold-solver
github_2023
java
954
TimefoldAI
triceo
@@ -0,0 +1,171 @@ +package ai.timefold.solver.core.impl.domain.variable.cascade; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore; +import ai.timefold.solver.core.impl.domain.variable.descriptor.GenuineVariableD...
Arguably, if the test can be parameterized, we should be able to do this with 1 test class, not 4, right? The test classes are nearly identical.
timefold-solver
github_2023
others
954
TimefoldAI
triceo
@@ -1367,6 +1367,135 @@ public class Customer { public void setNextCustomer(Customer nextCustomer) {...} ---- +[#tailChainVariable] +=== Updating tail chains + +The annotation `@CascadingUpdateShadowVariable` provides a built-in listener that updates a set of connected elements. +Timefold Solver triggers a user...
```suggestion It calls `updateArrivalTime` whenever a `previousCustomer` or `vehicle` changes. ```
timefold-solver
github_2023
others
954
TimefoldAI
triceo
@@ -1367,6 +1367,135 @@ public class Customer { public void setNextCustomer(Customer nextCustomer) {...} ---- +[#tailChainVariable] +=== Updating tail chains + +The annotation `@CascadingUpdateShadowVariable` provides a built-in listener that updates a set of connected elements. +Timefold Solver triggers a user...
```suggestion stopping when the method results in no change to the variable, or when it reaches the tail. ```
timefold-solver
github_2023
java
987
TimefoldAI
Christopher-Chianelli
@@ -920,6 +907,32 @@ private GeneratedGizmoClasses generateDomainAccessors(Map<String, SolverConfig> } } } + // The ConstraintWeightOverrides field is not annotated, but it needs a member accessor + AnnotationInstance solutionClassInstance = plann...
Python cannot use Quarkus, so this comment is worthless here ```suggestion ```
timefold-solver
github_2023
java
981
TimefoldAI
zepfred
@@ -102,6 +106,9 @@ The constraint (%s) is not in the default package (%s). Constraint packages are deprecated, check your constraint implementation.""" .formatted(constraintRef, getDefaultConstraintPackage())); } + if (workingSolution == null) { // ConstraintVe...
I recommend adding a test case as the existing tests did not catch that.
timefold-solver
github_2023
others
982
TimefoldAI
triceo
@@ -91,15 +91,6 @@ jobs: run: pip install tox build - - name: Quickly build timefold-solver - working-directory: ./timefold-solver - run: mvn -B -Dquickly clean install - - - name: Quickly Build timefold-solver-enterprise - working-directory: ./timefold-solver-enterp...
```suggestion - name: Build Timefold Solver for Python ```
timefold-solver
github_2023
others
982
TimefoldAI
triceo
@@ -20,8 +20,13 @@ jobs: runs-on: ${{matrix.os}} strategy: matrix: - os: [ubuntu-latest, windows-latest] - java-version: [ 17, 21, 22 ] #Latest two LTS + latest non-LTS. + os: [ ubuntu-latest, macos-latest, windows-latest ] + java-version: [ 21 ] # Latest LTS if not Ubuntu +...
Nice, didn't know this was possible.
timefold-solver
github_2023
others
982
TimefoldAI
triceo
@@ -19,7 +19,7 @@ jobs: strategy: matrix: module: ["spring-integration", "quarkus-integration"] - java-version: [ 17, 21, 22 ] #Latest two LTS + latest non-LTS. + java-version: [ 21 ] # Latest LTS
I wonder if it makes sense to do Windows and Mac here too. I could argue that, for _native_, it makes more sense than for the JVM.
timefold-solver
github_2023
others
946
TimefoldAI
lee-carlon
@@ -1,21 +1,139 @@ [#constraintConfiguration] -= Constraint configuration: adjust constraint weights dynamically += Adjusting constraint weights at runtime :doctype: book :sectnums: :icons: font Deciding the correct xref:constraints-and-score/overview.adoc#scoreConstraintWeight[weight] and xref:constraints-and-...
```suggestion The `Vehicle capacity` constraint in this planning solution has a weight of `2hard`, ```
timefold-solver
github_2023
others
946
TimefoldAI
lee-carlon
@@ -1,21 +1,139 @@ [#constraintConfiguration] -= Constraint configuration: adjust constraint weights dynamically += Adjusting constraint weights at runtime :doctype: book :sectnums: :icons: font Deciding the correct xref:constraints-and-score/overview.adoc#scoreConstraintWeight[weight] and xref:constraints-and-...
```suggestion The `Service finished after max end time` constraint has a weight of `0hard`, ```
timefold-solver
github_2023
others
946
TimefoldAI
lee-carlon
@@ -1,21 +1,139 @@ [#constraintConfiguration] -= Constraint configuration: adjust constraint weights dynamically += Adjusting constraint weights at runtime :doctype: book :sectnums: :icons: font Deciding the correct xref:constraints-and-score/overview.adoc#scoreConstraintWeight[weight] and xref:constraints-and-...
```suggestion In this way, you can solve the same problem by applying different constraint weights to each instance. ```
timefold-solver
github_2023
java
946
TimefoldAI
zepfred
@@ -1892,10 +1915,10 @@ default Constraint penalizeBigDecimal(String constraintPackage, String constrain * For non-int {@link Score} types use {@link #penalizeConfigurableLong(String, ToLongTriFunction)} or * {@link #penalizeConfigurableBigDecimal(String, TriFunction)} instead. * - * @deprecated P...
Should we include version `1.13.0` and update other stream classes?
timefold-solver
github_2023
java
946
TimefoldAI
zepfred
@@ -0,0 +1,53 @@ +package ai.timefold.solver.core.impl.domain.solution; + +import java.util.Set; + +import ai.timefold.solver.core.api.domain.common.DomainAccessType; +import ai.timefold.solver.core.api.domain.constraintweight.ConstraintConfiguration; +import ai.timefold.solver.core.api.domain.solution.ConstraintWeight...
Nice refactoring!
timefold-solver
github_2023
java
946
TimefoldAI
zepfred
@@ -237,9 +238,8 @@ public Expression visitExpression(Expression expression, ExecutionContext execut } else if (select.getType().isAssignableFrom(quadConstraintStreamPattern)) { templateCode = "#{any(ai.timefold.solver.core.api.score.stream.quad.QuadConstraintStream...
```suggestion LOGGER.warn("Cannot refactor to asConstraint() method for deprecated method ({}).", method); ```
timefold-solver
github_2023
others
955
TimefoldAI
triceo
@@ -96,6 +96,22 @@ </build> <profiles> + <profile> + <id>non-essential</id>
Can you please explain what purpose this serves exactly? Since the Python stuff apparently doesn't re-build anything, I don't understand why this profile needs to exist. Plus I really don't like having entire modules marked as "non essential".
timefold-solver
github_2023
others
955
TimefoldAI
triceo
@@ -0,0 +1,186 @@ +![Timefold Logo](https://raw.githubusercontent.com/TimefoldAI/timefold-solver/main/docs/src/modules/ROOT/images/shared/timefold-logo.png) + +# Timefold Solver for Python
If the TOML stuff etc. needs to be in the root of the repo, why does the README need to be in a subfolder? And wouldn't it make sense to have one unified README for the entire repo? I doubt that people will click to the "python" subdir to see a Python-specific README; they'll stay at the top level, and only see Jav...
timefold-solver
github_2023
python
955
TimefoldAI
triceo
@@ -15,9 +15,9 @@ class FetchDependencies(build_py): """ def create_stubs(self, project_root, command): subprocess.run([str((project_root / command).absolute()), 'dependency:copy-dependencies'], - cwd=project_root, check=True) + '-Dpython', '-Dquickly', '-D...
This could go into the special Maven profile, no? That way, the config would be shared without having to repeat it.
timefold-solver
github_2023
java
945
TimefoldAI
zepfred
@@ -23,12 +23,8 @@ public long getTimeMillisSpent() { return timeMillisSpent; } - public String getConstraintPackage() {
Should we first deprecate it before removing it?
timefold-solver
github_2023
java
945
TimefoldAI
zepfred
@@ -23,12 +23,8 @@ public long getTimeMillisSpent() { return timeMillisSpent; } - public String getConstraintPackage() { - return constraintRef.packageName(); - } - - public String getConstraintName() {
Same as above
timefold-solver
github_2023
java
945
TimefoldAI
zepfred
@@ -39,13 +35,9 @@ public Score getScoreTotal() { return scoreTotal; } - public String getConstraintId() {
Same as above
timefold-solver
github_2023
java
945
TimefoldAI
zepfred
@@ -942,16 +942,16 @@ public void groupBy_1Mapping1Collector() { // From scratch scoreDirector.setWorkingSolution(solution); assertScore(scoreDirector, - assertMatchWithScore(-1, TEST_CONSTRAINT_NAME, solution.getFirstEntity().toString(), 6), - assertMatchWithSco...
Are we still using the constraint package elsewhere? If not, why not remove it instead of using a `null` value?
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -273,16 +273,12 @@ System.out.println( ((0.01 + 0.02) + 0.03) == (0.01 + (0.02 + 0.03)) ); // retur This leads to __score corruption__. -Decimal numbers (``BigDecimal``) have none of these problems. - -[NOTE] -==== -BigDecimal arithmetic is considerably slower than ``int``, `long` or `double` arithmetic. -In ex...
```suggestion In some cases, it can be worthwhile multiplying _all_ constraint weights by the same power of ten, ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -849,6 +848,14 @@ Finally, we use <<constraintStreamsMappingTuples,mapping>> to calculate the viol For example, if the equipment has a `capacity` of `3`, and the `maximumOverlap` of the `resource` is `5`, then `violationAmount` will be `2`. If the amount is `0`, then the equipment is not being used over its capaci...
```suggestion For example, employees should have a similar number of shifts. ``` We can delete mutually here as similar makes the point :)
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -1217,6 +1224,79 @@ Consider the following naive implementation without `concat`: An employee with no assigned shifts _wouldn't have been penalized_ because no tuples were passed to the `groupBy` building block. +[#constraintStreamsConcatPadding] +==== Padding values + +Consider two constraint streams of differe...
```suggestion Consider two constraint streams of different cardinalities, for instance: ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -1217,6 +1224,79 @@ Consider the following naive implementation without `concat`: An employee with no assigned shifts _wouldn't have been penalized_ because no tuples were passed to the `groupBy` building block. +[#constraintStreamsConcatPadding] +==== Padding values + +Consider two constraint streams of differe...
```suggestion Instead of using `null` default, ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -1217,6 +1224,79 @@ Consider the following naive implementation without `concat`: An employee with no assigned shifts _wouldn't have been penalized_ because no tuples were passed to the `groupBy` building block. +[#constraintStreamsConcatPadding] +==== Padding values + +Consider two constraint streams of differe...
```suggestion This means only the matches that are present in both streams are considered. ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -1217,6 +1224,79 @@ Consider the following naive implementation without `concat`: An employee with no assigned shifts _wouldn't have been penalized_ because no tuples were passed to the `groupBy` building block. +[#constraintStreamsConcatPadding] +==== Padding values + +Consider two constraint streams of differe...
```suggestion To add all the `Employee` instances that do not have any shifts assigned, the `complement` building block is used. It looks at all the `Employee` instances already in the stream, and adds all known `Employee` instances that are not present to the stream. ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion Each task takes a day, but the tasks have different skill requirements. ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion that employee would probably quit and that doesn't help. ``` Or perhaps: that employee would probably quit and that's definitely not fair.
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion This makes schedule C fairer overall. ``` I added overall here to make it clearer that we're not just comparing Ann and Beth, but considering the entire schedule.
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion This is the definition of fairness we use in the remainder of this section. ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion Unfairness is a dimensionless number that measures how fair the solution is. A lower value indicates a fairer solution. ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion If the somewhat worsened performance of a `BigDecimal`-based score calculation is a concern, instead, you may decide to multiply the unfairness value by some power of ten to preserve precision, and only then round it to the nearest integer. This allows you to use the simple integer-based score types. ...
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion Otherwise, the unfairness constraint will dominate the score, ```
timefold-solver
github_2023
others
918
TimefoldAI
lee-carlon
@@ -0,0 +1,205 @@ +[#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...
```suggestion If you take this approach, we recommend that you preserve at least six decimal places of the unfairness value ```
timefold-solver
github_2023
java
918
TimefoldAI
Christopher-Chianelli
@@ -28,7 +28,7 @@ public BavetConcatUniConstraintStream(BavetConstraintFactory<Solution_> constrai @Override public boolean guaranteesDistinct() { - return false; // The two parents could have the same source; guarantee impossible.
Unsure about `concat` class names for the same carnality; maybe do `BavetUniConcatUniConstraintStream` so it has the same format as all the others?
timefold-solver
github_2023
java
918
TimefoldAI
Christopher-Chianelli
@@ -1095,6 +1096,34 @@ public void consecutiveUsage() { assertResult(collector, container, buildConsecutiveUsage()); } + @Override + @Test + public void loadBalance() { + var collector = ConstraintCollectors.<String, Integer, String> loadBalance((a, b) -> a, (a, b) -> b); + var co...
Maybe explain in a comment this is `sqrt((3-2.5)^2 + (2 - 2.5)^2) = sqrt(0.5^2 + 0.5^2) = sqrt(0.25 + 0.25) = sqrt(0.5)`
timefold-solver
github_2023
java
918
TimefoldAI
Christopher-Chianelli
@@ -418,4 +418,366 @@ default void rewards() { */ void rewards(String message); + /** + * Asserts that the {@link Constraint} being tested, given a set of facts, + * results in a specific penalty larger than given. + * <p> + * Ignores the constraint weight: it only asserts the match weig...
I wonder if we should have a `compareToGiven(Facts...).penalizesMore(String?)` Example usage: ```java constraintVerifier.verifyThat(MyConstraintProvider::fairnessConstraint) .given(Shift(Amy), Shift(Amy), Shift(Beth), Shift(Beth)) .compareToGiven(Shift(Amy), Shift(Beth), Shift(Beth), Shift(Beth)) ...
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -56,6 +60,16 @@ static <Score_ extends Score<Score_>> ConstraintAnalysis<Score_> of(ConstraintRe Objects.requireNonNull(score); } + public int matchCount() {
Deserves a Javadoc to explain the exception maybe being thrown.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -156,6 +170,51 @@ public String constraintName() { return constraintRef.constraintName(); } + /** + * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API.
```suggestion * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API. * The string is built fresh every time the method is called. ```
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -156,6 +170,51 @@ public String constraintName() { return constraintRef.constraintName(); } + /** + * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API. + * + * @return never null + */ + public String summarize() { + ...
In new code, we use `var` where possible.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -156,6 +170,51 @@ public String constraintName() { return constraintRef.constraintName(); } + /** + * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API. + * + * @return never null + */ + public String summarize() { + ...
Arguably, for short single-line strings, ```"""``` is unnecessary and more verbose. But careful to maintain the newline at the end.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -156,6 +170,51 @@ public String constraintName() { return constraintRef.constraintName(); } + /** + * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API. + * + * @return never null + */ + public String summarize() { + ...
Dtto.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -156,6 +170,51 @@ public String constraintName() { return constraintRef.constraintName(); } + /** + * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API. + * + * @return never null + */ + public String summarize() { + ...
Dtto.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -156,6 +170,51 @@ public String constraintName() { return constraintRef.constraintName(); } + /** + * Returns a diagnostic text that explains part of the score quality through the {@link ConstraintAnalysis} API. + * + * @return never null + */ + public String summarize() { + ...
Dtto.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -141,4 +145,63 @@ public Collection<ConstraintAnalysis<Score_>> constraintAnalyses() { return constraintMap.values(); } + /** + * Returns a diagnostic text that explains the solution through the {@link ConstraintAnalysis} API to identify which + * constraints cause that score quality.
```suggestion * constraints cause that score quality. * The string is built fresh every time the method is called. ```
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -141,4 +145,63 @@ public Collection<ConstraintAnalysis<Score_>> constraintAnalyses() { return constraintMap.values(); } + /** + * Returns a diagnostic text that explains the solution through the {@link ConstraintAnalysis} API to identify which + * constraints cause that score quality. + ...
One-line string, no need for string literals.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -141,4 +145,63 @@ public Collection<ConstraintAnalysis<Score_>> constraintAnalyses() { return constraintMap.values(); } + /** + * Returns a diagnostic text that explains the solution through the {@link ConstraintAnalysis} API to identify which + * constraints cause that score quality. + ...
Dtto.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -141,4 +145,63 @@ public Collection<ConstraintAnalysis<Score_>> constraintAnalyses() { return constraintMap.values(); } + /** + * Returns a diagnostic text that explains the solution through the {@link ConstraintAnalysis} API to identify which + * constraints cause that score quality. + ...
Dtto.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -141,4 +145,63 @@ public Collection<ConstraintAnalysis<Score_>> constraintAnalyses() { return constraintMap.values(); } + /** + * Returns a diagnostic text that explains the solution through the {@link ConstraintAnalysis} API to identify which + * constraints cause that score quality. + ...
Dtto.
timefold-solver
github_2023
java
923
TimefoldAI
triceo
@@ -53,6 +55,8 @@ public record ScoreAnalysis<Score_ extends Score<Score_>>(Score_ score,
Arguably, `ScoreAnalysis` needs an informative `toString()` too. Something like `Score analysis of score X with Y constraints`.
timefold-solver
github_2023
java
915
TimefoldAI
triceo
@@ -70,6 +70,17 @@ default SolverJobBuilder<Solution_, ProblemId_> withProblem(Solution_ problem) { SolverJobBuilder<Solution_, ProblemId_> withFinalBestSolutionConsumer(Consumer<? super Solution_> finalBestSolutionConsumer); + /** + * Sets the initialized solution consumer, which is called b...
This is not what was agreed, is it? First local search, yes. First custom phase, no. Custom phase may still be initializing. Also, arguably, the definition deserves a better explanation: "Sets the consumer of the first initialized solution. First initialized solution is the solution at the end of the last phase ...
timefold-solver
github_2023
java
915
TimefoldAI
triceo
@@ -275,4 +281,23 @@ public void solvingStarted(SolverScope<Solution_> solverScope) { } } } + + /** + * A listener that consumes the solution from a phase only if the phase initializes the solution. + */ + private final class InitializedSolutionPhaseListener extends PhaseLifecyc...
This seems to proliferate both to the phase, and to the phase scope. Is there any chance how we can only keep it on one of the two? It feels to me like this change touches more places than it needs to; if the information is available on the phase, or if it is available on the scope, why would it also need to be availab...
timefold-solver
github_2023
java
915
TimefoldAI
triceo
@@ -42,6 +44,27 @@ void consumeIntermediateBestSolution(Solution_ bestSolution, BooleanSupplier isE } } + // Called on the Solver thread. + void consumeInitializedSolution(Solution_ initializedSolution) { + if (initializedSolutionConsumer != null) { + // TODO - Do we need to sync...
Why would we need to?
timefold-solver
github_2023
java
915
TimefoldAI
triceo
@@ -42,6 +44,27 @@ void consumeIntermediateBestSolution(Solution_ bestSolution, BooleanSupplier isE } } + // Called on the Solver thread. + void consumeInitializedSolution(Solution_ initializedSolution) { + if (initializedSolutionConsumer != null) { + // TODO - Do we need to sync...
Isn't this a bit over-complicated? Why all the locking? We're calling a simple listener. (Unlike the best solution listener, this will only be called _once_, and therefore doesn't need to worry about triggering while another such event is already being consumed.) I'm not versed in this particular aspect of the code;...
timefold-solver
github_2023
java
915
TimefoldAI
triceo
@@ -77,6 +79,11 @@ public boolean isAssertShadowVariablesAreNotStaleAfterStep() { public abstract String getPhaseTypeString(); + @Override + public boolean isInitializationPhase() {
Arguably this needs a better name. What does it mean to be an "initialization phase"? I'd be more literal here. I'd call this "triggersFirstInitializedSolutionEvent()". Javadoc can then reference the definition of what that event is.
timefold-solver
github_2023
java
915
TimefoldAI
rsynek
@@ -42,12 +47,29 @@ void consumeIntermediateBestSolution(Solution_ bestSolution, BooleanSupplier isE } } + // Called on the Solver thread. + void consumeFirstInitializedSolution(Solution_ firstInitializedSolution) { + try { + // Called on the solver thread + // During ...
Can the following (in theory) happen? 1. here, we acquire the `firstSolutionConsumption` lock 2. now if the init event comes, it waits on https://github.com/TimefoldAI/timefold-solver/pull/915/files#diff-07ca1817df09fb6ca99e48c7070b6e09d9992a9d31e7b02bd821bf62ecf52dedR55 3. the consumer finishes the final best sol...
timefold-solver
github_2023
java
915
TimefoldAI
triceo
@@ -263,6 +264,173 @@ void solveGenerics() throws ExecutionException, InterruptedException { solverJob.getFinalBestSolution(); } + @Test + @Timeout(60) + void solveWithFirstInitializedSolutionConsumer() throws ExecutionException, InterruptedException {
This test is actually several independent tests in one; only CH, CH-LS, etc. Let's split them.
timefold-solver
github_2023
java
898
TimefoldAI
zepfred
@@ -184,28 +180,29 @@ public void removePhaseLifecycleListener(PhaseLifecycleListener<Solution_> phase protected void assertWorkingSolutionInitialized(AbstractPhaseScope<Solution_> phaseScope) { if (!phaseScope.getStartingScore().isSolutionInitialized()) { - InnerScoreDirector<Solution_, ?> s...
The logic looks good, but we should include a test case that covers this behavior.
timefold-solver
github_2023
others
894
TimefoldAI
Christopher-Chianelli
@@ -709,8 +726,8 @@ def print_timetable(time_table: Timetable) -> None: for lesson in lessons if lesson.room is not None and lesson.timeslot is not None } - row_format ="|{:<15}" * (len(rooms) + 1) + "|" - sep_format = "+" + ((("-" * 15) + "+") * (len(rooms) + 1)) + row_format = ("|{:<" ...
Missing the Enum below print_table
timefold-solver
github_2023
others
890
TimefoldAI
rsynek
@@ -558,16 +546,11 @@ There are additional parameters you can supply to your `solverConfig.xml`: <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"> <moveThreadCount>4...
Yep, this parameter has been always "a bit too much". Can we remove/deprecate it?
timefold-solver
github_2023
java
875
TimefoldAI
zepfred
@@ -1010,4 +1011,36 @@ void terminateScheduledSolverJobEarly_returnsInputProblem() throws ExecutionExce assertThat(result).isSameAs(inputProblem); assertThat(solverJob.isTerminatedEarly()).isTrue(); } + + public static class CustomThreadFactory implements ThreadFactory { + private stati...
Nice!
timefold-solver
github_2023
others
867
TimefoldAI
zepfred
@@ -218,6 +218,17 @@ test { } ---- -- +
The `Prerequisites` section does not include Python.