diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e8671045..8ae7223e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ - `max_travel_time` not accounted for with vehicle steps in solving mode (#954) - `max_travel_time` not accounted for in `RouteSplit` (#941) - Wrong capacity checks in `RouteSplit` (#981) +- Overflow related to scaling default time windows (#1020) #### Internals diff --git a/src/structures/typedefs.h b/src/structures/typedefs.h index 79ef1ec15..ed70b0e5f 100644 --- a/src/structures/typedefs.h +++ b/src/structures/typedefs.h @@ -190,19 +190,22 @@ struct StringHash { }; namespace utils { -inline Duration scale_from_user_duration(UserDuration d) { +constexpr inline Duration scale_from_user_duration(UserDuration d) { return DURATION_FACTOR * static_cast(d); } -inline UserDuration scale_to_user_duration(Duration d) { +constexpr inline UserDuration scale_to_user_duration(Duration d) { + assert(d <= + scale_from_user_duration(std::numeric_limits::max())); return static_cast(d / DURATION_FACTOR); } -inline Cost scale_from_user_cost(UserCost c) { +constexpr inline Cost scale_from_user_cost(UserCost c) { return DURATION_FACTOR * COST_FACTOR * static_cast(c); } -inline UserCost scale_to_user_cost(Cost c) { +constexpr inline UserCost scale_to_user_cost(Cost c) { + assert(c <= scale_from_user_cost(std::numeric_limits::max())); return static_cast(c / (DURATION_FACTOR * COST_FACTOR)); } } // namespace utils diff --git a/src/structures/vroom/time_window.cpp b/src/structures/vroom/time_window.cpp index 69832f78a..487526c68 100644 --- a/src/structures/vroom/time_window.cpp +++ b/src/structures/vroom/time_window.cpp @@ -13,10 +13,13 @@ All rights reserved (see LICENSE). namespace vroom { constexpr Duration TimeWindow::default_length = - std::numeric_limits::max(); + utils::scale_from_user_duration(std::numeric_limits::max()); TimeWindow::TimeWindow() - : start(0), end(std::numeric_limits::max()), length(end - start) { + : start(0), + end(utils::scale_from_user_duration( + std::numeric_limits::max())), + length(end - start) { } TimeWindow::TimeWindow(UserDuration start, UserDuration end)