Skip to content

Commit

Permalink
fix: only include tail chain move when using a single var (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepfred authored Jul 8, 2024
1 parent d5ed7e1 commit e7fae26
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private UnionMoveSelectorConfig determineDefaultMoveSelectorConfig(HeuristicConf
.withMoveSelectors(new ListChangeMoveSelectorConfig(), new ListSwapMoveSelectorConfig(),
new KOptListMoveSelectorConfig());
} else if (listVariableDescriptor == null) { // We only have basic variables.
if (hasChainedVariable) {
if (hasChainedVariable && basicVariableDescriptorList.size() == 1) {
return new UnionMoveSelectorConfig()
.withMoveSelectors(new ChangeMoveSelectorConfig(), new SwapMoveSelectorConfig(),
new TailChainSwapMoveSelectorConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import ai.timefold.solver.core.impl.testdata.domain.TestdataEntity;
import ai.timefold.solver.core.impl.testdata.domain.TestdataSolution;
import ai.timefold.solver.core.impl.testdata.domain.TestdataValue;
import ai.timefold.solver.core.impl.testdata.domain.chained.TestdataChainedEntity;
import ai.timefold.solver.core.impl.testdata.domain.chained.TestdataChainedSolution;
import ai.timefold.solver.core.impl.testdata.domain.list.TestdataListEntity;
import ai.timefold.solver.core.impl.testdata.domain.list.TestdataListSolution;
import ai.timefold.solver.core.impl.testdata.domain.list.TestdataListValue;
Expand Down Expand Up @@ -244,6 +246,16 @@ void solveListVariable() {
assertThat(solution).isNotNull();
}

@Test
void solveMultiVarChainedVariable() {
var solverConfig = PlannerTestUtils.buildSolverConfig(TestdataChainedSolution.class, TestdataChainedEntity.class);

var solution = TestdataChainedSolution.generateUninitializedSolution(6, 2);

solution = PlannerTestUtils.solve(solverConfig, solution);
assertThat(solution).isNotNull();
}

@Test
void solveListVariableWithExternalizedInverseAndIndexSupplies() {
var solverConfig = PlannerTestUtils.buildSolverConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ai.timefold.solver.core.impl.testdata.domain.chained;

import java.util.List;
import java.util.stream.IntStream;

import ai.timefold.solver.core.api.domain.solution.PlanningEntityCollectionProperty;
import ai.timefold.solver.core.api.domain.solution.PlanningScore;
Expand Down Expand Up @@ -74,4 +75,25 @@ public void setScore(SimpleScore score) {
// Complex methods
// ************************************************************************

public static TestdataChainedSolution generateUninitializedSolution(int valueCount, int entityCount) {
return generateSolution(valueCount, entityCount);
}

private static TestdataChainedSolution generateSolution(int valueCount, int entityCount) {
List<TestdataChainedEntity> entityList = IntStream.range(0, entityCount)
.mapToObj(i -> new TestdataChainedEntity("Generated Entity " + i))
.toList();
List<TestdataChainedAnchor> anchorList = IntStream.range(0, entityCount)
.mapToObj(i -> new TestdataChainedAnchor("Generated Anchor " + i))
.toList();
List<TestdataValue> valueList = IntStream.range(0, valueCount)
.mapToObj(i -> new TestdataValue("Generated Value " + i))
.toList();
TestdataChainedSolution solution = new TestdataChainedSolution();
solution.setChainedEntityList(entityList);
solution.setChainedAnchorList(anchorList);
solution.setUnchainedValueList(valueList);
return solution;
}

}

0 comments on commit e7fae26

Please sign in to comment.