Ronnie Barequet

advertisement
Min Cost Flow: Polynomial Algorithms
Overview
• Recap:
•Min Cost Flow, Residual Network
•Potential and Reduced Cost
•Polynomial Algorithms
•Approach
•Capacity Scaling
• Successive Shortest Path Algorithm Recap
• Incorporating Scaling
•Cost Scaling
• Preflow/Push Algorithm Recap
• Incorporating Scaling
•Double Scaling Algorithm - Idea
Min Cost Flow - Recap
• G=(V,E) is a directed graph
• Capacity u(v,w) for every (𝑣, 𝑀) ∈ 𝐸
• Balances: For every 𝑣 ∈ 𝑉 we will have a number
b(v)
• Cost c(v,w) for every 𝑣, 𝑀 ∈ 𝐸
• can assume non-negative
v1
4,1
5,1
5
v3
1,1
3,4
-2
v5
v2
3,3
-3
v4
Min Cost Flow - Recap
Compute feasible flow with min cost οƒ₯ xij cij
Residual Network - Recap
• We replace each arc 𝑖, 𝑗 ∈ 𝐸 by two arcs 𝑖, 𝑗 and
(𝑗, 𝑖).
• The arc (𝑖, 𝑗) has cost 𝑐𝑖𝑗 and residual capacity
π‘Ÿπ‘–π‘— = 𝑒𝑖𝑗 − π‘₯𝑖𝑗 .
• The arc (𝑗, 𝑖) has cost 𝑐𝑗𝑖 = −𝑐𝑖𝑗 and residual
capacity π‘Ÿπ‘—π‘– = π‘₯𝑖𝑗 .
• The residual network consists only of arcs with
positive residual capacity.
• A For a feasible flow x, G(x) is the residual
network that corresponds to the flow x.
Reduced Cost - Recap
• Let πœ‹: 𝑉 → 𝑅 be a potential function of the nodes in
V.
• Reduced cost: of an edge (u,v) :
πœ‹ =𝑐
𝑐𝑒,𝑣
𝑒,𝑣 − πœ‹ 𝑒 + πœ‹(𝑣)
Reduced Cost - Recap
• Theorem (Reduced Cost Optimality):
A feasible solution x* is an optimal solution of the
minimum cost flow problem

Exists Node potential function πœ‹ that satisfies the
following reduced cost optimality conditions:
πœ‹
∀ 𝑒, 𝑣 ∈ 𝐺 π‘₯ ∗ : 𝑐𝑒,𝑣
≥0
• Idea: No negative cycles in G(x*)
Min Cost Flow: Polynomial Algorithms
Approach
• We have seen several algorithm for the MCF
problem, but none polynomial – in logU, logC.
• Idea: Scaling!
• Capacity/Flow values
• Costs
• both
• Next Week: Algorithms with running time
independent of logU, logC
• Strongly Polynomial
• Will solve problems with irrational data
Capacity Scaling
Successive Shortest Path - Recap
• Pseudo-Flow – Flow which doesn’t necessarily
satisfy balance constraints
• Define imbalance function e for node i:
π‘₯𝑖𝑗 −
𝑒 𝑖 =𝑏 𝑖 −
𝑗: 𝑖,𝑗
π‘₯𝑗𝑖
𝑗: 𝑗,𝑖
• Define E and D as the sets of excess and Deficit
nodes.
• Observation:
𝑒(𝑖) = −
𝑖∈𝐸
𝑒(𝑖)
𝑖∈𝐷
Successive Shortest Path - Recap
• Lemma: Suppose pseudoflow x has potential πœ‹,
satisfying reduced cost optimality.
Letting d be the vector of distances from some
πœ‹
node s in G(x) with 𝑐i,j
as the length of (i,j), then:
• Potential πœ‹ ′ = πœ‹ − d also satisfies optimality
conditions
πœ‹′
• 𝑐i,j
= 0 for edges in shortest paths from s.
• Idea: triangle inequality
Successive Shortest Path - Recap
• Algorithm:
• Maintain pseudoflow x with pot. πœ‹, satisfying
reduced cost optimality.
• Iteratively, choose node s with positive excess
– e(s) > 0, until there none.
• compute shortest path distances d from s in
πœ‹
G(x) with 𝑐i,j
as the length of (i,j).
• Update πœ‹ ′ = πœ‹ − d. also satisfies optimality
conditions
• Push as much flow as possible along path
from s to some node t with e(t) < 0. (retains
optimality conditions w.r.t. πœ‹ ′ ).
Successive Shortest Path - Recap
• Algorithm Complexity:
• Assuming integrality, at most nU iterations.
• In each iteration, compute shortest paths,
• Using Dijkstra, bounded by O(m+nlogn) per
iteration
Capacity Scaling - Scheme
• Successive Shortest Path Algorithm may push very
little in each iteration.
• Fix idea: use scaling
• Modify algorithm to push  units of flow
• Ignore edges with residual capacity < 
• until there is no node with excess  or no node
with deficit 
• Decrease  by factor 2, and repeat
• Until  < 1.
Definitions
• Define
S βˆ† = 𝑖: 𝑒 𝑖 ≥ βˆ† - nodes with access at least 
T βˆ† = 𝑖: 𝑒 𝑖 ≤ −βˆ† - nodes with deficit at least 
• The -residual network G(x, ) is the subgraph of
G(x) with edges with residual capacity at least .
3
4
1
G(x)
3
3
2
4
3
Definitions
• Define
S βˆ† = 𝑖: 𝑒 𝑖 ≥ βˆ† - nodes with access at least 
T βˆ† = 𝑖: 𝑒 𝑖 ≤ −βˆ† - nodes with deficit at least 
• The -residual network G(x, ) is the subgraph of
G(x) with edges with residual capacity at least .
3
4
G(x, 3)
3
3
4
3
Main Observation in Algorithm
• Observation: Augmentation of  units must start
at a node in S(), along a path in G(x, ), and end at
a node in T().
• In the  -phase, we find shortest paths in G(x, ),
and augment over them.
• Thus, edges in G(x, ), will satisfy the reduced
optimality conditions.
• We will consider edges with less residual capacity
later.
Initializing phases
• In later -phases, “new” edges with residual capacity
 ο‚£ rij < 2 may be introduced to G(x, ).
