-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure the sort manner is applied to the default CH config (#1258)
This pull request corrects a bug that occurs when an entity selector configuration is created without using the sorting settings, particularly when the related entity has a difficulty weight factory defined `@PlanningEntity(difficultyWeightFactoryClass...`. The bug only affects solver configurations that do not define a phase list, as the solver sets the entity selector configuration before inner operations update the heuristic policy configuration. The issue does not affect the value selector config because no config is created by default (`DefaultSolverFactory#buildPhaseList`).
- Loading branch information
Showing
9 changed files
with
200 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...old/solver/core/impl/testdata/domain/difficultyweight/TestdataDifficultyWeightEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ai.timefold.solver.core.impl.testdata.domain.difficultyweight; | ||
|
||
import ai.timefold.solver.core.api.domain.entity.PlanningEntity; | ||
import ai.timefold.solver.core.api.domain.variable.PlanningVariable; | ||
import ai.timefold.solver.core.impl.domain.entity.descriptor.EntityDescriptor; | ||
import ai.timefold.solver.core.impl.domain.variable.descriptor.GenuineVariableDescriptor; | ||
import ai.timefold.solver.core.impl.testdata.domain.TestdataObject; | ||
|
||
@PlanningEntity(difficultyWeightFactoryClass = TestdataDifficultyWeightFactory.class) | ||
public class TestdataDifficultyWeightEntity extends TestdataObject { | ||
|
||
public static EntityDescriptor<TestdataDifficultyWeightSolution> buildEntityDescriptor() { | ||
return TestdataDifficultyWeightSolution.buildSolutionDescriptor() | ||
.findEntityDescriptorOrFail(TestdataDifficultyWeightEntity.class); | ||
} | ||
|
||
public static GenuineVariableDescriptor<TestdataDifficultyWeightSolution> buildVariableDescriptorForValue() { | ||
return buildEntityDescriptor().getGenuineVariableDescriptor("value"); | ||
} | ||
|
||
private TestdataDifficultyWeightValue value; | ||
|
||
public TestdataDifficultyWeightEntity(String code) { | ||
super(code); | ||
} | ||
|
||
public TestdataDifficultyWeightEntity(String code, TestdataDifficultyWeightValue value) { | ||
this(code); | ||
this.value = value; | ||
} | ||
|
||
@PlanningVariable(valueRangeProviderRefs = "valueRange") | ||
public TestdataDifficultyWeightValue getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(TestdataDifficultyWeightValue value) { | ||
this.value = value; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ld/solver/core/impl/testdata/domain/difficultyweight/TestdataDifficultyWeightFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ai.timefold.solver.core.impl.testdata.domain.difficultyweight; | ||
|
||
import ai.timefold.solver.core.impl.heuristic.selector.common.decorator.SelectionSorterWeightFactory; | ||
|
||
public class TestdataDifficultyWeightFactory implements | ||
SelectionSorterWeightFactory<TestdataDifficultyWeightSolution, TestdataDifficultyWeightEntity> { | ||
|
||
@Override | ||
public TestdataDifficultyWeightComparable createSorterWeight(TestdataDifficultyWeightSolution solution, | ||
TestdataDifficultyWeightEntity entity) { | ||
return new TestdataDifficultyWeightComparable(); | ||
} | ||
|
||
public static class TestdataDifficultyWeightComparable implements Comparable<TestdataDifficultyWeightComparable> { | ||
|
||
@Override | ||
public int compareTo(TestdataDifficultyWeightComparable other) { | ||
return 0; | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...d/solver/core/impl/testdata/domain/difficultyweight/TestdataDifficultyWeightSolution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ai.timefold.solver.core.impl.testdata.domain.difficultyweight; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import ai.timefold.solver.core.api.domain.solution.PlanningEntityCollectionProperty; | ||
import ai.timefold.solver.core.api.domain.solution.PlanningScore; | ||
import ai.timefold.solver.core.api.domain.solution.PlanningSolution; | ||
import ai.timefold.solver.core.api.domain.solution.ProblemFactCollectionProperty; | ||
import ai.timefold.solver.core.api.domain.valuerange.ValueRangeProvider; | ||
import ai.timefold.solver.core.api.score.buildin.simple.SimpleScore; | ||
import ai.timefold.solver.core.impl.domain.solution.descriptor.SolutionDescriptor; | ||
import ai.timefold.solver.core.impl.testdata.domain.TestdataObject; | ||
|
||
@PlanningSolution | ||
public class TestdataDifficultyWeightSolution extends TestdataObject { | ||
|
||
public static SolutionDescriptor<TestdataDifficultyWeightSolution> buildSolutionDescriptor() { | ||
return SolutionDescriptor.buildSolutionDescriptor(TestdataDifficultyWeightSolution.class, | ||
TestdataDifficultyWeightEntity.class); | ||
} | ||
|
||
public static TestdataDifficultyWeightSolution generateSolution() { | ||
return generateSolution(5, 7); | ||
} | ||
|
||
public static TestdataDifficultyWeightSolution generateSolution(int valueListSize, int entityListSize) { | ||
TestdataDifficultyWeightSolution solution = new TestdataDifficultyWeightSolution("Generated Solution 0"); | ||
List<TestdataDifficultyWeightValue> valueList = new ArrayList<>(valueListSize); | ||
for (int i = 0; i < valueListSize; i++) { | ||
TestdataDifficultyWeightValue value = new TestdataDifficultyWeightValue("Generated Value " + i); | ||
valueList.add(value); | ||
} | ||
solution.setValueList(valueList); | ||
List<TestdataDifficultyWeightEntity> entityList = new ArrayList<>(entityListSize); | ||
for (int i = 0; i < entityListSize; i++) { | ||
TestdataDifficultyWeightValue value = valueList.get(i % valueListSize); | ||
TestdataDifficultyWeightEntity entity = new TestdataDifficultyWeightEntity("Generated Entity " + i, value); | ||
entityList.add(entity); | ||
} | ||
solution.setEntityList(entityList); | ||
return solution; | ||
} | ||
|
||
private List<TestdataDifficultyWeightValue> valueList; | ||
private List<TestdataDifficultyWeightEntity> entityList; | ||
|
||
private SimpleScore score; | ||
|
||
public TestdataDifficultyWeightSolution(String code) { | ||
super(code); | ||
} | ||
|
||
@ValueRangeProvider(id = "valueRange") | ||
@ProblemFactCollectionProperty | ||
public List<TestdataDifficultyWeightValue> getValueList() { | ||
return valueList; | ||
} | ||
|
||
public void setValueList(List<TestdataDifficultyWeightValue> valueList) { | ||
this.valueList = valueList; | ||
} | ||
|
||
@PlanningEntityCollectionProperty | ||
public List<TestdataDifficultyWeightEntity> getEntityList() { | ||
return entityList; | ||
} | ||
|
||
public void setEntityList(List<TestdataDifficultyWeightEntity> entityList) { | ||
this.entityList = entityList; | ||
} | ||
|
||
@PlanningScore | ||
public SimpleScore getScore() { | ||
return score; | ||
} | ||
|
||
public void setScore(SimpleScore score) { | ||
this.score = score; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...fold/solver/core/impl/testdata/domain/difficultyweight/TestdataDifficultyWeightValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ai.timefold.solver.core.impl.testdata.domain.difficultyweight; | ||
|
||
import ai.timefold.solver.core.impl.testdata.domain.TestdataObject; | ||
|
||
public class TestdataDifficultyWeightValue extends TestdataObject { | ||
|
||
public TestdataDifficultyWeightValue(String code) { | ||
super(code); | ||
} | ||
|
||
} |