You are on page 1of 31

Flows

Building evacuation plan


people to
evacuate from
the offices

corridors and 10 10 5 50 15 15 15
stair ways 50
capacity 60 60

15 10 60 60 15 15 90’’ to evacuate a plane

(used athletes to prove it)

60’ to evacuate a ship

(used simulation)

50

For each person determine the path to follow to reach the meeting point
Do not violate the capacity
Maximum flow problem
Given a directed graph G = (N, A)
and t wo nodes s, t ∈ N
(integer) capacities uij ≥ 0, ∀(i, j) ∈ A
Send as much flow as possible from s to t
constraints
arc capacities
flow conser vation at intermediate nodes
Example

3
1 3
2
10 1 10

s 6 2 t

2
6
2 4
4
Building evacuation plan

people to
evacuate from t
the offices

corridors and 10 10 5 50 15 15 15
stair ways 50
capacity 60 60

15 10 60 60 15 15

s 50
Scheduling problem
m identical machines
set of jobs J = {1, . . . , n}
(pj , rj , dj )∀j ∈ J
processing release due
time time date

jobs executed on a single machine


they can be interrupted and resumed without loss of time
Determine an assignment job-machine
timing is satisfied
Alternative viewpoint
Interrupt the flow from s to t
destroy some arcs
3
1 3
2
10 1 10

s 6 2 t

2
6
2 4
4

cost proportional to the capacities


s-t cut
Given a directed graph G = (N, A)
and t wo nodes s, t ∈ N
(integer) capacities uij ≥ 0, ∀(i, j) ∈ A
Cut (Ns , Nt )
Ns ∪ Nt = N, Ns ∩ Nt = ∅, s ∈ Ns , t ∈ Nt

Capacity of the
! cut
U (Ns , Nt ) = uij
(i,j)∈A:i∈Ns ,j∈Nt

Flow!
traversing the cut !
x(Ns , Nt ) = xij − xji
(i,j)∈A:i∈Ns ,j∈Nt (j,i)∈A:j∈Nt ,i∈Ns

A+ (Ns , Nt )
<latexit sha1_base64="Dsb83jf6jDbv1LaJm6d9hjwAWyE=">AAAB8nicdVDLSgMxFM3UV62vqks3wSJUlCHT2teu6sZVqWBtoa1DJs20oZnMkGSEUvobblyouPVr3Pk3pg9BRQ9cOJxzL/fe40WcKY3Qh5VYWl5ZXUuupzY2t7Z30rt7tyqMJaENEvJQtjysKGeCNjTTnLYiSXHgcdr0hpdTv3lPpWKhuNGjiHYD3BfMZwRrI3XO706yNVed1lx97KYzyEbFQiWPILILyClVKoYgVCznc9AxZIoMWKDupt87vZDEARWacKxU20GR7o6x1IxwOkl1YkUjTIa4T9uGChxQ1R3Pbp7AI6P0oB9KU0LDmfp9YowDpUaBZzoDrAfqtzcV//LasfbL3TETUaypIPNFfsyhDuE0ANhjkhLNR4ZgIpm5FZIBlphoE1PKhPD1KfyfNHJ2xXauzzLVi0UaSXAADkEWOKAEquAK1EEDEBCBB/AEnq3YerRerNd5a8JazOyDH7DePgEIZ5CX</latexit>
A (Ns , Nt )

Properties
Given a feasible flow xij , ∀(i, j) ∈ A
for any cut (Ns , Nt )

the flow going from s to t equals the flow traversing the cut
v = x(Ns , Nt )

the flow traversing the cut is less than or equal to the capacity
of the cut
x(Ns , Nt ) ≤ U (Ns , Nt )

=
Can we prove that when x is optimum the equality holds?
Computation tool
Given a feasible flow

2 3
1 3
3 2
2 2
10 1 10
1
s 6 2 2 t
0

2
2 3 6
2 4
4 4

Can we improve the solution?


