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

Distance matrix moved to triangular shape. #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

moldhouse
Copy link

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.

@Turbo87
Copy link
Member

Turbo87 commented Jul 10, 2020

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

@moldhouse
Copy link
Author

Hey, we should revisit this sometime :)

Copy link
Member

@Turbo87 Turbo87 left a 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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

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::*;

Copy link
Member

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?

Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

2 participants