1 network flow & linear programming jeff edmonds york university cosc 3101 lecture 5...

147
1 Network Flow & Linear Programming Jeff Edmonds York University COSC 3101 Lecture 5 Optimization Problems Network Flow Def n Simple Example Application: Matching Flow Strategy Hill Climbing Augmenting Flow Primal-Dual Hill Climbing Min Cut Max Flow = Min Cut Running Time Linear Programming

Upload: jade-holt

Post on 21-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

1

Network Flow & Linear Programming

Jeff Edmonds York UniversityCOSC 3101Lecture 5

• Optimization Problems• Network Flow Defn

• Simple Example• Application: Matching• Flow Strategy• Hill Climbing• Augmenting Flow• Primal-Dual Hill Climbing• Min Cut• Max Flow = Min Cut• Running Time• Linear Programming

2

• Ingredients: • Instances: The possible inputs to the problem. • Solutions for Instance: Each instance has an

exponentially large set of solutions. •Cost of Solution: Each solution has an easy to

compute cost or value. • Specification • <preCond>: The input is one instance.• <postCond>: A valid solution with optimal cost.

(minimum or maximum)

Optimization Problems

3

• Instance: •A Network is a directed graph G • Edges represent pipes that carry flow• Each edge <u,v> has a maximum capacity c<u,v>

• A source node s out of which flow leaves• A sink node t into which flow arrives

Goal: Max Flow

Network Flow

4

• Instance: •A Network is a directed graph G • Edges represent pipes that carry flow• Each edge <u,v> has a maximum capacity c<u,v> • A source node s out of which flow leaves• A sink node t into which flow arrives

Network Flow

5

Network Flow

For some edges/pipes, it is not clear which direction the flow should go

in order to maximize the flow from s to t.

Hence we allow flow in both directions.

6

Network Flow

u v1719

244

This edge/pipe allows download at a rate of 1719kbpsOR upload at a rate of 244kbps

Not both simultaneously

7

Network Flow

u v75

10

This edge/pipe allows flow to the right at a rate of 75 L/sec

OR to the left right at a rate of 10 L/sec

8

Network Flow

u v15/75

0/10

This edge/pipe allows flow to the right at a rate of 75 L/sec

OR to the left right at a rate of 10 L/sec

Currently the flow is to the right at 15 L/sec

9

Network Flow

u v0/75

5/10

This edge/pipe allows flow to the right at a rate of 75 L/sec

OR to the left right at a rate of 10 L/sec

Currently the flow is to the left at 5 L/sec

10

• Solution: •The amount of flow F<u,v> through each edge.• Flow can’t exceed capacity i.e. F<u,v> c<u,v>.• Unidirectional flow

F<u,v> 0 and F<v,u> = 0 orF<u,v> = 0 and F<v,u> 0

Some texts:F<u,v> = -F<v,u>

Network Flow

11

• Solution: •The amount of flow F<u,v> through each edge.• Flow F<u,v> can’t exceed capacity c<u,v>.• Unidirectional flow• No leaks, no extra flow.

Network Flow

12

• Solution: •The amount of flow F<u,v> through each edge.• Flow F<u,v> can’t exceed capacity c<u,v>.• Unidirectional flow• No leaks, no extra flow.

For each node v: flow in = flow out u F<u,v> = w F<v,w>

Except for s and t.

Network Flow

13

•Value of Solution: • Flow from s into the network

minus flow from the network back into s. rate(F) = u F<s,u>

= flow from network into t minus flow back in. = u F<u,t> - v F<t,v>

- v F<v,s>

What about flow back into s? Goal:

Max Flow

Network Flow

14

A network with its edge capacities

Network Flow

What is the maximum that can flow from s to t?

15

A network with its edge capacities

Network Flow

The max total rate of the flow is 1+2-0 = 3.

flow/capacity = 2/5

Prove that total can not be higher.

16

No more flow can be pushedalong the top path because the

edge <b,c> is at capacity.

Similarly, the edge <e,f>.

No flow is pushed along the bottom path because this would decrease the total from s to t.

Network Flow

17

<U,V> is a minimum cut

Its capacity is the sum of the capacities crossing the cut

= 1+2 = 3.

<i,j> is not included in because it is going in the wrong

direction.

Network Flow

18

The edges crossing forward across the cut are at capacity

those crossing backwards have zero flow.

This is always true.

Network Flow

19

The maximum flow is 1+2=3

The minimum cut is 1+2=3.

These are always equal.

Network Flow

20

An Application: MatchingSam Mary

Bob Beth

John Sue

Fred Ann

Who loves whom.Who should be matched with whom

so as many as possible matchedand nobody matched twice?

3 matches Can we do better?

4 matches

21

An Application: Matching

s t

c<s,u> = 1• Total flow out of u = flow into u 1• Boy u matched to at most one girl.

1

c<v,t> = 1• Total flow into v = flow out of v 1• Girl v matched to at most one boy.

1u v

22

Network Flow• Strategy:• Push flow into s.• Must make decisions.• Get stuck and must backtrack.• Difficult and time consuming.

sc=100f=100

c=100

c=100

c=1f=100

23

Network Flow• Strategy:• Find a path for a single drop.• Push as much flow through as fits.

w = augment = Min<u,v> Path c<u,v>

24

Network Flow• Strategy:• Find a path for a single drop.• Push as much flow through as fits.

w = augment = Min<u,v> Path c<u,v>

flow/capacity = 20/21

25

Network Flow

• Given Flow F• Construct Augmenting Graph GF

• Find path P using BFS, DFS, or generic search algorithm

• Let w be the max amount flowcan increase along path P.

• Increase flow along path P by w. i.e newF = oldF + w × P

+w

+w+w+w

26

Network Flow

• Given Flow F• Construct Augmenting Graph GF

• Find path P using BFS, DFS, or generic search algorithm

• No path• Stop.

27

Hill ClimbingWe have a valid solution.(not necessarily optimal)

Take a step that goes up.

measure

progress

Value of our solution.

Problems:

Exit Can't take a step that goes up.

Running time?

Initially have the “zero

Local Max

Global Max

Can our Network Flow Algorithm get stuck in a local maximum?

Make small local changes to your solution toconstruct a slightly better solution.

If you take small step,could be exponential time.

28

Network Flow

Previous Input

Previous Output

Same Input

Can our Network Flow Algorithm get stuck in local max?

Worse Output

Need only one example.Yes!

29

Network Flow

30

Network Flow

Previous Input

Previous Output

Same Input

Yes! Our Network Flow Algorithm can get stuck.

Worse Output

Need only one example.

31

Hill ClimbingAvoiding getting stuck

in a local maximum

Good ExecutionBad Execution

• Made better choices of direction• Hard

• Back up an retry• Exponential time

• Define a bigger step

32

Hill ClimbingDifferent Solutions

Current Solution

Alg defines to where alg can stepi.e. what small local

changes can be made to current solution

This defines the topography

33

Hill ClimbingDifferent Solutions

Current Solution

Define a slightlybigger step

This defines the topography

Perhaps removes some local maxima

34

Network Flow

Previous Input

Previous Output

Same Input

Worse Output

Mistake?Putting 2 through

this edge

35

Network Flow

Mistake?Putting 2 through

this edge

We need to decrease the flow in this edge.

But if we decrease the total flow thenthe algorithm might run exponentially or forever.

We need to decrease the flow in this edgeAND increase the total flow.

36

Network Flow

Let us focus on how much we can CHANGE

the rate of flowthrough a given edge.

37

Network Flow

u v15/75

0/10

This edge/pipe allows flow to the right at a rate of 75 L/sec

OR to the left right at a rate of 10 L/sec

Currently the flow is to the right at 15 L/sec

38

Network Flow

u v15/75

0/10Currently the flow is to the right at 15 L/sec

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15

15

39

u v0/75

10/10Currently the flow is to the left at 10 L/sec

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = -10

15

Network Flow

40

Network Flow

Add 5 flow to right

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15

15

Current Flow

20

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 20

Resulting Flow

41

Network Flow

Add -5 flow to right

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15

15

Current Flow

10

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 10

Resulting Flow

Equivalent

Add 5 flow to left

42

Network Flow

Add -20 flow to right

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15

15

Current Flow

-5

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = -5

Resulting Flow

Add 20 flow to left

Equivalent

43

Network Flow

-5

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = -5

Resulting Flow

u v-5/75

0/10

Flow Graph

u v0/75

5/10

Flow Graph

Equivalent

44

Network Flow

15+Δ ≤ 75F<u,v>+Δ ≤ c<u,v>

Δ ≤ c<u,v>-F <u,v>

Walking Δ

u v15+Δ /75

0/10

New Flow Graph

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15

15

75-15 = 60

Allowed changeto the right

45

Network Flow

15-Δ ≥ -10F<u,v>-Δ ≥ -c<v,u>

Δ ≤ F <u,v> + c<v,u>u v

15- Δ /75

0/10

New Flow Graph

Walking Δ

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15Allowed Flow

≠ Allowed Change in Flow

15

Allowed changeto the left15+10=25

46

Network Flow

Δ ≤ F <u,v> + c<v,u>

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 15

Δ ≤ c<u,v>-F <u,v>u v

Augmentation Graph

15

75-15 = 60

Allowed changeto the right

Allowed changeto the left15+10=25

47

Network Flow

• Given Flow F• Construct Augmenting Graph GF

• Find path P

OldNew

Where we got stuck before

48

Network Flow

• Given Flow F• Construct Augmenting Graph GF

• Find path P • Let w be the max amount flow

can increase along path P. • Increase flow along path P by w.

i.e newF = oldF + w × P

+w

+w

+w-w?

49

Network Flow

• Given Flow F• Construct Augmenting Graph GF

• Find path P using BFS, DFS, or generic search algorithm

• No path• Stop.

50

Network FlowPrevious Input

Previous Output

Same Input

Worse Output

Same Output

51

52

An Application: MatchingSam Mary

Bob Beth

John Sue

Fred Ann

Who loves whom.Who should be matched with whom

so as many as possible matchedand nobody matched twice?

3 matches Can we do better?

4 matches

53

An Application: Matching

s t

Flow

s t

Augmentation Graph Augmentation Path

Alternates • adding edge• removing edge• adding edge• removing edge• adding edge

Extra edge added

s t

New Flow

54

An Application: MatchingSam Mary

Bob Beth

John Sue

Fred Ann

Who loves whom.Who should be matched with whom

so as many as possible matchedand nobody matched twice?

3 matches Can we do better?

4 matches

55

Network Flow

Can our Network Flow Algorithm get stuck in local max?

Need to prove for every input networkfor every choice of augmenting paths Maximum Flow is found!

No!

How?

56

Primal-Dual Hill Climbing

Mars settlement has hilly landscapeand many layers of roofs.

57

Primal-Dual Hill ClimbingPrimal Problem: • Exponential # of locations to stand.• Find a highest one.Dual problem:• Exponential # of roofs.• Find a lowest one.

58

Primal-Dual Hill ClimbingProve:• Every roof is above every location to stand. R L height(R) height(L) height(Rmin) height(Lmax) Is there a gap?

59

Primal-Dual Hill Climbing

Prove:• For every location to stand either:• the alg takes a step up or• the alg gives a reason that explains why not

by giving a ceiling of equal height.i.e. L [ L’ height(L’) > height(L) or R height(R) = height(L)]

or

But R L height(R) height(L)

No Gap

60

Primal-Dual Hill Climbing

Prove:• For every location to stand either:• the alg takes a step up or• the alg gives a reason that explains why not

by giving a ceiling of equal height. i.e. L [ L’ height(L’) > height(L) or R height(R) = height(L)]

or

Can't go up from this location and no matching ceiling.

Can't happen!

?

61

Primal-Dual Hill Climbing

Prove:• For every location to stand either:• the alg takes a step up or• the alg gives a reason that explains why not

by giving a ceiling of equal height. i.e. L [ L’ height(L’) > height(L) or R height(R) = height(L)]

or

No local maximum!

62

Primal-Dual Hill Climbing

Claim: Primal and dual have the same optimal value. height(Rmin) = height(Lmax)Proved: R L, height(R) height(L) Proved: Alg runs until it provides Lalg and Ralg

height(Ralg) = height(Lalg)

No Gap

height(Rmin) height(Ralg) = height(Lalg) height(Lmax)height(Rmin) height(Lmax)

Lalg witness that height(Lmax) is no smaller. Ralg witness that height(Lmax) is no bigger.

Exit

63

A network with its edge capacities

Network Flow

What is the maximum that can flow from s to t?

64

A network with its edge capacities

Network Flow

The max total rate of the flow is 1+2-0 = 3.

flow/capacity = 2/5

Prove that total can not be higher.

65

No more flow can be pushedalong the top path because the

edge <b,c> is at capacity.

Similarly, the edge <e,f>.

No flow is pushed along the bottom path because this would decrease the total from s to t.

Network Flow

66

<U,V> is a minimum cut

Its capacity is the sum of the capacities crossing the cut

= 1+2 = 3.

<i,j> is not included in because it is going in the wrong

direction.

Network Flow

67

The edges crossing forward across the cut are at capacity

those crossing backwards have zero flow.

This is always true.

Network Flow

68

The maximum flow is 1+2=3

The minimum cut is 1+2=3.

These are always equal.

Network Flow

69

Primal-Dual Network Flow

Primal Problem: Max Flow

Dual Problem:Min CutWhat are the roofs to the flows?

70

• Instance: • A Network is a directed graph G • Special nodes s and t.• Edges represent pipes that carry flow• Each edge <u,v> has a maximum capacity c<u,v>

Min Cut

s

t

71

• Instance: • A Network is a directed graph G • Special nodes s and t.• Edges represent pipes that carry flow• Each edge <u,v> has a maximum capacity c<u,v>

Min Cut

72

• Solution: C = partition of nodes <U,V> with sU, tV.

Min Cut

s

t

U

VYork

UC Berkeley

= Canada

= USA

73

Min Cut

s

t

York

UC Berkeley

Ontario

• Solution: C = partition of nodes <U,V> with sU, tV.

74

Min Cut

s

t

York

UC Berkeley

Toronto

• Solution: C = partition of nodes <U,V> with sU, tV.

75

Min Cut

s

t

York

UC Berkeley

York

• Solution: C = partition of nodes <U,V> with sU, tV.

76

Min Cut

s

t

York

UC Berkeley

UCB

• Solution: C = partition of nodes <U,V> with sU, tV.

77

Min Cut

s

t

York

UC Berkeley

Berkeley

• Solution: C = partition of nodes <U,V> with sU, tV.

78

Min Cut

s

t

York

UC Berkeley

U

V

• Solution: C = partition of nodes <U,V> with sU, tV.

79

•Value Solution C=<U,V>: cap(C) = how much can flow from U to V = uU,vV c<u,v>

Min Cut

s

t

U

V

u

v

Goal: Min Cut

80

•Theorem:• For all Networks MaxF rate(F) = MinC cap(C)

• Prove: F,C rate(F) cap(C)

Max Flow = Min Cut

UV

uv

• Prove: flow F, alg either• finds a better flow F• or finds cut C such that rate(F) = cap(C)

• Alg stops with an F and C for which rate(F) = cap(C)• F witnesses that the optimal flow can't be less• C witnesses that it can't be more.

Exit

81

• cap(C) = how much can flow from U to V = uU,vV c<u,v>

• rate(F,C) = Flow from U to V minus flow V to U = uU,vV F<u,v> - F<v,u>

• Lemma: rate(F) = rate(F,C) cap(C)

Max Flow = Min Cut• Prove: flow F, cut C rate(F) cap(C)

s

t

UV

York

UC Berkeley

= Canada= USA+

-

F<u,v> c<u,v> & F<v,u> 0No leaks, no extra flow.

82

Lemma: F,C rate(F,C) = rate(F)Proof: By induction on the size of U.Base case: C = <{s},G-{s}> rate(F) = Flow from s into the network minus flow from the network back into s = u F<s,u> - v F<v,t>

= rate(F,C) where C = <{s},G-{s}>

Max Flow = Min Cut

s

t

York

UC Berkeley

+

-

83

Lemma: F,C rate(F,C) = rate(F)Proof: By induction on the size of C.Base case: C = <{s},G-{s}>Inductive step: Move nodes across C one at a time.

Max Flow = Min Cut

Flow into x = Flow out.Hence, flow across cut does not change.

rate(F) = rate(F,C) cap(C)

84

•Theorem:• For all Networks MaxF rate(F) = MinC cap(C)

• Prove: F,C rate(F) cap(C)

Max Flow = Min Cut

UV

uv

• Prove: flow F, alg either• finds a better flow F• or finds cut C such that rate(F) = cap(C)

85

• Given Flow F• Construct Augmenting Graph GF

• Find path P • Let w be the max amount flow

can increase along path P. • Increase flow along path P by w.

i.e newF = oldF + w × P

+w

+w

+w-w

Max Flow = Min Cut

86

• Given Flow F• Construct Augmenting Graph GF

• Find path P using BFS, DFS, or generic search algorithm

• No path• Stop

Max Flow = Min Cut

87

• Let Falg be this final flow.

• Let cut Calg=<U,V>, • where U are the nodes reachable from s

in the augmented graph• and V not.

• Claim: rate(Falg) = cap(Calg)

Max Flow = Min Cut

Bad example because U might contain

more than s.

88

Max Flow = Min Cut• Prove: rate(Falg) = cap(Calg)

• Prove: rate(Falg,Calg) = cap(Calg)

=

89

cap(C) = how much can flow from U to V = uU,vV c<u,v>

• rate(F,C) = Flow from U to V minus flow V to U = uU,vV F<u,v> - F<v,u>

Max Flow = Min Cut• Prove: rate(Falg,Calg) = cap(Calg)

+

F<u’,v’>/c<u’,v’>

u vF<u,v>/c<u,v>

Flow GraphU V

v’ u’-

90

Max Flow = Min Cut

F<u’,v’>/c<u’,v’>

u vF<u,v>/c<u,v>

Flow GraphU V

v’ u’

need equal

need zero

+

-

cap(C) = how much can flow from U to V = uU,vV c<u,v>

• rate(F,C) = Flow from U to V minus flow V to U = uU,vV F<u,v> - F<v,u>

• Prove: rate(Falg,Calg) = cap(Calg)

91

Max Flow = Min Cut

u vF<u,v>/c<u,v>

Flow Graph

c<u,v>-F<u,v>

F<u’,v’>+c<v’,u’>

U V

v’ u’F<u’,v’>/c<u’,v’>

u

Augmentation GraphU V

v’

v

u’

reachable from s = = notnot edges

=0

=0

need equal+

need zero-

cap(C) = how much can flow from U to V = uU,vV c<u,v>

• rate(F,C) = Flow from U to V minus flow V to U = uU,vV F<u,v> - F<v,u>

• Prove: rate(Falg,Calg) = cap(Calg)

92

•Theorem:• For all Networks MaxF rate(F) = MinC cap(C)

• Prove: F,C rate(F) cap(C)

Max Flow = Min Cut

UV

uv

• Prove: flow F, alg either• finds a better flow F• or finds cut C such that rate(F) = cap(C)

• Alg stops with an F and C for which rate(F) = cap(C)• F witnesses that the optimal flow can't be less• C witnesses that it can't be more.

93

Hill Climbing

Problems:

Can our Network Flow Algorithm get stuck in a local maximum?

Local Max

Global MaxNo!

94

Hill Climbing

Problems:Running time?

If you take small step,could be exponential time.

95

Network Flow

96

Network Flow

Add flow 1

97

Network Flow

Add flow 1

98

Hill Climbing

Problems:Running time?• If each iteration you take

the biggest step possible,• Alg is poly time

• in number of nodes • and number of bits in capacities.

• If each iteration you take path with the fewest edges• Alg is poly time

• in number of nodes

99

Taking the biggest step possible

100

Linear Programming

101

A Hotdog

A combination of pork, grain, and sawdust, …

102

Constraints: • Amount of moisture• Amount of protein,• …

103

The Hotdog Problem

Given today’s prices,what is a fast algorithm to find the cheapest hotdog?

104

Abstract Out Essential Details

Cost: 29, 8, 1, 2

Amount to add: x1, x2, x3, x4

pork

grai

nw

ater

saw

dust

3x1 + 4x2 – 7x3 + 8x4 ≤ 122x1 - 8x2 + 4x3 - 3x4 ≤ 24

-8x1 + 2x2 – 3x3 - 9x4 ≤ 8x1 + 2x2 + 9x3 - 3x4 ≤ 31

Constraints: • moisture• protein,• …

29x1 + 8x2 + 1x3 + 2x4Cost of Hotdog:

105

29x1 + 8x2 + 1x3 + 2x4

Subject to:

Minimize:

Abstract Out Essential Details

3x1 + 4x2 – 7x3 + 8x4 ≤ 122x1 - 8x2 + 4x3 - 3x4 ≤ 24

-8x1 + 2x2 – 3x3 - 9x4 ≤ 8x1 + 2x2 + 9x3 - 3x4 ≤ 31

106

A Fast Algorithm

For decades people thought that there was no fast algorithm.

Then one was found!

Theoretical Computer Sciencefinds new algorithms every day.

3x1 + 4x2 – 7x3 + 8x4 ³ 12

2x1 - 8x2 + 4x3 - 3x4 ³ 24

-8x1 + 2x2 – 3x3 - 9x4 ³ 8x1 + 2x2 + 9x3 - 3x4 ³ 31

29x1 + 8x2 + 1x3 + 2x4

Subject to:

Minimize:

»

107

Network Flow as a Linear Program

• Given an instance of Network Flow: <G,c<u,v>> express it as a Linear Program: • The variables: • Maximize:• Subject to:

Flows f<u,v> for each edge.

<u,v>: F<u,v> c<u,v>. (Flow can't exceed capacity)v: u F<u,v> = w F<v,w> (flow in = flow out)

rate(F) = u F<s,u> - v F<v,s>

108

109

Primal

Dual

110

End

111

Network Flow

Locally in each edge,we see how much we can change the flow.

Allowed Flow ≠ Allowed Change in Flow

People find this hard.

This is my first attempt to explain it.

112

Network Flow

u v0/75

0/10

Old Flow Graph

Walking 10

u v10/75

0/10

New Flow Graph

113

Network Flow

u v0/75

0/10

Old Flow Graph

Walking 10

u v0/75

10/10

New Flow Graph

114

Network Flow

u v0/75

0/10

Old Flow Graph

Walking -10

u v-10/75

0/10

New Flow Graph

Same

Walking 10

u v0/75

10/10

New Flow GraphNot allowed

115

Network Flow

Walking -10

u v-10/75

0/10

New Flow Graph

Same

Walking 10

u v0/75

10/10

New Flow GraphNot allowed

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = -10

116

Network Flow

10+Δ ≤ 75F<u,v>+Δ ≤ c<u,v>

Δ ≤ c<u,v>-F <u,v>

Walking Δ

u v10+Δ /75

0/10

New Flow Graph

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 10

117

Network Flow

10-Δ ≥ -10F<u,v>-Δ ≥ -c<v,u>

Δ ≤ F <u,v> + c<v,u>u v

10- Δ /75

0/10

New Flow Graph

Walking Δ

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 10

118

Network Flow

Δ ≤ F <u,v> + c<v,u>

u vF<u,v>[-10,75]

Eqv Flow Graph

F<u,v> = 10

Δ ≤ c<u,v>-F <u,v>u v

Augmentation Graph

119

Network Flow

Locally in each edge,we see how much we can change the flow.

Allowed Flow ≠ Allowed Change in Flow

People find this hard.

This is my second attempt to explain it.

120

Network Flow

u v0/75

0/10

Flow Graph

u v75

10

Augmentation Graph

121

Network Flow

75-21=54

u v21/75

0/10

Flow Graph

u v

Augmentation Graph

2

21+2=23

Walking

122

Network Flow

75-21=54

u v21/75

0/10

Flow Graph

u v

Augmentation Graph

10

21-10=11

10 Edge shouldn’t have flow in both directions.

0

10 ?

Walking 10Walking -10

123

Network Flow

75-21=54

u v11/75

0/10

Flow Graph

u v

Augmentation Graph

1010 ?

Capacity of 10 not met

124

Network Flow

75-21=54

u v21/75

0/10

Flow Graph

u v

Augmentation Graph

2110 ?

Capacity of 10 exceeded

21

125

Network Flow

75-21=54

u v21/75

0/10

Flow Graph

u v

Augmentation Graph

21

21-21=0

10 ?

Capacity of 10 not met

Walking 21Walking -21

126

Network Flow

75-21=54

u v21/75

0/10

Flow Graph

u v

Augmentation Graph

21+10

21-21=0

10

10 ?21+10=31

Capacity of 10 met

Walking 21 and another 10

127

Network Flow

75-21=54

21+10=31

u v21/75

0/10

Flow Graph

u v

Augmentation Graph

25

21-25=-4

4

0

Walking 25

128

u vF<u,v>/c<u,v>

0/c<v,u>

Flow Graph

u v

Augmentation GraphF<u,v>+w

w

Walking

c<u,v>-F<u,v>

F<u,v>+c<v,u>

c<u,v>F<u,v>c<v,u>

Network Flow

129

u vF<u,v>/c<u,v>

0/c<v.u>

Flow Graph

u v

Augmentation GraphF<u,v>-w c<u,v>-F<u,v>

F<u,v>+c<v,u>

c<u,v>F<u,v>c<u,v>

w

Walking

Network Flow

130

131

Network Flow

How much flow can I have

in each direction?

u v0/75

0/10

Where can I stand in each direction?

132

Network Flow

How much flow can I have

in each direction?

75 to the right

u v75/75

0/10

Where can I stand in each direction?

133

Network Flow

How much flow can I have

in each direction?

75 to the right

u v0/75

10/10

10 to the left

Where can I stand in each direction?

134

Network Flow

u v15/75

0/10

Add 5 flow to rightWalking 5

u v20/75

0/10

15

20

135

Network Flow

u v15/75

0/10

Add 75-15=60 flow to right

Walking 75-15=60

u v75/75

0/10

15

136

Network Flow

u v15/75

0/10

How much flow can I add to right

How much can I change my position to the right?

75-15=60

15

u v75-15=60

Augmentation Graph

137

Network Flow

u vf/c

0/10

How much flow can I add to right

How much can I change my position to the right?

75-15=60

15

f-cu v

Augmentation Graph

138

Network Flow

u v15/75

0/10

Add 5 flow to leftWalking 5

u v15/75

5/10Edge shouldn’t

have flow in both directions.

15

10

139

Network Flow

u v15/75

0/10

Add 5 flow to leftWalking 5

u v15-5=10/75

0/10

15

10

140

Network Flow

u v15/75

0/10

Add 15 flow to leftWalking 15

u v15-15=0/75

0/10

15

141

Network Flow

u v15/75

0/10

Add 15+5=20 flow to left

Walking 15+5=20

u v-5/75

0/10Edge shouldn’t have negative flow.

15

-5

142

Network Flow

u v15/75

0/10

Add 15+5=20 flow to left

Walking 15+5=20

u v0/75

5/10

15

-5

143

Network Flow

u v15/75

0/10

Add 15+10=25 flow to left

Walking 15+10=25

u v0/75

10/10

15

144

Network Flow

u v15/75

0/10

How much flow can I add to left

How much can I change my position to the left?

15+10=25

15

15

u v

15+10=25Augmentation Graph

145

Network Flow

u vf/75

0/c

How much flow can I add to left

How much can I change my position to the left?

15+10=25

15

15

u v

f+cAugmentation Graph

146

u vF<u,v>/c<u,v>

0/c<v,u>

Flow Graph

u v

Augmentation GraphF<u,v>+w

w

Walking

c<u,v>-F<u,v>

F<u,v>+c<v,u>

c<u,v>F<u,v>c<v,u>

Network Flow

147

u vF<u,v>/c<u,v>

0/c<v.u>

Flow Graph

u v

Augmentation GraphF<u,v>-w c<u,v>-F<u,v>

F<u,v>+c<v,u>

c<u,v>F<u,v>c<u,v>

w

Walking

Network Flow