diff --git a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/constructionheuristic/placer/QueuedEntityPlacer.java b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/constructionheuristic/placer/QueuedEntityPlacer.java index 311dca8403f..d3a8d3f21bd 100644 --- a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/constructionheuristic/placer/QueuedEntityPlacer.java +++ b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/constructionheuristic/placer/QueuedEntityPlacer.java @@ -27,6 +27,8 @@ import org.optaplanner.core.impl.heuristic.selector.common.iterator.UpcomingSelectionIterator; import org.optaplanner.core.impl.heuristic.selector.entity.EntitySelector; import org.optaplanner.core.impl.heuristic.selector.move.MoveSelector; +import org.optaplanner.core.impl.heuristic.selector.move.generic.ChangeMoveSelector; +import org.optaplanner.core.impl.heuristic.selector.move.generic.SwapMoveSelector; public class QueuedEntityPlacer extends AbstractEntityPlacer implements EntityPlacer { @@ -71,8 +73,17 @@ protected Placement createUpcomingSelection() { entityIterator.next(); moveSelectorIterator = moveSelectorList.iterator(); } - MoveSelector moveSelector = moveSelectorIterator.next(); - moveIterator = moveSelector.iterator(); + + // See https://issues.redhat.com/browse/PLANNER-2933 + Object moveSelector = moveSelectorIterator.next(); + + if (moveSelector instanceof SwapMoveSelector) { + moveIterator = ((SwapMoveSelector) moveSelector).iterator(); + } else if (moveSelector instanceof ChangeMoveSelector) { + moveIterator = ((ChangeMoveSelector) moveSelector).iterator(); + } else if (moveSelector instanceof MoveSelector) { + moveIterator = ((MoveSelector) moveSelector).iterator(); + } } return new Placement<>(moveIterator); } diff --git a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/valuerange/descriptor/AbstractFromPropertyValueRangeDescriptor.java b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/valuerange/descriptor/AbstractFromPropertyValueRangeDescriptor.java index c2083c99a8a..e3e9fd37a77 100644 --- a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/valuerange/descriptor/AbstractFromPropertyValueRangeDescriptor.java +++ b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/valuerange/descriptor/AbstractFromPropertyValueRangeDescriptor.java @@ -162,7 +162,7 @@ private List transformCollectionToList(Collection collection) { // - If only ValueRange.createOriginalIterator() is used, cloning a Set to a List is a waste of time. // - If the List is a LinkedList, ValueRange.createRandomIterator(Random) // and ValueRange.get(int) are not efficient. - return (collection instanceof List ? (List) collection : new ArrayList<>(collection)); + return new ArrayList<>(collection); } } diff --git a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/variable/listener/support/NotifiableRegistry.java b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/variable/listener/support/NotifiableRegistry.java index 7b2d3b62ad4..1851c4c48e1 100644 --- a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/variable/listener/support/NotifiableRegistry.java +++ b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/domain/variable/listener/support/NotifiableRegistry.java @@ -80,9 +80,10 @@ Collection> get(EntityDescriptor entityDescriptor return sourceEntityToNotifiableMap.get(entityDescriptor); } - Collection> get(VariableDescriptor variableDescriptor) { - return sourceVariableToNotifiableMap.getOrDefault(variableDescriptor, - Collections.emptyList()); // Avoids null for chained swap move on an unchained var. + ArrayList> get(VariableDescriptor variableDescriptor) { + return (ArrayList>) sourceVariableToNotifiableMap.getOrDefault( + variableDescriptor, + new ArrayList<>()); // Avoids null for chained swap move on an unchained var. } Collection> get(ListVariableDescriptor variableDescriptor) { diff --git a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/heuristic/selector/move/composite/UniformRandomUnionMoveIterator.java b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/heuristic/selector/move/composite/UniformRandomUnionMoveIterator.java index 3ec128c845b..c8bb0a71306 100644 --- a/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/heuristic/selector/move/composite/UniformRandomUnionMoveIterator.java +++ b/core/optaplanner-core-impl/src/main/java/org/optaplanner/core/impl/heuristic/selector/move/composite/UniformRandomUnionMoveIterator.java @@ -19,14 +19,16 @@ package org.optaplanner.core.impl.heuristic.selector.move.composite; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Random; -import java.util.stream.Collectors; import org.optaplanner.core.impl.heuristic.move.Move; import org.optaplanner.core.impl.heuristic.selector.common.iterator.SelectionIterator; import org.optaplanner.core.impl.heuristic.selector.move.MoveSelector; +import org.optaplanner.core.impl.heuristic.selector.move.generic.ChangeMoveSelector; +import org.optaplanner.core.impl.heuristic.selector.move.generic.SwapMoveSelector; final class UniformRandomUnionMoveIterator extends SelectionIterator> { @@ -34,10 +36,23 @@ final class UniformRandomUnionMoveIterator extends SelectionIterator< private final Random workingRandom; public UniformRandomUnionMoveIterator(List> childMoveSelectorList, Random workingRandom) { - this.moveIteratorList = childMoveSelectorList.stream() - .map(Iterable::iterator) - .filter(Iterator::hasNext) - .collect(Collectors.toList()); + ArrayList>> list = new ArrayList<>(); + + // See https://issues.redhat.com/browse/PLANNER-2933 + Iterator iterator; + for (Object s : childMoveSelectorList) { + if (s instanceof SwapMoveSelector) { + iterator = ((SwapMoveSelector) s).iterator(); + } else if (s instanceof ChangeMoveSelector) { + iterator = ((ChangeMoveSelector) s).iterator(); + } else { + iterator = ((MoveSelector) s).iterator(); + } + if (iterator.hasNext()) { + list.add(iterator); + } + } + this.moveIteratorList = list; this.workingRandom = workingRandom; } @@ -56,5 +71,4 @@ public Move next() { } return next; } - }