110 likes | 203 Views
Mark Allen Weiss: Data Structures and Algorithm Analysis in Java. Chapter 9: Graphs. Scheduling Networks. Lydia Sinapova, Simpson College. Scheduling Networks. Definitions Purpose of the Model Algorithm Critical Activities Complexity Example. Definitions.
E N D
Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Chapter 9: Graphs Scheduling Networks Lydia Sinapova, Simpson College
Scheduling Networks • Definitions • Purpose of the Model • Algorithm • Critical Activities • Complexity • Example
Definitions A project can be described by its activities, their duration and the prerequisites of each activity Activity: a task, characterized by: duration prerequisites – other tasks that have to be completed in order to start the current task Event: a point in time, characterized by the completion of one or several activities
The Model Directed simple acyclic graph Nodes:events Source: starting event Sink: terminating event Edges:activities Each edge is labeled by a pair (name of the task, duration) , duration 0 Simple graph means: each pair of nodes connected by at most one edge
Purpose of the Model • Find the earliest occurrence time (EOT) of an event • Find the earliest completion time (ECT) of an activity • Find the slack of an activity: how much the activity can be delayed without delaying the project • Find the critical activities: must be completed on time in order not to delay the project
EOT and ECT Earliest occurrence time of an event EOT(source) = 0 EOT( j ) = max ( ECTs of all activities preceding the event) Earliest completion time of an activity ECT( j, k ) = EOT( j ) + duration( j, k)
Algorithm to Compute EOT and ECT 1. Sort the nodes topologically 2. For each event j : initialize EOT(j) = 0 3. For each event i in topological order For each event j adjacent from i : ECT(i,j) = EOT(i) + duration (i,j) EOT(j) = max(EOT(j) , ECT(i,j))
Algorithm to find the slack of activities Compute latest occurrence time LOT(j) , slack(i, j) 1. Initialize LOT(sink) = EOT(sink) 2. For each non-sink event i in the reverse topological order: LOT(i) = min(LOT( j ) – duration( i, j)) 3. For each activity (i,j) slack( i, j ) = LOT( j ) – ECT( i, j)
Critical Activities, Complexity Critical activities: slack(j) = 0 Critical path in the project: all edges are activities with slack = 0 The critical path is found using breadth-first (or depth-first) search on the edges Complexity: O(V + E) with adjacency lists, O(V2) with adjacency matrix
b / 1 2 3 c / 11 a / 2 e / 10 d / 2 6 1 f / 3 g / 9 h / 4 4 5 Example Topological sort: 1, 4, 2, 3, 5, 6 Critical Path: 1, 4, 2, 5, 6