Skip to content

Recost shortcuts in bidastar: first approach#2661

Closed
genadz wants to merge 9 commits intovalhalla:masterfrom
genadz:recost_shortcuts
Closed

Recost shortcuts in bidastar: first approach#2661
genadz wants to merge 9 commits intovalhalla:masterfrom
genadz:recost_shortcuts

Conversation

@genadz
Copy link
Copy Markdown
Contributor

@genadz genadz commented Oct 20, 2020

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Generally use squash merge to rebase and clean comments before merging
  • Update the changelog

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

@genadz genadz marked this pull request as draft October 20, 2020 19:02
@genadz
Copy link
Copy Markdown
Contributor Author

genadz commented Oct 20, 2020

@kevinkreiser there are some open questions I wanted to discuss:

  1. Should we skip path in case recosting fails ? or we should fallback to the current logic (right now is fallback).
  2. Should we recost transition costs for recovered shortcuts ? (I mean, we have transition cost between some edge in path and shortcut edge -> should we replace it by transition cost between the edge and first superseded edge that was recovered from shortcut ?)

@genadz genadz changed the title Recost shortcuts when form final path Recost shortcuts in final path Oct 21, 2020
@genadz genadz requested a review from kevinkreiser November 2, 2020 08:50
Comment thread src/thor/bidirectional_astar.cc Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is recosting shortcuts something that could benefit all A-star algorithms? If so, could this be implemented on the base-class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think yes, will check

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.

heavy plus for this one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

all A-start algorithms inherit from PathAlgorithm interface. as for me, it's too common in order to add recost_shortcut_forward to this interface. instead of that, I will define this function in a separate *.h file (in src/thor folder) that can be used by everyone

@genadz genadz marked this pull request as ready for review November 2, 2020 19:25
@genadz
Copy link
Copy Markdown
Contributor Author

genadz commented Nov 2, 2020

NOTE: right now shortcut speed equals to speed from the first superseded edge; so, if other superseded edges have different speeds -> after recosting we can get ETA significantly different from the base. this PR #2662 fixes it

@purew
Copy link
Copy Markdown
Contributor

purew commented Nov 2, 2020

Could you add some gurka tests for this recovering of shortcuts?

@kevinkreiser
Copy link
Copy Markdown
Member

@purew we already have tests for recovering shortcuts i dotn think we need more just for that. but we do need them specifically for this. the main point here is that the final path doesnt have shortcuts in it. so it would be enough to make a gurka map that has shortcuts, get a route that takes a shortcut, set the constrained speed on the non shortcut edges to a known value that is substantially different than the shortcut and then check that:

  1. you get back no shortcut edges
  2. your recosting works in that you get speeds/costs that look like the constrained speed you set

@kevinkreiser
Copy link
Copy Markdown
Member

@gena with respect to:

Should we recost transition costs for recovered shortcuts ? (I mean, we have transition cost between some edge in path and shortcut edge -> should we replace it by transition cost between the edge and first superseded edge that was recovered from shortcut ?)

No, you dont need to recompute the transition cost for those as the value will be the same.

Comment thread src/thor/bidirectional_astar.cc Outdated
Comment on lines 974 to 959
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.

why make this change? its a bunch of extra allocation and a whole extra loop over the path. what does this give us other than a slightly clearer while loop below?

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.

unless there is a clear reason to do this, i would highly suggest we revert this to using the label index and labelset directly in the while loop as was done before

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.

oh i see in the comment hints at it. you are saying that we have to start at the beginning to get the correct cost? i'm not sure its actually true though. i wonder what kind of penalty this adds. i think we can work around it by looking one label ahead and using that label as the "previous cost" for the recosting of the shortcut to avoid all this allocation

Copy link
Copy Markdown
Contributor Author

@genadz genadz Nov 3, 2020

Choose a reason for hiding this comment

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

let's suppose we go from the end to the beginning (as before), and we already processed some edges: edge_n, edge_n-1, ...., edge_k and then meet shortcut and recost the edge - it means that costs for all edges from n to k will be invalid anymore (because costs for edges n, n-1, ..., k include shortcut cost that we've just changed) and we must shift all of them by difference we get after recosting.
If we implement this approach directly - it will require approximately n * (number of shortcuts) additional operations (change costs) - doesn't look reasonable. But, I just realized, we can optimize it a little: let's save all cost changes to stack (~ (number of shortcuts) additional memory) and apply these changes once on the second pass - in this case overhead will be num_of_shourctus additional memory (solution implemented now requires n additional memory, so make sense to rewrite). WDYT?

Comment thread src/thor/bidirectional_astar.cc Outdated
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.

as soon as this fails should we log and return?

Copy link
Copy Markdown
Contributor Author

@genadz genadz Nov 3, 2020

Choose a reason for hiding this comment

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

  • On the one hand we already log errors in RecoverShortcut method, but from the other we can treat recovering error as recosting error here and log it.
  • It might be reasonable not to continue because we already know shortcut cost and there is no need to call recost_forward function in such case.

Comment thread src/thor/bidirectional_astar.cc Outdated
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.

the last PathId stores boths the cost so far and the transition cost at the beginning of the PathID. so i think you might have the transition cost in the wrong place. i always confuse mysefl on this but thats whta it looks like to me here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hm, didn't get this note. could you run the details ?

@alexey-gl
Copy link
Copy Markdown

Hello
While solving my #2692 problem I have tried to use this PR as possible solution.
Unfortunately it has not solved my issue completely.
I noticed when the route has several subsequent shortcuts only the first one was fully restored with original way ids. The rest still have way_id = 0 (i.e. they are still shortcuts). And I have to restored them during postprocessing with graph_reader.RecoverShortcut(...) stuff.
I suppose this PR should solve my issue.
Hope this comment will help with this PR testing.

@genadz genadz force-pushed the recost_shortcuts branch 2 times, most recently from ecf25a1 to 80e4375 Compare November 30, 2020 14:14
// Terminate if the cost threshold has been exceeded.
if (fwd_pred.sortcost() + cost_diff_ > threshold_) {
return FormPath(graphreader, options, origin, destination);
return FormPath(graphreader, options, origin, destination, forward_time_info, invariant);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure if it's fully correct to consider only forward time and ignore reverse time:

@genadz genadz marked this pull request as draft December 2, 2020 12:58
@genadz genadz changed the title Recost shortcuts in final path Recost shortcuts in bidastar: first approach Dec 7, 2020
@genadz
Copy link
Copy Markdown
Contributor Author

genadz commented Dec 7, 2020

Implemented new approach here #2711 . @kevinkreiser we should compare and choose the best one

@genadz
Copy link
Copy Markdown
Contributor Author

genadz commented Dec 7, 2020

Hello
While solving my #2692 problem I have tried to use this PR as possible solution.
Unfortunately it has not solved my issue completely.
I noticed when the route has several subsequent shortcuts only the first one was fully restored with original way ids. The rest still have way_id = 0 (i.e. they are still shortcuts). And I have to restored them during postprocessing with graph_reader.RecoverShortcut(...) stuff.
I suppose this PR should solve my issue.
Hope this comment will help with this PR testing.

hm, interesting note about subsequent shortcuts. I added unit test and it works)

@kevinkreiser
Copy link
Copy Markdown
Member

@genadz should we close this since we went with the other approach?

@genadz genadz closed this Mar 10, 2021
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.

4 participants