示例#1
0
 def test_dijkstra_all_pair_paths(self):
     paths = retworkx.graph_all_pairs_dijkstra_shortest_paths(
         self.graph, float
     )
     expected = {
         0: {
             1: [0, 1],
             2: [0, 2],
             3: [0, 2, 3],
             4: [0, 2, 3, 4],
             5: [0, 2, 5],
         },
         1: {0: [1, 0], 2: [1, 2], 3: [1, 2, 3], 4: [1, 2, 3, 4], 5: [1, 5]},
         2: {0: [2, 0], 1: [2, 1], 3: [2, 3], 4: [2, 3, 4], 5: [2, 5]},
         3: {0: [3, 2, 0], 1: [3, 2, 1], 2: [3, 2], 4: [3, 4], 5: [3, 2, 5]},
         4: {
             0: [4, 3, 2, 0],
             1: [4, 5, 1],
             2: [4, 3, 2],
             3: [4, 3],
             5: [4, 5],
         },
         5: {0: [5, 2, 0], 1: [5, 1], 2: [5, 2], 3: [5, 2, 3], 4: [5, 4]},
     }
     self.assertEqual(expected, paths)
示例#2
0
 def test_dijkstra_all_pair_shortest_paths_no_edges(self):
     graph = retworkx.PyGraph()
     graph.add_nodes_from(list(range(1000)))
     expected = {x: {} for x in range(1000)}
     self.assertEqual(
         expected,
         retworkx.graph_all_pairs_dijkstra_shortest_paths(graph, float),
     )
示例#3
0
 def test_dijkstra_all_pair_paths_with_node_removal(self):
     self.graph.remove_node(3)
     paths = retworkx.graph_all_pairs_dijkstra_shortest_paths(
         self.graph, float
     )
     expected = {
         0: {1: [0, 1], 2: [0, 2], 4: [0, 2, 5, 4], 5: [0, 2, 5]},
         1: {0: [1, 0], 2: [1, 2], 4: [1, 5, 4], 5: [1, 5]},
         2: {0: [2, 0], 1: [2, 1], 4: [2, 5, 4], 5: [2, 5]},
         4: {0: [4, 5, 2, 0], 1: [4, 5, 1], 2: [4, 5, 2], 5: [4, 5]},
         5: {0: [5, 2, 0], 1: [5, 1], 2: [5, 2], 4: [5, 4]},
     }
     self.assertEqual(expected, paths)
示例#4
0
 def test_dijkstra_all_pair_shortest_paths_empty_graph(self):
     graph = retworkx.PyGraph()
     self.assertEqual(
         {}, retworkx.graph_all_pairs_dijkstra_shortest_paths(graph, float)
     )