Пример #1
0
def test_isomorphism_iter2():
    # Path
    for L in range(2, 10):
        g1 = nx.path_graph(L)
        gm = vf2.GraphMatcher(g1, g1)
        s = len(list(gm.isomorphisms_iter()))
        assert_true(s == 2, s)
    # Cycle
    for L in range(3, 10):
        g1 = nx.cycle_graph(L)
        gm = vf2.GraphMatcher(g1, g1)
        s = len(list(gm.isomorphisms_iter()))
        assert_true(s == 2 * L)
Пример #2
0
 def test_subgraph(self):
     # A is the subgraph
     # B is the full graph
     head, tail = os.path.split(__file__)
     subgraph = self.create_graph(os.path.join(head, 'si2_b06_m200.A99'))
     graph = self.create_graph(os.path.join(head, 'si2_b06_m200.B99'))
     gm = vf2.GraphMatcher(graph, subgraph)
     assert_true(gm.subgraph_is_isomorphic())
Пример #3
0
 def test_subgraph(self):
     g1 = nx.Graph()
     g2 = nx.Graph()
     g1.add_edges_from(self.g1edges)
     g2.add_edges_from(self.g2edges)
     g3 = g2.subgraph([1, 2, 3, 4])
     gm = vf2.GraphMatcher(g1, g3)
     assert_true(gm.subgraph_is_isomorphic())
Пример #4
0
    def test_graph(self):
        g1 = nx.Graph()
        g2 = nx.Graph()
        g1.add_edges_from(self.g1edges)
        g2.add_edges_from(self.g2edges)
        gm = vf2.GraphMatcher(g1, g2)
        assert_true(gm.is_isomorphic())

        mapping = gm.mapping.items()
        mapping.sort()
        isomap = [('a', 1), ('b', 6), ('c', 3), ('d', 8), ('g', 2), ('h', 5),
                  ('i', 4), ('j', 7)]
        assert_true(mapping == isomap)
Пример #5
0
def test_graph_atlas():
    #Atlas = nx.graph_atlas_g()[0:208] # 208, 6 nodes or less
    Atlas = nx.graph_atlas_g()[0:100]
    alphabet = range(26)
    for graph in Atlas:
        nlist = graph.nodes()
        labels = alphabet[:len(nlist)]
        for s in range(10):
            random.shuffle(labels)
            d = dict(zip(nlist, labels))
            relabel = nx.relabel_nodes(graph, d)
            gm = vf2.GraphMatcher(graph, relabel)
            assert_true(gm.is_isomorphic())
Пример #6
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())
Пример #7
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())
Пример #8
0
 def test_graph(self):
     head, tail = os.path.split(__file__)
     g1 = self.create_graph(os.path.join(head, 'iso_r01_s80.A99'))
     g2 = self.create_graph(os.path.join(head, 'iso_r01_s80.B99'))
     gm = vf2.GraphMatcher(g1, g2)
     assert_true(gm.is_isomorphic())