Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research...

50
Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf ir. Rodrigo Rezende Amaral

Transcript of Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research...

Page 1: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Introduction to Operations Research

ANSWERS

Network Problems: A Review of Some Fundamental Algorithms

Prof. dr. E-H. Aghezzafir. Rodrigo Rezende Amaral

Page 2: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 6

(e.g., if a truck carries three packages, they should be from three different types)

Page 3: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 61

2

7

so

1

2

5

si

3

4

5

6

3

4

33

3

3

3

3

3

6

4

5

4

31

1

1

1

1

*

*

*

*

*

* * 5 arcs goes from each node on the left to the 5 nodes on the right

If max flow= 21 then all packages can be loaded.

Page 4: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 7

(Consider that the number of cars in each city is >> 300)

Page 5: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 7

C10

C11

Each node cit represents city i in time t

C21

C31

C41

C42

∞300

300

300

300

300

300

t = 0 t = 1 t = 2

Page 6: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 8

Page 7: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 8

Page 8: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

0* ∞ ∞ ∞ ∞ ∞ ∞ ∞

N.Y. Cleveland St. Louis Nashville Phoenix Dallas Salt Lake L.A.

d[v]π[v]

: path length from the source (NY) to v

: previous node which should be visited in order to achieve d[v]

v

Page 9: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

N.Y. N.Y. N.Y. St. Louis Cleveland Nashville Phoenix

0* 400* 950 800 ∞ ∞ ∞ ∞

0* 400* 950 800* 2200 1300 ∞ ∞

0* 400* 950* 800* 2200 1300 2000 ∞

0* 400* 950* 800* 2050 1300* 2000 ∞

0* 400* 950* 800* 2050* 1300* 2000* 2600

0* 400* 950* 800* 2050* 1300* 2000* 2600

0* 400* 950* 800* 2050* 1300* 2000* 2450*

N.Y. Cleveland St. Louis Nashville Phoenix Dallas Salt Lake L.A.

Page 10: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 8

b) Balanced transportation matrix:

Cleveland St. Louis Nashville Phoenix Dallas Salt Lake L.A.

N.Y.400

1950 800 ∞ ∞ ∞ ∞

1

Cleveland 10 ∞ ∞ 1800 900 ∞ ∞

1

St. Louis∞ 0 ∞

11100 600 ∞ ∞

1

Nashville∞ ∞

10 ∞ 600 1200 ∞

1

Phoenix∞ ∞ ∞ 0 ∞ ∞

1400

1

Dallas∞ ∞ ∞ 900

10 1000 1300

1

Salt Lake∞ ∞ ∞ ∞ ∞

10 600

1

1 1 1 1 1 1 1

Page 11: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 8

c) MCNFP

Cleveland St. Louis Nashville Phoenix Dallas Salt Lake L.A.

N.Y. x400

x950

x800

…∞ ∞ ∞

x∞

111 12 13 17

Cleveland x0 ∞ ∞ 1800 900 ∞

…∞

121

St. Louis x∞ 0 ∞ 1100 600 ∞ ∞

131

Nashville …∞ ∞ 0 ∞ 600 1200 ∞

1

Phoenix∞ ∞ ∞ 0 ∞ ∞

x400

157

Dallas∞ ∞ ∞ 900 0 1000

x1300

167

Salt Lake x∞

…∞ ∞ ∞

x∞

x0

x600

171 75 76 77

1 1 1 1 1 1 1

Page 12: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 8

c) MCNFP

400 950 800 ∞ ∞ ∞ ∞

0 ∞ ∞ 1800 900 ∞ ∞

∞ 0 ∞ 1100 600 ∞ ∞

∞ ∞ 0 ∞ 600 1200 ∞

∞ ∞ ∞ 0 ∞ ∞ 400

∞ ∞ ∞ 900 0 1000 1300

∞ ∞ ∞ ∞ ∞ 0 600

min 𝑧 =

𝑖=1

7

𝑗=1

7

𝑐𝑖𝑗𝑥𝑖𝑗

𝑠. 𝑡.

𝑖=1

7

𝑥𝑖𝑗 = 1 , 𝑓𝑜𝑟 𝑒𝑣𝑒𝑟𝑦 𝑗

