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

vf2_sub_graph_iso.hpp: fix bug when subgraph is filtered #282

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

count0
Copy link

@count0 count0 commented Jan 2, 2022

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.

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.
@jeremy-murphy
Copy link
Contributor

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?

Comment on lines 81 to 84
typename graph_traits<Graph>::vertices_size_type N = 0;
BGL_FORALL_VERTICES_T(v, g, Graph)
N++;
return N;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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).

Copy link
Author

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!

@jakobandersen
Copy link
Contributor

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?

Both graphs can be potentially be filtered, but I think the PR covers it. The check in success() is for whether all the vertices in the "small" graph has been mapped, and with the initial vertex count checks that is enough.

@count0
Copy link
Author

count0 commented Jan 4, 2022

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.)

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.

@jeremy-murphy
Copy link
Contributor

If necessary I could translate it to a minimal C++ code.

Yes, please, that is what I would like.

The develop branch appears to be green now, so we can actually merge this when it's done.

@jeremy-murphy
Copy link
Contributor

@count0 do you have time to address the issues I commented on and add the unit test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants