0

I am solving a variation on vehicle routing problem. The model worked until I implemented a change where certain vehicles and/or stops may remain unassigned because the construction filter does not allow the move due to time window considerations (late arrival not allowed).

The problem size is 2 trucks/3 stops. truck_1 has 2 stops (Stop_1 and Stop_2) assigned to it, and consequently 1 truck and 1 stop remain unassigned since truck_2 will arrive late to Stop_3.

I have the following error:

INFO  o.o.c.i.c.DefaultConstructionHeuristicPhase - Construction Heuristic phase (0) ended: step total (2), time spent (141), best score (-164hard/19387soft).

java.lang.IllegalStateException: Local Search phase started with an uninitialized Solution. First initialize the Solution. For example, run a Construction Heuristic phase first.
    at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.phaseStarted(DefaultLocalSearchPhase.java:119)
    at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:60)
    at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:213)
    at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)

I tried to set the planning variable to null (nullable = true) but it seems it is not allowed in case of chained variables. I am using Optaplanner 6.2.

Please help, Thank you, Piyush

  • 1
    I think you should add the following to clarify your question: How to make assigning stops to a vehicle optional when using a chained variable? A valid assignment could look like the following: `vehicle0 <- stop0 <- stop1` `vehicle1` `unassigned: stop2` – rinde Jan 18 '16 at 09:09

1 Answers1

1

Your construction filter may be too restrictive, it could prevent the construction heuristic from creating an initialized solution. You should remove the time window constraint from the construction filter and add it as a hard score constraint in your score calculator instead.

From the Optaplanner docs:

Instead of implementing a hard constraint, it can sometimes be built in. For example: If Lecture A should never be assigned to Room X, but it uses ValueRangeProvider on Solution, so the Solver will often try to assign it to Room X too (only to find out that it breaks a hard constraint). Use a ValueRangeProvider on the planning entity or filtered selection to define that Course A should only be assigned a Room different than X.

This can give a good performance gain in some use cases, not just because the score calculation is faster, but mainly because most optimization algorithms will spend less time evaluating unfeasible solutions. However, usually this not a good idea because there is a real risk of trading short term benefits for long term harm:

  • Many optimization algorithms rely on the freedom to break hard constraints when changing planning entities, to get out of local optima.
  • Both implementation approaches have limitations (feature compatiblity, disabling automatic performance optimizations, ...), as explained in their documentation.
Community
  • 1
  • 1
rinde
  • 1,181
  • 1
  • 8
  • 20
  • I see. The time window constraint was in the score calculator before (Drools Hard score) and it was set to minimize. I am working on changing it into a hard constraint. Previously, solutions that were not feasible were selected. I will try to find if there is a way to actually limit the score value itself in drools, but otherwise, please suggest another course of action? – Piyush Kumar Jan 14 '16 at 15:43
  • What do you mean by limit the score value itself? Generally, it should be fine for Optaplanner to have intermediate infeasible solutions, just not uninitialized solutions. – rinde Jan 14 '16 at 15:48
  • I meant putting an upper bound on the score value. As far as uninitialized solutions go, it seems reasonable to me that some trucks and/or stops may not be utilized for any reason during the construction phase. Would that not lead to an uninitialized solution anyway? – Piyush Kumar Jan 14 '16 at 16:46
  • _during the construction phase_, yes, but as soon as the construction phase is finished all stops must be assigned to a truck (this means that there may be trucks without any stops). – rinde Jan 14 '16 at 16:51
  • Right, and therein lies my problem. The problem that i am solving may have stops which remain unassigned. – Piyush Kumar Jan 14 '16 at 17:23
  • Ah ok, so perhaps you can create an additional vehicle (called "unassigned") to which you assign unassigned stops? I'm not sure about the performance of this solution but it at least seems to workaround the issue you are having. – rinde Jan 14 '16 at 17:42
  • That is a very good idea indeed. Let me see how that might work. I may upgrade the idea to fantastic later :) – Piyush Kumar Jan 14 '16 at 18:27
  • Perhaps you can also update your question, as it seems that your actual question is quite different from what you wrote. It also allows me to update the answer to what I proposed in the comments, this allows for better readability. – rinde Jan 14 '16 at 18:30
  • It might actually be leading to a corrupted undoMove. I am trying to work it out. – Piyush Kumar Jan 15 '16 at 19:59