0% found this document useful (0 votes)
514 views45 pages

Ford-Fulkerson Algorithm - Network Flow Problem

The document discusses the Ford-Fulkerson algorithm for solving the maximum flow problem in networks. It describes an oil pipeline network example and uses it to explain the key concepts of network flows, including valid flows, maximum flows, and the residual graph approach used by Ford-Fulkerson to incrementally find augmenting paths and push additional flow. It provides pseudocode for the Ford-Fulkerson algorithm and walks through a step-by-step example applying the approach to the oil pipeline network.

Uploaded by

veningston
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
514 views45 pages

Ford-Fulkerson Algorithm - Network Flow Problem

The document discusses the Ford-Fulkerson algorithm for solving the maximum flow problem in networks. It describes an oil pipeline network example and uses it to explain the key concepts of network flows, including valid flows, maximum flows, and the residual graph approach used by Ford-Fulkerson to incrementally find augmenting paths and push additional flow. It provides pseudocode for the Ford-Fulkerson algorithm and walks through a step-by-step example applying the approach to the oil pipeline network.

Uploaded by

veningston
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Design and Analysis of Algorithms (18CSE107)

Network Flow Problem


Ford Fulkerson Algorithm for Maximum Flow Problem

Veningston. K
Computer Science and Engineering
Unit V - Outline

• Network flow problem


– Ford Fulkerson Algorithm for Maximum Flow Problem

• NP–Hard and NP–Complete Problems


– Complexity Class - P, NP, NP-Complete, NP-Hard

– Is P=NP?

– Reducibility

•Design and Analysis of Algorithms


•2
(18CSE107)
Network flow Problem
• Oil Network
– Network of pipelines
– Ship as much oil as possible from source s to sink t.
– No storage on the way  oil enters node ‘b’ must leave ‘b’
– A flow of 7 is possible. Is this the maximum?

•Design and Analysis of Algorithms


•3
(18CSE107)
One possible flow
• We can flow 7 units from s to t

•Design and Analysis of Algorithms


•4
(18CSE107)
How to verify Network flow?
• We can locally verify the flow by checking at node d.
– The total quantity flowing into d is 2+1 i.e. 3
– The total quantity flowing out is again 3.
• We can do local checks like this and we can satisfy
that this is the valid flow.

•Design and Analysis of Algorithms


•5
(18CSE107)
Is this Maximum flow?
• We can locally verify the flow by checking at
node d.
– The total quantity flowing into d is 2+1 i.e. 3
– The total quantity flowing out is again 3.
• This is valid flow
• How do we know whether we have achieved
the maximum flow?

•Design and Analysis of Algorithms


•6
(18CSE107)
Oil Network (or) Flow network
• Network is a directed graph G = (V, E).
• Special nodes
– Source vertex s
– Sink vertex t
• Each edge e has a capacity Ce, which is a
weight associated with it.
• The flow is the quantity that we will assign for
each edge.
• Aim is to come up with a maximum flow.
•Design and Analysis of Algorithms
•7
(18CSE107)
Flow
• Flow must satisfy some basic conditions.
• Flow Fe for each edge e,
– Fe ≤ Ce
• Flow must always be less than the Capacity.
• There is no storage at internal nodes.
• At each node, except s and t, sum of
incoming flows equal to sum of outgoing
flows.
– This is called conservation of flow.
•Design and Analysis of Algorithms
•8
(18CSE107)
Conservation of flow
• Conservation of flow means that we cannot
generate anything or loose anything
– Anything that comes in must go out.
• Finally, we want to optimize the total volume
of the flow.
• Total volume of flow?
– Total volume of flow is sum of outgoing flow from
s.

•Design and Analysis of Algorithms


•9
(18CSE107)
Linear Programming (LP)
Formulation

• Variable Fe for each edge e


– Fsa , Fbd , Fce, …  There are 11 edges in the network
• Capacity constraints per edge
– Fba ≤ 10, …
• Conservation of flow at each internal node
– Fad+Fbd = Fdc+Fde + Fdt, …  considering node d
• Objective Function: Maximize the volume of
flow.
Maximize Fsa + Fsb + Fsc
•Design and Analysis of Algorithms
•10
(18CSE107)
Ford-Fulkerson Algorithm
• This algorithm directly solve network flow problem
by gradually building up an optimum flow.
• Algorithm assumes that it start with 0 flow
• Choose some path on which there is spare capacity
and then on this path, it augment the flow as much
as possible, so that flow of that path becomes
saturated.
– Choose a path from s to t that is not saturated and
augment the flow as much as possible.

