Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeWindow::length should be scaled #1015

Closed
kkarbowiak opened this issue Oct 18, 2023 · 2 comments
Closed

TimeWindow::length should be scaled #1015

kkarbowiak opened this issue Oct 18, 2023 · 2 comments
Labels
Milestone

Comments

@kkarbowiak
Copy link
Contributor

The length member of TimeWindow class defined here:

is initialised here:
TimeWindow::TimeWindow(UserDuration start, UserDuration end)
: start(utils::scale_from_user_duration(start)),
end(utils::scale_from_user_duration(end)),
length(end - start) {

Due to both start and end members being shadowed by start and end arguments, the computed length value is based on UserDuration instead of Duration.

At the moment it is not a big deal, because TimeWindow::length is used only in vehicle comparison:

friend bool operator<(const Vehicle& lhs, const Vehicle& rhs) {
// Sort by:
// - decreasing max_tasks
// - decreasing capacity
// - decreasing TW length
// - decreasing range (max travel time and distance)
return std::tie(rhs.max_tasks,
rhs.capacity,
rhs.tw.length,
rhs.max_travel_time,
rhs.max_distance) < std::tie(lhs.max_tasks,
lhs.capacity,
lhs.tw.length,
lhs.max_travel_time,
lhs.max_distance);
}
, which works correctly whether or not the value is scaled, and in job:
inline Duration get_tw_length(const std::vector<TimeWindow>& tws) {
return std::accumulate(std::next(tws.begin()),
tws.end(),
tws[0].length,
[](auto sum, auto tw) { return sum + tw.length; });
}
, where it is used to initialise Job::tw_length, which itself is not used anywhere and gets removed in #1014.

Anyway, to avoid any possible confusion in the future, I would propose to either scale the value: length(utils::scale_from_user_duration(end - start)) or add a length() member function and compute the value on the fly.

@jcoupey
Copy link
Collaborator

jcoupey commented Oct 19, 2023

Good catch. Indeed not a problem for the sorting we currently do but we should definitely get consistent values in case we use the length in conjunction with something else in the future. Can you add that to #1014?

@jcoupey jcoupey added this to the v1.14.0 milestone Oct 19, 2023
@jcoupey
Copy link
Collaborator

jcoupey commented Oct 19, 2023

Landed with #1014.

@jcoupey jcoupey closed this as completed Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants