Reading all shipments from a intial solution?

Hello,

i want to add initial jobs (shipments), thus need to be served and should not be re-assigned, to the vrpbuilder. I found a way, but it works only for one initial shipment. Having two or more initial shipments, i am doing it probably wrong with my current solution.

The xml-File from the initial solution contains two shipments. So i guess, this should not be the problem.

I found a example (iii) to read initial services:

private static Service getService(String serviceId, Builder vrpBuilder) {
        for (Job j : vrpBuilder.getAddedJobs()) {
            if (j.getId().equals(serviceId)) {
                return (Service) j;
            }
        }
        return null;
}

But doing it this way, i only get the most recent shipment and not all shipments.

Is there a other way to get all shipments from the initial solution?

I am using jsprit 1.6.2.

Thank You,
Snoopy

Hi Snoopy,

First of all, in jsprit, initial solution and initial route are two different things and apparently you are referring to the latter.

One thing you need to note about the initial route is that it imposes the sequence of the activities as you define them. For example, if you define the initial route as follows, the sequence of (1) the pickup of shipment 1, (2) the pickup of shipment 2, (3) the delivery of shipment 2, and (4) the delivery of shipment 1 will not change in the solution. This is because the jobs in the initial routes will not be ruined in the solving process.

Now back to your question about reading initial shipments.

  1. The method initialShipmentIds returns an ArrayList of ids of all the jobs in the vrp builder. If the vrp builder contains not only shipments and you want it to return ids of only shipments, you will need to add an if clause like if (j instanceof Shipment) in the for loop.

  2. What do you do with the returned ArrayList shipmentIds? Before knowing this, it would be difficult to understand why you only get the most recent shipment.

Best regards,
He

Hi jie31best,

thanks for your answer!

How adding initial routes works, should be what i am searching for. Imposing the sequence of the activites from the initial route is fine for my problem.

to 1)
I guess, the vrp builder should only contain shipments, because i am only working with shipments (no services).

to 2)
After getting the shipment ids from the initial solution, i add them to the vrpBuilder:

With reading the xml-file from this initial solution, initialShipmentIds contains only the id “1002”.:

I dont know, why number of shipments/jobs is 1 and not 2. Maybe this is another problem?

Thank You,
Snoopy

Can you log initialShipmentIds and see what ids are in it?

Also how many warnings do the addInitialShipmentsToVehicleRoutingProblem method throw?

The number of jobs (noJobs) in the solution printout shows that there is only 1 job which is in the vrp and not in the initial routes (i.e., the jobs in the initial routes will not be counted in noJobs).

The number of vehicles (noVehicles) in the solution printout shows that there is only 1 vehicle in the vrp, thus I suspect that the addInitialShipmentsToVehicleRoutingProblem method only successfully add 1 initial route to the vrp, which uses the vehicle t0 and adds the first job in the initialShipmentIds list.

Best regards,
He

Hi,

initialShipmentIds contains only the id “1002” after reading the xml-file from the initial solution (output like shown before). I also tried to manually set shipmentId to “1000” at this point but it returns null.

I used the debugger, to check the vrpBuilder.

At this point It has under “initialRoutes”->“VehicleRoute”->“touractivities”->“jobs” a shipment with the id “1000”- but somehow i don´t get a job with id “1000”. So i can´t add it to initialRoute_withShipments.

java.lang.IllegalStateException: cannot lock vehicle twice t0

Thank You,
Snoopy

Apparently vrpBuilder.getAddedJobs() does not contain a job whose id is “1000”.

The error means that you have more than one initial routes that uses the same vehicle t0, which is not allowed.

Hi,

thanks for your answer!

Reading the xml-File with the initial solutions does not work for me, but i tried a different way.

I changed two things and it seems to work:

(a) shipments are now added to the routeBuilder in correct order.
(b) add the initialRoute to a Collection for VehicleRoutes and add this collection to the vrpBuilder.

Greetz,
Snoopy