/Max_Flow_Problem

Ford-Fulkerson Algorithm

Primary LanguagePython

Discrete-Optimization

Ford Fulkerson Algorithm can be used to solve maximum flow problems in graph theory. It's an iterative method through which we tend to traverse the graph (network) nodes to find a path from the source node to the sink node. Afterward, we should find the minimum capacity along this path and subtract it from the capacity of all the edges of the path. This minimum flow should be held on one hand as the maximum flow of the network to be updated in the next iteration by addition. To put it another way, it means that if you have calculated the min flow of the first path as mf1 and the second path as mf2, and you have visited the sink node, the maximum flow of the network is mf1+mf2.

In this algorithm, you can choose between DFS or BFS traversal methods. If you choose BFS, the algorithm tends to consider the node that has stayed in the queue the longest. On the other hand, if you select the DFS method, the algorithm will consider the node added last.

About the time the original ford-fulkerson algorithm takes to solve the maximum flow problem: each iteration of the algorithm icludes finding a path, which refers to "Reachability" problem. Finding a path takes O(n^2) time. On the other hand, this algorithm comprises nC iterations in the worst case scenario where "n" is number of the nodes (except the source and the sink) and "C" is the maximum capacity of edges. Therefore, it takes the algorithm O(Cn^3) to solve the max flow problem. However, there is a problem with this. If you look at the O(Cn^3) again, you will notice that the linear dependence of time to C can pose a problem. If you add a zero to the max capacity, C will grow exponentially, and hence the time complexity is no longer polynomial. We can use BFS search strategy to remedy this issue. That's because using the BFS implies that we are augmenting flow along the shortest path in each iteration. It can be proved that this algorithm solves the max flow problem in time O(n^5).

We tend to choose the BFS strategy since we can be sure that we have traversed the shortest path with the first occurrence of the destination node. However, that's not true about the DFS strategy. Even if it finds the best path, it should traverse all the nodes to ensure there are no other better solutions. The shortest path refers to the path with fewer edges (regardless of its capacity, flow, etc.)

The maximum flow in the example graph is 15.0