𝑗=1

7

𝑥𝑖𝑗 = 1 , 𝑓𝑜𝑟 𝑒𝑣𝑒𝑟𝑦 𝑖

𝐴𝑙𝑙 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 ≥ 0

𝐶 =

Page 13: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 9

Page 14: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 9

Page 15: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 9

Graphical representation:

Page 16: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 9

a) LP formulation:

x12

x13x35

x34

x25

x24

x46

x56

Page 17: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

b) Ford-Fulkerson method

Page 18: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

b) Ford-Fulkerson method

Page 19: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

b) Ford-Fulkerson method

Page 20: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 10

of Exercise 8 using Prim's Algorithm.

(Consider the arcs as non-directed)

Page 21: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 10

Page 22: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 11

DeptShift

1 2 3

1 (6, 8) (11, 12) (7, 12)

2 (4, 6) (11, 12) (7, 12)

3 (2, 4) (10, 12) (5, 7)

Page 23: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 11

DeptShift

1 2 3 ∑j

1 6 ≤ x11 ≤ 8 11 ≤ x12 ≤ 12 7 ≤ x13 ≤ 12 ∑j=1,2,3 x1j≥ 26

2 4 ≤ x21 ≤ 6 11 ≤ x22 ≤ 12 7 ≤ x23 ≤ 12 ∑j=1,2,3 x2j≥ 24

3 2 ≤ x31 ≤ 4 10 ≤ x32 ≤ 12 5 ≤ x33 ≤ 7 ∑j=1,2,3 x3j≥ 19

∑i∑i=1,2,3 xi1 ∑i=1,2,3 xi2 ∑i=1,2,3 xi3

≥ 13 ≥ 32 ≥ 22

Min ∑∑ xij …

Page 24: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 11

We start with the maximum possible number of nurses for every department and every shift. Then maximize the number of nurses which can be unassigned.

DeptShift

1 2 3 ∑j=1,2,3

1 6 ≤ 8 ≤ 8 11 ≤ 12 ≤ 12 7 ≤ 12 ≤ 12 32 ≥ 26

2 4 ≤ 6 ≤ 6 11 ≤ 12 ≤ 12 7 ≤ 12 ≤ 12 30 ≥ 24

3 2 ≤ 4 ≤ 4 10 ≤ 12 ≤ 12 5 ≤ 7 ≤ 7 23 ≥ 19

∑i=1,2,3 18 36 31

≥ 13 ≥ 32 ≥ 22

∑∑ ẋij = 85

Page 25: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 11

DeptShift

1 2 3 ∑j=1,2,3

1 y11 ≤ 2 y12 ≤ 1 y13 ≤ 5 ∑j=1,2,3 y1j≤ 6

2 y21 ≤ 2 y22 ≤ 1 y23 ≤ 5 ∑j=1,2,3 y2j≤ 6

3 y31 ≤ 2 y32 ≤ 2 y33 ≤ 2 ∑j=1,2,3 y3j≤ 4

∑i=1,2,3 ∑i=1,2,3 yi1 ∑i=1,2,3 yi2 ∑i=1,2,3 yi3

≤ 5 ≤ 4 ≤ 9

Min ∑∑ xij = 85 - Max ∑∑ yij

We start with the maximum possible number of nurses for every department and every shift. Then maximize the number of nurses which can be unassigned.

Page 26: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 11

S

source of “unassigned

nurses”

Dept j Shift i t

∑i yij ∑j yijyij

# of unassigned nurses currently in dept j

# of unassigned nurses currently in dept j and shift i

# of unassigned nurses currently in shift i

Page 27: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 11

S S2 t

5

D1 S1

S3

D2

D3

6

2

Page 28: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 10

- First solve the problem with only 2 experient contractors.

Page 29: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 10

s

c2

c1

d3

d1

d2

(0, u1)

(c11, ∞) b(d1) = -r1

(cij, uij)

b(s) = ∑ ri

i j

Page 30: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Exercise 10

s

c2

c1

d3

d1

d2

(0, u1)

(c11, ∞)

b(d1’) = -(r1-1)

b(s) =