•Design and Analysis of Algorithms


•11
(18CSE107)
Network flow - Example
• It is very clear that the maximum flow possible is 2

• Ford-Fulkerson algorithm says that take any path


which exists and start flowing.
•Design and Analysis of Algorithms
•12
(18CSE107)
Bad Flow?
• What if one chooses a bad flow to begin with?
–sdet

•Design and Analysis of Algorithms


•13
(18CSE107)
Bad Flow?
• At this point, edge from s to d is now saturated and
edge from e to t is now saturated.

• We cannot make use of se and dt capacity to


take or generate the 2nd unit of flow.
•Design and Analysis of Algorithms
•14
(18CSE107)
NOTE
• It seems Ford-Fulkerson algorithm has a
bottleneck, if we choose the wrong path to
start with.
• The solution is to say that even if we have
taken a bad path, one of the things which we
can do is, reverse the decision which we made
earlier.

•Design and Analysis of Algorithms


•15
(18CSE107)
Residual Graph
• Add reverse edges to undo flow from previous
steps.
• Residual Graph: for each edge e with capacity
Ce and current flow Fe,
– Reduce capacity to Ce – Fe
– Add reverse edge with capacity Fe

•Design and Analysis of Algorithms


•16
(18CSE107)
Residual Graph - Example
• We can divert this flow in other way
• The one way to solve it is, to set up an extra edge allowing it
to flow things back. This is called Residual Graph.

•Design and Analysis of Algorithms


•17
(18CSE107)
Residual Graph - Example
• We will take the flow we just constructed and
the new will change the capacity.
– The forward edge s to d which had capacity 1 and
flow 1.
– Now, the residual capacity is 0.

Reduce capacity to Ce – Fe
Add reverse edge with capacity Fe

•Design and Analysis of Algorithms


•18
(18CSE107)
Residual Graph - Example
• Replace the regular edge’s weight by the actual
amount that is still available i.e. 0. [Ce – Fe]
• In addition, we add the new backward edge
which corresponds to the flow that we have
committed which we may want to change later.
• Example: We have sent a flow 1 from s to d.
• But, now we can reduce that flow by sending
some flow back from d to s.

•Design and Analysis of Algorithms


•19
(18CSE107)
Constructing a Residual Graph
• Take the original graph, then any flow that we
setup in an existing edge, we reduce the
capacity of edge by that flow
• And corresponding to that flow, we setup a
reverse edge, which allows us later to undo.

•Design and Analysis of Algorithms


•20
(18CSE107)
Ford-Fulkerson Algorithm
• Start with 0 flow
• Choose a path from s to t that is not saturated
and augment the flow as much as possible
• Build residual graph
• Repeat step 2 & 3 until there is no feasible
flow from s to t

•Design and Analysis of Algorithms


•21
(18CSE107)
Example 1
• In the given graph, we first start with the
wrong path and then we will build the
Residual Graph.

•Design and Analysis of Algorithms


•22
(18CSE107)
Example 1
• In this Residual Graph, there are paths which
could go from d to s, e to d, t to e.

•Design and Analysis of Algorithms


•23
(18CSE107)
Example 1
• In this Residual Graph, if we initiate a new
flow,
– This will end up producing 0 in se and new
edges back from es & td and flow from de
is restored to 1.
– The new edge from ed introduced in Residual
Graph will now disappear.

•Design and Analysis of Algorithms


•24
(18CSE107)
Example 1

•Design and Analysis of Algorithms


•25
(18CSE107)
Example 1

• In the New Graph, we find


that there are no valid edges
from s.
– Because, we have 0 capacity
in sd & se
– We cannot leave any more
flow from s

•Design and Analysis of Algorithms


•26
(18CSE107)
Example - 2
• The intuition is that all the 30
units can flow from s to t.
• But, the 30 units cannot flow
unlike the earlier case along
the edges of the graph.
– Because, if we take up 20 units
flow from sd, then we must
split it to 10 + 10

•Design and Analysis of Algorithms


•27
(18CSE107)
Example - 2
• Start the algorithm with flow 20,
–Sdet
• The algorithm will try to saturate this path.
• It can put 20 units flows through de

1st round
•Design and Analysis of Algorithms
•28
(18CSE107)
Example - 2
• Build the Residual Graph.
– The residual capacity from
de is now 10. Because, we
had a capacity of 30 and 20
is flowing through it.
– The red color edges are
residual edges which allows
us to reduce the 20 unit
back.

•Design and Analysis of Algorithms


