60

Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Networks and �owsFord-Fulkerson algorithm

Page 2: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let G = (V;E) be a dire ted graph. For vertex v 2 V we an de�ne its indegree (sisendaste) ��!deg(v) and outdegree(väljundaste) ��deg(v).If ��!deg(v) = 0 or ��deg(v) = 0, the vertex v is alled sour e(lähe) or sink (suue) of graph G, respe tively.Capa ity of graph G is a fun tion : E �! R +.The quantities��!deg (v) = Xe2EE(e)=(u;v) (e) and ��deg (v) = Xe2EE(e)=(v;u) (e)are alled -indegree and -outdegree of vertex v 2 V ,respe tively.Network (võrk) is a pair (G; ) where G is a dire tedgraph and its apa ity.

Page 3: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

Page 4: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Proposition. The sums of all -indegrees and -outdegreesof graph G are equal.Proof.Xv2V ��!deg (v) =Xv2V Xe2E

E(e)=(u;v) (e) =Xe2E (e) =Xv2V Xe2E

E(e)=(v;u) (e) =Xv2V ��deg (v) :

Page 5: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let (G; ) be a network. We assume that G has exa tlyone sour e s and exa tly one sink t.Flow (voog) on the network (G; ) is a fun tion ' : E �! R +,su h that� '(e) � (e) for every e 2 E.� ��!deg'(v) = ��deg'(v) for every v 2 V nfs; tg.The previous proposition implies ��deg'(s) = ��!deg'(t). Thisquantity is alled value (väärtus) of the �ow ' and de-noted j'j.The �ow is maximal if its value is the largest possible.We assume that G = (V;E) has no loops nor multipledire ted ar s, i.e. E � V � V .

Page 6: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

34

2 1 03 4

3 243

2 3 12 3

5

