skatsuta / vrp-solver

Capacitated Vehicle Routing Problem with Time Windows (CVRPTW) solver written in Python.
MIT License
88 stars 26 forks source link

add feature into time window #4

Closed beyhangl closed 3 years ago

beyhangl commented 3 years ago

Hi, thank you for this great experience sharing. It's a really promising repository for future projects.

I want to tell you about my specific feature.

As you know we have some time windows to visit clients. I need extra control for the back to depot before it closes.

So depots are open between 08:00 and 18:00 so vehicles have to back to their depots before close.

Do you know how can we add this feature into the time window?

Thanks

skatsuta commented 3 years ago

Hi @beyhangl, I'm glad if it helped you in some way.

Regarding your question, the simplest way would be to configure max_time parameter in a YAML file. I have added support of the parameter in 20faa70b1d2f614af6b080b01d566e8d39a57e44, and by using it you can limit the maximum route time per vehicle. For example, if a depot is open between 08:00 and 18:00, the maximum route time per vehicle must be less than 10 hours (600 min), so the max_time param should be set to 600. If you set it to a shorter time, you can be more certain that vehicles will be back to a depot before it closes.

If your needs can be met by the above method, it is the simplest and best, but if you have to control the return time to the depot in the form of time windows, you will need to use a different method. One possible way I can think of is to set different start and end nodes to all vehicles, as described in the documentation below: https://developers.google.com/optimization/routing/routing_tasks#setting-start-and-end-locations-for-routes

In your situation, you define two nodes (say call them A and B) representing the same single depot, one for a start node and the other for an end node. Time window of node A is set to, for example, (0, 0) and that of node B to (0, 600) (i.e. 10 hours). If you configure the start node of all vehicles to node A and the end node to node B, the VRP solver would provide a routing plan where all vehicles will arrive at node B (i.e. the depot) within 600 min time window.

I'm not sure the idea would actually work for your needs, but hope it helps.