google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.1k stars 2.11k forks source link

[Question] Regarding travel times + service times #1233

Closed calatian closed 5 years ago

calatian commented 5 years ago

I am working with a VRPTW with travel times to locations and service times for each location. I am setting a time window in which each location is available.

I have set the cost of each node (in the callback) to be travel time + service time, as has been recommended in other posts here. However, this makes the algorithm check if a location is available at the time the service has been completed, not at the time the vehicle arrives at the location. This is incorrect, as vehicles often are set to arrive before their available time window.

Is there any way we can set the callback to be just the travel time, and then let the algorithm know that the vehicle must wait at that location for a certain time (the service time) before traveling to the next location?

I am using Python 3. Thanks in advance.

Mizux commented 5 years ago

For service time modeling you should use:

transit_time(A, B) = service_time(A) + travel_time(A, B)

thus the CumulVar (and TW) at each node represent the arrival time at node (i.e. the start of the task to complete the time is checked). example: https://github.com/google/or-tools/blob/39f44709bba203f5ff3bc18fab8098739f189a6d/ortools/constraint_solver/samples/cvrptw.py#L138-L171

note: in your question there is no index so it's difficult to well understand how you have modeled it...

note: We recommend to use it that way since the break feature suppose the transit time to be modelized that way see: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/samples/cvrptw_break.py