Page 7: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Proposition. Consider a network (G; ) with G = (V;E).Let V = Vs _[Vt, su h that s 2 Vs and t 2 Vt. Let�(Vs; Vt) = Xe2E\(Vs�Vt)'(e)� Xe2E\(Vt�Vs)'(e) :Then �(Vs; Vt) is equal to the value of '.

Proof. Indu tion over jVsj.Base. If jVsj = 1 then Vs = fsg. The set Vs � Vt ontainsall the ar s originating from s and Vt � Vs = ;.Step. Let the laim hold for some sets Vs and Vt. Letx 2 Vtnftg, V 0s = Vs [ fxg and V 0t = Vtnfxg. It is enoughto prove �(Vs; Vt) = �(V 0s ; V 0t ).

Page 8: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

�(Vs; Vt) : �(V 0s ; V 0t ) :V � V Vs x V 0tVs +' +'x �'V 0t �'

V � V Vs x V 0tVs +'x +'V 0t �' �'�(Vs; Vt)� �(V 0s ; V 0t ) =V � V Vs x V 0tVs +'x �' �'V 0t +'= ��!deg'(x)� ��deg'(x) = 0 : �

Page 9: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

A ut (lõige) in the network (G; ) (where G = (V;E))is su h an ar set L � E that every dire ted path fromsour e to sink uses some ar from the set L.Alternatively: L � E is a ut, if there are no dire ted pathsfrom s to t in the graph (V;EnL).Capa ity (läbisaskevõime) of L is the quantity (L) =Pe2L (e).The ut is minimal if its apa ity is the smallest possible.

Page 10: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Theorem (Ford and Fulkerson). The value of all max-imal �ows in a network is equal to the apa ity of all theminimal uts.Proof. Let (G; ) be a network with G = (V;E), sour e sand sink t. We will show thatI. The value of no �ow is larger than the apa ity of any ut.II. For any maximal �ow ' there exists a ut with apa ityj'j.

Page 11: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Part I Let ' be a �ow and L a ut.Let Vs � V be the set of su h nodes v that there exists adire ted path from s to v without using any ar from L.Let Vt = V nVs. Sin e E \ (Vs � Vt) � L, we have (L) � Xe2E\(Vs�Vt) (e) � Xe2E\(Vs�Vt)'(e) � �(Vs; Vt) = j'j :

Page 12: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Part II Let ' be a maximal �ow.Let Vs � V be the set of all verti es v su h that:There exists an undire ted path s = v0 e1� v1 e2� � � � em� vm = v,su h that� If ei = (vi�1; vi) then '(ei) < (ei).� If ei = (vi; vi�1) then '(ei) > 0.We say that the �ow between vi�1 and vi is unsaturated(küllastamata).Su h a path is alled augmenting (suurendav).Let Vt = V nVs. We will show that t 2 Vt. Indeed, if t 2 Vsthen ' is not maximal:

Page 13: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let s = v0 e1� v1 e2� � � � em� vm = t be some augmentingpath. De�ne positive real numbers Æi as follows:

Æi = 8<: (ei)� '(ei); if ei = (vi�1; vi)'(ei); if ei = (vi; vi�1) :Let " = mini Æi and let '0 be the following �ow:

'0(e) =8>><>>:

'(e); if e 62 fe1; : : : ; emg'(e) + "; if e = ei = (vi�1; vi)'(e)� "; if e = ei = (vi; vi�1) :Then '0 is a �ow and j'0j = j'j+ ".

Page 14: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Constru tion of the sets Vs and Vt gives:� If e 2 E \ (Vs � Vt) then '(e) = (e).� If e 2 E \ (Vt � Vs) then '(e) = 0.Let L = E \ (Vs � Vt). Then L is a ut and (L) = j'j. �

Page 15: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Algorithm for �nding a maximal �ow (Ford-Fulkerson).Let (G; ) be a network with G = (V;E).Let ' be some initial �ow on the network (G; ), say, 8e :'(e) = 0.Repeat:1. Find an augmenting path s = v0 e1� v1 e2� � � � em� vm = t.If there is no su h path then stop and output '.2. Constru t '0 as des ribed 2 slides ago.3. Assign ' := '0.The augmenting path is found traversing the graph in somemanner.

Page 16: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Theorem. Ford-Fulkerson algorithm �nds a maximal �ow.

Proof. The algorithm obviously outputs a �ow. We needto prove that it does not stop before a maximal �ow isfound.We will show that if ' is not a maximal �ow then thereexists an augmenting path s t for it.Let Vs be the set of verti es v su h that there exists anaugmenting path from s to v and let Vt = V nVs. Assumethat t 2 Vt.Similarly to the proof of the previous theorem we get thatL = E \ (Vs � Vt) is a ut and (L) = j'j. Thus ' mustbe maximal. �

Page 17: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

00

0 0 00 0

0 000

0 0 00 0

0

Page 18: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

00

0 0 00 0

0 000

0 0 00 0

0

75 6

Page 19: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

50

0 0 00 5

0 000

0 0 00 5

0

Page 20: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

50

0 0 00 5

0 000

0 0 00 5

04 8 6

Page 21: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

54

0 0 00 5

0 000

4 0 00 5

4

Page 22: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

54

0 0 00 5

0 000

4 0 00 5

4

2 2 3 1

Page 23: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

64

0 0 00 5

0 100

4 0 01 6

4

Page 24: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

64

0 0 00 5

0 100

4 0 01 6

45 36 1 2

Page 25: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

64

1 1 01 5

0 200

4 0 01 6

5

Page 26: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

64

1 1 01 5

0 200

4 0 01 6

5

1 12 3

Page 27: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

74

1 1 10 5

0 200

4 0 11 6

5

Page 28: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

74

1 1 10 5

0 200

4 0 11 6

54 4 2

Page 29: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

74

3 1 10 5

0 220

4 0 31 6

5

Page 30: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

74

3 1 10 5

0 220

4 0 31 6

52 21 4 1

Page 31: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5 47 5 652

83 6

3635234

74

4 1 00 5

0 230

5 0 31 6

6

Page 32: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5

47

5

6

5

2

8

3 6

3

6

35

2

34

7

4

41 0

0

5

0 2

3

0

5

03

1 6

6

there is an augmenting path to these vertices

minimum cut: with circle ! without circle

Page 33: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Finding the augmenting path:Let Vs = fsg, W = fsg.While W 6= ; and t 62 Vs do:1. Somehow hoose v 2W . Remove it from the set W .2. For ea h e 2 E and vertex v in ident with it: if the�ow between v and e's other endpoint w is unsaturatedand w 62 Vs then(a) Add w to sets Vs and W .(b) Remember that v is the vertex �pre eding� w.If t 62 Vs then there is no augmenting path. If t 2 Vsone an onstru t an augmenting path moving from t by�pre eding� verti es to s.

Page 34: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Proposition. If apa ities of all the edges are integersthen the main y le of the algorithm is run at most j'jtimes where ' is a maximal �ow.Proof. Ea h iteration in reases the value of the �ow. Sin eour omputations do not introdu e non-integers, ea h in- rease has to be at least by 1. �

Page 35: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

We will now assume that the augmenting path is foundusing breadth-�rst traversal of the graph (Edmonds-Karpalgorithm).The augmenting path s = v0 e1� v1 e2� � � � em� vm = t foundwill have the following property:For ea h i, the path s = v0 e1� v1 e2� � � � ei� vi is theshortest augmenting path from sour e to vi.Let (G; ) be a network with G = (V;E) and let ' be a�ow on it. Denote the length of the shortest path fromsour e to v 2 V as Æ'(v).

Page 36: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Proposition. Let '0; '1; '2; : : : be the sequen e of �owsgenerated during the maximal �ow �nding algorithm. Thenfor ea h v 2 V the sequen e Æ'i(v) is non-de reasing.

Proof. Consider the �ows 'n and 'n+1 in this sequen eand let B = fv j Æ'n+1(v) < Æ'n(v)g. Assume that B is notempty and let v 2 B be su h that Æ'n+1(v) is the smallestpossible.Let P 0 be the shortest augmenting path from sour e to vw.r.t the �ow 'n+1. Let u be the vertex pre eding v onthis path. Sin e Æ'n+1(u) < Æ'n+1(v), we have u 62 B.Consider the �ow 'n between the verti es u and v.

Page 37: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

If 'n is unsaturated between the verti es u and v thenÆ'n(v) � Æ'n(u) + 1 � Æ'n+1(u) + 1 = Æ'n+1(v)and v 62 B, a ontradi tion.If 'n is saturated between the verti es u and v then let Pnbe the augmenting path from sour e to sink that was usedto generate 'n+1 from 'n.In 'n+1, the �ow between u and v be omes unsaturated.Thus, in the path Pn there exists an edge � � �� v � u�� � � . A ording to the properties of Pn we get Æ'n(v) =Æ'n(u)� 1. Consequently,Æ'n(v) = Æ'n(u)�1 � Æ'n+1(u)�1 = Æ'n+1(v)�2 < Æ'n+1(v)and v 62 B, a ontradi tion. �

Page 38: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Theorem. Edmonds-Karp algorithm makes at most(jV j � 2) � jEj iterations.Proof. Consider the nth iteration of the algorithm. On thisiteration, the augmenting path Pn : s = v0 e1� v1 e2� � � � em�vm = t is onstru ted. Call the pair of verti es (vi�1; vi) riti al if the respe tive quantity Æi (showing how mu hthe �ow between vi�1 and vi must be hanged to make itsaturated) is minimal (i.e. Æi = ").Ea h iteration has a riti al pair of verti es. On the nextiteration it be omes saturated.Let's ount the number of iterations where a pair (u; v) anbe riti al. If it is riti al on the nth iteration, we haveÆ'n(v) = Æ'n(u) + 1.

Page 39: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

To make (u; v) again riti al on iteration number n0 > n,there must exist another augmenting path Pn0 ontainingthe ar � � �� v � u� � � � . ThenÆ'n0 (u) = Æ'n0 (v) + 1 � Æ'n(v) + 1 = Æ'n(u) + 2;thus every time when (u; v) is riti al, Æ'(u) has in reasedat least by 2.The quantity Æ'(u) an not exeed jV j � 2 (when (u; v) is riti al). Thus (u; v) is riti al at most jV j�22 times. Thenumber of vertex pairs (u; v) is at most 2 � jEj. �

Page 40: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let (G; ) be a network. Also, let each edge e of G be

assigned a cost (e) 2 R (possibly negative).

Let ' be a flow on (G; ) the cost of the flow is (') := Xe2E(G) (e)'(e) :We are looking for a maximum flow with the minimum

cost.

Page 41: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let (G; ), G = (V;E) be a network (with any number

of sources and sinks). f : E −→ R + is a circulation

(ringlus) on (G; ), if� f(e) � (e) for all e 2 E.� ��!degf(v) = ��degf(v) for all v 2 V .

Let : E −→ R + give the costs of edges. We’re looking

for a minimum-cost circulation in (G; ).Finding the minimum-cost maximum flow can be reduced

to finding the minimum-cost circulation.

Page 42: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5

47

5

6

5

2

8

3 6

3

6

35

2

34

2

3

2 4

4

3

3

1 0352

2

42

31

capacity cost

Page 43: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5

47

5

6

5

2

8

3 6

3

6

35

2

34

2

3

2 4

4

3

3

1 0352

2

42

31

capacity cost

a lot �(a lot)

Page 44: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let (G; ), G = (V;E) be a network and f a circulation

on it. The residual network (jääkvõrk) (Gf ; f), made

up of the residual graph G = (V;Ef ) and the residual

circulation is defined as follows:� For any e = (u; v) 2 E:

– If f(e) < (e), then e+ 2 Ef . Also, E(e+) = (u; v)

and f(e+) = (e)� f(e).– If f(e) > 0, then e� 2 Ef . Also, E(e�) = (v; u) and f(e�) = f(e).

Page 45: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

5

47

5

6

5

2

8

3 6

3

6

35

2

34

7

4

31 1

0

5

0 2

2

0

4

03

1 6

5

1614

2

14

3

2

22

3 5 12 1 1 5

4

7

5

61232

4

4 15

6

Page 46: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let f be a circulation on (G; ) and f 0 a circulation on the

residual network (Gf ; f). Define (f + f 0) : E −→ R by:8e 2 E : (f + f 0)(e) = f(e) + f 0(e+)� f 0(e�)

(if some edge e+ or e� does not exist, then assume that f 0

on it equals 0)Theorem. f + f 0, as defined above, is a circulation on(G; ) (for any f; f 0).

Page 47: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Proof. First show that 0 � (f + f 0)(e) � (e) for anye 2 E.

0 = f(e)� f(e�) � f(e)� f 0(e�) �f(e) + f 0(e+)� f 0(e�) �f(e) + f 0(e+) � f(e) + f(e+) = (e);

(again, f 0, applied to a non-existing edge, gives 0)

Page 48: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Show that

����!degf+f 0(v) = ����degf+f 0(v) for any v 2 V .����!degf+f 0(v) = Xe2EE(e)=(u;v)(f + f 0)(e) =

Xe2EE(e)=(u;v)

�f(e) + f 0(e+)� f 0(e�)� =

��!degf(v) + Xe2EE(e)=(u;v)

�f 0(e+)� f 0(e�)�

Page 49: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

We haveXe2EE(e)=(u;v) f 0(e+) +

Xe2EE(e)=(v;w) f 0(e�) =

���!degf 0(v) =

���degf 0(v) = Xe2EE(e)=(v;w) f 0(e+) +Xe2E

E(e)=(u;v) f 0(e�) :

ThusXe2E

E(e)=(u;v)�f 0(e+)� f 0(e�)� = Xe2E

E(e)=(v;w)�f 0(e+)� f 0(e�)� :

Page 50: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

����!degf+f 0(v) = ��!degf(v) + Xe2E

E(e)=(u;v)�f 0(e+)� f 0(e�)� =

��degf(v) + Xe2EE(e)=(v;w)

�f 0(e+)� f 0(e�)� =

Xe2EE(e)=(v;w)

�f(e) + f 0(e+)� f 0(e�)� =

Xe2EE(e)=(v;w)(f + f 0)(e) = ����degf+f 0(v)

Page 51: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let f and g be circulations on (G; ), G = (V;E). Let(g � f) : Ef −→ R be defined by: For any e 2 E:� if g(e) � f(e), then (g � f)(e+) = g(e) � f(e) and(g � f)(e�) = 0;� if g(e) < f(e), then (g� f)(e+) = 0 and (g� f)(e�) =f(e)� g(e).Theorem. g � f , as defined above, is a circulation on(Gf ; f ).Theorem. f + (g � f) = g.Proofs are similar to the proof of the previous theorem.

Page 52: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Let f be a circulation on (G; ), G = (V;E). Let : E −→R give the costs of the edges of G. Define the costs f ofedges of (Gf ; f) as follows: f(e+) = (e) f(e�) = � (e)

for any e 2 E.

Theorem. Let f be a circulation on (G; ), G = (V;E),and f 0 a circulation on the residual network (Gf ; f). Let : E −→ R give the costs of the edges of G. Then (f +f 0) = (f) + f(f 0).Proof: from the definition of f + f 0.

Page 53: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Lemma. If the network (G; ), G = (V;E) (the costs of

edges are given by ) has no cycles with negative costs,

then the minimum-cost circulation on this network is the

zero circulation.

Proof. Using mathematical induction over the cardinality

of supp f = fe 2 E : f(e) > 0g;

show that any circulation f has a non-negative cost.

Base. j supp f j = 0. Then (f) = 0.

Page 54: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Step. j supp f j = n > 0. Let V 0 � V be the set of all

vertices, such that some edge e with f(e) > 0 ends there.

There are also edges e with f(e) > 0 starting from all these

vertices.

Graph (V 0; supp f) contains a directed cycle C. Let Æ =mine2C f(e). Define the following circulation g:g(e) = 8<:f(e); if e 62 Cf(e)� Æ; if e 2 C :

Then j supp gj < j supp f j and (g) = (f) � Æ � (C). As (C) � 0, then (f) � (g) � 0. �

Page 55: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Theorem. Let (G; ) be a network, the costs of its edges,

and f a circulation on it. f is minimal-cost iff the network(Gf ; f ) has no cycles of negative cost.

Proof. ). If (Gf ; f) had cycles of negative cost, then it

also would contain a negative-cost circulation f 0. But thenf + f 0 would have smaller cost than f .(. Let f be a circulation on (G; ) whose cost is not mini-

mal. Let f� be a minimal-cost circulation on (G; ). Thenf� � f is a negative-cost circulation on (Gf ; f). Hence it

also contains cycles of negative cost. �

Page 56: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Algorithm to find a minimum-cost circulation in (G; )

with the costs of edges . Let f be some initial circulation.

Repeat:

1. Find a negative-cost cycle C in (Gf ; f). If such C does

not exist, then f is a circulation of minimum cost.

2. Let Æ = mine?2C f(e?). Let f 0 be a circulation in(Gf ; f ), such that f 0(e?) = Æ or f 0(e?) = 0, depending

on whether e? lies on C or not.

3. Set f := f + f 0.The initial f may be found using e.g. the Ford-Fulkerson

algorithm.

Page 57: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

3

3

11

4 5 12

5

4

7

5

61232

5

36

5

47

5

6

5

2

8

3 6

3

6

35

2

34

7

4

41 0

0

5

0 2

3

0

5

03

1 6

6 6

2

2

3

1

2 4

3

1 03

3

3

4

24

2

25 -2

1

-1

-3

1

2-4 4

4

-4

-3

033

-33 -4

-2-5-2

2

2

Page 58: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

3

3

11

4 5 12

5

4

7

5

61232

5

36

5

47

5

6

5

2

8

3 6

3

6

35

2

34

7

4

41 0

0

5

0 2

3

0

5

03

1 6

6 6

2

2

3

1

2 4

3

1 03

3

3

4

24

2

25 -2

1

-1

-3

1

2-4 4

4

-4

-3

033

-33 -4

-2-5-2

2

2

Page 59: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

3

41

4 53

4

4

7

5

61232

4

46

5

47

5

6

5

2

8

3 6

3

6

35

2

34

7

4

40 0

0

5

0 2

4

0

4

13

1 6

6 6

2

2

3

1

2 4

3

1 03

3

3

4

24

2

25 -2

1

-1

-3

1

24

-4

-3

033

-33 -4

-2-5-2

2

2

Page 60: Netpeeter/teaching/graafid08s/... · 2012. 2. 2. · Let (G;) b e a net w ork. W e assume that G has exactly one source s and exactly sink t. Flow (vo o g) on the net w ork (G;) is

Bellman-Ford’s algorithm may be used to find a cycle of

negative cost.

Add an additional vertex x to Gf . Add arcs of cost 0 from x

to all other vertices. Find the distances of all vertices fromx (length of edge � cost of edge); also find the shortest

paths.

If something happens at the jV j-th iteration of the Bellman-

Ford algorithm, then the back-pointers of all vertices (to

previous vertices on shortest paths) will give us a cycle of

negative length.