예제 #1
0
    def setUp(self):
        G1 = cnlti(nx.grid_2d_graph(2, 2), first_label=0, ordering="sorted")
        G2 = cnlti(nx.lollipop_graph(3, 3), first_label=4, ordering="sorted")
        G3 = cnlti(nx.house_graph(), first_label=10, ordering="sorted")
        self.G = nx.union(G1, G2)
        self.G = nx.union(self.G, G3)
        self.DG = nx.DiGraph([(1, 2), (1, 3), (2, 3)])
        self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1)

        self.gc = []
        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (2, 8), (3, 4), (3, 7), (4, 5),
                          (5, 3), (5, 6), (7, 4), (7, 6), (8, 1), (8, 7)])
        C = [[3, 4, 5, 7], [1, 2, 8], [6]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (1, 3), (1, 4), (4, 2), (3, 4), (2, 3)])
        C = [[2, 3, 4],[1]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (3, 2), (2, 1)])
        C = [[1, 2, 3]]
        self.gc.append((G,C))

        # Eppstein's tests
        G = nx.DiGraph({0:[1], 1:[2, 3], 2:[4, 5], 3:[4, 5], 4:[6], 5:[], 6:[]})
        C = [[0], [1], [2],[ 3], [4], [5], [6]]
        self.gc.append((G,C))

        G = nx.DiGraph({0:[1], 1:[2, 3, 4], 2:[0, 3], 3:[4], 4:[3]})
        C = [[0, 1, 2], [3, 4]]
        self.gc.append((G, C))
예제 #2
0
    def setUp(self):
        G1 = cnlti(nx.grid_2d_graph(2, 2), first_label=0, ordering="sorted")
        G2 = cnlti(nx.lollipop_graph(3, 3), first_label=4, ordering="sorted")
        G3 = cnlti(nx.house_graph(), first_label=10, ordering="sorted")
        self.G = nx.union(G1, G2)
        self.G = nx.union(self.G, G3)
        self.DG = nx.DiGraph([(1, 2), (1, 3), (2, 3)])
        self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1)

        self.gc = []
        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (2, 8), (3, 4), (3, 7), (4, 5),
                          (5, 3), (5, 6), (7, 4), (7, 6), (8, 1), (8, 7)])
        C = [[3, 4, 5, 7], [1, 2, 8], [6]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (1, 3), (1, 4), (4, 2), (3, 4), (2, 3)])
        C = [[2, 3, 4],[1]]
        self.gc.append((G, C))

        G = nx.DiGraph()
        G.add_edges_from([(1, 2), (2, 3), (3, 2), (2, 1)])
        C = [[1, 2, 3]]
        self.gc.append((G,C))

        # Eppstein's tests
        G = nx.DiGraph({0:[1], 1:[2, 3], 2:[4, 5], 3:[4, 5], 4:[6], 5:[], 6:[]})
        C = [[0], [1], [2],[ 3], [4], [5], [6]]
        self.gc.append((G,C))

        G = nx.DiGraph({0:[1], 1:[2, 3, 4], 2:[0, 3], 3:[4], 4:[3]})
        C = [[0, 1, 2], [3, 4]]
        self.gc.append((G, C))
예제 #3
0
 def setUp(self):
     G1=cnlti(nx.grid_2d_graph(2,2),first_label=0,ordering="sorted")
     G2=cnlti(nx.lollipop_graph(3,3),first_label=4,ordering="sorted")
     G3=cnlti(nx.house_graph(),first_label=10,ordering="sorted")
     self.G=nx.union(G1,G2)
     self.G=nx.union(self.G,G3)
     self.DG=nx.DiGraph([(1,2),(1,3),(2,3)])
     self.grid=cnlti(nx.grid_2d_graph(4,4),first_label=1)
예제 #4
0
def test_shortest_simple_paths():
    G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    paths = nx.shortest_simple_paths(G, 1, 12)
    assert_equal(next(paths), [1, 2, 3, 4, 8, 12])
    assert_equal(next(paths), [1, 5, 6, 7, 8, 12])
    assert_equal([len(path) for path in nx.shortest_simple_paths(G, 1, 12)],
                 sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
예제 #5
0
def test_shortest_simple_paths():
    G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    paths = nx.shortest_simple_paths(G, 1, 12)
    assert_equal(next(paths), [1, 2, 3, 4, 8, 12])
    assert_equal(next(paths), [1, 5, 6, 7, 8, 12])
    assert_equal([len(path) for path in nx.shortest_simple_paths(G, 1, 12)],
                 sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
 def setUp(self):
     from networkx import convert_node_labels_to_integers as cnlti
     self.grid = cnlti(nx.grid_2d_graph(4, 4),
                       first_label=1,
                       ordering="sorted")
     self.cycle = nx.cycle_graph(7)
     self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
예제 #7
0
 def setup_class(cls):
     from networkx import convert_node_labels_to_integers as cnlti
     cls.grid = cnlti(nx.grid_2d_graph(4, 4),
                      first_label=1,
                      ordering="sorted")
     cls.cycle = nx.cycle_graph(7)
     cls.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
예제 #8
0
 def setUp(self):
     G = networkx.Graph()
     from networkx import convert_node_labels_to_integers as cnlti
     G = cnlti(networkx.grid_2d_graph(4, 4),
               first_label=1,
               ordering="sorted")
     self.G = G
예제 #9
0
def test_shortest_simple_paths():
    G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    paths = nx.shortest_simple_paths(G, 1, 12)
    assert next(paths) == [1, 2, 3, 4, 8, 12]
    assert next(paths) == [1, 5, 6, 7, 8, 12]
    assert [len(path) for path in nx.shortest_simple_paths(G, 1, 12)
            ] == sorted(len(path) for path in nx.all_simple_paths(G, 1, 12))
예제 #10
0
    def setUp(self):
        from networkx import convert_node_labels_to_integers as cnlti
        self.grid = cnlti(nx.grid_2d_graph(4, 4),
                          first_label=1,
                          ordering="sorted")
        self.cycle = nx.cycle_graph(7)
        self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
        self.XG = nx.DiGraph()
        self.XG.add_weighted_edges_from([('s', 'u', 10), ('s', 'x', 5),
                                         ('u', 'v', 1), ('u', 'x', 2),
                                         ('v', 'y', 1), ('x', 'u', 3),
                                         ('x', 'v', 5), ('x', 'y', 2),
                                         ('y', 's', 7), ('y', 'v', 6)])
        self.MXG = nx.MultiDiGraph(self.XG)
        self.MXG.add_edge('s', 'u', weight=15)
        self.XG2 = nx.DiGraph()
        self.XG2.add_weighted_edges_from([[1, 4, 1], [4, 5, 1], [5, 6, 1],
                                          [6, 3, 1], [1, 3, 50], [1, 2, 100],
                                          [2, 3, 100]])

        self.XG3 = nx.Graph()
        self.XG3.add_weighted_edges_from([[0, 1, 2], [1, 2, 12], [2, 3, 1],
                                          [3, 4, 5], [4, 5, 1], [5, 0, 10]])

        self.XG4 = nx.Graph()
        self.XG4.add_weighted_edges_from([[0, 1, 2], [1, 2, 2], [2, 3, 1],
                                          [3, 4, 1], [4, 5, 1], [5, 6, 1],
                                          [6, 7, 1], [7, 0, 1]])
        self.MXG4 = nx.MultiGraph(self.XG4)
        self.MXG4.add_edge(0, 1, weight=3)
        self.G = nx.DiGraph()  # no weights
        self.G.add_edges_from([('s', 'u'), ('s', 'x'), ('u', 'v'), ('u', 'x'),
                               ('v', 'y'), ('x', 'u'), ('x', 'v'), ('x', 'y'),
                               ('y', 's'), ('y', 'v')])
예제 #11
0
 def setUp(self):
     z=[3,4,3,4,2,4,2,1,1,1,1]
     self.G=cnlti(nx.generators.havel_hakimi_graph(z),first_label=1)
     self.cl=list(nx.find_cliques(self.G))
     H=nx.complete_graph(6)
     H=nx.relabel_nodes(H,dict( [(i,i+1) for i in range(6)]))
     H.remove_edges_from([(2,6),(2,5),(2,4),(1,3),(5,3)])
     self.H=H
예제 #12
0
 def setup_method(self):
     z = [3, 4, 3, 4, 2, 4, 2, 1, 1, 1, 1]
     self.G = cnlti(nx.generators.havel_hakimi_graph(z), first_label=1)
     self.cl = list(nx.find_cliques(self.G))
     H = nx.complete_graph(6)
     H = nx.relabel_nodes(H, dict([(i, i + 1) for i in range(6)]))
     H.remove_edges_from([(2, 6), (2, 5), (2, 4), (1, 3), (5, 3)])
     self.H = H
예제 #13
0
 def test_path_graph(self):
     P10 = cnlti(nx.path_graph(10), first_label=1)
     assert nx.node_boundary(P10, []) == set()
     assert nx.node_boundary(P10, [], []) == set()
     assert nx.node_boundary(P10, [1, 2, 3]) == {4}
     assert nx.node_boundary(P10, [4, 5, 6]) == {3, 7}
     assert nx.node_boundary(P10, [3, 4, 5, 6, 7]) == {2, 8}
     assert nx.node_boundary(P10, [8, 9, 10]) == {7}
     assert nx.node_boundary(P10, [4, 5, 6], [9, 10]) == set()
예제 #14
0
 def test_path_graph(self):
     P10 = cnlti(nx.path_graph(10), first_label=1)
     assert_equal(nx.node_boundary(P10, []), set())
     assert_equal(nx.node_boundary(P10, [], []), set())
     assert_equal(nx.node_boundary(P10, [1, 2, 3]), {4})
     assert_equal(nx.node_boundary(P10, [4, 5, 6]), {3, 7})
     assert_equal(nx.node_boundary(P10, [3, 4, 5, 6, 7]), {2, 8})
     assert_equal(nx.node_boundary(P10, [8, 9, 10]), {7})
     assert_equal(nx.node_boundary(P10, [4, 5, 6], [9, 10]), set())
예제 #15
0
def test_shortest_simple_paths_directed_with_weight_fucntion():
    def cost(u, v, x):
        return 1
    G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    paths = nx.shortest_simple_paths(G, 1, 12)
    assert next(paths) == [1, 2, 3, 4, 8, 12]
    assert next(paths) == [1, 5, 6, 7, 8, 12]
    assert ([len(path) for path in nx.shortest_simple_paths(G, 1, 12, weight=cost)]
            == sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
예제 #16
0
 def test_path_graph(self):
     P10 = cnlti(nx.path_graph(10), first_label=1)
     assert_equal(nx.node_boundary(P10, []), set())
     assert_equal(nx.node_boundary(P10, [], []), set())
     assert_equal(nx.node_boundary(P10, [1, 2, 3]), {4})
     assert_equal(nx.node_boundary(P10, [4, 5, 6]), {3, 7})
     assert_equal(nx.node_boundary(P10, [3, 4, 5, 6, 7]), {2, 8})
     assert_equal(nx.node_boundary(P10, [8, 9, 10]), {7})
     assert_equal(nx.node_boundary(P10, [4, 5, 6], [9, 10]), set())
예제 #17
0
    def setup_class(cls):
        from networkx import convert_node_labels_to_integers as cnlti

        # NB: graphscope.nx does not support grid_2d_graph(which use tuple as node)
        # we use a tricky way to replace it.
        grid = cnlti(grid_2d_graph(4, 4), first_label=1, ordering="sorted")
        cls.grid = nx.Graph(grid)
        cls.cycle = nx.cycle_graph(7)
        cls.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
예제 #18
0
 def setUp(self):
     self.null = nx.null_graph()
     self.P1 = cnlti(nx.path_graph(1), first_label=1)
     self.P3 = cnlti(nx.path_graph(3), first_label=1)
     self.P10 = cnlti(nx.path_graph(10), first_label=1)
     self.K1 = cnlti(nx.complete_graph(1), first_label=1)
     self.K3 = cnlti(nx.complete_graph(3), first_label=1)
     self.K4 = cnlti(nx.complete_graph(4), first_label=1)
     self.K5 = cnlti(nx.complete_graph(5), first_label=1)
     self.K10 = cnlti(nx.complete_graph(10), first_label=1)
     self.G = nx.Graph
예제 #19
0
 def setUp(self):
     self.null=nx.null_graph()
     self.P1=cnlti(nx.path_graph(1),first_label=1)
     self.P3=cnlti(nx.path_graph(3),first_label=1)
     self.P10=cnlti(nx.path_graph(10),first_label=1)
     self.K1=cnlti(nx.complete_graph(1),first_label=1)
     self.K3=cnlti(nx.complete_graph(3),first_label=1)
     self.K4=cnlti(nx.complete_graph(4),first_label=1)
     self.K5=cnlti(nx.complete_graph(5),first_label=1)
     self.K10=cnlti(nx.complete_graph(10),first_label=1)
     self.G=nx.Graph
예제 #20
0
 def setup_class(cls):
     cls.null = nx.null_graph()
     cls.P1 = cnlti(nx.path_graph(1), first_label=1)
     cls.P3 = cnlti(nx.path_graph(3), first_label=1)
     cls.P10 = cnlti(nx.path_graph(10), first_label=1)
     cls.K1 = cnlti(nx.complete_graph(1), first_label=1)
     cls.K3 = cnlti(nx.complete_graph(3), first_label=1)
     cls.K4 = cnlti(nx.complete_graph(4), first_label=1)
     cls.K5 = cnlti(nx.complete_graph(5), first_label=1)
     cls.K10 = cnlti(nx.complete_graph(10), first_label=1)
     cls.G = nx.Graph
예제 #21
0
 def test_complete_graph(self):
     K10 = cnlti(nx.complete_graph(10), first_label=1)
     assert_equal(nx.node_boundary(K10, []), set())
     assert_equal(nx.node_boundary(K10, [], []), set())
     assert_equal(nx.node_boundary(K10, [1, 2, 3]), {4, 5, 6, 7, 8, 9, 10})
     assert_equal(nx.node_boundary(K10, [4, 5, 6]), {1, 2, 3, 7, 8, 9, 10})
     assert_equal(nx.node_boundary(K10, [3, 4, 5, 6, 7]), {1, 2, 8, 9, 10})
     assert_equal(nx.node_boundary(K10, [4, 5, 6], []), set())
     assert_equal(nx.node_boundary(K10, K10), set())
     assert_equal(nx.node_boundary(K10, [1, 2, 3], [3, 4, 5]), {4, 5})
예제 #22
0
 def test_path_graph(self):
     P10 = cnlti(nx.path_graph(10), first_label=1)
     assert list(nx.edge_boundary(P10, [])) == []
     assert list(nx.edge_boundary(P10, [], [])) == []
     assert list(nx.edge_boundary(P10, [1, 2, 3])) == [(3, 4)]
     assert sorted(nx.edge_boundary(P10, [4, 5, 6])) == [(4, 3), (6, 7)]
     assert sorted(nx.edge_boundary(P10, [3, 4, 5, 6, 7])) == [(3, 2), (7, 8)]
     assert list(nx.edge_boundary(P10, [8, 9, 10])) == [(8, 7)]
     assert sorted(nx.edge_boundary(P10, [4, 5, 6], [9, 10])) == []
     assert list(nx.edge_boundary(P10, [1, 2, 3], [3, 4, 5])) == [(2, 3), (3, 4)]
예제 #23
0
 def test_complete_graph(self):
     K10 = cnlti(nx.complete_graph(10), first_label=1)
     assert_equal(nx.node_boundary(K10, []), set())
     assert_equal(nx.node_boundary(K10, [], []), set())
     assert_equal(nx.node_boundary(K10, [1, 2, 3]), {4, 5, 6, 7, 8, 9, 10})
     assert_equal(nx.node_boundary(K10, [4, 5, 6]), {1, 2, 3, 7, 8, 9, 10})
     assert_equal(nx.node_boundary(K10, [3, 4, 5, 6, 7]), {1, 2, 8, 9, 10})
     assert_equal(nx.node_boundary(K10, [4, 5, 6], []), set())
     assert_equal(nx.node_boundary(K10, K10), set())
     assert_equal(nx.node_boundary(K10, [1, 2, 3], [3, 4, 5]), {4, 5})
예제 #24
0
 def setUp(self):
     from networkx import convert_node_labels_to_integers as cnlti
     self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1,
                       ordering="sorted")
     self.cycle = nx.cycle_graph(7)
     self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
     self.neg_weights = nx.DiGraph()
     self.neg_weights.add_edge(0, 1, weight=1)
     self.neg_weights.add_edge(0, 2, weight=3)
     self.neg_weights.add_edge(1, 3, weight=1)
     self.neg_weights.add_edge(2, 3, weight=-2)
예제 #25
0
 def setUp(self):
     from networkx import convert_node_labels_to_integers as cnlti
     self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1,
                       ordering="sorted")
     self.cycle = nx.cycle_graph(7)
     self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
     self.neg_weights = nx.DiGraph()
     self.neg_weights.add_edge(0, 1, weight=1)
     self.neg_weights.add_edge(0, 2, weight=3)
     self.neg_weights.add_edge(1, 3, weight=1)
     self.neg_weights.add_edge(2, 3, weight=-2)
예제 #26
0
 def setup_class(cls):
     from networkx import convert_node_labels_to_integers as cnlti
     cls.grid = cnlti(nx.grid_2d_graph(4, 4),
                      first_label=1,
                      ordering="sorted")
     cls.cycle = nx.cycle_graph(7)
     cls.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
     cls.neg_weights = nx.DiGraph()
     cls.neg_weights.add_edge(0, 1, weight=1)
     cls.neg_weights.add_edge(0, 2, weight=3)
     cls.neg_weights.add_edge(1, 3, weight=1)
     cls.neg_weights.add_edge(2, 3, weight=-2)
예제 #27
0
    def setUp(self):
        from networkx import convert_node_labels_to_integers as cnlti

        self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
        self.cycle = nx.cycle_graph(7)
        self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
        self.XG = nx.DiGraph()
        self.XG.add_weighted_edges_from(
            [
                ("s", "u", 10),
                ("s", "x", 5),
                ("u", "v", 1),
                ("u", "x", 2),
                ("v", "y", 1),
                ("x", "u", 3),
                ("x", "v", 5),
                ("x", "y", 2),
                ("y", "s", 7),
                ("y", "v", 6),
            ]
        )
        self.MXG = nx.MultiDiGraph(self.XG)
        self.MXG.add_edge("s", "u", weight=15)
        self.XG2 = nx.DiGraph()
        self.XG2.add_weighted_edges_from(
            [[1, 4, 1], [4, 5, 1], [5, 6, 1], [6, 3, 1], [1, 3, 50], [1, 2, 100], [2, 3, 100]]
        )

        self.XG3 = nx.Graph()
        self.XG3.add_weighted_edges_from([[0, 1, 2], [1, 2, 12], [2, 3, 1], [3, 4, 5], [4, 5, 1], [5, 0, 10]])

        self.XG4 = nx.Graph()
        self.XG4.add_weighted_edges_from(
            [[0, 1, 2], [1, 2, 2], [2, 3, 1], [3, 4, 1], [4, 5, 1], [5, 6, 1], [6, 7, 1], [7, 0, 1]]
        )
        self.MXG4 = nx.MultiGraph(self.XG4)
        self.MXG4.add_edge(0, 1, weight=3)
        self.G = nx.DiGraph()  # no weights
        self.G.add_edges_from(
            [
                ("s", "u"),
                ("s", "x"),
                ("u", "v"),
                ("u", "x"),
                ("v", "y"),
                ("x", "u"),
                ("x", "v"),
                ("x", "y"),
                ("y", "s"),
                ("y", "v"),
            ]
        )
예제 #28
0
 def test_path_graph(self):
     P10 = cnlti(nx.path_graph(10), first_label=1)
     assert_equal(list(nx.edge_boundary(P10, [])), [])
     assert_equal(list(nx.edge_boundary(P10, [], [])), [])
     assert_equal(list(nx.edge_boundary(P10, [1, 2, 3])), [(3, 4)])
     assert_equal(sorted(nx.edge_boundary(P10, [4, 5, 6])),
                  [(4, 3), (6, 7)])
     assert_equal(sorted(nx.edge_boundary(P10, [3, 4, 5, 6, 7])),
                  [(3, 2), (7, 8)])
     assert_equal(list(nx.edge_boundary(P10, [8, 9, 10])), [(8, 7)])
     assert_equal(sorted(nx.edge_boundary(P10, [4, 5, 6], [9, 10])), [])
     assert_equal(list(nx.edge_boundary(P10, [1, 2, 3], [3, 4, 5])),
                  [(2, 3), (3, 4)])
예제 #29
0
 def test_complete_graph(self):
     K10 = cnlti(nx.complete_graph(10), first_label=1)
     ilen = lambda iterable: sum(1 for i in iterable)
     assert_equal(list(nx.edge_boundary(K10, [])), [])
     assert_equal(list(nx.edge_boundary(K10, [], [])), [])
     assert_equal(ilen(nx.edge_boundary(K10, [1, 2, 3])), 21)
     assert_equal(ilen(nx.edge_boundary(K10, [4, 5, 6, 7])), 24)
     assert_equal(ilen(nx.edge_boundary(K10, [3, 4, 5, 6, 7])), 25)
     assert_equal(ilen(nx.edge_boundary(K10, [8, 9, 10])), 21)
     assert_equal(sorted(nx.edge_boundary(K10, [4, 5, 6], [9, 10])),
                  [(4, 9), (4, 10), (5, 9), (5, 10), (6, 9), (6, 10)])
     assert_equal(sorted(nx.edge_boundary(K10, [1, 2, 3], [3, 4, 5])),
                  [(1, 3), (1, 4), (1, 5), (2, 3), (2, 4),
                   (2, 5), (3, 4), (3, 5)])
예제 #30
0
 def test_complete_graph(self):
     K10 = cnlti(nx.complete_graph(10), first_label=1)
     ilen = lambda iterable: sum(1 for i in iterable)
     assert_equal(list(nx.edge_boundary(K10, [])), [])
     assert_equal(list(nx.edge_boundary(K10, [], [])), [])
     assert_equal(ilen(nx.edge_boundary(K10, [1, 2, 3])), 21)
     assert_equal(ilen(nx.edge_boundary(K10, [4, 5, 6, 7])), 24)
     assert_equal(ilen(nx.edge_boundary(K10, [3, 4, 5, 6, 7])), 25)
     assert_equal(ilen(nx.edge_boundary(K10, [8, 9, 10])), 21)
     assert_equal(sorted(nx.edge_boundary(K10, [4, 5, 6], [9, 10])),
                  [(4, 9), (4, 10), (5, 9), (5, 10), (6, 9), (6, 10)])
     assert_equal(sorted(nx.edge_boundary(K10, [1, 2, 3], [3, 4, 5])),
                  [(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4),
                   (3, 5)])
    def test_complete_graph(self):
        K10 = cnlti(nx.complete_graph(10), first_label=1)

        def ilen(iterable):
            return sum(1 for i in iterable)

        assert list(nx.edge_boundary(K10, [])) == []
        assert list(nx.edge_boundary(K10, [], [])) == []
        assert ilen(nx.edge_boundary(K10, [1, 2, 3])) == 21
        assert ilen(nx.edge_boundary(K10, [4, 5, 6, 7])) == 24
        assert ilen(nx.edge_boundary(K10, [3, 4, 5, 6, 7])) == 25
        assert ilen(nx.edge_boundary(K10, [8, 9, 10])) == 21
        assert_edges_equal(nx.edge_boundary(K10, [4, 5, 6], [9, 10]),
                           [(4, 9), (4, 10), (5, 9), (5, 10), (6, 9), (6, 10)])
        assert_edges_equal(nx.edge_boundary(K10, [1, 2, 3], [3, 4, 5]),
                           [(1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5),
                            (3, 4), (3, 5)])
예제 #32
0
def test_bidirectional_shortest_path_restricted():
    grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    cycle = nx.cycle_graph(7)
    directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
    length, path = _bidirectional_shortest_path(cycle, 0, 3)
    assert_equal(path, [0, 1, 2, 3])
    length, path = _bidirectional_shortest_path(cycle, 0, 3, ignore_nodes=[1])
    assert_equal(path, [0, 6, 5, 4, 3])
    length, path = _bidirectional_shortest_path(grid, 1, 12)
    assert_equal(path, [1, 2, 3, 4, 8, 12])
    length, path = _bidirectional_shortest_path(grid, 1, 12, ignore_nodes=[2])
    assert_equal(path, [1, 5, 6, 10, 11, 12])
    length, path = _bidirectional_shortest_path(grid,
                                                1,
                                                12,
                                                ignore_nodes=[2, 6])
    assert_equal(path, [1, 5, 9, 10, 11, 12])
    length, path = _bidirectional_shortest_path(grid,
                                                1,
                                                12,
                                                ignore_nodes=[2, 6],
                                                ignore_edges=[(10, 11)])
    assert_equal(path, [1, 5, 9, 10, 14, 15, 16, 12])
    length, path = _bidirectional_shortest_path(directed_cycle, 0, 3)
    assert_equal(path, [0, 1, 2, 3])
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_shortest_path,
        directed_cycle,
        0,
        3,
        ignore_nodes=[1],
    )
    length, path = _bidirectional_shortest_path(directed_cycle,
                                                0,
                                                3,
                                                ignore_edges=[(2, 1)])
    assert_equal(path, [0, 1, 2, 3])
    assert_raises(
        nx.NetworkXNoPath,
        _bidirectional_shortest_path,
        directed_cycle,
        0,
        3,
        ignore_edges=[(1, 2)],
    )
예제 #33
0
def test_bidirectional_shortest_path_restricted():
    grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    cycle = nx.cycle_graph(7)
    directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
    length, path = _bidirectional_shortest_path(cycle, 0, 3)
    assert_equal(path, [0, 1, 2, 3])
    length, path = _bidirectional_shortest_path(cycle, 0, 3, ignore_nodes=[1])
    assert_equal(path, [0, 6, 5, 4, 3])
    length, path = _bidirectional_shortest_path(grid, 1, 12)
    assert_equal(path, [1, 2, 3, 4, 8, 12])
    length, path = _bidirectional_shortest_path(grid, 1, 12, ignore_nodes=[2])
    assert_equal(path, [1, 5, 6, 10, 11, 12])
    length, path = _bidirectional_shortest_path(grid, 1, 12, ignore_nodes=[2, 6])
    assert_equal(path, [1, 5, 9, 10, 11, 12])
    length, path = _bidirectional_shortest_path(grid, 1, 12, ignore_nodes=[2, 6], ignore_edges=[(10, 11)])
    assert_equal(path, [1, 5, 9, 10, 14, 15, 16, 12])
    length, path = _bidirectional_shortest_path(directed_cycle, 0, 3)
    assert_equal(path, [0, 1, 2, 3])
    assert_raises(nx.NetworkXNoPath, _bidirectional_shortest_path, directed_cycle, 0, 3, ignore_nodes=[1])
    length, path = _bidirectional_shortest_path(directed_cycle, 0, 3, ignore_edges=[(2, 1)])
    assert_equal(path, [0, 1, 2, 3])
    assert_raises(nx.NetworkXNoPath, _bidirectional_shortest_path, directed_cycle, 0, 3, ignore_edges=[(1, 2)])
 def setUp(self):
     G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
     self.G = G
 def setUp(self):
     G=networkx.Graph() 
     from networkx import convert_node_labels_to_integers as cnlti
     G=cnlti(networkx.grid_2d_graph(4,4),first_label=1,ordering="sorted")
     self.G=G
예제 #36
0
 def setUp(self):
     G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
     self.G = G
예제 #37
0
 def setUp(self):
     from networkx import convert_node_labels_to_integers as cnlti
     self.grid=cnlti(nx.grid_2d_graph(4,4),first_label=1,ordering="sorted")
     self.cycle=nx.cycle_graph(7)
     self.directed_cycle=nx.cycle_graph(7,create_using=nx.DiGraph())
예제 #38
0
 def setUp(self):
     self.null=nx.null_graph()
     self.P10=cnlti(nx.path_graph(10),first_label=1)
     self.K10=cnlti(nx.complete_graph(10),first_label=1)
예제 #39
0
 def setUp(self):
     self.null = nx.null_graph()
     self.P10 = cnlti(nx.path_graph(10), first_label=1)
     self.K10 = cnlti(nx.complete_graph(10), first_label=1)