isomorphism#
- graph_tool.structure.isomorphism(g1, g2, vertex_inv1=None, vertex_inv2=None, isomap=False, edge_label=None)[git][source]#
Check whether two graphs are isomorphic.
- Parameters:
- g1
Graph First graph.
- g2
Graph Second graph.
- vertex_inv1
VertexPropertyMap(optional, default:None) Vertex invariant of the first graph. Only vertices with the same invariants are considered in the isomorphism.
- vertex_inv2
VertexPropertyMap(optional, default:None) Vertex invariant of the second graph. Only vertices with the same invariants are considered in the isomorphism.
- isomap
bool(optional, default:False) If
True, aVertexPropertyMapwith the isomorphism mapping is returned as well.- edge_labelpair of
EdgePropertyMap(optional, default:None) Edge labels of the first and second graph (in this order). If given, only isomorphisms that map every edge to one with the same label are considered.
- g1
- Returns:
- is_isomorphism
bool Trueif both graphs are isomorphic, otherwiseFalse.- isomap
VertexPropertyMap Isomorphism mapping corresponding to a property map belonging to the first graph which maps its vertices to their corresponding vertices of the second graph.
- is_isomorphism
See also
subgraph_isomorphismEmbeddings of a graph as a subgraph of another
bliss_automorphism_groupAutomorphism group with bliss
nauty_automorphism_groupAutomorphism group with nauty or Traces
weisfeiler_lehman_hashHash of a graph that is invariant under isomorphism
Notes
Without edge labels, the algorithm of [boost-isomorphism] is used, with the number of self-loops of each vertex included in its invariant. This algorithm does not take into account the multiplicities of the edges, so that if either graph has parallel edges between distinct vertices, or if edge labels are given, the isomorphism is searched instead with the VF2 algorithm of
subgraph_isomorphism(), with the vertex invariants as vertex labels, which maps every edge to a distinct edge, and takes into account self-loops and parallel edges.References
Examples
>>> g = gt.random_graph(100, lambda: (3,3)) >>> g2 = gt.Graph(g) >>> gt.isomorphism(g, g2) True >>> g.add_edge(g.vertex(0), g.vertex(1)) <...> >>> gt.isomorphism(g, g2) False
With edge labels, the isomorphisms must preserve them:
>>> g = gt.circular_graph(4) >>> g2 = gt.circular_graph(4) >>> l1 = g.new_ep("int", vals=[0, 1, 0, 1]) >>> l2 = g2.new_ep("int", vals=[0, 0, 1, 1]) >>> gt.isomorphism(g, g2, edge_label=(l1, l2)) False