简体   繁体   中英

How to make only some tours return to depot in vehicle routing problem with or-tools?

In the instance of the Vehicle Routing Problem (VRP) with Google's OR-Tools that I'm trying to solve, only certain routes (tours) should end at the starting point, ie the depot.

I can edit the distances from every location to the depot. Setting them all to 0 will have the effect of setting an arbitrary end location and the routes will look kind of "radial" with a center in the depot. Whereas setting a distance from every location to the depot will make the routes look "circular".

The question is, how to model the problem so that only some of the routes (containing a specific type of node) will be "circular"?

Here some examples:
"Radial" (starting from center 0). eg: https://github.com/google/or-tools/raw/stable/ortools/constraint_solver/doc/vrp_starts_ends_solution.svg?sanitize=true src: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/doc/VRP.md#multiple-starts-ends
note: in this example each vehicle has a different start node and all use the same depot end node aka 0

Loop: (Starting from depot and returning to it).
eg: https://github.com/google/or-tools/raw/stable/ortools/constraint_solver/doc/vrp_global_span_solution.svg?sanitize=true src: https://github.com/google/or-tools/blob/stable/ortools/constraint_solver/doc/VRP.md#global-span-constraints

Simply create a dummy node, with distance zero from any nodes like you say BUT also keep your depot.

When building the RoutingIndexManager you can pass a start/end list so in the end list choose between your dummy node or the real depot in order to have the vehicle coming back to depot or not.

And in your "print/display" method you can check the end node index and draw/print accordingly...

note: you can find the python script used to generate these svg in the source tree (ed I didn't run it for months so it may be broken (TODO: add CI jobs on it ^^))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM