当前位置: 首页>>代码示例>>Python>>正文


Python graphs.Graph类代码示例

本文整理汇总了Python中graphs.Graph的典型用法代码示例。如果您正苦于以下问题:Python Graph类的具体用法?Python Graph怎么用?Python Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Graph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_edge_not_valid_vertex

    def test_add_edge_not_valid_vertex(self):
        """Tests the add_edge method in a graph with a non-existing vertex.
        """
        graph = Graph(graph = { 'A' : [] })

        graph.add_edge('A', 'B')
        self.assertFalse(graph.has_edge('A', 'B'), 'No edge between A and non-existing B.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:7,代码来源:test_graphs.py

示例2: test_has_edge_no_connexion

    def test_has_edge_no_connexion(self):
        """Tests the has_edge method for a graph without connexion.
        """
        graph = Graph(graph = {'Z' : []})

        self.assertFalse(graph.has_edge('Z', 'A'), 'There is no edge between Z to A.')
        self.assertFalse(graph.has_edge('Z', None), 'There is no edge between Z and a None vertex.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:7,代码来源:test_graphs.py

示例3: build_graph

def build_graph(code):
    graph = Graph()
    blocks = [b["name"] for b in code["blocks"]]
    edges = [(b["name"], e) for b in code["blocks"] for e in b["next_block"]]
    graph.add_nodes(*blocks)
    graph.add_edges(*edges)
    return graph
开发者ID:minuteman3,项目名称:cs4071-ssa-optimiser,代码行数:7,代码来源:util.py

示例4: test_has_edge_directed

    def test_has_edge_directed(self):
        """Tests the has_edge method for a directed graph.
        """
        directed = Graph(graph = { 'C' : ['D'], 'D' : [] }, is_directed = True)

        self.assertTrue(directed.has_edge('C', 'D'), 'There is an edge from C to D.')
        self.assertFalse(directed.has_edge('D', 'C'), 'There is no edge from D to C.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:7,代码来源:test_graphs.py

示例5: test_has_edge_undirected

    def test_has_edge_undirected(self):
        """Tests the has_edge method for an undirected graph.
        """
        undirected = Graph(graph = { 'A' : ['B'], 'B' : ['A'] })

        self.assertTrue(undirected.has_edge('A', 'B'), 'There is an edge between A and B.')
        self.assertTrue(undirected.has_edge('B', 'A'), 'There is an edge between B and A.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:7,代码来源:test_graphs.py

示例6: test_contains_vertex

    def test_contains_vertex(self):
        """Tests the contains_vertex method with a single vertex.
        """
        data = { 'A' : [] }
        graph = Graph(graph=data)

        self.assertTrue(graph.contains_vertex('A'), 'The graph contains A.')
        self.assertFalse(graph.contains_vertex('B'), 'The graph does not contain B.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:8,代码来源:test_graphs.py

示例7: test_degree

 def test_degree(self):
     """Tests the degree methods in a graph.
     """
     graph = Graph(graph = { 'A' : ['B', 'C'], 'B' : ['A'], 'C' : [] })
     
     self.assertEqual(graph.interior_degree('A'), 1, 'There is 1 edge coming to A.')
     self.assertEqual(graph.exterior_degree('A'), 2, 'There are 2 edges extending from A.')
     self.assertEqual(graph.degree('A'), 3, 'There are 3 edges from and to A.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:8,代码来源:test_graphs.py

示例8: test_remove_unexisting_edge_with_unexisting_vertex

    def test_remove_unexisting_edge_with_unexisting_vertex(self):
        """Tests the remove_edge method in a graph between an existing vertex and a non-existing one.
        """
        graph = Graph(graph = { 'A' : [] })

        self.assertFalse(graph.has_edge('A', 'C'), 'There cannot be edge between A and C.')
        graph.remove_edge('A', 'C')
        self.assertFalse(graph.has_edge('A', 'C'), 'Nothing changed.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:8,代码来源:test_graphs.py

示例9: test_add_vertex

    def test_add_vertex(self):
        """Tests the add_vertex method with an empty graph.
        """
        graph = Graph()

        self.assertFalse(graph.contains_vertex('A'), 'The graph does not contain A yet.')
        graph.add_vertex('A')
        self.assertTrue(graph.contains_vertex('A'), 'The graph now contains A.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:8,代码来源:test_graphs.py

示例10: test_remove_unexisting_edge

    def test_remove_unexisting_edge(self):
        """Tests the remove_edge method in a graph without edge between two vertex
        """
        graph = Graph(graph = { 'A' : [], 'B' : [] })

        self.assertFalse(graph.has_edge('A', 'B'), 'There is no edge between A and B.')
        graph.remove_edge('A', 'B')
        self.assertFalse(graph.has_edge('A', 'B'), 'Nothing changed.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:8,代码来源:test_graphs.py

示例11: test_remove_edge_undirected

    def test_remove_edge_undirected(self):
        """Tests the remove_edge method in an undirected graph.
        """
        graph = Graph(graph = { 'A' : ['B'], 'B' : ['A'] })

        self.assertTrue(graph.has_edge('A', 'B'), 'There is an edge between A and B.')
        graph.remove_edge('A', 'B')
        self.assertFalse(graph.has_edge('A', 'B'), 'No more edge between A and B.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:8,代码来源:test_graphs.py

示例12: __init__

    def __init__(self):
        Graph.__init__(self)

        # stop to cluster matching
        self.stop_to_cluster = {}

        # cluster's name to node id matching
        self.cluster_id = {}
开发者ID:siuying,项目名称:gogogo-hk,代码行数:8,代码来源:TransitGraph.py

示例13: test_circular_layout

 def test_circular_layout(self):
   G = Graph.from_edge_pairs([], num_vertices=4)
   expected = np.array([[1,0],[0,1],[-1,0],[0,-1]])
   assert_array_almost_equal(G.layout_circle(), expected)
   # edge cases
   for nv in (0, 1):
     G = Graph.from_edge_pairs([], num_vertices=nv)
     X = G.layout_circle()
     self.assertEqual(X.shape, (nv, 2))
开发者ID:all-umass,项目名称:graphs,代码行数:9,代码来源:test_embed.py

示例14: test_add_edge_undirected

    def test_add_edge_undirected(self):
        """Tests the add_edge method for an undirected graph.
        """
        graph = Graph(graph = { 'A' : [], 'B' : [] })

        self.assertFalse(graph.has_edge('A', 'B'), 'There is no edge between A and B.')

        graph.add_edge('A', 'B')

        self.assertTrue(graph.has_edge('A', 'B'), 'There is now an edge between A and B.')
开发者ID:informaticienzero,项目名称:Graphs,代码行数:10,代码来源:test_graphs.py

示例15: test_kernelize

 def test_kernelize(self):
   graphs = [
       Graph.from_edge_pairs(PAIRS),
       Graph.from_adj_matrix(ADJ),
       Graph.from_adj_matrix(coo_matrix(ADJ)),
       Graph.from_adj_matrix(csr_matrix(ADJ)),
   ]
   for G in graphs:
     for kernel in ('none', 'binary'):
       K = G.kernelize(kernel)
       assert_array_equal(K.matrix('dense'), ADJ)
     self.assertRaises(ValueError, G.kernelize, 'foobar')
开发者ID:all-umass,项目名称:graphs,代码行数:12,代码来源:test_transformation.py


注:本文中的graphs.Graph类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。