S.Richmond
S.Richmond

Reputation: 11558

Local Search phase needs to start from an initialized solution - But how?

I am writing a modified version of the Task Assignment example with my own domain model.

In my model each Task can have a NextTask and a PreviousTask and an Assignee. All 3 are configured as PlanningVariables:

...
/** PreviousTask is a calculated task that the Resource will complete before this one. */
@PlanningVariable(valueRangeProviderRefs = { "tasksRange" }, graphType = PlanningVariableGraphType.CHAINED)
public Task PreviousTask;
@InverseRelationShadowVariable(sourceVariableName = "PreviousTask")
public Task NextTask;
@AnchorShadowVariable(sourceVariableName = "PreviousTask")
public Resource Assignee;

I have been stuck on the Local Search Phase step for some time now as it appears to require an initialized state of my planning variables (Task.PreviousTask in this case).

Error log:

2020-07-16 15:00:15.341  INFO 4616 --- [pool-1-thread-1] o.o.core.impl.solver.DefaultSolver       : Solving started: time spent (65), best score (-27init/[0]hard/[0/0/0/0]soft), environment mode (REPRODUCIBLE), random (JDK with seed 0).
2020-07-16 15:00:15.356  INFO 4616 --- [pool-1-thread-1] .c.i.c.DefaultConstructionHeuristicPhase : Construction Heuristic phase (0) ended: time spent (81), best score (-27init/[0]hard/[0/0/0/0]soft), score calculation speed (90/sec), step total (0).
2020-07-16 15:00:15.376 ERROR 4616 --- [pool-1-thread-1] o.o.c.impl.solver.DefaultSolverManager   : Solving failed for problemId (5e433f57-8c75-4756-8a9c-4c4ca4a83d6d).

java.lang.IllegalStateException: Local Search phase (1) needs to start from an initialized solution, but the planning variable (Task.PreviousTask) is uninitialized for the entity (com.redhat.optaplannersbs.domain.Task@697ea710).
Maybe there is no Construction Heuristic configured before this phase to initialize the solution.

I've been pouring over the documentation and trying to figure out what I've missed or broken between it and the source example but I cannot work it out. I have no Construction Heuristic configured (Same as the example), and I could not see where in the example does it ever set the previousTaskOrEmployee variable before solving.

I could supply a random PreviousTask in the initial solution model, but surely at least 1 of the tasks would have no previous task?

Upvotes: 0

Views: 357

Answers (1)

Radovan Synek
Radovan Synek

Reputation: 1029

May I ask if you have <localSearch/> in your solverConfig.xml? If so, the <constructionHeuristic/> has to be there as well.

If none of these phases (CH nor LS) is configured, both Construction Heuristic and Local Search is added with default parameters. But once the appears in the solverConfig.xml, it's considered an override of the defaults, and a user is supposed to take care of initializing the solution (most often by providing the Construction Heuristic configuration).

Upvotes: 1

Related Questions