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 cost wrapper #829

Merged
merged 37 commits into from
Nov 23, 2022
Merged

Refactor cost wrapper #829

merged 37 commits into from
Nov 23, 2022

Conversation

jcoupey
Copy link
Collaborator

@jcoupey jcoupey commented Nov 17, 2022

Issue

This PR is an attempt to fix #828.

Tasks

  • Get rid of division in CostWrapper::cost and duration
  • Scale internal times received in input
  • Get back to original values after solving in all vroom::Solution-related objects
  • Check for non-regressions
  • Update CHANGELOG.md
  • review

@jcoupey
Copy link
Collaborator Author

jcoupey commented Nov 21, 2022

Scaling input durations internally means we have to also scale values in time windows. The problem is that when using regular timestamps like 1669022846, scaling by a factor of 100 will quickly bring us over the limit for a uint32_t. My first attempt in 6d38cc6 has been to switch Cost and Duration types to uint64_t. It works but is not ideal since it means that we'll store matrices that are basically twice the size in RAM for no benefit (the travel time values themselves fit in a uint32_t).

To avoid the memory overhead my plan is to refactor types further so that:

  1. Cost and Duration are only user-facing types used in the json and C API, they stay uint32_t.
  2. Everything cost or duration-related internally is computed as a signed int (int64_t gives us plenty of room).
  3. Everything cost or duration-related internally is stored as a signed int.

That last point is the one requiring the most changes, but as soon as everything happens in the signed world with enough room, we should be safe from the kind or problem spotted in #831, while not increasing our memory footprint.

@jcoupey
Copy link
Collaborator Author

jcoupey commented Nov 21, 2022

I finally went with introducing new "user-facing" cost types UserCost and UserDuration that are uint32_t. Set aside the naming, nothing changed from the API usage (both json and C ).
On top of that, now everything cost/duration-related internally is signed (int64_t), including storage in various objects such as Job, TimeWindow etc.

Just as sketched in #828, a scaling phase applies upon problem definition, then back when formatting solutions.

@jcoupey
Copy link
Collaborator Author

jcoupey commented Nov 21, 2022

nothing changed from the API usage (both json and C )

Well, almost: as the last CI build failure shows, users of the C API that provide custom matrices will have to switch from vroom::Matrix<vroom::Duration> to vroom::Matrix<vroom::UserDuration> (same underlying type).

@jcoupey
Copy link
Collaborator Author

jcoupey commented Nov 23, 2022

This adds a lot more boilerplate than I first though it would, especially in order to make sure reported results are consistent in output after scaling back to UserCost and UserDuration values. But I think it's worth the trouble since:

  • it will open up to further scaling options (required in Better costs modelling at vehicle level #788);
  • getting rid of the integer division for values scaling upon each call to cost or duration does seem to improve computing time.

On that last point, here are some values for average instance computing time per benchmark class, using -x 5 on the usual VRPTW benchmarks.

Instances master PR at f47a036 Delta (%)
Solomon 459 436 -5.0
Homberger 200 1889 1794 -5.0
Homberger 400 9215 8706 -5.5
Homberger 600 22562 21371 -5.3
Homberger 800 44047 42003 -4.6
Homberger 1000 76170 72887 -4.3

@jcoupey jcoupey added this to the v1.13.0 milestone Nov 23, 2022
@jcoupey jcoupey merged commit a4955ba into master Nov 23, 2022
@jcoupey jcoupey deleted the refactor/cost-wrapper branch November 24, 2022 08:33
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 this pull request may close these issues.

Refactor CostWrapper
1 participant