-
Notifications
You must be signed in to change notification settings - Fork 188
fix: restore support for null values in sortable value ranges #2239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+304
−5
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...r/core/testdomain/list/unassignedvar/sort/TestdataAllowsUnassignedListSortableEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package ai.timefold.solver.core.testdomain.list.unassignedvar.sort; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import ai.timefold.solver.core.api.domain.entity.PlanningEntity; | ||
| import ai.timefold.solver.core.api.domain.variable.PlanningListVariable; | ||
| import ai.timefold.solver.core.testdomain.TestdataObject; | ||
| import ai.timefold.solver.core.testdomain.common.TestSortableComparator; | ||
| import ai.timefold.solver.core.testdomain.common.TestdataSortableValue; | ||
|
|
||
| @PlanningEntity | ||
| public class TestdataAllowsUnassignedListSortableEntity extends TestdataObject { | ||
|
|
||
| @PlanningListVariable(allowsUnassignedValues = true, valueRangeProviderRefs = "valueRange", | ||
| comparatorClass = TestSortableComparator.class) | ||
| private List<TestdataSortableValue> valueList; | ||
|
|
||
| public TestdataAllowsUnassignedListSortableEntity() { | ||
| } | ||
|
|
||
| public TestdataAllowsUnassignedListSortableEntity(String code) { | ||
| super(code); | ||
| this.valueList = new ArrayList<>(); | ||
| } | ||
|
|
||
| public List<TestdataSortableValue> getValueList() { | ||
| return valueList; | ||
| } | ||
|
|
||
| public void setValueList(List<TestdataSortableValue> valueList) { | ||
| this.valueList = valueList; | ||
| } | ||
|
|
||
| } |
84 changes: 84 additions & 0 deletions
84
...core/testdomain/list/unassignedvar/sort/TestdataAllowsUnassignedListSortableSolution.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package ai.timefold.solver.core.testdomain.list.unassignedvar.sort; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| 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.hardsoft.HardSoftScore; | ||
| import ai.timefold.solver.core.impl.domain.solution.descriptor.SolutionDescriptor; | ||
| import ai.timefold.solver.core.testdomain.common.TestdataSortableValue; | ||
|
|
||
| @PlanningSolution | ||
| public class TestdataAllowsUnassignedListSortableSolution { | ||
|
|
||
| public static SolutionDescriptor<TestdataAllowsUnassignedListSortableSolution> buildSolutionDescriptor() { | ||
| return SolutionDescriptor.buildSolutionDescriptor( | ||
| TestdataAllowsUnassignedListSortableSolution.class, | ||
| TestdataAllowsUnassignedListSortableEntity.class, | ||
| TestdataSortableValue.class); | ||
| } | ||
|
|
||
| public static TestdataAllowsUnassignedListSortableSolution generateSolution(int valueCount, int entityCount, | ||
| boolean shuffle) { | ||
| var entityList = new ArrayList<>(IntStream.range(0, entityCount) | ||
| .mapToObj(i -> new TestdataAllowsUnassignedListSortableEntity("Generated Entity " + i)) | ||
| .toList()); | ||
| var valueList = new ArrayList<>(IntStream.range(0, valueCount) | ||
| .mapToObj(i -> new TestdataSortableValue("Generated Value " + i, i)) | ||
| .toList()); | ||
| if (shuffle) { | ||
| var random = new Random(0); | ||
| Collections.shuffle(entityList, random); | ||
| Collections.shuffle(valueList, random); | ||
| } | ||
| TestdataAllowsUnassignedListSortableSolution solution = new TestdataAllowsUnassignedListSortableSolution(); | ||
| solution.setValueList(valueList); | ||
| solution.setEntityList(entityList); | ||
| return solution; | ||
| } | ||
|
|
||
| private List<TestdataSortableValue> valueList; | ||
| private List<TestdataAllowsUnassignedListSortableEntity> entityList; | ||
| private HardSoftScore score; | ||
|
|
||
| @ValueRangeProvider(id = "valueRange") | ||
| @ProblemFactCollectionProperty | ||
| public List<TestdataSortableValue> getValueList() { | ||
| return valueList; | ||
| } | ||
|
|
||
| public void setValueList(List<TestdataSortableValue> valueList) { | ||
| this.valueList = valueList; | ||
| } | ||
|
|
||
| @PlanningEntityCollectionProperty | ||
| public List<TestdataAllowsUnassignedListSortableEntity> getEntityList() { | ||
| return entityList; | ||
| } | ||
|
|
||
| public void setEntityList(List<TestdataAllowsUnassignedListSortableEntity> entityList) { | ||
| this.entityList = entityList; | ||
| } | ||
|
|
||
| @PlanningScore | ||
| public HardSoftScore getScore() { | ||
| return score; | ||
| } | ||
|
|
||
| public void setScore(HardSoftScore score) { | ||
| this.score = score; | ||
| } | ||
|
|
||
| public void removeEntity(TestdataAllowsUnassignedListSortableEntity entity) { | ||
| this.entityList = entityList.stream() | ||
| .filter(e -> e != entity) | ||
| .toList(); | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
...old/solver/core/testdomain/unassignedvar/sort/TestdataAllowsUnassignedSortableEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ai.timefold.solver.core.testdomain.unassignedvar.sort; | ||
|
|
||
| import ai.timefold.solver.core.api.domain.entity.PlanningEntity; | ||
| import ai.timefold.solver.core.api.domain.variable.PlanningVariable; | ||
| import ai.timefold.solver.core.testdomain.TestdataObject; | ||
| import ai.timefold.solver.core.testdomain.common.TestSortableComparator; | ||
| import ai.timefold.solver.core.testdomain.common.TestdataSortableValue; | ||
|
|
||
| @PlanningEntity | ||
| public class TestdataAllowsUnassignedSortableEntity extends TestdataObject { | ||
|
|
||
| @PlanningVariable(allowsUnassigned = true, valueRangeProviderRefs = "valueRange", | ||
| comparatorClass = TestSortableComparator.class) | ||
| private TestdataSortableValue value; | ||
|
|
||
| public TestdataAllowsUnassignedSortableEntity() { | ||
| } | ||
|
|
||
| public TestdataAllowsUnassignedSortableEntity(String code) { | ||
| super(code); | ||
| } | ||
|
|
||
| public TestdataSortableValue getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| public void setValue(TestdataSortableValue value) { | ||
| this.value = value; | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
...d/solver/core/testdomain/unassignedvar/sort/TestdataAllowsUnassignedSortableSolution.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package ai.timefold.solver.core.testdomain.unassignedvar.sort; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Random; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| 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.hardsoft.HardSoftScore; | ||
| import ai.timefold.solver.core.impl.domain.solution.descriptor.SolutionDescriptor; | ||
| import ai.timefold.solver.core.testdomain.common.TestdataSortableValue; | ||
|
|
||
| @PlanningSolution | ||
| public class TestdataAllowsUnassignedSortableSolution { | ||
|
|
||
| public static SolutionDescriptor<TestdataAllowsUnassignedSortableSolution> buildSolutionDescriptor() { | ||
| return SolutionDescriptor.buildSolutionDescriptor( | ||
| TestdataAllowsUnassignedSortableSolution.class, | ||
| TestdataAllowsUnassignedSortableEntity.class, | ||
| TestdataSortableValue.class); | ||
| } | ||
|
|
||
| public static TestdataAllowsUnassignedSortableSolution generateSolution(int valueCount, int entityCount, | ||
| boolean shuffle) { | ||
| var entityList = new ArrayList<>(IntStream.range(0, entityCount) | ||
| .mapToObj(i -> new TestdataAllowsUnassignedSortableEntity("Generated Entity " + i)) | ||
| .toList()); | ||
| var valueList = new ArrayList<>(IntStream.range(0, valueCount) | ||
| .mapToObj(i -> new TestdataSortableValue("Generated Value " + i, i)) | ||
| .toList()); | ||
| if (shuffle) { | ||
| var random = new Random(0); | ||
| Collections.shuffle(entityList, random); | ||
| Collections.shuffle(valueList, random); | ||
| } | ||
| TestdataAllowsUnassignedSortableSolution solution = new TestdataAllowsUnassignedSortableSolution(); | ||
| solution.setValueList(valueList); | ||
| solution.setEntityList(entityList); | ||
| return solution; | ||
| } | ||
|
|
||
| private List<TestdataSortableValue> valueList; | ||
| private List<TestdataAllowsUnassignedSortableEntity> entityList; | ||
| private HardSoftScore score; | ||
|
|
||
| @ValueRangeProvider(id = "valueRange") | ||
| @ProblemFactCollectionProperty | ||
| public List<TestdataSortableValue> getValueList() { | ||
| return valueList; | ||
| } | ||
|
|
||
| public void setValueList(List<TestdataSortableValue> valueList) { | ||
| this.valueList = valueList; | ||
| } | ||
|
|
||
| @PlanningEntityCollectionProperty | ||
| public List<TestdataAllowsUnassignedSortableEntity> getEntityList() { | ||
| return entityList; | ||
| } | ||
|
|
||
| public void setEntityList(List<TestdataAllowsUnassignedSortableEntity> entityList) { | ||
| this.entityList = entityList; | ||
| } | ||
|
|
||
| @PlanningScore | ||
| public HardSoftScore getScore() { | ||
| return score; | ||
| } | ||
|
|
||
| public void setScore(HardSoftScore score) { | ||
| this.score = score; | ||
| } | ||
|
|
||
| public void removeEntity(TestdataAllowsUnassignedSortableEntity entity) { | ||
| this.entityList = entityList.stream() | ||
| .filter(e -> e != entity) | ||
| .toList(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.