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

Reduce compute_best_route_split_choice complexity #962

Closed
jcoupey opened this issue Aug 4, 2023 · 1 comment
Closed

Reduce compute_best_route_split_choice complexity #962

jcoupey opened this issue Aug 4, 2023 · 1 comment

Comments

@jcoupey
Copy link
Collaborator

jcoupey commented Aug 4, 2023

The RouteSplit operator logic is to pick an existing route with at least two jobs, then choose the best possible splitting rank r of that route in begin_route (jobs up to r excluded) and end_route (jobs after r) in such a way that:

  • there exists an empty vehicle begin_v for which begin_route is valid;
  • there exists an empty vehicle end_v for which end_route is valid;
  • the sum of the costs for both routes above is minimal.

Then the operator is applied if said sum of costs is lower than the initial (single route) cost.

While looking back at this for #941, I noticed that costs are recomputed for each route portion and vehicle candidate using utils::route_eval_for_vehicle here and here.

This function goes through alll route jobs to evaluate the costs, adding start/end cost along the way. On the other hand we have SolutionState::fwd_costs at hand that allows to evaluate any route chunk for any vehicle with a single difference (so in constant time). This would not include start/end costs that would have to be added manually.

Basically we can swap this evaluation that is linear in the route chunk size with a constant-time evaluation. The good part is that whenever this operator is used (i.e. if there are at least two empty vehicles available), this evaluation is performed for all routes, for all splitting ranks, and at most twice for all empty vehicle, so one could expect a significant impact.

@jcoupey
Copy link
Collaborator Author

jcoupey commented Aug 4, 2023

Turns out the gain is not that huge. On a perf check, the number of samples for compute_best_route_split_choice goes from 2.35% down to 1.94%.

I'll still include the changes while I'm working on that area of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant