1 outline minimum spanning tree maximal flow algorithm lp formulation

53
1 Outline Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

Upload: kyla-kidner

Post on 31-Mar-2015

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

1

OutlineOutline

Minimum Spanning Tree

Maximal Flow Algorithm LP formulation

Page 2: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

2

The Minimum Spanning Tree Problem

最小延展樹問題

Page 3: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

3

8.1.2 The Minimum Spanning Tree Problem

application context nodes are cities (節點是城市) arcs are potential highways to be built to connect the cities (線段是連接城市的高速公路)

what is the cheapest way (i.e., shortest total distance) to have all cities connected? (最短的公路網將所有城市連接起來)

Page 4: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

4

8.1.2 The Minimum Spanning Tree Problem

general concept tree: a connected network such that the n nodes

of the network are connected by n-1 arcs which is a tree?

Page 5: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

5

8.1.2 The Minimum Spanning Tree Problem

think about this the cheapest way to connect all cities should be

a tree called spanning tree, as it connects all cities

the only question: how to find the cheapest spanning tree?

只要細想,每個人都懂。

Page 6: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

6

8.1.2 The Minimum Spanning Tree Problem

question: would the cheapest arc always in the minimum spanning tree?

must be

an arc in the spanning tree

an arc not in the spanning tree

the cheapest arc, not in the spanning tree

Page 7: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

7

8.1.2 The Minimum Spanning Tree Problem

question: would we find the minimum spanning tree by always selecting the cheapest unselected arc?

no, see, e.g., the cheapest three arcs.

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 8: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

8

8.1.2 The Minimum Spanning Tree Problem

Let us grow the minimum spanning tree step by step, i.e., add the arcs one by one. (一步一步的養大這minimum spanning tree. )

As argued before, arc (1, 2) must be in the minimum spanning tree.

Thus, we have a small tree T{1, 2}.

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

331

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 9: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

9

8.1.2 The Minimum Spanning Tree Problem

In the minimum spanning tree, which of the three arcs, (1, 3), (2, 3), and (2, 4), should be connected to the tree T{1, 2} grown so far?

Arc (1, 3) of length 18 should be in the minimum spanning tree. Why?

Considered a spanning tree without arc (1, 3).

The cost of the spanning tree can be reduced by swapping an arc with higher cost with arc (1, 3).

Thus, arc (1, 3) should be in the minimum spanning tree.

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

331

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 10: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

10

8.1.2 The Minimum Spanning Tree Problem

to find the minimum spanning tree: start with the arc of minimum cost to from a

tree (從最便宜的公路開始) grow the tree by adding an arc connecting to it

such that (每次加一條公路) adding the arc maintains a tree (保持 tree的形式) , and

among possible arcs to add, the added arc is of the lowest cost (選能加上的公路中最便宜的)

Page 11: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

11

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 12: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

12

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 13: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

13

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 14: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

14

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 15: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

15

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 16: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

16

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 17: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

17

8.1.2 The Minimum Spanning Tree Problem

1

4

3

5

6

7

213

18

20

22

27

30

49

18

26

24

32

33

Page 18: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

18

The Maximal Flow Problem最大流量問題

Page 19: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

19

Railway Map Each railway

segment has a capacity (i.e., upper bound of tonnage (per day)).

What is the maximal flow from, say, Paris to Moscow?

http://www.worldchanging.com/archives/009028.html

Page 20: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

20

The Maximal Flow Problem

The number beside an arc is the capacity of flow along the arc. (管線旁的數字是管線的容量) The movement can be of either direction.

What is the maximal flow from node 1 to node 4?

1 4

3

210

3

2

6

6

Page 21: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

21

The Maximal Flow Problem

At any moment, we need to keep track of the flow and the residual capacity (i.e., remaining capacity) of an arc.

1 4

3

20

0

0

0

0

10 6

2

63

0 0

number beside an arc: boxed = residual capacity, normal = current flow.

Page 22: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

22

The Maximal Flow Problem

1 4

3

26

0

0

6

0

4 0

2

63

6 6

1 4

3

20

0

0

0

0

10 6

2

63

0 0

The route 124 allows a flow of 6 units.

Page 23: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

23

The Maximal Flow Problem

1 4

3

26

0

0

6

0

4 0

2

63

6 6

1 4

3

28

0

2

6

2

2 0

0

43

6 66+2 6+2

The route 1234 allows a flow of 2 units.

Page 24: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

24

The Maximal Flow Problem

The route 134 allows a a flow of 3 units.

1 4

3

28

0

2

6

2

2 0

0

43

6 66+2 6+2

1 4

3

28

3

2

6

2+3

2 0

0

10

6 66+2 6+2

6+2+3 6+2+3

Page 25: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

25

The Maximal Flow Problem

The maximal flow from node 1 to node 4 is 11 units. The flow pattern is shown below, with the residual capacities of arcs boxed.

1 4

3

28

3

2

6

5

11 11

0

0

0

1

2

Page 26: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

26

The Maximal Flow Problem

The method seems all right: We first find a route of positive flow from the

source to the sink. Find the residual capacities of arcs by

subtracting added flows from their (residual) capacities.

Keep on repeating the above two steps until no route with positive flow can be added.

However, the method can run into trouble.

Page 27: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

27

The Maximal Flow Problem

1 4

3

210

3

2

6

6

1 4

3

20

0

0

0

0

10 6

2

63

0 0

Page 28: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

28

The Maximal Flow Problem

1 4

3

20

0

0

0

0

10 6

2

63

0 0

1 4

3

20

2

2

2

0

10 4

0

61

2 2

The route 1324 allows a flow of 2 units.

Page 29: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

29

The Maximal Flow Problem

1 4

3

24

2

2

6

0

6 0

0

61

6 6

The route 124 allows a flow of 4 units.

1 4

3

20

2

2

2

0

10 4

0

61

2 2

Page 30: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

30

The Maximal Flow Problem

1 4

3

24

3

2

6

1

6 0

0

50

7 7

The route 134 allows a flow of 1 unit.

1 4

3

24

2

2

6

0

6 0

0

61

6 6

Page 31: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

31

The Maximal Flow Problem

There seems to be no more flow to node 4, because residual capacity of arc (1, 3) = 0, arc (2, 3) = 0, arc (2, 4) = 0

1 4

3

24

3

2

6

1

6 0

0

50

7 7

Page 32: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

32

The Maximal Flow Problem

However, this does not make sense, because the flow is found to be 11 units before.

What is wrong?

1 4

3

24

3

2

6

1

7 7

Page 33: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

33

The Maximal Flow Problem

Compare the two flow patterns. Any observations?

In the second case, the flow in the vertical arc is in the wrong direction.

1 4

3

28

32

6

511 11

00

0

1

2

1 4

3

24

32

6

1

6 00

50

7 7

Page 34: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

34

The Maximal Flow Problem

In a large network, how can we be sure which direction to follow when we add flows one by one?

There should be ways to revert the direction of a wrong flow.

1 4

3

24

2

2

4

1

7 72

1

Page 35: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

35

The Maximal Flow Problem

Suppose that we send 2 units from node 1 to node 2 to take up the capacity of node 2 to node 4 of the red flow.

The red flow is along arc (3, 2) is then re-directed to arc (3, 4).

1 4

3

24

2

2

4

1

7 72

1 5

00

0

61 4

3

24

2

4

1

7+2 7+22

1

2

2

Page 36: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

36

The Maximal Flow Problem

The result:

Two more units of flow can be sent along the route 1234

1 4

3

26

3

0

6

3

9 9

3

02

0

4

1 4

3

26+2

3

2

6

5

9+2 9+2

1

00

0

2

Page 37: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

37

The Maximal Flow Problem There is a labeling algorithm basically keeping track

of the flows, the residual capacities, and the re-direction of flows.

The algorithm works for networks with capacity limits on bi-directional flows on arcs. It is possible to have different limits for the two directions of the same arc. (容許 i 到 j 跟 j 到 i 的 capacity不一樣)

i j3 5

the capacity of i j flow the capacity of j i flow

Page 38: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

38

The Maximal Flow Problem

Find the maximal flow from node 1 to node 4 for the following network. The number beside an arc is the capacity limit of the arc. All arcs are bi-directional.

1 4

3

210

3

2

6

6

Page 39: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

39

The Maximal Flow Problem Since node 1 is the source, flow can only be possible from

node 1 to node 2. Thus, arc (1, 2) is practically a directed arc.

Similar, flow can only be possible from node 1 to node 3, node 2 to node 4, and node 3 to node 4. Thus, practically arcs (1, 3), (2, 4), and (3, 4) are directed arcs.

The flow on (2, 3) can be on either direction.

