java example for vrp with time window and service time

242 views
Skip to first unread message

ajdab...@gmail.com

unread,
Sep 8, 2016, 7:58:23 AM9/8/16
to or-tools-discuss
hi 

I am currently working on VRP with time window & service time. Basically there are number of jobs and vehicles. Jobs have to be completed in a given time window and has expected time duration for completion. All vehicles start from depot.

I was reading through the documents for or-tool and found  https://developers.google.com/optimization/routing/tsp/vehicle_routing_time_windows in c++

Is there corresponding java example? 


Driss Lahlou

unread,
Sep 8, 2016, 8:21:48 AM9/8/16
to or-tools...@googlegroups.com
Hello,

There is a CapacitatedVehicleRoutingProblemWithTimeWindows.java example. You can get rid of the capacity dimension if you don't need it. 

I hope this helps.

Regards,

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

driss

ajdab...@gmail.com

unread,
Sep 8, 2016, 8:49:31 AM9/8/16
to or-tools-discuss
I looked at  the example & did remove capacity dimension but it looks like starting and ending locates for each vehicle are random for each iteration. Also does not have service time considered for each job.

May be i m not understanding the code. Vehicle does not seem to go to job locations at all just some random points. 





On Thursday, September 8, 2016 at 7:21:48 AM UTC-5, Driss Lahlou wrote:
Hello,

There is a CapacitatedVehicleRoutingProblemWithTimeWindows.java example. You can get rid of the capacity dimension if you don't need it. 

I hope this helps.

Regards,
On Thu, Sep 8, 2016 at 1:58 PM, <ajdab...@gmail.com> wrote:
hi 

I am currently working on VRP with time window & service time. Basically there are number of jobs and vehicles. Jobs have to be completed in a given time window and has expected time duration for completion. All vehicles start from depot.

I was reading through the documents for or-tool and found  https://developers.google.com/optimization/routing/tsp/vehicle_routing_time_windows in c++

Is there corresponding java example? 


--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

driss

Driss Lahlou

unread,
Sep 8, 2016, 9:36:26 AM9/8/16
to or-tools...@googlegroups.com
To set the start and end depots of vehicles, you should change this code. This means that you need to fill the "vehicleStarts" and "vehicleEnds" arrays with the start and end indices of each vehicle, and add their real location to the "locations" variable (we are using random locations in the example).
If you want to calculate the distances based on the location, you can modify this callback depending on your rules, or you can return values from some pre-calculated distance matrix if you have it.

Service time can be added to the transportation time, so for a given client, the transit variable of the time dimension will be the sum of transportation and service times.

I hope this helps.


To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

driss

ajdab...@gmail.com

unread,
Sep 8, 2016, 5:07:56 PM9/8/16
to or-tools-discuss
Thanks for info.

I changed 

 private void buildFleet(int numberOfVehicles,

                          int xMax, int yMax,

                          int endTime,

                          int capacity,

                          int costCoefficientMax) {

    logger.info("Building fleet.");

    vehicleStarts = new int[numberOfVehicles];

    vehicleEnds = new int[numberOfVehicles];

    for (int vehicle = 0; vehicle < numberOfVehicles; ++vehicle) {

      vehicleStarts[vehicle] = locations.size();


      //all vehicles start from deopt and should come back in 8 hrs


      Double lat = {real lat}  *10000000;

      Double lon = {real long} *10000000;

      locations.add(Pair.of(lat.intValue(),lon.intValue()));

      vehicleEnds[vehicle] = locations.size();

      locations.add(Pair.of(lat.intValue(),lon.intValue()));

      vehicleEndTime.add(endTime);

      vehicleCostCoefficients.add(randomGenerator.nextInt(costCoefficientMax) + 1);

      

    }

  }



Also i changed my order window as following. Basically i have two windows 8 to 1 and 1 to 6. ( 300 is 5 hrs in minutes) 

orderTimeWindows.add(Pair.of(window,window+300));


For orders also i am using actual lat and long.


Removed capacity.


For some reason all the orders are dropped  & i see following on screen

======================================================

