Read solution from XML and use it as initial solution

Hi everybody,

I am impressed by the jsprit results and I would really like to take it further to the next level of problem I am having. Here’s a quick description of a use case:

  • I have a CVRPTW problem (I’m using services as jobs) that gets solved and the solution is stored in XML when done as
        new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml");
  • now, my circumstances change a bit, assume 1 more job needs to be added to the solution. In order not to restart the whole algorithm again from scratch to speed up the process, I’d like to use the old solution from XML file as the initial solution (and not as InitialRoutes because I’m OK if routes change) as:
VrpXMLReader reader = new VrpXMLReader(vrpBuilder, fileSolutions);"output/problem-with-solution.xml");
Service Service.Builder.newInstance(...);

VehicleRoutingProblem problem =;
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(problem).buildAlgorithm();

VehicleRoutingProblemSolution oldSolution = Solutions.bestOf(fileSolutions);
VehicleRoutingProblemSolution initialSolution =
                    new VehicleRoutingProblemSolution(
algorithm.addInitialSolution(oldSolution); //<-- **this is where error happens**

Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();

But I can’t go pass addInitialSolution as I keep on getting following error:

Exception in thread "main" java.lang.IllegalStateException: act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem
. thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that 
 then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem
	at com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm.verifyAndAdaptSolution(
	at com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm.addInitialSolution(
	at net.epilog.atlas.dms.poc.jsprit.ProblemSolver.main(

The problem is that VehicleRoutes are built automatically by the VrpXMLReader :confused: Do I need to implement my own XMLReader to build VehicleRoutes as requested?

I am only interested in first feasible solution, therefore the focus is on finding solution fast.

Thanks in advance!

Powered by Discourse