graphhopper / jsprit

jsprit is a java based, open source toolkit for solving rich vehicle routing problems
https://www.graphhopper.com/open-source/
Apache License 2.0
1.64k stars 605 forks source link

Added conditional time windows #555

Open marcanpilami opened 1 year ago

marcanpilami commented 1 year ago

Use case: some vehicles are not allowed to go to some places only at certain times. For example, many european towns restrict "big" trucks during day time to prevent blocking small roads, but small vehicles stay allowed. Or markets at certain hours forbid all but the smallest vehicles. Etc.

So we need a mecanism to make TW optional. This is what is implemented here: TW can now be inherited, implementing a new extension point verifying if the TW should be applied. If not, the TW is reduced to the default TW (infinity, as already used in other classes).

Side note: I've first asked how to do on S/O at https://stackoverflow.com/questions/76993532/jsprit-conditional-time-windows - I'm very open to other solutions of course. This is my first foray into jsprit code so I would understand if it was found lacking in many ways.

marcanpilami commented 1 year ago

The PR was updated since its inception: first version only allowed conditional time window. Current version now also allows to do time window exclusions (so as for example to forbid a place for some vehicle types during some hours, as in our initial use case stated above).

To do this, the time window container (TimeWindows), which was already an interface, now allows multiple implementations. This container becomes responsible for giving the list of time windows to apply, dependening on the insertion context.