java.lang.IllegalStateException: Local Search phase (1) needs to start from an initialized solution, but the planning variable (Visit.previousRouteEvent) is uninitialized for the entity
Initialize the solution by configuring a Construction Heuristic phase before this phase.
at org.optaplanner.core.impl.phase.AbstractPhase.assertWorkingSolutionInitialized(AbstractPhase.java:141)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.phaseStarted(DefaultLocalSearchPhase.java:124)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:66)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:214)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
As a side note, I believe the author of this post was experiencing the same problem.
I debugged the code and the problem seems to be in LocalSearchDecider.decideNextStep:
for (Move move : moveSelector) {
LocalSearchMoveScope moveScope = new LocalSearchMoveScope(stepScope);
moveScope.setMoveIndex(moveIndex);
moveIndex++;
moveScope.setMove(move);
// TODO use Selector filtering to filter out not doable moves
if (!move.isMoveDoable(scoreDirector)) {
logger.trace(" Move index ({}) not doable, ignoring move ({}).", moveScope.getMoveIndex(), move);
} else {
doMove(moveScope);
if (forager.isQuitEarly()) {
break;
}
}
if (termination.isPhaseTerminated(stepScope.getPhaseScope())) {
break;
}
}
<solver>
<solutionClass>RouteSolution</solutionClass>
<entityClass>AbstractRouteEvent</entityClass>
<entityClass>Visit</entityClass>
<scoreDirectorFactory>
<scoreDefinitionType>HARD_SOFT_LONG</scoreDefinitionType>
<scoreDrl>routeScoreRules.drl</scoreDrl>
<initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<termination>
<unimprovedMillisecondsSpentLimit>30000</unimprovedMillisecondsSpentLimit>
</termination>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
<unionMoveSelector>
<changeMoveSelector/>
<swapMoveSelector/>
<subChainChangeMoveSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
</subChainChangeMoveSelector>
<subChainSwapMoveSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
</subChainSwapMoveSelector>
</unionMoveSelector>
<acceptor>
<lateAcceptanceSize>200</lateAcceptanceSize>
</acceptor>
<forager>
<acceptedCountLimit>1</acceptedCountLimit>
</forager>
<termination>
<unimprovedStepCountLimit>100</unimprovedStepCountLimit>
</termination>
</localSearch>
</solver><unionMoveSelector>
<cacheType>STEP</cacheType>
<selectionOrder>SHUFFLED</selectionOrder>
<changeMoveSelector/>
<swapMoveSelector/>
<!-- other selectors --></unionMoveSelector>