Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 26

MAXIMUM FLOW PROBLEM

Maximum Flow Problem


In optimization theory, maximum flow problems
involve finding a feasible flow through a flow
network that obtains the maximum possible flow rate.

Example:
Real-life example: Suppose we want to send trucks from
city s to city t, and the capacity of each edge represents
the number of trucks that can go on that road every
hour. What is the maximum number of trucks that we
can send from s to t every hour?
Maximum Flow Problem
In optimization theory, maximum flow problems
involve finding a feasible flow through a flow
network that obtains the maximum possible flow rate.
Example:
Imagine that there are roads running from city A to city B. Cars are
driving on the roads, but there are always traffic jams on some
sections of roads, and the rest are empty. You need to understand
whether you need new roads or you can distribute the flow of the
vehicles in such a way as to make better use of the existing routes.
What is the maximum number of cars that can travel from A to B
now?
Maximum Flow Problem
In optimization theory, maximum flow problems
involve finding a feasible flow through a flow
network that obtains the maximum possible flow rate.
Example:
Imagine you are given a task to come up with an efficient
solution to produce airline schedules for thousands of routes each
day. You may have to consider multiple factors like equipment
usage, crew allocation, customer satisfaction, and some
unpredictable weather conditions and breakdowns, etc. Don’t
worry, there’s something to help you with. ;) You can think of this
as a maximum-flow problem and solve it using the Ford Fulkerson
method
What is the maximum flow problem?
What is the greatest rate at which
material can be sent (shipped)
from source to the sink without
violating any capacity constraints?

Given a flow network G with source s and sink t, the maximum flow
problem is an optimization problem to find a flow of maximum
value from s to t. Flow network G=(V, E), is essentially just a
directed graph where each edge has a nonnegative flow capacity.
The Ford Fulkerson Method

The Ford Fulkerson method, also known as ‘augmenting path


algorithm’ is an effective approach to solve the maximum flow
problem. The Ford Fulkerson method depends on two main
concepts and they are:

1. Residual Network
2. Augmenting paths
Residual Network

 It is a graph, that has the same vertices as the original network


with one or two edges for each edge in the original network.
 And it indicates the additional possible flow through the
network.
 For each edge, we’ll calculate the additional flow as follows.

 So, to create a residual network we will take our original


network and will update the capacity of each edge with the
additional flow corresponding to that edge.
 Then we will also add reverse edges to indicate the amount of
flow currently going across the edges of the original network.
Residual Network

 In the example, for each edge, the first


value represents the flow value and the
second stands for the capacity of the edge.
 Consider the edge C->D. Here the flow is 11
and the capacity of the edge is 14. So, if we
calculate the additional flow for this edge,
we get 14-11 = 3.
 So in the residual network, we can update
the capacity of the C->D edge as 3, and then
add a reverse edge with value 11 (flow
value of the original network) between C
and D.
 Repeat this for all the edges, and here’s
what we get as the residual network.
Augmenting path

Given a flow network G=(V,


E), the augmenting path is a
simple path from s to t in the
corresponding residual graph
of the flow network.
Ford-Fulkerson Algorithm
E = number of the edges in the flow network.
f(e) = flow along the edge 𝑒.
𝑐(𝑒) = Capacity of the edge 𝑒.
 Initialize the maxFlow with 0 i.e. maxFlow=0
 Use BFS/DFS to search for a path between the vertices 𝑠 and 𝑡. Here
existence of path 𝑃 means, for every edge 𝑒 in 𝑃,𝑓(𝑒) < 𝑐(e) must
hold. If such a path exists then -
o flowCanBeAdded = 𝑚𝑖𝑛(𝑐(𝑒)−𝑓(𝑒)) for each edge 𝑒 in 𝑃.
o maxFlow = maxFlow + flowCanBeAdded
o For each edge e in 𝑃, 𝑓(𝑒)=𝑓(𝑒) + flowCanBeAdded
 In the other case (There does not exist any path between 𝑠 and 𝑡)
