This preview shows pages 1–18. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: ' n "i . hmgto Unuemts mSt Lows Engineering AllPairs Shortest Paths and
Faster MinCost Flows Jon Turner
Computer Science & Engineering
Washington University www.ar1.wustl.edu/~jst :1, Washmgton UnlverSItymStlouis Engineering Floyd’s Algorithm l Dynamic programming algorithm for allpairs problem >> initialize dist(u,v) to /ength(u,v) if there is an edge from u to v,
zero if u=v and co otherwise >> apply the following step to each vertex v
Labeling Step: if dist(v,v)<0, abort: there is a negative cycle;
otherwise for each pair u,w with dist(u,w)>dist(u,v)+dist(v,w),
replace dist(u,w) by dist(u,v)+dist(v,w)
.Store path information in separate midpoint mapping >> values initialized to null and midpoint(u,w) assigned value v
whenever dist(u,w) is assigned the value dist(u,v)+dist(v,w) >> construct paths with a recursive procedure that uses midpoint
 Runs in @(n3) time regardless of number of edges >> also requires @(nz) space; for very dense graphs, its simplicity
makes it faster than Dijkstra's algorithm E Washington University in St. Louis Engineering Dijkstra’s Algorithm for All Pairs I For non—negative edge lengths use Dijkstra’s algorithm
to solve all pairs problem in O(mn+n2og n) time >>can get same time bound with negative edge lengths by first
transforming edge lengths >>first, add vertex 5 to G and zero length edge [s,v] to every v 0 /ength(a,d) = /ength’(a,d)
+distance(d) distance(a)
= 1+(3)—0=2 >> use breadth—first algorithm to compute distance(v)=length of
shortest path from s to v in augmented graph >>apply Dijkstra's algorithm to G with a new length function,
length’(u,v)=length(u,v)+distance(u)—distance(v) >>to get path length in original graph, apply reverse transform :1, Mshlngton UnwersuymStlouis Engineering Validity of Edge Length Transform  Theorem 7.8. For any edge [u,v], /ength’(u,v)20 and
for every path p from a vertex X to a vertex y,
length’(p)=/ength(p)+distance(X)—distance(y). Proof. First part of the theorem is implied by Theorem 7.3
Second part is proved by induction on number of edges in p
Basis: p =1. Immediate from the definition of length’ Induction: p=k+1. Let q be path containing first k edges of p
and let 2 be last vertex on q. Then, Iength’(p) = /ength’(q) + /ength’(z,y)
= Iength(q) + distance(x) — distance(z)
+ /ength(z, y) + distance(z) — distance(y)
= Iength(p) + distance(x) — distance(y) :1, Mshmgton UniverSItymStlouis Engineering Review Questions 1. Draw a directed graph with at least six vertices and ten edges, with edge weights in
the range [—2, 5], taking care to avoid negative length cycles. Draw a second copy
of the graph, in which each edge length has been replaced by the transformed lengths described on page 3. . Pick two vertices from your graph, and pick two different 3 edge paths connecting
these vertices. Compute the lengths of these paths using both the original lengths
and the transformed lengths. For each path, what is the difference between the
path length computed with the original edge lengths, and the path length computed
using the transformed edge lengths? . How does the length of a cycle in a graph using the transformed edge lengths
compare to the length of the same cycle using the original edge lengths? Explain. E Washington University in St. Louis Minimum Cost Flows cap,cost
\‘ 6,1 Engineering  Max flow can be generalized by adding edge costs >> costs are skew symmetric; cost(v,w)=cost(w,v) >> for flow f, cost'(f)=>:,r(\,/W)>Ocost(v,w)f(v,w)=2V1W cost(v,w)f(v,w)/2 >> cost of path is defined as sum of edge costs and residual graph is
defined as before; cost(v,w) in R is same as in G >> A flow f has minimum cost if there is no flow 9 with g=f that
has lower cost than f >> mincost, maxflow problem: seek min cost flow with max value IGeneral strategies for finding minimum cost flows
>>cost reduction — add flow to negative cost cycles
>>min cost augmentation  add flow to min cost augmenting paths 6 E \X/ashington University in St. Louis Engineering Min—Cost Augmenting Path Algorithm .Find min cost flow using augmenting path algorithm
and selecting min cost paths
>> O((# of steps)(time to find a min cost augmenting path))
>> for integer capacities, number of steps is at most f* >> since residual graphs may have negative cost edges, we must
use an algorithm that can handle negative cost edges >> using breadthfirst scanning, running time is O(mnf*) ICan improve by transforming edge costs to be 20 >> transformed edge costs preserve relative lengths of paths, while
eliminating negative edges >> this allows use of Dijkstra’s algorithm to find shortest paths,
reducing running time to (mn+f*(m+nlog n)) >> as flow is added, edge costs transformations must be updated
to reflect changes in residual graph :1, Washmgton UnwersuymStlouis Engineering Maintaining Transformed Edge Costs  Let cost0(u,v)= cost(u,v)
>> construct an augmented graph G’ from G by adding new vertex
5' with zero cost edge to each vertex in G >> compute dist0(u)=length of shortest path from s’ to u in
G' (using breadthfirst scanning) >> for all edges [u,v] in G, define
costl(u,v)=cost0(u,v)+dist0(u)dist0(v) cost1(v,u)=—cost1(u,v) I Repeat the following steps until no augmenting path >> let distk(u) be length of shortest path from s to u in current
residual graph, where cost of an edge [u,v] in residual graph is
given by costk(u,v) (compute distk using Dijkstra's algorithm)
>> saturate selected path; for all edges [u,v] in G compute,
costk+1(u,v) =costk(u,v) +distk(u)distk(v)
>> will show that new costs are non—negative and shortest paths in
residual graph are the same for new cost function as for old —
Engineering E \X/ashington University in St. Louis Example Original Network with dist0 Step 1. showing costl distl, spt and path cap,cost 0 E \X/ashington University in St. Louis Engineering Correctness of Algorithm .Invariant: if Rk is residual graph at start of step k,
>> costk(u,v)20 for all (u,v) in Rk
>> for any sX path p defined on edges (u,v) where either (u,v) or
(v,u) is in G
costk(p) =cost0(p)(dist0(x) +   +distk_1(x))
so, a mincost s—x path with respect to costk is a min—cost path
with respect to the original costs Proof. For k=1, claim follows from Theorem 7.8; so assume that in
RH, costk_1(u,v)20, costk_1(p)=cost0(p)—(dist0(x)++distk_2(x)) for
all s—X paths, p
In step k—l, distk_1(x) is computed using cost,(_1 and min cost path
is selected using these distances; for any edge (u,v) in RH,
costk_1(u,v)2distk_1(v)—distk_l(u)
and for (u,v) on the path,
costk_1(u, v) =distk_1(v)—distk_1(u) In E Washington University in St. Louis Correctness of Algorithm Engineering After saturating path, we compute costk(u,v) for all (u,v) using costk(u, v) =costk_1(u, v) +distk_1(u) d/'stk_1( v)
=costk_1(u,v)—(distk_1(v)—distk_1(u)) For any edge (u,v) in Rk_1, the right side of the expression is 20, so in this case, costk(u,v)20 Suppose (u,v) is in an edge Rk, but not in R“; in this case, it is the reverse of some edge on the augmenting path; since the right side of the above expression is zero for augmenting path edges, skew symmetry implies costk(u,v)=0 in R,(_1 augmenting path Last part follows from induction hypothesis and definition of costk
costk(p) =costk_1 (p) +distk_1 (s)—distk_1(x) = costk_1(p)—distk_1(x)
= (cost0(p)—(dist0(x)+    +distk_2(x)))—distk_1(x) I 11 II E \X/ashington University in St. Louis Engineering Better Min Cost Augmentation lRecap of version using transformed edge costs
>> transform edge costs to make them non—negative
cost1(u,v)=cost(u,v)+dist(u)dist(v) cost1(v,u)=—cost1(u,v)
>> repeat the following steps until no augmenting path 0 let distk(u) be length of shortest path from s to u in current residual
graph, where cost of an edge [u,v] in residual graph is given by
costk(u,v) (compute distk using Dijkstra's algorithm) 0 saturate selected path; for all edges [u,v] in G compute,
costk+l(u,v)=costk(u,v)+distk(u)—distk(v) uAlternate approach to cost transform
>> define current costs in terms of vertex labels
>> transform labels to effectively transform costs ICan also use vertex labels for scaling algorithm
>> allows use of higher capacity augmenting paths 1’) :1, Washmgton UnwersuymStlouis Engineering Using Vertex Labels to Transform Costs ICost transform for leastcost augmenting path algorithm
costk+1(u, v) =costk( u, v) +distk(u)d/'stk( v)
and consequently,
costk+1(u,v)=cost0(u,v)+(dist0(u)++distk(u))
—(dist0(v)++distk(v)) IThis enables an alternate viewpoint >>define current cost in terms of original cost and vertex labels )t
>>transform labels as flow changes to effectively transform edges  Revised algorithm
>>initiaize k(u)=distance from s’ to u in augmented graph
>>define current cost=cost;‘(u,v)=cost(u,v)+}t(u)—}»(v)
>>during each augmenting step, 0 let dist,_(u) be length of shortest path (w.r.t. C055) from s to u in
current residual graph; saturate shortest s—t path 0 for each vertex u, let x(u)=)t(u)+dist,_(u) I? E Washington University in St. Louis Exercises .The figure below shows the state in the
execution of Floyd’s algorithm for the
allpairs shortest path problem, after
the first three labeling steps. The
distance array is shown at right. Engineering Show the distance array after each of
the last two labeling steps. 1/! E Washington University in St. Louis Engineering 2.Appy the edge transformation The right hand ﬁgure shows the graph described in the notes to the graph in
the previous problem to obtain a set of
nonnegative edge lengths. Use
Dijkstra’s algorithm to compute
shortest path trees rooted at 3.
Compare the distances from a to all
other vertices in your computed
shortest path tree to those obtained in
the previous problem. Explain the
correspondence between the two sets
of distances. Compile the program for
Dijkstra’s algorithm with transformed
edge lengths that you will find on the
web site. Familiarize yourself with the
program and use it to compute shortest
path distances for several graphs. The left hand ﬁgure below shows the
graph with the original edge weights
and distances from a source vertex 5
with a zero length edge to each original
vertex (5 and its edges are not shown). with the transformed edge costs and
the distances from a computed using
these edge costs. The distances
computed in the last problem from a to
the other four vertices are 1, 3, 4 and
2. The costs shown at right above can
be obtained from these costs by adding
the label shown at left above for a (1)
and subtracting the labels for b, c, d
and e (these labels are 3, 5, 0 and 0). TC —
Engineering E \X/ashington University in St. Louis 3. Suppose we assign labels Mu) to each vertex of a directed graph with
a length function defined on its edges. Let /ength’(u,v)=/ength(u,v)+
(x(u)—x(v)). For a path p=u1,u2,....,ur, let /ength(p)=/ength(u1,u2)
+/ength(u1,u2)+ . . . + /ength(ur_1,u,) and let /ength’(p) be defined
similarly. Show that for two paths p and q joining the same pair of
vertices, that /ength(p)s/ength(q) if and only if /ength’(p)s/ength’(q). For any such path p,
/ength’(p) = /ength(u1,u2) +/ength(u2,u3)+... +/ength(u,_1 ,u,) +(}\(U1) MU2)) + (A(u2)_}\(u3)) +  + “(Ur—1 )_}‘(ur))
=length(p)+k (UHMur) So, the following lines are equivalent.
/ength’(p) S /ength’(q)
/ength(p)+k(u1)—k(ur) S /ength(q)+k(u1)—}t(u,)
/ength(p) S /ength(q) IK E Washington University in St. Louis 4.The figures below show an instance of
the minimum cost, maximum flow
problem, with some ﬂow, and the
residual graph corresponding to this —
Engineering Transform the edge costs in the
residual graph to make them non
negative. Also, show the distances from
s using the transformed costs. 1’7 E Washington University in St. Louis Find the shortest augmenting path
using the transformed costs, add flow
to that path and show the new residual
graph with the new transformed edge
costs and new distance values. Identify
the shortest augmenting path in this
residual graph. —
Engineering IO ...
View
Full
Document
This note was uploaded on 03/08/2012 for the course CSE 542 taught by Professor Jonturner during the Spring '12 term at Washington State University .
 Spring '12
 JonTurner

Click to edit the document details