-
Notifications
You must be signed in to change notification settings - Fork 5
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
Distance matrix moved to triangular shape. #23
base: master
Are you sure you want to change the base?
Conversation
…emory footprint by 50 percent.
hmm, I'm pretty sure that when I last benchmarked it calculating the full square was more efficient 🤔 I'll have a closer look once I'm back from vacation |
Hey, we should revisit this sometime :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hard time doing a proper review here because this PR seems to change several different things at once.
e.g. the full- to half-matrix change should probably be split off from the olc_forward.rs
implementation. similar for the typo fixes etc.
.gitignore
Outdated
@@ -3,3 +3,4 @@ | |||
**/*.rs.bk | |||
Cargo.lock | |||
.criterion | |||
.vscode/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this stuff belongs in your global gitignore file (see https://docs.github.com/en/github/using-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer) 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out :)
src/parallel.rs
Outdated
@@ -4,14 +4,12 @@ cfg_if! { | |||
if #[cfg(feature = "rayon")] { | |||
use rayon::slice; | |||
pub use rayon::prelude::*; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for removing the whitespace here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this happened as I was trying to add another optional rayon feature. I added it again.
Distances in the distance matrix are only computed to preceding points. This speeds up distance calculation by ~50% and reduces memory footprint. For flights for which only one iteration is needed, benching indicates a speed up of around 15% overall. For flights with multiple iterations, I was not able to bench any kind of speed up. For longer flights with many fixes, the reduction of memory should be an improvement and could allow scoring of longer flights on smaller devices.
Moving the distance matrix to a triangular shape effectively only allows scoring in one direction. In the original implementation, the first iteration was scored 'backwards' to find potential starting points. The following iterations were then scored 'forward', starting at the selected points. This is not possible with the triangular matrix anymore.
Now, the first iteration is scored 'backwards' as well. Potential starting points and their corresponding solutions are identified. But we can not start at these points anymore. So after a start point is picked, valid end points for this start points are identified and when iterating backwards, only they are allowed by penalising other end points. The solution of this iteration is guaranteed to be as good as the solution when starting from start point in a forward manner. In the test flight, the exact number of iterations were needed. I believe that there are cases where the solution can even be better (as it is not limited to end at start point) which would result in less iteration.
In olc_forward, the same algorithms is provided with the other half of the triangular matrix, scoring everything the other way. For the average flight, this implementation seems to need more iterations, as the typical solution seems to be biased towards the start.