Foudatios of Operatios Research Master of Sciece i Computer Egieerig Roberto Cordoe roberto.cordoe@uimi.it Tuesday 13.15-15.15 Thursday 10.15-13.15 http://homes.di.uimi.it/~cordoe/courses/2014-for/2014-for.html Lesso 7: Project plaig Como, Fall 2013 1 / 27
Project plaig A project cosists of a set N = {a 1,..., a } of activities A duratio d : N R + is associated to each activity A precedece relatio coects some pairs of activities: a i a j meas that activity a j ca start oly after activity a i has eded A project ca be modelled by a arc-weighted directed graph G = N, A odes stad for activity start evets, plus a fictitious ode s for the begiig of the project ad a fictitious ode t for the ed of the project arcs stad for precedece costraits: the give oes plus the fact that s precedes all activities ad all activities precede t the arc cost c ij = d i stads for the activity duratio: the startig times of activities a i ad a j must differ at least by d i The graph represetig a project is acyclic otherwise, the start evet of a activity should follow its ed evet: a logical paradox, or a deadlock 2 / 27
The problem Fid for each activity a i N a start time x i respectig the precedece costraits so as to miimize the overall duratio f = x t x s i. e. the time eeded to complete the whole project We covetioally set x s = 0 ad defie as i the earliest start time for activity a i N i ay feasible solutio τi max the latest start time for activity a i N i ay optimal solutio All solutios with τi mi x i τi max for all a i N are optimal slack σ i = τi max τi mi the amout of time by which a activity ca be postpoed without affectig the overall duratio critical activity a activity with idetical earliest ad latest time σ i = 0 A critical activity caot be postpoed without delayig the whole project Property: The cost of each directed path from s to t is a lower boud o the overall duratio f f c Pst for all P st path from s to t Proof: P st is a sequece of activities that must be performed i the same order i which they are visited i the path 3 / 27
Example Activity Duratio Predecessors A 3 - B 2 A C 3 A D 3 C E 4 B,C F 5 B G 1 C,D,E Why does s reach oly A? Why is t reached oly by F ad G? 4 / 27
The Critical Path Method CPM The critical path method CPM fids a solutio x : N R such that all costraits are respected the overall duratio equals the maximum cost of a path from s to t f xt = max {c Pst : P st is a path from s to ti G} If the cost of a feasible solutio equals a lower boud o the optimum the solutio is optimal by cotradictio: if it were ot optimal, the optimum would be smaller tha the lower boud The CPM fids τi mi, τi max ad the slack σ i for each activity a i N applyig dyamic programmig Remember that ay solutio with i x i i is optimal 5 / 27
The Critical Path Method CPM 1 Sort the odes topologically the graph is acyclic by defiitio, s = 0 ad t = s precedes ad t follows all the other odes I order to fid a optimal solutio 2 Set τ0 mi = 0 3 Compute the earliest time τh mi of each ode h N for h τh mi = max τ mi i: i, h h icreasig from 1 to h computig the miimum cost paths with iverted sig costs The optimal solutio is x i = i I order to fid all optimal solutios 4 set = f x 5 Compute the latest time h ad its cost is f x = of each ode h N h = mi i: h, i + h h decreasig from 1 to 0 computig backward miimum cost paths with iverted sig costs 6 / 27
Applicatio of the CPM 1 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h 0 1 2 3 4 5 6 7 8 0 := 0 := For h := 1 dowto 0 do h := mi i N: h, i + h Retur, 7 / 27
Applicatio of the CPM 2 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 1 1 := max 0 + d 0 = 0 Retur, 8 / 27
Applicatio of the CPM 3 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 2 2 := max 1 + d 1 = 3 Retur, 9 / 27
Applicatio of the CPM 4 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 3 3 := max 1 + d 1 = 3 Retur, 10 / 27
Applicatio of the CPM 5 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 4 4 := max 3 + d 3 = 6 Retur, 11 / 27
Applicatio of the CPM 6 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 5 5 := max 2 + d 2, 3 + d 3 = = 6 Retur, 12 / 27
Applicatio of the CPM 7 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 6 6 := max 2 + d 2 = 5 Retur, 13 / 27
Applicatio of the CPM 8 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 7 7 := max 3 + d 3, 4 + d 4, 5 + d 5 = 10 Retur, 14 / 27
Applicatio of the CPM 9 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 8 8 := max 6 + d 6, 7 + d 7 = = 11 Retur, 15 / 27
Applicatio of the CPM 10 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 8 := 11 Retur, 16 / 27
Applicatio of the CPM 11 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 7 7 := mi 8 d 7 = 10 Retur, 17 / 27
Applicatio of the CPM 12 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 6 6 := mi 8 d 6 = 6 Retur, 18 / 27
Applicatio of the CPM 13 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 5 5 := mi 7 d 5 = 6 Retur, 19 / 27
Applicatio of the CPM 14 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 4 4 := mi 7 d 4 = 7 Retur, 20 / 27
Applicatio of the CPM 15 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h Retur, 0 1 2 3 4 5 6 7 8 h = 3 3 := mi 4 d 3, 5 d 3, 7 d 3 = 3 21 / 27
Applicatio of the CPM 16 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h Retur, 0 1 2 3 4 5 6 7 8 h = 2 2 := max 5 d 2, 6 d 2 = = 4 22 / 27
Applicatio of the CPM 17 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h Retur, 0 1 2 3 4 5 6 7 8 h = 1 1 := max 2 d 1, 3 d 1 = = 0 23 / 27
Applicatio of the CPM 18 CPMN, A, d TopologicalSortN 0 := 0 For h := 1 to do i N:i,h h := For h := 1 dowto 0 do h := mi i N: h, i + h 0 1 2 3 4 5 6 7 8 h = 0 0 := mi 1 d 0 = 0 Retur, 24 / 27
Critical path A optimal solutio always has at least oe critical path, that is a path from s to t whose odes correspod to critical activities s, A, C, E, G, t is a critical path A, C, E ad G are critical activities B, D ad F are ocritical activities: their startig time ca be delayed by the same slack σ 2 = σ 4 = σ 6 = 1 without affectig the overall shortest duratio f = 11 25 / 27
Gatt diagram at earliest The Gatt diagram is a temporal represetatio of a project the horizotal axis represet time the activities are distributed alog the vertical axis activity schedules are horizotal segmets 1 from τi mi to τi m i the diagram at earliest 2 from τi max d i to τi max i the diagram at latest i d i i A 3 0 3 B 2 3 5 C 3 3 6 D 3 6 9 E 4 6 10 F 5 5 10 G 1 10 11 + d i 26 / 27
Gatt diagram at latest The Gatt diagram is a temporal represetatio of a project the horizotal axis represet time the activities are distributed alog the vertical axis activity schedules are horizotal segmets 1 from τi mi to τi m i the diagram at earliest 2 from τi max d i to τi max i the diagram at latest i d i i A 3 0 3 B 2 4 6 C 3 3 6 D 3 7 10 E 4 6 10 F 5 6 11 G 1 10 11 + d i 27 / 27