:Assignment(time0 (480..780) | time1 (780..1080) | time2 (480..780) | time3 (480..780) | time4 (480..780) | time5 (780..1080) | time6 (480..780) | time7 (780..1080) | time8 (480..780) | time9 (480..780) | time10 (480..780) | time11 (480..780) | time12 (780..1080) | time13 (780..1080) | time14 (480..780) | time15 (480..780) | time16 (480..780) | time17 (780..1080) | time18 (780..1080) | time19 (780..1080) | time20 (480..780) | time21 (780..1080) | time22 (480..780) | time23 (780..1080) | time24 (480..780) | time25 (780..1080) | time26 (480..780) | time27 (480..780) | time28 (780..1080) | time29 (480..780) | time30 (780..1080) | time31 (0..1440) | time32 (0..1440) | time33 (0..1440) | time34 (0..1440) | time35 (0..1440) | time36 (0..1440) | time37 (0..1440) | time38 (0..1440) | time39 (0..1440) | time40 (0..1440) | time41 (0..1440) | time42 (0..1440) | time43 (0..1440) | time44 (0..1440) | time45 (0..1440) | time46 (0..1440) | time47 (0..1440) | time48 (0..1440) | time49 (0..1440) | time50 (0..1440) | time51 (0..1440) | time52 (0..1440) | time53 (0..1440) | time54 (0..1440) | time55 (0..1440) | time56 (0..1440) | time57 (0..1440) | time58 (0..1440) | time59 (0..1440) | time60 (0..1440) | time61 (0..1440) | time62 (0..1440) | time63 (0..1440) | time64 (0..1440) | Nexts0 (0) | Nexts1 (1) | Nexts2 (2) | Nexts3 (3) | Nexts4 (4) | Nexts5 (5) | Nexts6 (6) | Nexts7 (7) | Nexts8 (8) | Nexts9 (9) | Nexts10 (10) | Nexts11 (11) | Nexts12 (12) | Nexts13 (13) | Nexts14 (14) | Nexts15 (15) | Nexts16 (16) | Nexts17 (17) | Nexts18 (18) | Nexts19 (19) | Nexts20 (20) | Nexts21 (21) | Nexts22 (22) | Nexts23 (23) | Nexts24 (24) | Nexts25 (25) | Nexts26 (26) | Nexts27 (27) | Nexts28 (28) | Nexts29 (29) | Nexts30 (30) | Nexts31 (48) | Nexts32 (49) | Nexts33 (50) | Nexts34 (51) | Nexts35 (52) | Nexts36 (53) | Nexts37 (54) | Nexts38 (55) | Nexts39 (56) | Nexts40 (57) | Nexts41 (58) | Nexts42 (59) | Nexts43 (60) | Nexts44 (61) | Nexts45 (62) | Nexts46 (63) | Nexts47 (64) | Active0 (0) | Active1 (0) | Active2 (0) | Active3 (0) | Active4 (0) | Active5 (0) | Active6 (0) | Active7 (0) | Active8 (0) | Active9 (0) | Active10 (0) | Active11 (0) | Active12 (0) | Active13 (0) | Active14 (0) | Active15 (0) | Active16 (0) | Active17 (0) | Active18 (0) | Active19 (0) | Active20 (0) | Active21 (0) | Active22 (0) | Active23 (0) | Active24 (0) | Active25 (0) | Active26 (0) | Active27 (0) | Active28 (0) | Active29 (0) | Active30 (0) | Active31 (1) | Active32 (1) | Active33 (1) | Active34 (1) | Active35 (1) | Active36 (1) | Active37 (1) | Active38 (1) | Active39 (1) | Active40 (1) | Active41 (1) | Active42 (1) | Active43 (1) | Active44 (1) | Active45 (1) | Active46 (1) | Active47 (1) | Vehicles0 (-1) | Vehicles1 (-1) | Vehicles2 (-1) | Vehicles3 (-1) | Vehicles4 (-1) | Vehicles5 (-1) | Vehicles6 (-1) | Vehicles7 (-1) | Vehicles8 (-1) | Vehicles9 (-1) | Vehicles10 (-1) | Vehicles11 (-1) | Vehicles12 (-1) | Vehicles13 (-1) | Vehicles14 (-1) | Vehicles15 (-1) | Vehicles16 (-1) | Vehicles17 (-1) | Vehicles18 (-1) | Vehicles19 (-1) | Vehicles20 (-1) | Vehicles21 (-1) | Vehicles22 (-1) | Vehicles23 (-1) | Vehicles24 (-1) | Vehicles25 (-1) | Vehicles26 (-1) | Vehicles27 (-1) | Vehicles28 (-1) | Vehicles29 (-1) | Vehicles30 (-1) | Vehicles31 (0) | Vehicles32 (1) | Vehicles33 (2) | Vehicles34 (3) | Vehicles35 (4) | Vehicles36 (5) | Vehicles37 (6) | Vehicles38 (7) | Vehicles39 (8) | Vehicles40 (9) | Vehicles41 (10) | Vehicles42 (11) | Vehicles43 (12) | Vehicles44 (13) | Vehicles45 (14) | Vehicles46 (15) | Vehicles47 (16) | Vehicles48 (0) | Vehicles49 (1) | Vehicles50 (2) | Vehicles51 (3) | Vehicles52 (4) | Vehicles53 (5) | Vehicles54 (6) | Vehicles55 (7) | Vehicles56 (8) | Vehicles57 (9) | Vehicles58 (10) | Vehicles59 (11) | Vehicles60 (12) | Vehicles61 (13) | Vehicles62 (14) | Vehicles63 (15) | Vehicles64 (16) | (2211))


Cant figure out whats wrong.  Happy to share complete code if needed.

Reply all
Reply to author
Forward
0 new messages