Skip to content

Commit 61e0a33

Browse files
authored
fix: fetching outer values before calling inner nodes (#1965)
Companion for TimefoldAI/timefold-solver-enterprise#397
1 parent 5edc6ce commit 61e0a33

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

core/src/main/java/ai/timefold/solver/core/impl/heuristic/selector/move/generic/list/RandomSubListChangeMoveIterator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ class RandomSubListChangeMoveIterator<Solution_> extends UpcomingSelectionIterat
3434

3535
@Override
3636
protected Move<Solution_> createUpcomingSelection() {
37-
if (!subListIterator.hasNext() || !destinationIterator.hasNext()) {
37+
if (!subListIterator.hasNext()) {
3838
return noUpcomingSelection();
3939
}
40-
40+
// The inner node may need the outer iterator to select the next value first
4141
var subList = subListIterator.next();
42+
if (!destinationIterator.hasNext()) {
43+
return noUpcomingSelection();
44+
}
4245
var destination = findUnpinnedDestination(destinationIterator, listVariableDescriptor);
4346
if (destination == null) {
4447
return noUpcomingSelection();

core/src/main/java/ai/timefold/solver/core/impl/heuristic/selector/move/generic/list/kopt/KOptListMoveIterator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ private Move<Solution_> pickTwoOptMove() {
7272
if (!originIterator.hasNext()) {
7373
return NoChangeMove.getInstance();
7474
}
75+
// The inner node may need the outer iterator to select the next value first
76+
Object firstValue = originIterator.next();
7577
@SuppressWarnings("unchecked")
7678
var valueIterator = (Iterator<Node_>) valueSelector.iterator();
7779
if (!valueIterator.hasNext()) {
7880
return NoChangeMove.getInstance();
7981
}
80-
81-
Object firstValue = originIterator.next();
8282
Object secondValue = valueIterator.next();
83-
8483
var firstElementPosition = listVariableStateSupply.getElementPosition(firstValue)
8584
.ensureAssigned();
8685
var secondElementPosition = listVariableStateSupply.getElementPosition(secondValue)

0 commit comments

Comments
 (0)