Пример #1
0
def _find_augmenting_path (graph, capacities, flows, source, sink, path):
    """Helper method to find an augmenting path in the graph. An augmenting path is a path whose
    flow can be increased (none of the edges in the path has a maximized flow). This is used in
    the Ford-Fulkerson algorithm.

    @param graph - A graph object.
    @param capacities - A dictionary of tuples (source, target) representing edges, to their capacities
    @param flows - A dictionary of tuples (source, target) representing edges, to their current flows
    @param source - The source node.
    @param sink - The sink node.
    @param path - The current path (recursively builds it).
    @return res - The augmenting path.
    """
    if source == sink:
        return path
    for b in graph.adjNodes[source]:
        residual = capacities[(source, b)] - flows[(source, b)]
        if residual > 0 and (source, b) not in util.get_edge_list_from_path(path):
            res = _find_augmenting_path(graph, capacities, flows, b, sink, path + [b])
            if res != None:
                return res
Пример #2
0
 def test_multiNodePath(self):
     path = ['a', 'b', 'c', 'd', 'e']
     edgeList = [('a', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'e')]
     self.assertEqual(util.get_edge_list_from_path(path), edgeList)
Пример #3
0
 def test_singleNodePath(self):
     path = ['a']
     self.assertEqual(util.get_edge_list_from_path(path), [])