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);
reader.read("output/problem-with-solution.xml");
Service Service.Builder.newInstance(...).....build();
vrpBuilder.addJob(newService);

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

VehicleRoutingProblemSolution oldSolution = Solutions.bestOf(fileSolutions);
VehicleRoutingProblemSolution initialSolution =
                    new VehicleRoutingProblemSolution(
                            oldSolution.getRoutes(),
                            Collections.singleton(newService),
                            Double.MAX_VALUE
                    );
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 
 VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() 
 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(VehicleRoutingAlgorithm.java:165)
	at com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm.addInitialSolution(VehicleRoutingAlgorithm.java:149)
	at net.epilog.atlas.dms.poc.jsprit.ProblemSolver.main(ProblemSolver.java:572)

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!