-
Notifications
You must be signed in to change notification settings - Fork 379
Simplify TW logic #558
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
Simplify TW logic #558
Conversation
I quickly tried to see the difference between Happy to have some feedback if anyone has a clue on the "theoretical" impact of such a change. |
I'd suspect that this regresses performance for instances that do a lot of If it turns out to be a performance regression, you could try replacing the |
I'd say I'm not really concerned about turning Instances with only shipments are not affected as they always use |
This kind of change is always a pain to benchmark as variations in computing times are sometimes higher across several runs than across different versions. What I did to try and smooth things was:
The initial changes show a +2.5% increase of the overall solving time, then switching to arrays brings that down to +1.6%. I think we can definitely live with that tiny increase for the sake of simplifying the code and its downstream maintenance. Another thing I meant to try was to move the implementation of the changed function to the header file. @krypt-n do you reckon that could improve things a bit? Could not test this actually since without further change to the build I hit a linking problem with undefined references to the range versions from other compilation units. |
I do think it could, but I find it hard to measure. The benchmark VRPTW instances don't call |
Worth trying anyway because we're now simply redirecting to another function so the implementation is at most a couple lines. And the same also applies to I just tried that in the last commit and I'm a bit confused about why there are missing references at linking stage (see previous CI fail). |
There are some instantiations of the template functions missing in the cpp file. These should be enough: diff --git a/src/structures/vroom/tw_route.cpp b/src/structures/vroom/tw_route.cpp
index 55717c5..8c22038 100644
--- a/src/structures/vroom/tw_route.cpp
+++ b/src/structures/vroom/tw_route.cpp
@@ -1044,6 +1044,35 @@ template bool TWRoute::is_valid_addition_for_tw(
const Index first_rank,
const Index last_rank) const;
+template bool
+TWRoute::is_valid_addition_for_tw(const Input& input,
+ const std::array<Index, 1>::iterator first_job,
+ const std::array<Index, 1>::iterator last_job,
+ const Index first_rank,
+ const Index last_rank) const;
+
+template bool TWRoute::is_valid_addition_for_tw(
+ const Input& input,
+ const std::array<Index, 1>::const_iterator first_job,
+ const std::array<Index, 1>::const_iterator last_job,
+ const Index first_rank,
+ const Index last_rank) const;
+
+template bool TWRoute::is_valid_addition_for_tw(
+ const Input& input,
+ const std::vector<Index>::const_iterator first_job,
+ const std::vector<Index>::const_iterator last_job,
+ const Index first_rank,
+ const Index last_rank) const;
+
+
+template void
+TWRoute::replace(const Input& input,
+ const std::array<Index, 1>::const_iterator first_job,
+ const std::array<Index, 1>::const_iterator last_job,
+ const Index first_rank,
+ const Index last_rank);
+
|
Argh yes, I always seem to get fooled that way as those were not necessary as long as the implementation stayed in the The good news is that it seems we're on something very interesting: the computing time increase now turns in a significant reduction (-17.4% on my small empirical tests). It looks like moving the various implementations to the header file largely overcomes the overhead of creating a temporary array and doing an extra I'll benchmark the current state of the PR with the usual VRPTW benchmarks (though PDPTW are likely "affected" too) and report. |
That was too good to be true, especially given that not a lot of code is made available to other compilation units. This observation seems to be only related to the system load while running on a couple instances on my local laptop and I can't actually reproduce that difference any more... I did run tests on my usual benchmarking machine and it comes down to:
|
I'm still curious about this as it sounds counter-intuitive. My guess would be that this happens because we only perform TW checks as a last resort after checking all other constraints. Maybe this also means there are some other low hanging fruits in term of code optimization. |
Issue
This PR implements the changes discussed in #557.
Tasks
is_valid_addition_for_tw
replace
withinadd
CHANGELOG.md