return the maxFlow.
Ford-Fulkerson Method

1. Initially, set the flow 'f' of every edge to 0


2. While there exists an augmenting path 'p' in the residual network
augment the flow 'f' along 'p‘
3. return flow 'f'
Ford-Fulkerson Method

Step 1: Set the flow of every edge to 0


Ford-Fulkerson Method

Step 2: Now, find an augmenting path in the residual network. Here, I select
the path s -> A -> D -> t. Then we have to identify the bottleneck capacity (i.e.
maximum flow for that path) for the selected path. As you can see, along this
path, the bottleneck capacity is 8. Now without violating the capacity
constraint, update the flow values of the edges in the augmenting path. Then
you will get the following flow network and the residual network.
Ford-Fulkerson Method

Step 3: Then I select the augmenting path s -> C -> D -> t. Now the bottleneck
capacity is 2.
Ford-Fulkerson Method

Step 4: The augmenting path s -> A -> B->t, the bottleneck capacity is 2.
Ford-Fulkerson Method

Step 5: Augmenting path s -> C -> D -> B->t, the bottleneck capacity is 6.
Ford-Fulkerson Method

Step 6: Augmenting path s -> C -> D -> A-> B->t, bottleneck capacity is 1.

 Look! Now there are no paths left from the s to t in the residual graph. So,
there is no possibility to add flow. This means the Ford Fulkerson method is
complete and we are ready to find the maximum flow.
 Since the maximum flow is equal to the flow coming out of the source, in
this example, the maximum flow is 10+9 = 19.
Pseudocode
FordFulkerson(Graph G, Node s, Node t):
Initialize flow of all edges e to 0.
while(there is augmenting path(P) from s to t
in the residual graph):
Find augmenting path between s and t.
Update the residual graph.
Increase the flow.
return

Link
Example 2

We can see that the initial flow of all the paths is 0. Now we will
search for an augmenting path in the network.
One such path is 𝑠→𝐴→𝐵→𝑡s→A→B→t with residual capacities
as 7, 5, and 8. Their minimum is 5, so as per the Ford-Fulkerson
method we will increase a flow of 5 along the path.
Example 2
Example 2
Now, we will check for other possible augmenting paths, one such path can
be 𝑠→𝐷→𝐶→𝑡 with residual capacities as 4, 2, and 5 of which 2 is the minimum. So we
will increase a flow of 2 along the path.
Example 2
 One can easily observe from the figure that we can't increase the flow along paths A→B and 𝐷→𝐶 as
their flow has reached their maximum capacity.
 So to find other augmenting paths, we must take care that these edges must not be part of the path.
 One such path can be 𝑠→𝐷→𝐴→𝐶→𝑡 𝑤𝑖𝑡ℎ 𝑟𝑒𝑠𝑖𝑑𝑢𝑎𝑙 𝑐𝑎𝑝𝑎𝑐𝑖𝑡𝑖𝑒𝑠 𝑎𝑠 2,3,3 𝑎𝑛𝑑 3 o𝑓 𝑤ℎ𝑖𝑐ℎ 2 𝑖𝑠 𝑡ℎ𝑒
m𝑖𝑛𝑖𝑚𝑢𝑚 𝑠𝑜 𝑤𝑖𝑙𝑙 𝑖𝑛𝑐𝑟𝑒𝑎𝑠𝑒𝑎 𝑓𝑙𝑜𝑤 𝑜𝑓 is the minimum so will increase a flow of 2 along the path.
Example 2
 An augmenting path that is possible in the current residual network is 𝑠→𝐴→𝐶→𝑡 with residual
capacities as 2, 1, and 1 of which 1 is minimum.
 So we will increase the flow of 1 along the path after which our network will look like -
Example 2
Now there are no more augmenting paths possible in the network, so
the maximum flow is the total flow going out of source or total flow
coming in sink i.e. 6+4=5+5=10
Q&A
Thank You.

You might also like