πœ‹
• We ignored them until now, so possibly 𝑐i,j
<0
• Solution: saturate such edges.
i
j
Capacity Scaling Algorithm
Capacity Scaling Algorithm
Initial values.
0 pseudoflow and potential (optimal!)
Large enough 
Capacity Scaling Algorithm
In beginning of -phase, fix optimality
condition on “new” edges with resid.
Cap.  ο‚£ rij < 2 by saturation
Capacity Scaling Algorithm
augment path in G(x,) from node in
S() to node in T()
Capacity Scaling Algorithm Correctness
• Inductively, The algorithm maintains a reduced
cost optimal flow x w.r.t. πœ‹ in G(x, ).
• Initially this is clear.
• At the beginning of the -phase, “new” arcs s.t.
 ο‚£ rij < 2 are introduced, may not satisfy
optimality.
πœ‹
Saturation of edges such that 𝑐i,j
< 0 suffices,
πœ‹
πœ‹
since the reversal satisfies 𝑐j,i
= −𝑐i,j
> 0.
• Augmenting flow in shortest path procedure in
G(x, ) retains optimality
Capacity Scaling Algorithm Correctness
• When =1, G(x, ) = G(x).
• The algorithm ends with 𝑆 1 = πœ™, or 𝑇 1 = πœ™.
• By integrality, we have a feasible flow.
Capacity Scaling Algorithm Assumption
• We assume path from k to l in G(x, ) exists.
• And we assume we can compute shortest distances
from k to rest of nodes.
• Quick fix: initially, add dummy node D with
artificial edges (1,D) and (D,1) with infinite
capacity and very large cost.
Capacity Scaling Algorithm –
Complexity
• The algorithm has O(log U) phases.
• We analyze each phase separately.
Capacity Scaling Algorithm – Phase
Complexity
• Let’s assess the sum of excesses at the
beginning.
• Observe that when -phase begins, either
𝑆 2βˆ† = πœ™, or 𝑇 2βˆ† = πœ™.
E
D
Thus the sum of excesses (= sum of deficits)
is less than 2π‘›βˆ†
Capacity Scaling Algorithm – Phase
Complexity – Cont.
• Saturation of edges in the beginning of the
phase saturate edges with rij < 2. This may
add at most 2π‘šβˆ† to the sum of excesses
Capacity Scaling Algorithm – Phase
Complexity – Cont.
• Thus the sum of excesses is less than 2(π‘š
+ 𝑛)βˆ†
• Therefore, at most 2π‘š + 2𝑛 augmentations
can be performed in a phase.
• In total: O π‘š βˆ™ (π‘š + π‘›π‘™π‘œπ‘”π‘›) per phase.
Capacity Scaling Algorithm –
Complexity
• O π‘š βˆ™ (π‘š + π‘›π‘™π‘œπ‘”π‘›) per phase.
 O π‘™π‘œπ‘”π‘ˆ βˆ™ π‘š βˆ™ (π‘š + π‘›π‘™π‘œπ‘”π‘›)
