I have a large graph in which I want to find a subgraph isomorphism using the built-in VF2 algorithm in NetworkX. Both the 'haystack' as well as 'needle' graphs are directed. Take the following trivial example:
from networkx.algorithms.isomorphism import DiGraphMatcher
G1 = nx.complete_graph(20, nx.DiGraph)
G2 = nx.DiGraph()
G2.add_edge(1, 2)
list(DiGraphMatcher(G1, G2).subgraph_isomorphisms_iter())
The final line returns an empty list []
.
My understanding is that this should return all edges in the graph, and indeed, if I substitute GraphMatcher
for DiGraphMatcher
, I get a list of all edges.
Is there something wrong with DiGraphMatcher
, or perhaps something wrong with my understanding of what DiGraphMatcher
should be doing?
Versions:
- Python: 3.7.7
- NetworkX: 2.4
Example undirected graph code (replaces all DiGraph
with Graph
, otherwise the same):
from networkx.algorithms.isomorphism import GraphMatcher
G1 = nx.complete_graph(20, nx.Graph)
G2 = nx.Graph()
G2.add_edge(1, 2)
list(GraphMatcher(G1, G2).subgraph_isomorphisms_iter())