Skip to content

Commit

Permalink
Fix inner to outer ordering issues
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Jan 5, 2024
1 parent faad486 commit 46d3853
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,12 @@ class PathOrderOptimizer
// initialize the roots set with all possible nodes
std::unordered_set<Path> roots;
std::unordered_set<Path> leaves;
std::unordered_map<Path, size_t> num_incoming_edges;
for (const auto& path : paths_)
{
roots.insert(path.vertices_);
leaves.insert(path.vertices_);
num_incoming_edges.emplace(path.vertices_, 0);
}

// remove all edges from roots with an incoming edge
Expand All @@ -371,6 +373,7 @@ class PathOrderOptimizer
{
roots.erase(v);
leaves.erase(u);
num_incoming_edges.find(v)->second ++;
}

// We used a shared visited set between runs of dfs. This is for the case when we reverse the ordering tree.
Expand All @@ -379,16 +382,24 @@ class PathOrderOptimizer
Point2LL current_position = start_point_;

std::function<std::vector<Path>(const Path, const std::unordered_multimap<Path, Path>&)> get_neighbours
= [current_position, this](const Path current_node, const std::unordered_multimap<Path, Path>& graph)
= [&current_position, &num_incoming_edges, this](const Path current_node, const std::unordered_multimap<Path, Path>& graph)
{
std::vector<Path> order; // Output order to traverse neighbors

const auto& [neighbour_begin, neighbour_end] = graph.equal_range(current_node);
auto candidates_iterator = ranges::make_subrange(neighbour_begin, neighbour_end);
std::unordered_set<Path> candidates;
for (const auto& [_, neighbour] : candidates_iterator)
for (const auto& [_, neighbour] : ranges::make_subrange(neighbour_begin, neighbour_end))
{
candidates.insert(neighbour);
// we only want to visit nodes that have no incoming edges, this is for the situation where we
// are printing paths from inner to outer. As the ordering tree is reversed, and we start traversing
// from an arbitrary leaf we might encounter a junction. All paths from the other leaf-side(s) of the junction
// should be printed before continuing the junctions. Only once every branch of the junction has been ordered
// we can continue with the junction itself.
num_incoming_edges.find(neighbour)->second --;
if (num_incoming_edges.at(neighbour) == 0)
{
candidates.insert(neighbour);
}
}

auto local_current_position = current_position;
Expand Down

0 comments on commit 46d3853

Please sign in to comment.