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


Python graph.Graph类代码示例

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


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

示例1: test_dijkstra_simple

 def test_dijkstra_simple(self):
     graph = Graph('test/netfiles/test1.net.xml', False)
     costs = {}
     for edge in graph.edges:
         costs[edge] = 1
     graph.set_destination_and_costs(graph.edges[-1], costs)
     self.assertEqual(graph.dijkstra(graph.edges[1], costs), ['-25','5'])
开发者ID:OR2013,项目名称:OnlinePathOptimalization,代码行数:7,代码来源:graph_test.py

示例2: test_dijkstra_complex

 def test_dijkstra_complex(self):
     graph = Graph('test/netfiles/test4.net.xml', False)
     costs = {}
     for edge in graph.edges:
         costs[edge] = 1
     graph.set_destination_and_costs('30668', costs)
     self.assertEqual(graph.dijkstra('-31439', costs), ['-31439','-30057','-28887','28866','-23377','-22520','-21950','-17064','-16421','-15637','-3694','-3348','-158','144','-212','213','-370','420','-809','1807','-2481','2488','2556','-3837','3836','4158','4982','12338','-20947','-20171','20161','20824','-22781','-22135','22133','22780','27742','29467','30668'])
开发者ID:OR2013,项目名称:OnlinePathOptimalization,代码行数:7,代码来源:graph_test.py

示例3: test_get_vertices_for_directed_graph

    def test_get_vertices_for_directed_graph(self):
        g = Graph(True)
        g.add_edge((1,2))

        actual = g.get_vertices()
        expected = [1,2]
        self.assertEqual(actual, expected, 'should return all vertices')
开发者ID:mindis,项目名称:learn,代码行数:7,代码来源:test_graph.py

示例4: test_set_edge_value_if_edge_exists

    def test_set_edge_value_if_edge_exists(self):
        g = Graph(True)
        g.add_edge((1,2,10))
        g.set_edge_value((1,2), 20)

        self.assertEqual(g.table[1][2], 20,
                'should have updated the edge value')
开发者ID:mindis,项目名称:learn,代码行数:7,代码来源:test_graph.py

示例5: test_add_users_to_a_graph

    def test_add_users_to_a_graph(self):
        graph = Graph()
        user = User()
        user_id = user.get_id()
        graph.add_user(user)

        assert user_id in graph.users and graph.users[user_id] == user
开发者ID:ehyoon,项目名称:ka-interview,代码行数:7,代码来源:test_classes.py

示例6: test_set_edge_value_works_for_undirected_graphs

    def test_set_edge_value_works_for_undirected_graphs(self):
        g = Graph(False)
        g.add_edge((1,2,10))
        g.set_edge_value((1,2), 30)

        self.assertEqual(g.table[1][2], 30, 'has updated the edge')
        self.assertEqual(g.table[2][1], 30, 'reverse edge was updated too')
开发者ID:mindis,项目名称:learn,代码行数:7,代码来源:test_graph.py

示例7: test_split_edge_with_value

    def test_split_edge_with_value(self):
        edge = (1,2,3)
        g = Graph()
        (tail, head, value) = g.split_edge(edge)

        self.assertEqual(tail, 1)
        self.assertEqual(head, 2)
        self.assertEqual(value, 3)
开发者ID:mindis,项目名称:learn,代码行数:8,代码来源:test_graph.py

示例8: test_incident_in_directed_graph

    def test_incident_in_directed_graph(self):
        g = Graph(directed = True)
        g.add_edge((2,1))
        g.add_edge((3,1))

        actual = g.incident(1)
        expected = [2, 3]
        self.assertEqual(actual, expected, '1 has two incident vertexes')
开发者ID:mindis,项目名称:learn,代码行数:8,代码来源:test_graph.py

示例9: test_get_edge_value_in_directed_graph

    def test_get_edge_value_in_directed_graph(self):
        g = Graph(True)
        g.add_edge((1,2,3))

        self.assertEqual(g.get_edge_value((1,2)), 3,
                'should have stored value')
        self.assertIsNone(g.get_edge_value((2,1)),
                'should have no value for reverse edge')
开发者ID:mindis,项目名称:learn,代码行数:8,代码来源:test_graph.py

示例10: test_set_edge_value_if_graph_is_directed_and_inverse_edge_exists

    def test_set_edge_value_if_graph_is_directed_and_inverse_edge_exists(self):
        g = Graph(True)
        g.add_edge((1,2,10))
        g.add_edge((2,1,20))
        g.set_edge_value((1,2), 30)

        self.assertEqual(g.table[1][2], 30, 'has updated the edge')
        self.assertEqual(g.table[2][1], 20, 'reverse edge remained the same')
开发者ID:mindis,项目名称:learn,代码行数:8,代码来源:test_graph.py

示例11: test_add_edge_multiple_times_nothing_happens

    def test_add_edge_multiple_times_nothing_happens(self):
        g = Graph(True)
        g.add_edge((1,2,3))
        g.add_edge((1,2,3))
        g.add_edge((1,2,3))
        g.add_edge((1,2,3))

        self.assertIn(1, g.table, 'should have stored the tail in table')
        self.assertIn(2, g.table[1], 'should have stored the head in table')
开发者ID:mindis,项目名称:learn,代码行数:9,代码来源:test_graph.py

示例12: test_connect_users_in_a_graph

    def test_connect_users_in_a_graph(self):
        graph = Graph()
        user1 = User()
        user2 = User()
        graph.add_user(user1)
        graph.add_user(user2)

        graph.connect_users(user1.get_id(), user2.get_id())
        assert user2 in user1.get_connections() and user1 in user2.get_connections()
开发者ID:ehyoon,项目名称:ka-interview,代码行数:9,代码来源:test_classes.py

示例13: test_add_edge_for_directed_graph

    def test_add_edge_for_directed_graph(self):
        g = Graph(True)
        g.add_edge((1,2,3))

        self.assertIn(1, g.table, 'should have stored a key for tail vertex')
        self.assertIn(2, g.table[1], 'should have stored the edge')
        self.assertEqual(g.table[1][2], 3, 'should have stored the edge value')

        self.assertIn(2, g.table, 'should not have stored the node')
        self.assertNotIn(1, g.table[2], 'should not have stored the reverse edge')
开发者ID:mindis,项目名称:learn,代码行数:10,代码来源:test_graph.py

示例14: constructor

def constructor(M, sigma, kind='log'):
    g = Graph()
    for i in range(len(M)):
        for j in range(len(M[i])):
            for p in range(len(M)):
                for q in range(len(M[i])):
                    if p != i or q != j:
                        g.add_edge(get_name(i, j), get_name(p, q), weight(M, [i, j], [p, q], kind, sigma))
    g.normalize()
    return g
开发者ID:162,项目名称:gbvs-justgecko,代码行数:10,代码来源:constructor.py

示例15: test_add_edge_for_undirected_graph

    def test_add_edge_for_undirected_graph(self):
        g = Graph(False)
        g.add_edge((1,2,3))

        self.assertIn(1, g.table, 'should have stored a key for tail vertex')
        self.assertIn(2, g.table[1], 'should have stored the edge')
        self.assertEqual(g.table[1][2], 3, 'should have stored the edge value')

        self.assertIn(2, g.table, 'should have stored a key for head vertex')
        self.assertIn(1, g.table[2], 'should have stored the reversed edge')
        self.assertEqual(g.table[2][1], 3, 'should have stored the edge value')
开发者ID:mindis,项目名称:learn,代码行数:11,代码来源:test_graph.py


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