∑ ri

c4

c3

(exp.)

d1’

d2’

d3’(inexp.)

(c11, ∞)

(c12, ∞)

(c12, ∞)

(c13, ∞)

(c13, ∞)

(0, u3)(c31, ∞)

(c32, ∞)

(c33, ∞)

b(d1) = -1

b(d2’) = -(r2-1)

b(d2) = -1

(exp.)

(inexp.)

b(d3’) = -(r3-1)

b(d3) = -1

Page 31: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Minimum Cost Flow Problem - Exercise 1

Page 32: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

• Negative Cycle Algorithm

– Find a feasible flow

– While there exist a negative cycle C in the residual graph

• Find the minimum Δ of the residual capacities in C

• Augment the flow in C with Δ units

• Update the residual graph

Minimum Cost Flow Problem - Exercise 1

Page 33: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

2222

10

10

Cost: 110+50+330+110 = 600

Minimum Cost Flow Problem - Exercise 1

Page 34: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

2222

1010

38

2

Original Graph Residual Graph

∞ ∞12 20

10

22 22

10

Minimum Cost Flow Problem - Exercise 1

Page 35: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

1410

4

5

-5-15

15

5

-5

5

11

-11

Residual Graph (Costs)

Minimum Cost Flow Problem - Exercise 1

Page 36: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

14-10

4

5

-5-15

15

5

-5

5

11

-11

Negative cost cycle

Minimum Cost Flow Problem - Exercise 1

Page 37: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

38

2

∞ ∞12 20

10

22 22

10

Negative cost cycle

2 units can be send through this cycle

Minimum Cost Flow Problem - Exercise 1

Page 38: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

2020

12

10

2

Previous Cost: 110+50+330+110 = 600

Current Cost: 132+50+8+300+100 = 590 = 600 + 2 * (-5)

Minimum Cost Flow Problem - Exercise 1

Page 39: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

-5-15

5

54

-4

10

5

-5

15

-11

5

No more negative cycles can be found

Minimum Cost Flow Problem - Exercise 1

Page 40: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

2020

12

10

2

Minimum Cost Flow Problem - Exercise 1

Page 41: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Minimum Cost Flow Problem - Exercise 2

Page 42: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

50

2525

50

25

50 75

Flow

Minimum Cost Flow Problem - Exercise 2

Page 43: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

25

575

15

10 5

40

50

50

50 75

25

25 25

60

50

40

40

50

100

40

Residual Forward Flow Residual Backward Flow

Minimum Cost Flow Problem - Exercise 2

Page 44: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

15

10 45

5

8 15

5

-10

-15

-8 -15

-5

-10 -45

10

30

10

10

30

45

25

X Cost of using the arc

Minimum Cost Flow Problem - Exercise 2

Page 45: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

15

10 45

5

8 15

5

-10

-15

-8 -15

-5

-10 -45

10

30

10

10

30

45

25

2525

50 40

Minimum Cost Flow Problem - Exercise 2Negative

cost cycle

25 units can be send through this cycle

Page 46: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

50 2525

50

25

50 75

Flow

Minimum Cost Flow Problem - Exercise 2

Page 47: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

25

30 100

15

10 5

40

50

50

50 75

25

25 25

60

25

15

40

50

100

40

Residual Forward Flow Residual Backward Flow

Minimum Cost Flow Problem - Exercise 2

Page 48: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Residual Forward Flow Residual Backward Flow

5

-10

-15

-8 -15

-5

10 10

10

30

45

25

15

-10

10 45

-1030

8

15

5

Minimum Cost Flow Problem - Exercise 2

Page 49: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

Residual Forward Flow Residual Backward Flow

5

-10

-15

-8 -15

-5

10 10

10

30

45

25

15

-10

10 45

-1030

8

15

5

No more negative cycle can be found

Minimum Cost Flow Problem - Exercise 2

Page 50: Network Problems: A Review of Some Fundamental Algorithms · Introduction to Operations Research ANSWERS Network Problems: A Review of Some Fundamental Algorithms Prof. dr. E-H. Aghezzaf

50

50

50 75

25

25

25

Solution

Minimum Cost Flow Problem - Exercise 2