Skip to content

Commit

Permalink
Merge branch 'fix/tw-scaling-overflow'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Nov 17, 2023
2 parents 8ace3b6 + f8022df commit b992830
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions src/structures/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>(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<UserDuration>::max()));
return static_cast<UserDuration>(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<Cost>(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<UserCost>::max()));
return static_cast<UserCost>(c / (DURATION_FACTOR * COST_FACTOR));
}
} // namespace utils
Expand Down
7 changes: 5 additions & 2 deletions src/structures/vroom/time_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ All rights reserved (see LICENSE).
namespace vroom {

constexpr Duration TimeWindow::default_length =
std::numeric_limits<Duration>::max();
utils::scale_from_user_duration(std::numeric_limits<UserDuration>::max());

TimeWindow::TimeWindow()
: start(0), end(std::numeric_limits<Duration>::max()), length(end - start) {
: start(0),
end(utils::scale_from_user_duration(
std::numeric_limits<UserDuration>::max())),
length(end - start) {
}

TimeWindow::TimeWindow(UserDuration start, UserDuration end)
Expand Down

0 comments on commit b992830

Please sign in to comment.