Cost Scaling
Approximate Optimality
• A pseudoflow (flow) x is said to be ο₯optimal for some ο₯>0 if for some pot. πœ‹,
πœ‹
𝑐i,j
≥ −πœ€ for every edge (i,j) in G(x).
Approximate Optimality Properties
• Lemma: For a min. cost flow problem with integer costs, any
feasible flow is C-optimal. In addition, if ε < 1/𝑛, then any ο₯optimal feasible flow is optimal.
• Proof:
• Part 1 is easy: set πœ‹ = 0.
• Part 2: for any cycle W in G(x),
πœ‹
𝑐
=
𝑐
π‘Š i,j
π‘Š i,j ≥ −πœ€π‘› > −1.
applying integrality, it follows
follows.
b
4
a
π‘Š 𝑐i,j
-5
c
-2
3
d
≥ 0. The lemma
Algorithm Strategy
• The previous lemma suggests the following
strategy:
1. Begin with feasible flow x and πœ‹ = 0, which is
C-optimal
2. Iteratively improve from and ο₯-optimal flow (x,
πœ‹) to an ο₯/2-optimal flow (x’, πœ‹′), until ο₯ < 1/n.
• We discuss two methods to implement the
underlying improvement procedure.
• The first is a variation of the Preflow Push
Algorithm.
Preflow Push Recap
Distance Labels
• Distance Labels Satisfy:
• d(t) = 0, d(s) = n
• d(v) ≤ d(w) + 1
if r(v,w) > 0
• d(v) is at most the distance from v to t in
the residual network.
•  s must be disconnected from t …
Terms
• Nodes with positive excess are called
active.
• Admissible arc in the residual graph:
v
w
d(v) = d(w) + 1
The preflow push algorithm
While there is an active node {
pick an active node v and push/relabel(v)
}
Push/relabel(v) {
If there is an admissible arc (v,w) then {
push  = min {e(v) , r(v,w)} flow from v to w
} else {
d(v) := min{d(w) + 1 | r(v,w) > 0} (relabel)
}
Running Time
• The # of relabelings is (2n-1)(n-2) < 2n2
• The # of saturating pushes is at most 2nm
• The # of nonsaturating pushes is at most
4n2m – using potential Φ = Σv active d(v)
Back to Min Cost Flow…
Applying Preflow Push’s technique
• Our motivation was to find a method to
improve an ο₯-optimal flow (x, πœ‹) to an ο₯/2optimal flow (x’, πœ‹′).
• We use Push Preflow’s technique:
• Labels: πœ‹(i)
• Admissible edge in residual network:
πœ‹
if − πœ€ 2 ≤ 𝑐i,j
<0
i
• Relabel: Increase πœ‹(i) by πœ€ 2
πœ‹
𝑐i,j
j
𝑐i,j + πœ‹ j − πœ‹ i < 0
Initialization
• We first transform the input ο₯-optimal flow
(x, πœ‹) to an ο₯/2-optimal pseduoflow (x’, πœ‹′).
• This is easy
• Saturate edges with negative reduced
cost.
• Clear flow from edges with positive
reduced cost.
-10
v
w
Obtain a πœ€
2
- optimal pseudoflow
Push/relabel until no active
nodes exist
Correctness
• Lemma 1: Let x be pseudo-flow, and x’ a
feasible flow.
Then, for every node v with excess in x,
there exists a path P in G(x) ending at a
node w with deficit, and its reversal is a
path in G(x’).
• Proof: Look at the difference x’-x, and
observe the underlying graph (edges with
negative difference are reversed).
Lemma 1: Proof Cont.
• Proof: Look at the difference x’-x, and
observe the underlying graph (edges with
negative difference are reversed).
3
3
4
2
0
1
3
3
2
4
3
-
3
4
2
5
2
Lemma 1: Proof Cont.
• Proof: Look at the difference x’-x, and
observe the underlying graph (edges with
negative difference are reversed).
w
v
S
• There must be a node with deficit reachable,
otherwise x’ isn’t feasible
Correctness (cont)
Corollary: There is an outgoing residual arc incident
with every active vertex
Corollary: So we can push/relabel as long as there is
an active vertex
Correctness – Cont.
• Lemma 2: The algorithm maintains an ο₯/2optimal pseudo-flow (x’, πœ‹′),
• Proof: By induction on the number of
operations.
• Initially, optimal preflow.
Correctness – Cont.
πœ‹
• Push on edge where − πœ€ 2 ≤ 𝑐i,j
< 0 may
πœ‹
introduce (j,i) to G(x), but that’s OK: 𝑐j,i
= −𝑐i,jπœ‹ > 0.
Correctness – Cont.
• Relabel operation at node i occurs when
πœ‹
there’s no admissible arc - 0 ≤ 𝑐i,j
for every
edge emanating from i in the residual
network.
πœ‹
• Relabel decreases 𝑐i,j
by πœ€ 2, so it satisfies
πœ€ -optimality condition.
2
πœ‹
• Relabel increases 𝑐j,i
, so it clearly still
satisfies πœ€ 2-optimality condition.
Correctness (cont)
• Lemma 3: When (and if) the algorithm stops the
preflow is an ο₯/2-optimal feasible flow (x’, πœ‹′).
Proof:
It is a feasible flow since there is no active vertex.
It is ο₯/2-optimal since πœ‹’ satisfies ο₯/2-optimality
conditions.
Complexity
• Lemma : a node is relabeled at most 3n
times.
Lemma 2 – Cont.
• Proof: Let x’ be the πœ€-opt. input flow, f and x’ an
intermediate πœ€ 2 -opt. pseudo-flow. Let , ’ be
the respective potentials. Take the path P from v
to w as described in Lemma 1.
πœ€
2 -opt. gives:
−ε
2
βˆ™ 𝑙𝑒𝑛 𝑃 ≤
πœ€-opt. gives: −ε βˆ™ 𝑙𝑒𝑛 𝑃 ≤
=
𝑃 −𝑐i,j
+ πœ‹′ 𝑣 − πœ‹′ 𝑀
πœ‹
𝑃 𝑐i,j
=
πœ‹′
𝑐
π‘Ÿπ‘’π‘£(𝑃) j,i
𝑃 𝑐i,j
+πœ‹ 𝑀 −πœ‹ 𝑣
Lemma 2 – Cont.
−ε
βˆ™ 𝑙𝑒𝑛 𝑃 ≤
2
πœ‹
𝑐i,j
=
𝑃
𝑐i,j + πœ‹ 𝑀 − πœ‹ 𝑣
𝑃
πœ‹′
𝑐j,i
=
−ε βˆ™ 𝑙𝑒𝑛 𝑃 ≤
π‘Ÿπ‘’π‘£(𝑃)
−𝑐i,j + πœ‹′ 𝑣 − πœ‹′ 𝑀
𝑃
−3ε
βˆ™ 𝑙𝑒𝑛 𝑃 ≤ πœ‹ 𝑀 − πœ‹ ′ 𝑀
2
− πœ‹ 𝑣 − πœ‹′ 𝑣
Nodes never become
deficit nodes, so πœ‹ ′ 𝑀
is untouched
Lemma 2 – Cont.
−ε
βˆ™ 𝑙𝑒𝑛 𝑃 ≤
2
πœ‹
𝑐i,j
=
𝑃
𝑐i,j + πœ‹ 𝑀 − πœ‹ 𝑣
𝑃
πœ‹′
𝑐j,i
=
−ε βˆ™ 𝑙𝑒𝑛 𝑃 ≤
π‘Ÿπ‘’π‘£(𝑃)
−𝑐i,j + πœ‹′ 𝑣 − πœ‹′ 𝑀
𝑃
3ε
βˆ™ 𝑙𝑒𝑛 𝑃 ≥ πœ‹ 𝑣 − πœ‹ ′ 𝑣
2
Complexity Analysis (Cont.)
• Lemma: The # of saturating pushes is at
most O(nm).
• Proof: same as in Preflow Push.
Complexity Analysis – non
Saturating Pushes
• Def: The admissible network is the graph
of admissible edges.
-2
4
2
2
-2
-1
-4
Complexity Analysis – non
Saturating Pushes
• Def: The admissible network is the graph
of admissible edges.
-2
-2
-1
-4
Complexity Analysis – non
Saturating Pushes
• Def: The admissible network is the graph
of admissible edges.
• Lemma: The admissible network is acyclic
throughout the algorithm.
• Proof: induction.
Complexity Analysis – non
Saturating Pushes – Cont.
• Lemma: The # of nonsaturating pushes is
O(n2m).
• Proof: Let g(i) be the # of nodes reachable
from i in admissible network
• Let Φ = Σi active g(i)
Complexity Analysis – non
Saturating Pushes – Cont.
• Φ = Σi active g(i)
• By acyclicity, decreases (by at least one) by
every nonsaturating push
i
j
Complexity Analysis – non
Saturating Pushes – Cont.
• Φ = Σi active g(i)
• Initially g(i) = 1.
• Increases by at most n by a saturating push : total
increase O(n2m)
• Increases by each relabeling by at most n (no
incoming edges become admissible): total increase <
O(n3)
•  O(n2m) non saturating pushes
Cost Scaling Summary
• Total complexity O(n2mlog(nC)).
• Can be improved using ideas used to
improve preflow push
Double Scaling
(If Time Permits)
Double Scaling Idea
• Use capacity scaling to implement improveapproximation
• New ‘tricks’ used:
• Transform network to bipartite network
on nodes V ∪ 𝐸.
• Augment on admissible paths
(generalization of shortest paths and
push on edges)
• Find admissible paths greedily (DFS),
and relabel potentials in retreats.
Network Transformation
b(i)
Cij, uij
i
xij
b(j)
b(i)
j
i
Cij, ο‚₯
-uij
0, ο‚₯
b(j)
(i,j)
xij
j
rij
• Bipartite network on nodes V ∪ 𝐸. For
Convenience, shall refer to V as N1, and to E
as N2.
• All edges from N1 to N2.
• No capacities
Improve approximation
Initialization
• Recall: receives (x, πœ‹) which is ο₯-optimal.
• If we reset x’:=0, then G(x’) = G.
• No capacities – G is a subgraph of G(x).
πœ‹
• ο₯-optimality means −ε ≤ 𝑐i,j
for all edges in
G(x), and in particular in G.
• Adding ο₯ to πœ‹(j) for every j in N2, obtains
an optimal pseudoflow.
N1
N2
+ο₯
Capacity Scaling - Scheme
• While S() 
• Pick a node kοƒŽ S().
• search for an admissible path using DFS
• On retreat from node i, relabel: increase πœ‹(i)
by πœ€ 2
• Upon finding a deficit node, augment  units
of flow in path.
• Decrease  by factor 2, and repeat
• Until  < 1.
Double Scaling - Correctness
• Assuming algorithm ends, immediate, since we
augment along admissible path.
• (Residual path from excess to node to deficit node
always exists – see cost scaling algorithm)
• We relabel when indeed no outgoing admissible
edges.
Double Scaling - Complexity
• O(log U) phases.
• In each phase, each augmentation clears a node
from S() and doesn’t introduce a new one.
so O(m) augmentations per phase.
Double Scaling Complexity – Cont.
• In each augmentation,
• We find a path of length at most 2n (admissible
network is acyclic and bipartite)
• Need to account retreats.
Double Scaling Complexity – Cont.
• In each retreat, we relabel.
• Using above lemma, potential cannot grow more
than O(l), where l is a length of path to a deficit
node.
• Since graph is bipartite, l = O(n).
• So in all augmentations, O(n (m+n)) = O(mn)
retreats.
N1
N2
Double Scaling Complexity – Cont.
• To sum up:
• Implemented improve-approximation using
capacity scaling
• O(log U) phases.
• O(m) augmentations per phase.
• O(n) nodes in path
• O(mn) node retreats in total.
• Total complexity: O(log(nC) log(U) mn)
Thank You
Download