What are the possible changes?
Residual graph
Consider G = (N, A) s, t ∈ N
(integer) capacities uij ≥ 0, ∀(i, j) ∈ A
feasible flow xij , ∀(i, j) ∈ A
+
GR (x) = (N, A(x) = A (x) ∪ A (x))−

+
A (x) = {(i, j) 2 A : xij < uij }
the flow can be increased by at least one unit

A− (x) = {(j, i) : (i, j) ∈ A : xij > 0}


the flow can be decreased by at least one unit
Combine the changes
Path from s to t in GR (x)

flow augmentation

Can we prove that if there are no paths the flow is maximum?


Augmenting_paths (G, s, t, x)
foreach (i,j) ∈ A do x[i,j]←0
repeat
GR ←Residual graph(x);
Graph_search(GR,s,P);
if P[t]≠0 then Augment_flow(P,x);
until P[t]=0

Augment_flow(P,x)
ϑ←Residual_capacity(P,x)
foreach (i,j) ∈ P do if (i,j) ∈ A+ then x[i,j] ← x[i,j]+ϑ
else x[j,i] ← x[j,i]-ϑ
Very important property
Given a directed graph G = (N, A)
and t wo nodes s, t ∈ N

either there is a path pst

or there is a cut (Ns , Nt ), s ∈ Ns , t ∈ Nt


such that each arc of the cutset is (i, j) : i ∈ Nt , j ∈ Ns
Complexity issues
How to select the augmenting path

Edmonds and Karp


Select the augmenting path with the minimum number of arcs
O(m2n)
Assignment problem
workers jobs
1 6

2 7

3 8

4 9

5 10

Compatibility
Assign jobs to workers (at most one worker per job)
Maximize the number of pairs
Maximum cardinality assignment
Given a bipartite graph G = (S, T, A)
A⊆S×T
Matching M ⊆ A
no t wo arcs are incident in the same node

The problem can be easily reduced to a Maximum Flow

unit capacities

how does the complexity change?


10
A waste disposal problem
cost, capacity

landfill

pile of waste

55

burner

pile of waste processing center


recycling center
Road construction
excess of material

3 4 2
level of the road
3 3 3

lack of material

Cost of moving material from one site to an adjacent one = 1 per truck

Distribute the material at minimum cost

Pedemontana: estimated earth movement 35 x 106 m3


Minimum cost flow problem
Given a graph G = (N, A)
node balances bi , ∀i ∈ N
bi < 0 offering node
<latexit sha1_base64="ErNFCiT3Bqkl9W9EcKVxmiQ3JVQ=">AAAB63icdVDLSsNAFJ3UV62vqks3g0VwFSatfQRcFN24rGC00IYymU7aoZNJmJkIJfQb3LhQcesPufNvnLQVVPTAhcM593LvPUHCmdIIfViFldW19Y3iZmlre2d3r7x/cKviVBLqkZjHshtgRTkT1NNMc9pNJMVRwOldMLnM/bt7KhWLxY2eJtSP8EiwkBGsjeQFA3aOBuUKslGj7tYQRHYdOU3XNQShRqtWhY4hOSpgic6g/N4fxiSNqNCEY6V6Dkq0n2GpGeF0VuqniiaYTPCI9gwVOKLKz+bHzuCJUYYwjKUpoeFc/T6R4UipaRSYzgjrsfrt5eJfXi/VYcvPmEhSTQVZLApTDnUM88/hkElKNJ8agolk5lZIxlhiok0+JRPC16fwf+JVbdd2rs8q7YtlGkVwBI7BKXBAE7TBFegADxDAwAN4As+WsB6tF+t10VqwljOH4Aest08F0I5f</latexit>

bi > 0 demanding node


bi = 0 transfer node
!
w.l.o.g. let us assume that bi = 0
i∈N
costs cij , ∀(i, j) ∈ A
capacities uij ≥ 0, ∀(i, j) ∈ A
send the required flow (flow balance constraints)
capacity constraints
minimize the cost of the flow
Generalization
Max Flow and Shortest Path Tree problem can be seen as
special cases of the Minimum Cost Flow Problem

