diff --git a/core/core-impl/src/main/java/ai/timefold/solver/core/impl/solver/FitProcessor.java b/core/core-impl/src/main/java/ai/timefold/solver/core/impl/solver/FitProcessor.java index 7bbe662ed3..a0b103f883 100644 --- a/core/core-impl/src/main/java/ai/timefold/solver/core/impl/solver/FitProcessor.java +++ b/core/core-impl/src/main/java/ai/timefold/solver/core/impl/solver/FitProcessor.java @@ -50,19 +50,21 @@ public List> apply(InnerScoreDirector>(); - var moveIndex = 0L; - for (var move : placement) { - recommendedFitList.add(execute(scoreDirector, move, moveIndex, clonedElement, valueResultFunction)); - moveIndex++; - } - recommendedFitList.sort(null); - return recommendedFitList; + var placementIterator = entityPlacer.iterator(); + if (!placementIterator.hasNext()) { + throw new IllegalStateException(""" + Impossible state: entity placer (%s) has no placements. + """.formatted(entityPlacer)); } - throw new IllegalStateException(""" - Impossible state: entity placer (%s) has no placements. - """.formatted(entityPlacer)); + var placement = placementIterator.next(); + var recommendedFitList = new ArrayList>(); + var moveIndex = 0L; + for (var move : placement) { + recommendedFitList.add(execute(scoreDirector, move, moveIndex, clonedElement, valueResultFunction)); + moveIndex++; + } + recommendedFitList.sort(null); + return recommendedFitList; } finally { entityPlacer.stepEnded(stepScope); entityPlacer.phaseEnded(phaseScope);