1 4

3

2

10

3

2

6

6

0

0

0

0

2

Page 40: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

40

The Maximal Flow Problem

1 4

3

2

10

3

2

6

6

0

0

0

0

2

00

The route 1324 allows a flow of 2 units.

2

the residual capacity of flowing from node 1 to node 3

the residual capacity of flowing from node 3 to node 1

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

2

10

4 2

4

2

Page 41: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

41

The Maximal Flow Problem

The route 124 allows a flow of 4 units.

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

2

10

4 2

4

2

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

2

10

4 2

4

2 66 64

0

6

Page 42: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

42

The Maximal Flow Problem

The route 134 allows a flow of 1 unit.2

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

10

4 2

4

2 66 64

0

6

2

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

2

10

4 2

4

2 66 64

0

6 77

03

5

1

Page 43: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

43

The Maximal Flow Problem

The route 1234 allows a flow of 4 unit.

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

2

10

4 2

4

2 66 64

0

6 77

03

5

1

1 4

3

2

10

3

2

6

6

0

0

0

0

2

002

2

10

4 2

4

2 66 64

0

6 77

03

5

15

11

4

0

8

1

211

Page 44: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

44

The Maximal Flow Problem

How to get the flows?

Compare with the original. The differences in (residual) capacities give the actual flows.

1 4

3

2

2

0

0

0

1

8

3

5

6

4

1111

1 4

3

2

10

3

2

6

6

0

0

0

0

2

00

12: 8 units 13: 3 units

23: 2 units 24: 6 units

34: 5 units

maximal flow from node 1 to node 4 : 11 units

Page 45: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

45

A Linear Program Formulation of

the Maximal Flow Problem

Page 46: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

46

LP Formulation of the Maximal Flow Problem

Oil is pumped out at node 1, temporarily stored at nodes 2, 3, and 4, and eventually sent the refinery at node 5 through the pipe lines. In the following, arc represents a pipe line, with its capacity (i.e., barrels of oil per day) written beside it. Formulate a linear program to find the maximal amount of oil sent from node 1 to node 5. A maximal flow problem can be formulated as a linear program

(and solved by an optimizer).

1 4

3

245

35

4025

10

5

50

20

15

Page 47: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

47

LP Formulation of the Maximal Flow Problem

Let xij be the number of barrels of oil pumped from node i to node j; xij 0.

Because node 1 is the source, x21 = x31 = 0.

Similarly, x52 = x53 = x54 = 0 because node 5 is the sink.

Because we do not know the direction of flow in arc (2, 3), we are not sure which of x23 and x32 should be equal to zero.

Similarly, we have no idea of fixing which of x24 and x42, and of x34 and x43, to zero.

1 4

3

245

35

40 25

10

5

50

2015

Page 48: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

48

LP Formulation of the Maximal Flow Problem

We further introduce a variable x51. Effectively we act an artificial arc from node 5 to node 1.

1 4

3

245

35

4025

10

5

50

20

15

x51

Page 49: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

49

LP Formulation of the Maximal Flow Problem

Each LP constraint matches with a physical relationship of the problem.

There are two types of constraints: conservation of flow: the amount of oil into a

node must be the same as the amount out of the node.

bounds on flow: 0 xij capacity of i to j flow

Page 50: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

50

LP Formulation of the Maximal Flow Problem

objective function: max x51, conservation of flow

node 1: x51 = x12 + x13, node 2: x12 + x32 + x42 = x23 + x24 + x25, node 3: x13 + x23 + x43 = x32 + x34 + x35, node 4: x24 + x34 = x42 + x43 + x45, node 5: x25 + x35 + x45 = x51,

1 4

3

245

35

40 25

10

5

50

2015

Page 51: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

51

LP Formulation of the Maximal Flow Problem

bounds: 0 x12 45, 0 x13 35, 0 x23, x32 40, 0 x24, x42 25, 0 x25 50, 0 x34, x43 10, 0 x35 15, 0 x45 20

1 4

3

245

35

4025

10

5

50

20

15

Page 52: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

52

LP Formulation of the Maximal Flow Problem

Read Example 8-6 for more example.

Page 53: 1 Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation

53

Assignment #3

Chapter 8 Problem 1 (a), (b), plus

(c) Formulate this problem as a mathematical programming model.

Problem 10 Problem 16 (a) Find the maximal flow of this

network, and (b) Formulate the problem as a linear program.