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

Refactor CostWrapper #828

Closed
jcoupey opened this issue Nov 17, 2022 · 1 comment · Fixed by #829
Closed

Refactor CostWrapper #828

jcoupey opened this issue Nov 17, 2022 · 1 comment · Fixed by #829
Labels
Milestone

Comments

@jcoupey
Copy link
Collaborator

jcoupey commented Nov 17, 2022

We've introduced CostWrapper to be able to scale travel times on the fly based on vehicles speed_factor values. The current implementation is that we compute a scaling factor in the ctor:

: discrete_duration_factor(std::round(1 / speed_factor * DIVISOR)),

Then when a duration value is requested, we scale the original matrix value (DIVISOR is 100 to keep a fair amount of precision since speed_factor is a double):

Duration duration(Index i, Index j) const {
Duration c = duration_data[i * duration_matrix_size + j];
return (c * discrete_duration_factor) / DIVISOR;
}

The advantage of this approach is that even if speed_factor is a double, it keeps all our computations in the integer world (see #491). The current implementation have drawbacks though:

  • we're still doing an integer division for each call to duration or cost (heavily used!);
  • we still have rounding issues when getting back to seconds by dividing: depending on the speed_factor value, this can lead to different matrix durations being scaled to the same value.

I'd like to try to get rid of the division and simply use scaled values all over internally. This would amount to describing all durations as hundredth of second internally. We'd have to apply that change to all time-related values and round back to seconds upon solution formatting. This would add some code boilerplate but could improve precision while reducing computing time.

@jcoupey
Copy link
Collaborator Author

jcoupey commented Nov 17, 2022

A possible concern is that this would also lower by a factor of 100 the threshold for potential overflows which we check in Input::check_cost_bound. I'm not too worried by this at first glance.

This was referenced Nov 17, 2022
@jcoupey jcoupey added this to the v1.13.0 milestone Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant