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

fix(intersection): fix infinite loop in tsort #5332

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion planning/behavior_velocity_intersection_module/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ mergeLaneletsByTopologicalSort(
id2lanelet[id] = lanelet;
ind++;
}
// NOTE: this function aims to traverse the detection lanelet backward from ego side to farthest
// side, so if lane B follows lane A on the routing_graph, adj[B][A] = true
for (const auto & lanelet : lanelets) {
const auto & followings = routing_graph_ptr->following(lanelet);
const int dst = lanelet.id();
Expand All @@ -628,18 +630,25 @@ mergeLaneletsByTopologicalSort(
if (!has_no_previous(src)) {
continue;
}
// So `src` has no previous lanelets
branches[(ind2id[src])] = std::vector<lanelet::Id>{};
auto & branch = branches[(ind2id[src])];
lanelet::Id node_iter = ind2id[src];
std::set<lanelet::Id> visited_ids;
while (true) {
const auto & destinations = adjacency[(id2ind[node_iter])];
// NOTE: assuming detection lanelets have only one previous lanelet
// NOTE: assuming detection lanelets have only one "previous"(on the routing_graph) lanelet
const auto next = std::find(destinations.begin(), destinations.end(), true);
if (next == destinations.end()) {
branch.push_back(node_iter);
break;
}
if (visited_ids.find(node_iter) != visited_ids.end()) {
// loop detected
break;
}
branch.push_back(node_iter);
visited_ids.insert(node_iter);
node_iter = ind2id[std::distance(destinations.begin(), next)];
}
}
Expand Down