Example #1
0
def test_isomorphism_iter1():
    # As described in:
    # http://groups.google.com/group/networkx-discuss/browse_thread/thread/2ff65c67f5e3b99f/d674544ebea359bb?fwc=1
    g1 = nx.DiGraph()
    g2 = nx.DiGraph()
    g3 = nx.DiGraph()
    g1.add_edge('A', 'B')
    g1.add_edge('B', 'C')
    g2.add_edge('Y', 'Z')
    g3.add_edge('Z', 'Y')
    gm12 = vf2.DiGraphMatcher(g1, g2)
    gm13 = vf2.DiGraphMatcher(g1, g3)
    x = list(gm12.subgraph_isomorphisms_iter())
    y = list(gm13.subgraph_isomorphisms_iter())
    assert_true({'A': 'Y', 'B': 'Z'} in x)
    assert_true({'B': 'Y', 'C': 'Z'} in x)
    assert_true({'A': 'Z', 'B': 'Y'} in y)
    assert_true({'B': 'Z', 'C': 'Y'} in y)
    assert_true(len(x) == len(y))
    assert_true(len(x) == 2)
Example #2
0
def test_selfloop():
    # Simple test for graphs with selfloops
    edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 2), (2, 4), (3, 1), (3, 2),
             (4, 2), (4, 5), (5, 4)]
    nodes = range(6)

    for g1 in [nx.Graph(), nx.DiGraph()]:
        g1.add_edges_from(edges)
        for _ in range(100):
            new_nodes = list(nodes)
            random.shuffle(new_nodes)
            d = dict(zip(nodes, new_nodes))
            g2 = nx.relabel_nodes(g1, d)
            if not g1.is_directed():
                gm = vf2.GraphMatcher(g1, g2)
            else:
                gm = vf2.DiGraphMatcher(g1, g2)
            assert_true(gm.is_isomorphic())
Example #3
0
def test_multiedge():
    # Simple test for multigraphs
    # Need something much more rigorous
    edges = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8),
             (8, 9), (9, 10), (10, 11), (10, 11), (11, 12), (11, 12), (12, 13),
             (12, 13), (13, 14), (13, 14), (14, 15), (14, 15), (15, 16),
             (15, 16), (16, 17), (16, 17), (17, 18), (17, 18), (18, 19),
             (18, 19), (19, 0), (19, 0)]
    nodes = range(20)

    for g1 in [nx.MultiGraph(), nx.MultiDiGraph()]:
        g1.add_edges_from(edges)
        for _ in range(10):
            new_nodes = list(nodes)
            random.shuffle(new_nodes)
            d = dict(zip(nodes, new_nodes))
            g2 = nx.relabel_nodes(g1, d)
            if not g1.is_directed():
                gm = vf2.GraphMatcher(g1, g2)
            else:
                gm = vf2.DiGraphMatcher(g1, g2)
            assert_true(gm.is_isomorphic())