You are on page 1of 74

Chapter 5

MAXIMUM FLOW
Introduction
Flow networks can model many problems:
 Liquids flowing through pipes,
 Parts through assembly lines,
 Current through electrical networks,
 Information through communication
networks.
Introduction
Example: Trucking Problem
 The Vancouver factory is
the source s, and the
Winnipeg warehouse is
the sink t .
 The company ships
products through
intermediate cities, but
only c(u,v) crates per
day can go from city u to
city v.
 Each edge is labeled
with its capacity.
Introduction
Example:
 Trucking Problem
A flow f in G with value . Each edge is labeled by.
The slash notation merely separates the flow and capacity; it
does not indicate division.
Definitions
A flow network is a connected directed graph G(V,E)
in which each edge has a nonnegative capacity
It has two specifics vertices for called the source and
one called the sink (termination) of the network.
In most cases, the source vertex s does not have edges
directed toward s (all the edges connected to s are
directed from s to other vertices , means they have the
form
Also, the edges connected to the sink vertex t are
directed toward t, means they have the form .
Definitions
 In a directed graph the value on each edge is the
maximum flow that can be transported along this edge.
These values are called the capacities of the edges. Each
edge has a capacity value , or each edge has a capacity
The nonnegative quantity assigned to an edge is called
and it represents the used capacity of that edge.
When there can be no flow from to , and =0
Definitions
The assigned flow for an edge should not be greater than the
capacity of this edge. (i.e. constraint of capacity). (not
exceed the given capacity).
A Network with all edges are respecting this property is
called a compatible network.
The flow enters in each vertex must equal to the flow leaving
this vertex. We call this property “flow conservation”. This is
applied for all vertices except for s and t.

i.e. the flow-in into a vertex other than the source or sink must
equal the total flow out of that vertex—informally, “flow in equals
flow out.”
Example
In the Network flow below, the flow conservation
concepts is verified.
 Input flow of x =output flow of x :(1+3=0+2+2)
 Input flow of z= output flow of z: (3+2=3+2)
The value of a flow f is defined as:

where represents the flow-out of the source s and represents the flow-in o
the source s.
But we have :
Therefore, the value of the network flow f is equal to the value
of the flow of the source s, because we don’t have any losses
during transportation (in the network):

|.| denotes the flow value not the absolute value


is also equal to the flow-in to the vertex t:
Example
 the flow of the network in the figure below is equal to 9
«flow-out of s»

 The flow of the network is also equal to «flow-in of t»


Definitions
An edge is called saturated if the flow of this edge
is equal to its capacity (meaning we cannot increase
the flow value of that edge).
A Network flow is complete, if each path from s
to t contains at least one saturated edge.
Maximum-flow problem
In the maximum-flow problem, we are given a flow
network G with source s and sink t, and we wish to find a
flow of maximum value.
The example below shows a flow =19, which is not the
maximum possible flow that we can send from s to t.
In the maximum-flow problem we wish to compute the
greatest rate at which we can ship material from the source to
the sink without violating any capacity constraints.
Maximum-flow problem
As example for the figure below: To have the Maximum flow
of the network, we need to determine the largest number p of
crates per day that we can ship from s to t.
We are not concerned with how long it takes for a given crates
to get from the factory to the warehouse; we care only that p
crates per day leave the factory (vertex s) and p crates per day
arrive at the warehouse (vertex t)
Maximum-flow problem
We can model the “flow” of shipments with a flow in this
network because the number of crates shipped per day from
one city to another is subject to a capacity constraint.
Additionally, the model must obey flow conservation, i.e.
the number of crates enter an intermediate city must equal to
the number of crates leaving from this city. Otherwise,
crates would accumulate at intermediate cities, which is not
acceptable.
Maximum-flow problem
A network flow is maximum implies that this
network flow becomes complete, but the reverse is
not true
Algorithm Ford and Fulkerson
This algorithm finds the maximum flow that can
be transported through the edges of a given
Network.
 The algorithm shows the flows assigned to all the
edges of the network.
The algorithm uses the concept of residual graph
noted as
Algorithm Ford and Fulkerson
Residual Graph
 has the same vertices as G, however it has different edges.
 the values on the edges of are the residual flows that can be
assigned to each edge.
What are the residual flows?
How can we determine the set of edges of ?
Algorithm Ford and Fulkerson
Residual Graph
 has the same vertices as G, however it has different edges.
 the values on the edges of are the residual flows that can be
assigned to each edge.
What are the residual flows?
How can we determine the set of edges of ?
Algorithm Ford and Fulkerson
Residual Graph
What are the residual flows?
How can we determine the set of edges of ?
Algorithm Ford and Fulkerson
How can we determine the set of edges of ?
For each edge in the graph G,
a. If then add edge inwith a flow value equal to .
b. If , then add the edge in Gf with a flow value equal to
Example
 Find the residual graph of the graph G below.

Conclusion:
For each edge in G we have in two edges and based on:
 in exists if
 exists in Gf if (different than zero)
Example 1
 Find the residual graph of the graph G
below.
Example 1
 Find the residual graph of the graph G
below.
Example 2
 Why it is useful to get ?

Add 4 to the flow if edge


belong to G, and subtract 4
from the
Example 3
 Why it is useful to find ?
Algorithm Ford and Fulkerson
1.Initialize flow of all edges to 0 ()
2.Draw on the residual graph
3.Find a path P from the vertex s to the vertex t in (suppose that the
egdes belong to the path P are where
4.If P cannot be found, goto step 8.
5.Find the flow minimum m that can be sent along this path,

6.Apply m to the flows in the graph G as follow:


i. If then
ii. Else ( then this is a residual edge:
7.Goto step 2
8.End of the algorithm
Example 1
Determine the flow maximum of this network using the
algorithm of Ford and Fulkerson
Example 2
Determine the flow
maximum of this network
using the algorithm of Ford
and Fulkerson.
solution
Example 3
Determine the flow
maximum of this network
using the algorithm of Ford
and Fulkerson.
Example 4
Determine the flow
maximum of this network
using the algorithm of Ford
and Fulkerson.
10
Example 4
Gf G

The shaded lines are the


edges of the chosen path.
* Path 1: s,v1,v3,v2,v4,t
m=min(16,12,9,14,4)=4
*path 2: s,v1,v2,v4,v3,t
m=min(12,10,10,7,20)=7
*path 3: s,v2,v1,v3,t
m=min(13,11,8,13)=8
*path 4:s,v2,v3,t
m=min(5,4,5)=4
The final network is the
network with maximal
flow which is equal to :
11+12=23
Explanation
Cut of Flow networks
Cut of flow network?
Capacity of the cut?
Net-flow across the cut ?
minimum cut of a network?
Cut of flow network
A cut of flow network is a partition of V into and
such that and . (Similar to the cut shown in MST, but
in this case, we have directed graph)
Cut of flow network
The capacity of the cut (S,T) is defined to be:
Cut of flow network
The net-flow across the cut is defined to be:
Cut of flow network
The net-flow
Cut of flow network
The net-flow
Cut of flow network
The net-flow
Minimum Cut of a network
A minimum cut of a network is a cut whose
capacity is minimum over all cuts of the network
Minimum Cut of a network
the minimum cut of the network is the cut
of minimum capacity (i.e. C(S,T)=23)
Minimum Cut of a network
The maximum flow is equal to the
value of the minimum cut of the
network.
Example:
if we apply Ford and Fulkerson
algorithm for the following network,
we will get a flow =23, because the
minimum cut capacity is =23.
As conclusion :
The maximum flow value can be
determined from the minimum cut
capacity of the network.
Example
1. Find the cut-minimum of the graph below
2. Find the maximum flow of the graph below (vertex s is
the source and the vertex t is the sink)
Cost of flow network
In some applications, each edge in the network are
associated with a number that represents the cost of
transferring one unit of flow through this edge. The cost
could of time units, money unit, etc.…
Cost of flow network
Example: calculate the cost of transferring the flow
showing in the graph.

Remark: the cost of the flow is calculated using all the edges of the network
having flow’s value different than zero.
Minimum Cost Network Flow Problem
A variant of the max-flow problem
Each edge has capacity and cost :
we must pay as amount of money for each unit flow
flowing through
 Problem: find the maximum flow that has the
minimum total cost
Minimum Cost Network Flow Problem
The algorithm of Ford and Fulkerson can solve the
problem of minimum cost network flow.
After getting residual graph, the algorithm needs to
search the path from s to t having the minimum cost
(shortest path to go from s to t).
Minimum Cost Network Flow Problem
Residual in this case?
Minimum Cost Network Flow Problem
The residual graph in this case is determined as:
For each edge in the graph G,
a. If then add edge inwith a flow value equal to , and
unit cost equal to
b. If , then add the edge in with a flow value equal to ,
and unit cost equal to
Minimum Cost Network Flow Problem
1. Initialize flow of all edges to 0 ()
2. Draw on the residual graph
3. Find the shortest path P from the vertex s to the vertex t in (suppose
that the egdes belong to the path P are where
4. If P cannot be found, goto step 8.
5. Find the flow minimum m that can be sent along this path,

6. Apply m to the flows in the graph G as follow:


i. If then
ii. Else ( then this is a residual edge:
7. Goto step 2
8. End of the algorithm
Minimum Cost Network Flow Problem
Example 1:
(300,1) u
(500,10)
s (500,1)
t
(300,1) v
(600,1)

0/(300,1) u 0/(300,1) u
0/(500,10) 0/(500,10)
s 0/(500,1) s 0/(500,1)
t t
0/(300,1) v 300/(300,1) v
0/(600,1) 300/(600,1)
Shortest path from s to t:
s,v,t; min=300;
(300,1) u 300/(300,1) u
(500,10) 0/(500,10)
s (500,1)
t s 300/(500,1)
t
(300,-1) v (300,1) 300/(300,1) v 600/(600,1)
(300,-1)
Shortest path from s to t: s,u,v,t; min=300;

(300,-1) u
(500,10) 300/(300,1) u
s (200,1) 0/(500,10)
(200,-1) t s 300/(500,1)
(300,-1) v t
300/(300,1) v 600/(600,1)
(600,-1)

There are no more path from s to t Flow maximum is 600, at minimum cost :
300*1+300*1+300*1+600*1=1500
Minimum Cost Network Flow Problem
Example 2: (4,8)
4 (7,3)
(5,4)
2
(2,5)
1 (3,5)
(5,2) 5 7
(8,2)
3 (3,4)
(2,6) 6

Source vertex is 1, sink vertex is 7.


The numbers associated to each edge (capacity, unity cost).
(4,8) (4,8)
4 4
(5,4) 2 (7,3) (5,4) 2 (7,3)
(2,5) (2,5)
1 (3,5) 1 (3,5)
(5,2) 5 7 (5,2) 7
(8,2) 5
(8,2)
3 (3,4) 3
6 (3,4)
(2,6) (2,6) 6

Shortest path from 1 to 7:


1,3,5,7; min(8,5,3)=3;
0/(4,8)
4 (4,8)
0/(5,4) 2 0/(7,3) 4
0/(2,5) (5,4) 2 (7,3)
1 (2,5)
3/(3,5) 1
3/(5,2) 5 7 (3,-5)
(2,2) 5 7
3/(8,2) (5,2)
3
6 0/(3,4) 3
0/(2,6) (3,-2)
(3,-2) (3,4)
(2,6) 6

Shortest path from 1 to 7:


1,3,6,7; min(5,2,3)=2;
0/(4,8)
4 (4,8)
0/(5,4) 2 0/(7,3) 4
0/(2,5) (5,4) 2 (7,3)
1 3/(3,5) (2,5)
3/(5,2) 7 1 (3,-5)
5 7
5/(8,2) (2,2) 5
3 (3,2)
2/(3,4) 3 (3,-2) (1,4)
6
2/(2,6) (5,-2)
(2,-6) 6
Shortest path from 1 to 7:
(2,-4)
1,2,4,7; min(5,4,7)=4;

(4,-3)
(4,-4) (4,-8)
4/(4,8) (1,4) 4
4 2 (3,3)
4/(5,4) 2 4/(7,3) (2,5)
0/(2,5) 1 (3,-5)
1 3/(3,5) (2,2) 5 7
3/(5,2) 5 7 (3,2)
5/(8,2) 3 (3,-2) (1,4)
3 (5,-2)
6 2/(3,4)
(2,-6) 6
2/(2,6)
(2,-4)
There are no more path from 1 to 7
4/(4,8)
4
4/(5,4) 2 4/(7,3)
0/(2,5)
1 3/(3,5)
3/(5,2) 5 7
5/(8,2)
3
6 2/(3,4)
2/(2,6)

The flow of the network is : 4+5=9


The cost of the flow is equal to
4*4+5*2+4*8+0*5+3*2+2*6+2*4+3*5+4*3=111
Extensions of the algorithm’s Ford and
Fulkerson
1. Networks with multiple sources and sinks
2. Networks having undirected edges
3. Networks having vertices with capacities
1. Networks with multiple sources and
sinks
A maximum-flow problem may
have several sources and sinks,
rather than just one of each.
for example, instead of having
one factory, we might have a set
of m factories and a set of n
warehouses . Fortunately, this
problem is no harder than
ordinary maximum flow.
1. Networks with multiple sources and sinks
We can reduce the problem of
determining a maximum flow in a
network with multiple sources and
multiple sinks to an ordinary
maximum-flow problem
We add a supersource and add a
directed edge with capacity for each .
We also create a new supersink and
add a directed edge with capacity for
each
1. Networks with multiple sources and
sinks
Extensions of the algorithm’s Ford and
Fulkerson
1. Networks with multiple sources and sinks
2. Networks having undirected edges
3. Networks having vertices with capacities
2. Networks having edges undirected
Transform the network to a directed graph and
then apply the algorithm of Ford and Fulkerson.
This can be done by :
For each undirected edge {i,j} of capacity , we add
two directed edges : (i,j) of capacity and (j,i) of
capacity .
Example: 10
11 A B 4
11 A B 4
S 3 5 t
S 3 5 t
9 10
C 4 D 9 10
C 4 D
Extensions of the algorithm’s Ford and
Fulkerson
1. Networks with multiple sources and sinks
2. Networks having edges undirected
3. Networks having vertices with capacities
3. Networks having vertices with capacities
If the network contains vertices that has some capacity constraints. For
example, if the vertex B of the network below has a capacity of 13.

7 CB=13
11 A B 4
S 3 5 t
9 10
C 4 D

Ford and Fulkerson algorithm are applied to networks with edges


capacity constraints; therefore, we need to transform the vertex capacity
into edge capacity. So how do we do?
3. Networks having vertices with capacities
We add an additional vertex B’ to the network, and we
assign the capacity of B to the edge between B’ and B.

CB B 4
11 A B’ t
S 3 5
9 10
C 4 D

You might also like