-
Notifications
You must be signed in to change notification settings - Fork 63
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
Hydrofabric network cycle detection #718
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
#include <stdexcept> | ||
#include <boost/graph/reverse_graph.hpp> | ||
#include <boost/graph/graph_utility.hpp> | ||
#include <boost/graph/undirected_dfs.hpp> | ||
#include<boost/graph/properties.hpp> | ||
|
||
using namespace network; | ||
|
||
|
@@ -96,6 +98,20 @@ void Network::init_indicies(){ | |
} | ||
} | ||
|
||
//Do a cycle check and report cycles in the topology if they exist | ||
std::vector<std::pair<Graph::vertex_descriptor, Graph::vertex_descriptor>> cycles; | ||
detect_cycles vis(&cycles); | ||
//Run an undirected, depth first search applying the loop detector visitor | ||
//cycles added as vertex pairs for the closing edge of the cycle | ||
boost::undirected_dfs(this->graph, vis, make_assoc_property_map(vis.vertex_coloring), make_assoc_property_map(vis.edge_coloring)); | ||
if(cycles.size() > 0){ | ||
std::string msg = "The following features form a cycle:\n"; | ||
for(auto p : cycles){ | ||
msg += "\t"+get_id(p.first)+" --> "+get_id(p.second)+"\n"; | ||
} | ||
throw std::domain_error("Cycle(s) detected in hydrofabric\n"+msg); | ||
Comment on lines
+108
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As phrased, this message might confusingly suggest that the identifying elements of distinct cycles are actually the set of elements in a single cycle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would something like
be more clear? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's an improvement. Maybe "The following features each form the connecting edge of a cycle" (added 'each')? I realize we probably don't need to word-smith this much more, since anyone encountering this is pretty likely to make their way back to us to help with getting it resolved. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like added "each" to be clear when multiple cycles are found. I'll touch it up and rebase. |
||
} | ||
|
||
boost::topological_sort(this->graph, std::back_inserter(this->topo_order), | ||
boost::vertex_index_map(get(boost::vertex_index, this->graph))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just making the name a bit more verbose for clarity. Alternately,
Just don't name the temporary visitor object at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like the latter a bit better