advertisement

CmSc250 Intro to Algorithms Laboratory exercise 09: Scheduling Networks The purpose of this laboratory exercise is to implement the algorithms for computing the earliest occurrence times (EOT) of the events in a scheduling network, the earliest completion times (ECT) of the tasks, and the slack of each task. Here is the algorithm: 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: Latest occurrence time LOT(j) LOT(sink) = EOT(sink) Initialize LOT with LOT(sink) Here we use the reverse topological order For each non-sink event i in the reverse topological order: For each activity (i,j) slack(i,j) = LOT(j) – ECT(i,j) LOT(i) = min(LOT(i), LOT(j) – duration(i,j)) The algorithms need the following data structures: 1. A two dimensional array that gives the duration of the tasks – this is the graph representation 2. An array that contains the nodes sorted in topological order 3. An array that will give the EOT of each event. This array has to be initialized with 0 4. A two dimensional array that will give the ECT of each task. It has to be initialized with 0. 5. An array that will give the LOT for each event 6. A two dimensional array that will give the slack of each activity. It has to be initialized with -1. Download the classes Queue.java (if you don't have it) and Networks.java. The Networks class outlines the algorithm. It contains the graph representation and the method for topological sort. Implement the algorithms (follow the comments in the source code) and test it for the following example (provided in the Networks class): 1 Durations of each task in a network with 6 events (i.e. the corresponding graph will have 6 nodes) 1 2 3 4 1 2 3 4 5 6 0 0 0 0 0 0 2 0 0 2 0 0 0 1 0 0 0 0 5 6 3 0 0 0 10 0 0 0 11 0 9 0 0 0 4 0 0 0 The program should output the following: - the topological sort - the array containing the EOTs , - the array containing the ECTs, - the array containing the LOTs - the array containing the slacks Results for the provided example: Topological sort 1 4 2 3 5 6 EOT 0 5 6 3 15 19 ECT 0 0 0 0 0 0 2 0 0 5 0 0 0 6 0 0 0 0 3 0 0 0 0 0 0 15 0 12 0 0 0 0 17 0 19 0 -1 2 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 0 -1 3 -1 -1 -1 -1 2 -1 0 -1 LOT 0 5 8 3 15 19 Slack table -1 3 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 If the program is not completed in class, e-mail the completed program by Monday 11/22, 5 pm. 2