Download Maxflow-PF

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Network science wikipedia , lookup

Path integral formulation wikipedia , lookup

Traffic flow wikipedia , lookup

Signal-flow graph wikipedia , lookup

Three-phase traffic theory wikipedia , lookup

Dijkstra's algorithm wikipedia , lookup

Computational fluid dynamics wikipedia , lookup

Transcript
Network Optimization Models:
Maximum Flow Problems
In this handout:
• The problem statement
• Solving by linear programming
• Augmenting path algorithm
Maximum Flow Problem
• Given:
Directed graph G=(V, E),
Supply (source) node O, demand (sink) node T
Capacity function u: E  R .
Given the arc capacities,
send as much flow as possible
from supply node O to demand node T
through the network.
• Goal:
• Example:
A
4
O
4
5
4
B 6
4
C 5
D 5
T
Characteristics of a feasible flow
• Let xij denote the flow through arc i  j .
• Capacity kij of arc i  j is the upper bound on the flow shipped
through arc i  j .
Thus, we have the following constraints:
0  xij  kij
, for any arc i  j
• Every node i, except the source and the sink,
should satisfy the conservation-of-flow constraint, i.e.,
flow into node i = flow out of node i
In terms of xij the constraint is
x
arcs ji
ji

x
arcs i k
ik
, for any node i  O, T
• For any flow that satisfies the conservation-of-flow constraints,
flow out of the source = flow into the sink
This is the amount we want to maximize.
Linear Program for the
Maximum Flow Problem
• Summarizing, we have the following linear program:
maximize x max
s.t.
x
x
arcs ji
arcs jT
ji

Oj

x
x
arcs i k
arcs i T
0  xij  kij
ik
, for any node i  O, T
iT
 x max
, for any arc i  j
This linear program can be solved by a Simplex
method or Excel Solver add-in.
2
x12
1
x13
5
x14
4
x25
4
4
3
4 x34
4
x35
6
5
x46
x56
5
6
5
Objective function: maximize xmax
Capacity constraints:
x12 ≤ 4, x13 ≤ 5, x14 ≤ 4, x25 ≤ 4, x34 ≤ 4, x35 ≤ 6,
x45 ≤ 5, x56 ≤ 5
Conservation-of-flow constraint:
x12 = x25, x13 = x34+x35, x14+x34=x46, x24+x35=x56
Constraint for the sourse and sink node:
x12+x13+x14=x46+x56=xmax
Non-negativity constraints: xij≥0
• There is also a method, which can be applied
directly in the graph:
Augmenting Path Algorithm.
Augmenting Path Algorithm
• Idea: Find a path from the source to the sink,
and use it to send as much flow as possible.
• In our example,
5 units of flow can be sent through the path O  B  D  T ;
Then use the path O  C  T to send 4 units of flow.
The total flow is 5 + 4 = 9 at this point.
• Can we send more?
A
4
O
4
5
5
4
B
4
4
5
6
4
C
5
D
5
5
T
Towards the Augmenting Path Algorithm
• If we redirect 1 unit of flow
from path O  B  D  T to path O  B  C  T,
then the freed capacity of arc D  T could be used
to send 1 more unit of flow through path O  A  D  T,
making the total flow equal to 9+1=10 .
• To realize the idea of redirecting the flow in a systematic way,
we need the concept of residual capacities.
A
1
4
O
4
5
5
4
1
4
B
4 1
C
45
6
54
5
45
D
5
T
Residual capacities
• Suppose we have an arc with capacity 6 and current flow 5:
5
D
B
6
• Then there is a residual capacity of 6-5=1
for any additional flow through B  D .
• On the other hand,
at most 5 units of flow can be sent back from D to B, i.e.,
5 units of previously assigned flow can be canceled.
In that sense, 5 can be considered as
the residual capacity of the reverse arc D  B .
• To record the residual capacities in the network,
we will replace the original directed arcs with undirected arcs:
The number at B is the residual capacity of BD;
5
B 1
D
the number at D is the residual capacity of DB.
Residual Network
• The network given by the undirected arcs and residual capacities
is called residual network.
• In our example,
the residual network before sending any flow:
0
4
O 4
5
0
A 4
B 6
4
0 0
5
C
0
0
D 5
0
0
T
Note that the sum of the residual capacities on both ends of an arc
is equal to the original capacity of the arc.
• How to increase the flow in the network
based on the values of residual capacities?
Augmenting paths
• An augmenting path is a directed path
from the source to the sink in the residual network
such that
every arc on this path has positive residual capacity.
• The minimum of these residual capacities
is called the residual capacity of the augmenting path.
This is the amount
that can be feasibly added to the entire path.
• The flow in the network can be increased
by finding an augmenting path
and sending flow through it.
Updating the residual network
by sending flow through augmenting paths
Continuing with the example,
• Iteration 1: O  B  D  T is an augmenting path
with residual capacity 5 = min{5, 6, 5}.
• After sending 5 units of flow
through the path O  B  D  T,
the new residual network is:
0
4
O
4
50
A
4
05 B 16
4
0 0
C 5
05
0
D 50
05
0
T
Updating the residual network
by sending flow through augmenting paths
• Iteration 2:
O  C  T is an augmenting path
with residual capacity 4 = min{4, 5}.
• After sending 4 units of flow
through the path O  C  T,
the new residual network is:
0
4
O 0
4
0
A
4
5 B 1
4
40 0
C 15
5
0
D 0
5
40
T
Updating the residual network
by sending flow through augmenting paths
• Iteration 3:
O  A  D  B  C  T is an augmenting path
with residual capacity 1 = min{4, 4, 5, 4, 1}.
• After sending 1 units of flow
through the path O  A  D  B  C  T ,
the new residual network is:
10
34
O
0
0
A 3
4
5 B 21
34
4 10
C 01
45
10
D 0
5
54
T
Terminating the Algorithm:
Returning an Optimal Flow
• There are no augmenting paths in the last residual network.
So the flow from the source to the sink cannot be increased
further, and the current flow is optimal.
• Thus, the current residual network is optimal.
The optimal flow on each directed arc of the original network
is the residual capacity of its reverse arc:
flow(OA)=1, flow(OB)=5, flow(OC)=4,
flow(AD)=1, flow(BD)=4, flow(BC)=1,
flow(DT)=5, flow(CT)=5.
The amount of maximum flow through the network is
5 + 4 + 1 = 10
(the sum of path flows of all iterations).
The Summary of the
Augmenting Path Algorithm
• Initialization: Set up the initial residual network.
• Repeat
– Find an augmenting path.
– Identify the residual capacity c* of the path; increase the flow
in this path by c*.
– Update the residual network: decrease by c* the residual
capacity of each arc on the augmenting path; increase by c*
the residual capacity of each arc in the opposite direction on
the augmenting path.
Until no augmenting path is left
• Return the flow corresponding to
the current optimal residual network