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

Aggregation updates: update opposing local idx after aggregating the edges, added classification check for aggregation, and shortcut length changes #4570

Merged
merged 16 commits into from
Feb 13, 2024

Conversation

gknisely
Copy link
Member

@gknisely gknisely commented Feb 6, 2024

Issue

While running through the valhalla regression suite of tests, we noticed that our tests at roundabouts were failing. This is due to the graph connectivity is broken at the roundabouts. Did not appear to be happening at all roundabouts. Issue was due to not updating the opposing local idx after aggregating the edges.

Additional issue was found with ferry reclassification. Determined that some edges were split at pedestrian edges had different classifications due to the reclassification of ferry edges (e.g., https://www.openstreetmap.org/way/204337649) Therefore, we shut off aggregation on these edges.

Also, when building shortcuts it was seen that the shortcut length was different than the sum of the lengths of the edges comprising the shortcut. This can cause issues with elevation builder which relies on the length of the edge and the length of the shape being nearly equal. When creating shortcuts, we previously simply added the lengths of each directed edge of the shortcut. Since these are stored as integer precision this can lead to roundoff errors. This PR changes the length of the shortcut to be the length of the shape rather than the sum of the lengths of the edges. This requires a change to shortcut recovery to allow some roundoff when checking shortcut length compared to sum of the edge lengths.

Tasklist

…s a catastrophic error - so no use continuing.
…original edge of the shortcut can lead to roundoff issues that lead to edgeinfo offset errors when adding elevation.
…ifference in elevation. No longer add each elevation along the edge.
… directed edge lengths) we need to add a roundoff to the length comparison when recovering shortcuts.
…plete. Also, added classification check due to ferry reclassification
@gknisely
Copy link
Member Author

gknisely commented Feb 6, 2024

co-author @dnesbitt61

@gknisely gknisely changed the title Aggregation fixes Aggregation updates: update opposing local idx after aggregating the edges, added classification check for aggregation, and shortcut length changes Feb 6, 2024
auto d = std::abs(heights[i] - heights[i + 1]);
diff = d < diff ? diff : d;
}
auto d = std::abs(heights[i] - heights[i - 1]);
Copy link
Member

Choose a reason for hiding this comment

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

this was missing the first height. Made this consistent with the bss check below. No need for if check anymore either.

LOG_ERROR("GraphTileBuilder TileID: " + std::to_string(header_->graphid().tileid()) +
" offset stored in directed edge: = " + std::to_string(offset) +
" current ei offset= " + std::to_string(edge_info_offset_));
throw std::runtime_error("EdgeInfo offsets incorrect when reading GraphTile");
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 a critical error. If we see one, we likely see a bunch more throughout the tile. I think we should throw an error here.

// Names can be different in the forward and backward direction
bool diff_names = tilebuilder.OpposingEdgeInfoDiffers(tile, directededge);

// Get the length from the shape. This prevents roundoff issues when forming
// elevation.
uint32_t length = valhalla::midgard::length(shape);
Copy link
Member

Choose a reason for hiding this comment

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

Length of shortcut is not always equal to the sum of the links of the directed edges comprising the shortcut due to directed edge length being cast to integer - thus leading to roundoff errors. This discrepancy between shortcut length (stored in the directed edge) and shape length can lead to elevation encoding issues.

Copy link
Member

Choose a reason for hiding this comment

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

good catch!

for (size_t i = 1; i < heights.size(); i++) {
auto d = std::abs(heights[i] - heights[i - 1]);
diff = d < diff ? diff : d;
LOG_INFO(" " + std::to_string(heights[i]));
Copy link
Member

Choose a reason for hiding this comment

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

why the change to INFO though? I remember this being crazy noisy, like 100s mb logs per minute. likely rather the function above, not the btf one, but IMO debug logging is enough for all of them

Copy link
Member

Choose a reason for hiding this comment

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

ughh...this is a mistake. sorry.

if (current_edge == nullptr || accumulated_length > shortcut->length()) {
++edge_count;
roundoff_error = std::round(edge_count * 0.5) + 1;
if (current_edge == nullptr || accumulated_length > (shortcut->length() + roundoff_error)) {
Copy link
Member

Choose a reason for hiding this comment

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

this check may not be needed. Accumulating edge lengths (which have been truncated to int) should never lead to being greater than the shortcut length computed from the shape (and then truncated to int).

@@ -183,7 +189,7 @@ struct shortcut_recovery_t {
}

// we somehow got to the end via a shorter path
if (accumulated_length < shortcut->length()) {
if (accumulated_length < (shortcut->length() - roundoff_error)) {
Copy link
Member

Choose a reason for hiding this comment

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

but using roundoff here is definitely needed.

@nilsnolde
Copy link
Member

Is it possible to come up with a gurka test map for the roundabout/ferry cases this PR fixes?

@gknisely
Copy link
Member Author

gknisely commented Feb 7, 2024

Is it possible to come up with a gurka test map for the roundabout/ferry cases this PR fixes?

@nilsnolde I tried to create one for roundabout and could not make it happen as you need large number of ways and nodes. As for the ferry, I did not try and was wondering if I can add it later?

nilsnolde
nilsnolde previously approved these changes Feb 7, 2024
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

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

I didn't check much of the logic, approving on the premise that a full planet build and regression test suite passed:)

@gknisely gknisely merged commit 30068b1 into master Feb 13, 2024
8 of 9 checks passed
@gknisely gknisely deleted the aggregation_fixes branch February 13, 2024 18:04
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.

None yet

3 participants