260 likes | 270 Views
Discover the fundamentals of scheduling theory to efficiently manage resources like time, manpower, and space. Learn about task states, precedence relations, and algorithms for optimal scheduling.
E N D
Scheduling Theory By Sarah Walker
Introduction to Scheduling • Scheduling is used to arrange, coordinate and plan the utilization of resources to achieve an objective. • In today’s world, time is a scarce commodity, so making the best of it can be very important. • It can also be useful to look at other things we might be interested in getting the most possible use out of: • Cash flow • Manpower • Space • For our purposes, we will mostly be concerned with time management. • Scheduling can be difficult because currently there are no algorithms that guarantee optimization.
Definitions • Processor – someone (or something) who does the work for a given task. • Denoted where N is the number of processors. • Task – indivisible amount of work that is by nature carried out by a single processor. • At any time during a project, a task will be in any the four following states: • Ineligible – the task cannot be started at this time • Ready – the task could be started at this time • In execution – the task is currently being carried out by a processor • Completed.
More Definitions • Processing time – the amount of time it takes one processor to complete a given task. • We will assume that all processors have the same processing time for a task • Precedence relations – if task X precedes task Y (abbreviated X Y), then task Y cannot be started until task X is completed. • Example: you can’t put your shoes on before you put your socks on. • Two tasks are considered independent if there are no precedence relations between them. • The finishing time for a project is the duration from the start of the first task to the end of the last task.
Using Digraphs To Represent Precedence Relations • Create a vertex for each task. • Give each task a label using capital letters. • Put the tasks’ processing times in parenthesis after its label. • Draw an arc between them based on their given precedence relation.
An Important Note Precedence relations cannot form a cycle. Trying to schedule these four tasks would be impossible. Y X Z W
Example 1 • Let’s assume we want to build a habitat on mars using two processors, P1 and P2, and we are given the tasks and precedence relations that appear in the following two tables:
AP(7) AF(5) IF(5) PL(4) IC(1) FW(6) AW(6) IW(7) IP(4) PD(3) HU(4) START (0) END (0) AD(8) ID(5) PU(3) EU(2) Example 1 (continued) • Given the preceding information, we can draw the following digraph: • The tasks labeled START and END are not real tasks, they are added for our convenience • It is now easy to visualize the project as a flow that begins at START and concludes at END. • We give these fictitious tasks processing times of zero, so they don’t affect time calculations for the project.
The Priority List Model • A project digraph is a great to describe the information we have, but we need something that tells us how to make a schedule. • To do this, we make a priority list in which we put the tasks in order of their priority of execution. • If task X comes before task Y in the priority list, we should try to accomplish X before Y.
A(6) D(2) B(5) END (0) START (0) C(7) E(5) Example 2:Launching a Satellite • Suppose we are launching a satellite that has five different system checks that need to be done by two different computers P1 and P2. We will call the system checks A(6), B(5), C(7), D(2), and E(5). • Now assume the priority list is in reverse alphabetical order, so the precedence relations are given by the following digraph: Priority List: E(5), D(2), C(7), B(5), A(6)
X X A Helpful Hint • When creating a schedule, it can be helpful to update your priority list as you go by using these symbols: X Task X is ready. Task X is in execution. Task X is completed. X Task X is ineligible.
A(6) D(2) B(5) END (0) START (0) C(7) E(5) Example 2 (continued) • Time T=0 hr (start of project). C(7), B(5), and A(6) are the only ready tasks. Following the priority list, we assign C(7) to P1,and B(5) P2. • Time T=5 hr. P1 is still busy with C(7); P2 has just completed B(5). A(6) is the only available ready task. We assign A(6) to P2. • Time T=7 hr. P1 has just completed C(7); P2 is busy with A(6). E(5) has just become a ready task. We assign E(5) to P1. • Time T=11 hr. P2has just completed A(6); P1 is busy with E(5). D(2) has just become ready, so we assign D(2) to P2. • Time T=12 hr. P1 has just completed E(5); P2 is busy with D(2). There are no tasks left, so P1 sits idle. • Time T=13 hr. P2 has just completed the last task, D(2). The project is complete. Finishing time is 13 hours. Priority List: E(5), D(2), C(7), B(5), A(6)
Example 2 (continued) We end up with the following schedule: Time: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 Idle C(7) E(5) B(5) A(6) D(2)
Decreasing-Time Algorithm • It seems logical that doing the longer tasks first may result in more optimal scheduling, so we consider the decreasing-time algorithm. • In this algorithm, we simply create a priority list in which the longest task comes first, then the second longest, and so on. We then use that priority list to make a schedule.
Decreasing-Time Algorithm (continued) • In most cases however, the decreasing-time algorithm does not yield an optimal schedule. • It can be much more efficient to look at the long term benefits of starting a task early in a project.
Critical Paths • The critical path for a vertex X is the path from X to END that has the longest total processing time. • Let’s go back to the Martian Habitat example: Consider the vertex HU.There are three paths from HU to END. (i) HU, IC, FW, END ---- processing time is 11 (ii) HU, PD, END ---- processing time is 7 (iii) HU, EU, END ---- processing time is 6 AP(7) AF(5) IF(5) PL(4) IC(1) FW(6) AW(6) IW(7) IP(4) PD(3) HU(4) START (0) END (0) AD(8) ID(5) PU(3) EU(2) So, the critical path for HU is HU, IC, FW, END, and its critical time is 11.
Backflow Algorithm • Finding critical paths using this method can become quite tedious in projects with a lot of tasks, so we use an algorithm called the backflow algorithm. • The algorithm moves backward from END to START building a critical path as it goes. • If we know the critical times for all the vertices “in front” of a vertex X, we choose among these the vertex with the largest critical time (call it C). • The critical time of X is then obtained by adding the processing time of X to the critical time of C. • We will write the critical time of a vertex in square brackets after the task’s processing time (which is in parentheses). • Once we have all the critical times, we get the critical path for a vertex by always moving to the adjacent vertex with the greatest critical time.
AP(7) AF(5) IF(5) PL(4) IC(1) FW(6) AW(6) IW(7) IP(4) PD(3) HU(4) START (0) END (0) AD(8) ID(5) PU(3) EU(2) Return to the Martian Habitat Example [11] [7] [6] [3] [11] [0] [5] [2] • Step 1. We start at END, and assign a critical value of 0. • Step 2. We move backward to the three vertices that are incident to END, namely, FW(6), PD(3), and EU(2). For each of them, the critical time is its processing time plus zero, so the critical times are FW[6], PD[3], and EU[2]. • Step 3. From FW[6], we move backward to IC(1). The only vertex incident from IC(1) is FW[6], so the critical time for IC is [1+6 = 7]. We record a [7] next to IC in the graph. • Step 4. We move backward to HU(4). There are three vertices incident from it (IC[7], PD[3], and EU[2]), and the one with the largest critical time is IC[7]. It follows that the critical time for HU is [4+7=11]. At this stage, we can also find critical times of PL(4), and PU(3). For PL(4), the only vertex incident from it is IC[7], so its critical time is [4+7=11]. For PU(3), the only vertex incident from it is EU[2], so its critical time is [3+2=5].
[11] [7] [6] [3] [11] [0] AP(7) [5] [2] AF(5) IF(5) PL(4) IC(1) FW(6) AW(6) IW(7) IP(4) PD(3) HU(4) START (0) END (0) AD(8) ID(5) PU(3) EU(2) [34] [32] [27] [28] [22] [15] [34] [18] [10] • Step 5. We move backward to IP(4). There are two vertices incident from it (HU[11] and PU[5]). The critical time for IP is [4+11=15]. We can also move backward to ID(5) and find its critical time, which is [10]. • Step 6. We can now move backward to IW(7), we can see that its critical time is [7+15=22]. • Step 7. Move backward to IF(5), and we can see that its critical time is [5+22=27]. • Step 8. We now move back to AP(7), AF(5), AW(6) and AD(8). Their respective critical times are [7+27=34], [5+27=32], [6+22=28], and [8+10=18]. • Step 9. Finally, we move to START, following the same rules. The critical time is [0+34=34]. This is the critical time for the entire project.
AP(7) [34] AF(5) [32] IF(5) [27] PL(4) [11] IC(1) [7] FW(6) [6] AW(6) [28] IW(7) [22] IP(4) [15] PD(3) [3] HU(4) [11] START (0) [34] END (0) [0] AD(8) [18] ID(5) [10] PU(3) [5] EU(2) [2] To find the critical path for this project we just follow the veritices with the largest critical time. START, AP, IE, IW, IP, HU, IC, FW, END
Critical-Path Algorithm • Make a priority list in which tasks are written in order of decreasing critical times. • Create a schedule using that priority list. • Although the critical-path algorithm is the best and most commonly used scheduling algorithm, it does not guarantee an optimal schedule.
AP(7) [34] AF(5) [32] IF(5) [27] PL(4) [11] IC(1) [7] FW(6) [6] AW(6) [28] IW(7) [22] IP(4) [15] PD(3) [3] HU(4) [11] START (0) [34] END (0) [0] AD(8) [18] ID(5) [10] PU(3) [5] EU(2) [2] Critical Path Algorithm (continued) If we use the critical path algorithm for the Martian habitat problem, we get the following priority list: AP[34], AF[32], AW[28], IF[27], IW[22], AD[18], IP[15], PL[11], HU[11], ID[10], IC[7], FW[6], PU[5], PD[3], EU[2]
Time: 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 P1 HU IC AP IF IW IP FW EU P2 AF AW AD PL ID PU PD Idle The finishing time is 36 hours. However, it is not an optimal schedule, by trial and error, we find the optimal schedule: Time: 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 P1 AP IF IW IP ID IC FW P2 AF AW AD PL HU PD PU EU Critical Path Algorithm (continued) The schedule that results from the previous priority list looks like this: The finishing time is 35 hours
Class Example • Given the following digraph and priority list, schedule the project with two processors: A(8) D(12) F(1) START (0) B(5) END (0) C(9) E(6) G(2) Priority List: D, C, A, E, B, G, F
Solution Time: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 C(9) Idle P1 E(6) G(2) P2 A(8) B(5) D(12) F(1)