Asking to customize VRPTW - setting objective function and end-depot location

784 views
Skip to first unread message

hss...@hnu.kr

unread,
Oct 10, 2016, 2:24:06 AM10/10/16
to or-tools-discuss

I am a beginner of or-Tools. 

I have a goal to implement itinerary builder for trip using PYTHON based on VRP with time window library. I need to implement following scenario; 

"When a user chooses several places to visit on the map, computer automatically build itinerary which include sequence of visit, arrival time for each place, and so on. However, some places should be visited within specified time window."

 

So I modified VRPTW Python code which is provided on the following web page.

https://developers.google.com/optimization/routing/tsp/vehicle_routing_time_windows#the-entire-program

 

1)  For the itinerary builder for trip, 1 vehicle with infinitive capacity is enough and there exist no time constraints so I changed following statements from original Python code;

 

num_vehicles = 1

VehicleCapacity = 10000000000

horizon = 40 * 3600

tw_duration = 40 * 3600

start_times = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

 

After I run, I satisfied with following results;

Route 0: 0 Load(0) Time(0, 0) -> 30 Load(0) Time(1, 20954) -> 26 Load(14) Time(4202, 25155) -> ...

 

Next, I set start_times of almost places to 0 and tw_duration to horizon except a place because most places can be visited at any time but some places should be visited specified time. For example, museum should be visited only at day time and some night market should be visited only at night time. So I set start_times of 30th location to 15000 so that 30th location can be visited later.

 

For this purpose, I changed start_times of places as follows;

start_times = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15000,0]

 

But the result was not what I wanted. A vehicle waited until 15000 seconds in order to keep the visiting sequence ;

Route 0: 0 Load(0) Time(0, 0) -> 30 Load(0) Time(15000, 20954) -> 26 Load(14) Time(19201, 25155) -> ...

 

I guess above result happens because cost function is defined with only distance. Is it correct guess? How can I change cost function from distance to total travel time (waiting time + service time + transit time) ?

 

2) For my itinerary builder, start depot and end depot will be different. How can I set end_depot location differently?

 

I am using Spyder 3 editor with anaconda 3-4.2.0 windows version and recent or-tools (library.or-tools.python.examples_4.3.3805) in windows 7 OS.

 

Please answer me with Python code! Thanks in advance.

 

From Song

Ken Alton

unread,
Oct 11, 2016, 10:33:29 AM10/11/16
to or-tools...@googlegroups.com
1) You might try calling time_dimension.SetSpanCostCoefficientForAllVehicles(int64 coefficient) with some coefficient so the solver attempts to minimize the total time of the route(s).

2) In order to have a different end depot you would need to remove the call to routing.setDepot() and instead set the start and end depots for each vehicle in the RoutingModel constructor:
       routing = pywrapcp.RoutingModel(num_locations, num_vehicles, [0], [1])
where in this case there is one vehicle starting at node 0 and ending at node 1.


--
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.

hss...@hnu.kr

unread,
Oct 13, 2016, 2:54:26 AM10/13/16
to or-tools-discuss
Hello Alton,
Thank you so much. It works well.


2016년 10월 11일 화요일 오후 11시 33분 29초 UTC+9, Ken Alton 님의 말:
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages