Valid input to CVRPTW #4173
-
Hello, Following the advice provided #4171, I have been able to get the code https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/samples/vrp_time_windows.cc up and running on Windows and Linux (there was a versioning issue on Windows with ZLib which I fixed) I have a few questions on the sample vrp_time_windows.cc file. (a) traditional VRPTWs have a vehicle capacity as well as customer demand. The example provided does not seem to take as input customer demand and vehicle capacity. Is there a different canonical example that does this? (b) Additionally, the solomon instances have a service time at each customer. That does not seem to be taken as input either in the example code. (c) VRPTWs have to traditionally find out the optimal number of vehicles to use, while the example provided takes Is it possible to solve the capacitated vehicle routing problem with time windows (where each customer has a demand, vehicles are capacitated, there is a positive service time at each customer) where the number of vehicles used is not an input and is figured out endogeneously by the algorithm? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
a) See https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/samples/vrp_capacity.cc#L150 It's important to understand the underlying theory of dimensions: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L3017 b) Most solvers (or academic resources) assume that you can embed this service into the transit. Often at departure-time. You will find this in https://github.com/google/or-tools/blob/stable/examples/cpp/cvrptw.cc#L116 As this is quite common (as well as objective-weight tuning), some of my code looks like: Matrix transit_driving_time = Matrix(4, 4);
transit_driving_time << 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16;
Vector source_service_time = Vector(4);
source_service_time << 200, 201, 202, 203;
// callback-functions will be created which add up the variadic arguments and respect the underlying dimensionality (here cardinality = 2)
auto [working_time_cb_ptr, working_time_eval_ptr] = tf.construct_callback_evaluator_pair(transit_driving_time * 1, source_service_time * 1); c) Most solvers (or solver-models) assume that you can give an upper-bound. This is exactly what or-tools is asking for too. The solver can always "not use a vehicle / tour" and with https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L1193 you can add costs for assignments giving the solver an incentive to not use some vehicle. See also: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L1642 Summary: or-tools routing-solver is more a rich VRP solver (and not limited to XX_VRP_YY) -> there is a lot which can be modelled. Greetings, |
Beta Was this translation helpful? Give feedback.
-
Totally off topic, but wow, modern C++ certainly looks different from what I used back in the old days ('96).
…On Tue, Apr 09, 2024 at 09:20:56AM -0700, sschnug wrote:
**a)** See https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/samples/vrp_capacity.cc#L150
Basically a (constrained) *dimension* linked to 1-dimensional transit (we don't care about "a -> moves to-> b", but add capacity due to "leaving a"). Keep in mind: dimensions are additive. You can use dimensions of vrptw example as well as dimensions of cvrp examples (but respect uniqueness -> see return-type of AddDimensionXXX).
It's important to understand the underlying theory of dimensions: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L3017
**b)** Most solvers (or academic resources) assume that you can embed this service into the transit. Often at departure-time.
You will find this in https://github.com/google/or-tools/blob/stable/examples/cpp/cvrptw.cc#L116
As this is quite common (as well as objective-weight tuning), some of my code looks like:
```cpp
Matrix transit_driving_time = Matrix(4, 4);
transit_driving_time << 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16;
Vector source_service_time = Vector(4);
source_service_time << 200, 201, 202, 203;
auto [working_time_cb_ptr, working_time_eval_ptr] = tf.construct_callback_evaluator_pair(transit_driving_time * 1, source_service_time * 1);
```
**c)** Most solvers (or solver-models) assume that you can give an upper-bound. This is exactly what or-tools is asking for too. The solver can always "not use a vehicle / tour" and with https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L1193 you can add costs for assignments giving the solver an incentive to not use some vehicle.
See also: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L1642
Greetings,
Sascha
--
Reply to this email directly or view it on GitHub:
#4173 (comment)
You are receiving this because you are subscribed to this thread.
Message ID: ***@***.***>
--
James E. Marca
Activimetrics LLC
|
Beta Was this translation helpful? Give feedback.
-
@sschnug Based on your response, I am working on trying to incorporate it into my context. I am still unclear how to incorporate your suggestions fully. I have figured out the capacity part using the example you gave. I am now trying to incorporate the service time part. Suppose there is a 2 customer problem with 3 nodes, 0 (depot), 1 and 2 Based on this, I have:
Now, the only place where time_matrix is referred to in the template I am working with are: or-tools/ortools/constraint_solver/samples/vrp_time_windows.cc Lines 118 to 119 in 5f7eabb and Should I be doing in place of the line above the following?
This does not appear right to me because in the traditional VRPTW, if a vehicle arrives at a customer before the starting/opening of the time window, it has to wait until the starting time windows before service can start. If purely transit time and service times are added together (if I understand your suggestion correctly), then, the algorithm will not be correct because it will not be able to account for this waiting time. Could I request you to clarify? Thank you. |
Beta Was this translation helpful? Give feedback.
a) See https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/samples/vrp_capacity.cc#L150
Basically a (constrained) dimension linked to 1-dimensional transit (we don't care about "a -> moves to-> b", but add capacity due to "leaving a"). Keep in mind: dimensions are additive. You can use dimensions of vrptw example as well as dimensions of cvrp examples (but respect uniqueness -> see return-type of AddDimensionXXX).
It's important to understand the underlying theory of dimensions: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/routing.h#L3017
b) Most solvers (or academic resources) assume that you can embed this service into the transit. Often …