예제 #1
0
 def test_path_beginning_equals_end(self):
     graph = multi_digraph_from_json('test_multigraph.json')
     for node in graph:
         new_graph, paths = bellman_ford_multi(graph, node)
         for path in paths:
             if path:
                 self.assertEqual(path[0], path[-1])
예제 #2
0
 def test_loop_from_source(self):
     graph = multi_digraph_from_json('test_multigraph.json')
     for node in graph:
         new_graph, paths = bellman_ford_multi(graph, node, loop_from_source=True)
         for path in paths:
             if path:
                 self.assertEqual(path[0], path[-1])
                 self.assertEqual(node, path[0])
예제 #3
0
 def test_path_beginning_equals_end(self):
     __location__ = os.path.realpath(
         os.path.join(os.getcwd(), os.path.dirname(__file__)))
     graph = multi_digraph_from_json(os.path.join(__location__, 'test_multigraph.json'))
     for node in graph:
         new_graph, paths = bellman_ford_multi(graph, node)
         for path in paths:
             if path:
                 self.assertEqual(path[0], path[-1])
예제 #4
0
 def test_positive_ratio(self):
     graph = multi_digraph_from_json('test_multigraph.json')
     for node in graph:
         new_graph, paths = bellman_ford_multi(graph, node)
         for path in paths:
             if path:
                 # assert that the path is a negative weight cycle
                 ratio = calculate_profit_ratio_for_path(new_graph, path)
                 # python float precision may round some numbers to 1.0.
                 self.assertGreaterEqual(ratio, 1.0)
예제 #5
0
 def test_positive_ratio(self):
     __location__ = os.path.realpath(
         os.path.join(os.getcwd(), os.path.dirname(__file__)))
     graph = multi_digraph_from_json(os.path.join(__location__, 'test_multigraph.json'))
     for node in graph:
         new_graph, paths = bellman_ford_multi(graph, node)
         for path in paths:
             if path:
                 # assert that the path is a negative weight cycle
                 ratio = calculate_profit_ratio_for_path(new_graph, path)
                 # python float precision may round some numbers to 1.0.
                 self.assertGreaterEqual(ratio, 1.0)