•29
(18CSE107)
Example - 2
• Now, we will look for an
another path. For
instance, we find the path
sedt
– For this path, the constraint
is 10.
– We have only 10 flowing
out s to begin with.

2nd round
•Design and Analysis of Algorithms
•30
(18CSE107)
Example - 2
• Build the residual graph

This edge gets restored back by 10. Because, total flow from de
was 20 in the 1st round, -10 in the 2nd round. Therefore, the residual
edge is 30-10 = 20.
•Design and Analysis of Algorithms
•31
(18CSE107)
Example - 2
• Now, edges from s are 0. Because, it is
saturated.
• There is no outgoing flow possible from s in
this residual graph.
• Therefore, we can say that there is no more
feasible path and stop the algorithm.
• We have achieved the flow of 30 in the given
graph, which is maximum.
•Design and Analysis of Algorithms
•32
(18CSE107)
Important Properties

• Optimality – Cut

• Minimum Cut

• Maximum Flow

•Design and Analysis of Algorithms


•33
(18CSE107)
Optimality - Cut
• Edges {ad, bd, sc} disconnect s and t
– (s-t)-cut
• Flow from s to t must go through this cut
– Flow cannot exceed cut capacity 7
• In general, max flow cannot exceed min cut capacity

•Design and Analysis of Algorithms


•34
(18CSE107)
Optimality - Cut
• If we disconnect this graph by cutting these 3 edges {ad, bd,
sc}
– In this cut, the total flow capacity is 7
• Any flow, must cross from LHS to RHS through the edges part
of this cut.

LHS

RHS
•Design and Analysis of Algorithms
•35
(18CSE107)
Bad Flow?
• This cut supports the total flow capacity of 7
• Therefore, the optimum flow can definitely not exceed 7
in this example graph.
• This cut will prevent any flow more than 7
flowing from LHS to RHS.

•Design and Analysis of Algorithms


•36
(18CSE107)
Definition of Cut
• Cut is any set of edges which disconnect s
from t.
• We can calculate the minimum cut from all
the cuts possible.
• It is pretty clear that the maximum flow
cannot exceed the minimum cut. Because,
the flow has to cross this cut.

•Design and Analysis of Algorithms


•37
(18CSE107)
Time complexity Analysis
• Ford-Fulkerson Algorithm
– Choose augmenting paths wisely.
– If we keep going through the middle edge de,
200 iterations to find max flow.
• Ford-Fulkerson Algorithm (FFA) can take time
proportional to max capacity at worst case.

•Design and Analysis of Algorithms


•38
(18CSE107)
Proof
• In this example graph, if we choose the below
path (wrong path).

Residual Graph
•Design and Analysis of Algorithms
•39
(18CSE107)
Proof
• Next time, if we go in the reverse direction,

Residual Graph

•Design and Analysis of Algorithms


•40
(18CSE107)
Proof
• In this way, we may keep zigzagging.
• It will take 200 iterations in order to find the flow as 200.
• The best way is that we can do it in 2 iterations cleverly.

•Design and Analysis of Algorithms


•41
(18CSE107)
Time complexity Analysis
• It depends crucially on how we pick the path
to augment.
– How do we take the feasible path which still exists
in the residual graph?
• FFA is going to take time proportional to the
capacity of the edges, which is not a good
implementation.
– Every time we setup a residual graph, we have to
find a path from s to t and then augment it.
•Design and Analysis of Algorithms
•42
(18CSE107)
Time complexity Analysis

• It runs in polynomial time provided all edge


capacities are polynomial bounded integers.
• With big edge capacities, the algorithm can
require a very large number of iterations to
complete.
– We have at most f iterations, and each iteration
takes O(E+V) time, the worst-case run time is
O((E+V)f) which is O(Ef).

•Design and Analysis of Algorithms


•43
(18CSE107)
Time complexity Analysis
• We can either use BFS or DFS for finding a path from
one node to another node.
– It is typically an exploration of graph.
• If we use BFS, we can find shortest path in terms of
number of edges.
– We will be always augmenting the shortest path in terms
of the edges.
• If we have choices to augment the following paths,
– sdt
– sdet ✘
– set
•Design and Analysis of Algorithms
•44
(18CSE107)
Time complexity Analysis
• BFS will say that the path s  d  t with 2
edges can be augmented.
• If we use BFS in Ford-Fulkerson Algorithm,
then it turns out that we will always get time
proportional to the product of Vertices and
Edges i.e. O(V*E)

•Design and Analysis of Algorithms


•45
(18CSE107)

You might also like