Initial solution or initialRoute. Both Not Useful

Perhaps there is a disconnect.

Initially there are some Vehicles, some Shipments and the costMatrix.
We solve the vehicle routing problem and get the solution.

Now, if one newShipment comes. then instead of solving complete vehicleRoutingProblem (some Vehicle, some Shipments + 1 new Shipment, the new CostMatrix), I am solving:
VehicleRoutingProblem which consists of shipments of vehicleRoute and one Shipment and using oldRoute as my initial solution.

This is done for all the oldRoutes.

Finally, which routes has least cost increment is outputted.

This method may not provide the optimal solution but it is rather time efficient than solving complete VehicleRoutingProblem in one go.

Okay. Sorry for the confusion.

I understand what you are trying to do here.

Just to double check, whenever you try to solve the “one route + new shipment” vrp with initial solution, you have made sure that the jobs in the vrp and those in the initial solution (including those in the one route and the new shioment in the unassigned jobs list) are the same, right?

Moreover, have you tried solving the “one route + new shipment” vrp WITHOUT using initial solution?

Yes, that works. But in this case, we are not utilizing the oldRoute information using which may result in faster solution.

Just one point:
new VehicleRoutingProblemSolution(Collections.singleton(route), Collections.singleton(shipment), Double.MAX_VALUE);
the Collections.singleton(route) does not contain the newShipment.

Understood.

Have you tried with a more appropriate cost for the initial solution instead of Double.MAX_VALUE?

Maybe something like costOfTheRoute + maxCosts * 2 * (4 - shipment.getPriority()), where costOfTheRoute is the cost of the route which is calculated in the same way as in the objective function (does a = getCost(route); calculate it?), and check Jsprit class to see how maxCosts is calculated.

Yes, It calculate the total distance of the route.
I have changed the cost to 20*a;

It again shows:
java.lang.ArrayIndexOutOfBoundsException

hmm, could you send me the route and the new shipment which throws the error? I haven’t been able to reproduce the error.

The error is thrown in the very first iteration(as I am iterating over all the older VehicleRoute), if I use addInitialSolution method
Problem starts during the .searchSolution.

Surprisingly, even I did not get any error but in that case my problem size was very small.

Hi jie31best,

I have tackled the problem.
Thats how I did:
Created tsp(vehicle Routing Problem) added all jobs (shipments) and vehicles(one vehicle).

then Created new VehicleRouteBuilder and added .setJobActivityFactory(tsp.getJobActivityFactory())
and then added the shipments to the vehicleRouteBuilder.

Used this VehicleRouteBuilder.build() to feed in the initial solution which is required during algorithm.
Things are running correctly.

1 Like

Cool.

Have you figured out what caused the error?

I guess, VehicleRoutingProblem defines some sort of indexing on jobs. Directly using solution of one vehicleRoutingProblem and feeding it into other VehicleRoutingProblem may cause error.
That is why I did not directly use the route of older problem and directly feed it into new problem as initial solution. I created vehicleRouteBuilder and add the getJobActivityFactory() of new VehicleRoutingProblem which has all jobs(Jobs of old route and newJob) and then added all jobs of old VehicleRoutingProblem (which did not have newJob) to VehicleRouteBuilder.

1 Like