!
min cij xij
(i,j)∈A
! !
xji − xij = bi ∀i ∈ N
(j,i)∈BS(i) (i,j)∈F S(i)

0 ≤ xij ≤ uij ∀(i, j) ∈ A


A simple yield management problem

Rome Florence Bologna Milan

p number of seats
bij i < j persons willing to go from i to j
fij i < j ticket price for going from i to j

Accept the reser vations so as to maximize the earning


Changing a feasible solution
Given a feasible flow
-4 2, 2 1
1 3 0

3 i j
1, 2 cost, capacity
2, 4 1 1, 5
0

0 2 4
3, 3 3 4

Can we change the solution?


What changes preserve the feasibility?

What is the effect on the objective function of sending one


unit of flow along a cycle?
Residual graph
Consider G = (N, A)
(integer) capacities uij ≥ 0, ∀(i, j) ∈ A
costs cij , ∀(i, j) ∈ A
feasible flow xij , ∀(i, j) ∈ A
+
GR (x) = (N, A(x) = A (x) ∪ A (x))

+
A (x) = {(i, j) 2 A : xij < uij }
the flow can be increased by at least one unit
+
cost: cij , 8(i, j) 2 A (x)

A (x) = {(j, i) : (i, j) ∈ A : xij > 0}


the flow can be decreased by at least one unit


cost: −cij , ∀(j, i) ∈ A −
(x)
Characterizing the optimal solution
If in the residual graph there is a negative cost cycle

the flow can be improved

We can prove that


If there are no negative cost cycles the flow is optimal
Negative cycle elimination
x←Feasible_flow;
GR ←Residual graph(x);
while Negative_cost_cycle(C, GR)
ϑ←Residual_capacity(C, x);
Update_flow(ϑ, C, x);
Update(GR)

Update_flow(C, ϑ, x)
foreach (i,j) ∈ C do if (i,j) ∈ A+ then x[i,j] ← x[i,j]+ϑ
else x[j,i] ← x[j,i]-ϑ
Detecting negative cost cycles
From the complexity analysis we know that a node cannot be
inserted into Q more than n-1 times

If a node is inserted n times

negative cost cycle


Starting feasible flow
Disregard the arc costs
Consider the 0
5, 3
2

flow in the 1 3
3, 2
original arcs 2, 10 7, 1 1, 10

-3 5 4, 6 7, 2 6 t
3
2
1, 2 1, 6
s
2 4
2, 4
2
-2 1
Add a source and a sink
Connect the source to all offer nodes
Connect the demand nodes to the sink
Move the balances on the capacities
Compute! the maximum flow from s to t
If the flow = bi then there is a feasible solution
i:bi >0
Complexity issues
initialization max flow

at each iteration: SPT_L_queue O(mn)


update the flow
O(n)
update the graph

How many iterations at worst?


Selecting the cycle according to a particular rule
O(m2 n log n) iterations
A distribution problem
-10 1, 10 10
oranges -10 1 3 10
1, 10
1, 10 1, 10
5 6 20, 10 1000, 10
1, 10
1, 10
2 4
pears -10
-10 1, 10 10
10

Multicommodity flow

A set of flow variables for each commodity

Flows of different commodities concur in the use of


common resources (arc capacities)
A multi terminal routing problem
We want to route traffic the intranet net work of Politecnico
unit routing costs capacities (in both directions) Origin/Destination matrix
LC
2 15 o/d MiL MiB CO LC CR PC MN

CO 6 10 9 6 MiL - 80 30 0 15 2 10

5 25 MiB 10 5 MiB 70 - 0 20 0 5 5
11 5
CR MN CO 20 5 - 3 1 0 0
4 9 1 100
7 10 8 10 13 9
LC 1 3 1 - 2 0 1
3 7 MiL 12 5 CR 10 2 3 0 - 4 1

PC PC 2 5 0 0 3 - 0

MN 10 15 0 0 2 1 -

Problem:send the required flows from origins to destinations,


satisfy the capacities,
minimize the overall cost

You might also like