-
Notifications
You must be signed in to change notification settings - Fork 212
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
vf2_sub_graph_iso.hpp: fix bug when subgraph is filtered #282
base: develop
Are you sure you want to change the base?
Conversation
This fixes a bug when num_vertices() returns a value that does not match the actual number of vertices. This happens for instances of filtered_graph<>. The fix involves looping over the graph to count the actual number of vertices. The performance overhead is negligible.
Thanks for contributing a fix. Could I ask you to please also add a small unit test that demonstrates the new functionality? (I.e. the test should fail without your changes.) I don't know the details of this algorithm -- do we only have to check if one graph is filtered, and not the other one? |
typename graph_traits<Graph>::vertices_size_type N = 0; | ||
BGL_FORALL_VERTICES_T(v, g, Graph) | ||
N++; | ||
return N; |
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.
typename graph_traits<Graph>::vertices_size_type N = 0; | |
BGL_FORALL_VERTICES_T(v, g, Graph) | |
N++; | |
return N; | |
typedef typename graph_traits<Graph>::vertex_iterator iter; | |
std::pair<iter, iter> vs = vertices(g); | |
return std::distance(vs.first, vs.second); |
The old num_vertices()
takes constant time, so having a raw loop which forces linear time is not ok. With std::distance()
it should only take linear time when needed (e.g., for filtered_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.
This is a good suggestion!
Both graphs can be potentially be filtered, but I think the PR covers it. The check in |
This problem has been noticed in graph-tool (which is built on top of BGL), for which there is a simple example where the code fails: https://git.skewed.de/count0/graph-tool/-/issues/715 If necessary I could translate it to a minimal C++ code. |
Yes, please, that is what I would like. The |
@count0 do you have time to address the issues I commented on and add the unit test? |
This fixes a bug when num_vertices() returns a value that does not match
the actual number of vertices. This happens for instances of
filtered_graph<>.
The fix involves looping over the graph to count the actual number of
vertices. The performance overhead is negligible.