Skip to content

Distance matrix moved to triangular shape.#23

Open
moldhouse wants to merge 5 commits into
glide-rs:masterfrom
weglide:master
Open

Distance matrix moved to triangular shape.#23
moldhouse wants to merge 5 commits into
glide-rs:masterfrom
weglide:master

Conversation

@moldhouse

Copy link
Copy Markdown

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

Turbo87 commented Jul 10, 2020

Copy link
Copy Markdown
Member

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
Copy Markdown
Author

Hey, we should revisit this sometime :)

@Turbo87 Turbo87 left a comment

Copy link
Copy Markdown
Member

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.

Comment thread .gitignore Outdated
**/*.rs.bk
Cargo.lock
.criterion
.vscode/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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 :)

Comment thread src/parallel.rs
if #[cfg(feature = "rayon")] {
use rayon::slice;
pub use rayon::prelude::*;

Copy link
Copy Markdown
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
Copy Markdown
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