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

Allow expansion into a region when not_thru_pruning_ is false on 2nd pass #2978

Merged
merged 29 commits into from
Apr 7, 2021

Conversation

gknisely
Copy link
Member

@gknisely gknisely commented Apr 1, 2021

Issue

This PR resolves an edge case where we may encounter only_restrictions with edges being marked as not_thru. Basically the only way to get in this area is via this edge based on the restriction, but it is also marked as not_thru. To resolve this issue, we set the not_thru to false for all edges only if the global not_thru_pruning_ is false. not_thru_pruning_ is only set to false on the 2nd pass in route_action. See the gurka test not_thru_pruning_ as it is based on the following real world example:

This way/edge is marked as a not_thru edge.

Screenshot from 2021-04-06 22-03-51

But the only way to get into this area is this way/edge due to the only restriction.

Screenshot from 2021-04-06 22-04-10

So basically in the forward or reverse expansion in bidirectional A* we stop expanding due to the edge being marked as not_thru.
I tried removing logic to not mark this edge as not_thru in Mjolnir; however, the following edge is also marked as not_thru so we would just uturn on the original edge and still not traverse into this area.

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog

Requirements / Relations

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

@gknisely gknisely changed the title Allow restricted thru [WIP] Allow restricted thru Apr 1, 2021
// to false here only if allow_restricted_thru is true and we are not restricted.
// This bool is only set to true on the 2nd pass in route_action. See the gurka
// test allow_restricted_thru
bool thru = (pred.not_thru_pruning() || !meta.edge->not_thru());
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: I think a var name of not_thru_pruning would be more appropriate since it reflects the not_thru pruning state of the current edge label (i.e whether we're culling-out not_thru edges or not)

Copy link
Member

Choose a reason for hiding this comment

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

I would call this not_thru_pruning and not confuse the issue with the restriction name.

@@ -37,6 +37,11 @@ void TimeDepReverse::Clear() {
}
edgelabels_rev_.clear();
adjacencylist_rev_.clear();

// Set the ferry flag to false
has_ferry_ = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this isn't related to the not_thru issue? the has_ferry flag was simply missing from this implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mandeepsandhu correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

cc @danpat note the missing has_ferry

// based on the restriction, but it is also marked as not_thru. We set the not_thru
// to false here only if allow_restricted_thru is true. This bool is only set to true
// on the 2nd pass in route_action. See the gurka test allow_restricted_thru
bool thru = (allow_restricted_thru() ? false : (pred.not_thru_pruning() || !meta.edge->not_thru()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the condition being checked different than the forward direction? Here we're switching off pruning without checking if the predecessor edge has restriction or not (i.e using pred.restrictions()).

Copy link
Member Author

Choose a reason for hiding this comment

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

@mandeepsandhu unfortunately we can't. I will explain when I fill in the details above.

Copy link
Member

Choose a reason for hiding this comment

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

I would simply have a not_thru_pruning option that is true on the first pass and false on the 2nd pass. No need (in my opinion) to check for restrictions - just disable all not_thru pruning on the 2nd pass. This was mostly added as a performance optimization for cycling and pedestrian (where hierarchies are not useful).

}
},
std::exception);
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "F"}, "auto", {});
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm, why is not failing to find a route anymore with your change? This is a simple not_thru case and the previous open edge does not have any restriction on it. I thought this case would still throw a no-route exception since there's no other restriction involved.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mandeepsandhu in the reverse search not_thru is not considered anymore on the 2nd pass

@gknisely gknisely changed the title [WIP] Allow restricted thru Allow expansion into a region when not_thru_pruning_ is false on 2nd pass Apr 7, 2021
@gknisely gknisely marked this pull request as ready for review April 7, 2021 02:30
@@ -324,11 +326,17 @@ inline bool BidirectionalAStar::ExpandForwardInner(GraphReader& graphreader,
float sortcost =
newcost.cost + astarheuristic_forward_.Get(t2->get_node_ll(meta.edge->endnode()), dist);

// There is an edge case where we may encounter only_restrictions with edges being
// marked as not_thru. Basically the only way to get in this area is via this edge
Copy link
Member

Choose a reason for hiding this comment

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

confusing description. The edge that is restricted is not marked as not_thru. I guess the "only_restriction" means the path can only go onto the not_thru edge, but Valhalla doesn't really have the notion of "only" - it just has edges that are restricted / not allowed.

@@ -92,6 +92,8 @@ void MultiModalPathAlgorithm::Clear() {

// Set the ferry flag to false
has_ferry_ = false;
// Set not thru pruning to true
not_thru_pruning_ = true;
Copy link
Member

Choose a reason for hiding this comment

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

aren't multi-modal routes always forward search (not bidirectional) - and we don't use not_thru pruning except in bidirectional A*?

@@ -43,6 +43,8 @@ void TimeDepForward::Clear() {

// Set the ferry flag to false
has_ferry_ = false;
// Set not thru pruning to true
not_thru_pruning_ = true;
Copy link
Member

Choose a reason for hiding this comment

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

same comment as multi-modal

/**
* Set the not_thru_pruning_
* @param pruning set the not_thru_pruning_ to pruning value.
* only set on the second pass
Copy link
Member

Choose a reason for hiding this comment

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

this is set to true on first pass for bidirectional, so this comment line is incorrect

Copy link
Member

Choose a reason for hiding this comment

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

I would consider moving the comments on not_thru pruning from bidirectional_astar.cc into here.

@@ -106,6 +124,8 @@ class PathAlgorithm {

bool has_ferry_; // Indicates whether the path has a ferry

bool not_thru_pruning_; // Indicates whether to allow access into a restricted no thru region.
Copy link
Member

Choose a reason for hiding this comment

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

take out the word restricted, change to "into a not-thru region"

@@ -549,11 +557,17 @@ inline bool BidirectionalAStar::ExpandReverseInner(GraphReader& graphreader,
float sortcost =
newcost.cost + astarheuristic_reverse_.Get(t2->get_node_ll(meta.edge->endnode()), dist);

// There is an edge case where we may encounter only_restrictions with edges being
Copy link
Member

Choose a reason for hiding this comment

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

consider moving this lengthy comment into the PathAlgorithm method that sets not_thru pruning.

@@ -57,6 +57,8 @@ void AStarBSSAlgorithm::Clear() {

// Set the ferry flag to false
has_ferry_ = false;
// Set not thru pruning to true
not_thru_pruning_ = true;
Copy link
Member

Choose a reason for hiding this comment

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

I thought only bidirectional A* uses not_thru_pruning?

dnesbitt61
dnesbitt61 previously approved these changes Apr 7, 2021
dnesbitt61
dnesbitt61 previously approved these changes Apr 7, 2021
@gknisely gknisely merged commit 5936d06 into master Apr 7, 2021
@gknisely gknisely deleted the allow_restricted_thru branch February 22, 2024 13:26
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.

3 participants