MATHEMATICAL THOUGHT AND PRACTICE Chapter 8: The Mathematics of Scheduling Chasing the Critical Path The Basic Elements of Scheduling The Mathematics of Scheduling The tasks. We define a task as an indivisible unit of work and thus always carried out by a single i l processor. W We use capital letters A, B, C…, to represent the tasks. At any time, a task can be : The processors. Every job requires workers. N represents the number of processors and P1, P2, P3, … PN to denote the processors themselves. The Mathematics of Scheduling The processing times. The processing time for a given task X is the amount of time, without interruption, required by one processor to execute X. X Thus, Th the h notation i X(5) tells us that the task called X has a processing time of 5 units. Completed In execution Ready Ineligible 1 The Mathematics of Scheduling The Mathematics of Scheduling The precedence relations. Precedence relations are formal restrictions on the order in which the tasks can be executed, much like those course prerequisites that tell you that you can’t take course Y until you have completed course X. A precedence relation can be conveniently abbreviated by writing X→Y or described graphically in (a). The Mathematics of Scheduling When a pair of tasks X and Y have no precedence requirements, the tasks are independent. Graphically, there are no arrows connecting them (b). The Mathematics of Scheduling We cannot have a set of precedence relations that form a cycle as shown in (d). Clearly, this is logically impossible! The Mathematics of Scheduling Precedence relations are transitive: If X→Y and Y→Z , then it must be true that X→Z as shown in (c). Repairing a Wreck www.bbc.co.uk Imagine you just wrecked your car. The garage has two processors, P1 and P2. The repairs can be broken i into four f tasks: k (A) exterior i body (4 hours), (B) engine repairs (5 hours), (C) painting and exterior finish (7 hours), and (D) repair transmission (3 hours). The only precedence relation A→ C . 2 Repairing a Wreck (a) is very inefficient: All short tasks are assigned to P1 and long to P2. The project finishing time (duration from the start to finish) is 12 hours. So Fin = 12 hours. (b) looks better but violates precedence: A→ C. But if we force P2 to be idle for one hour, we get a perfectly good schedule as shown in (c). Fin = 11 hours. Digraphs www.shamogi.de Repairing a Wreck Can we do better? No! The precedence relation A(4)→ C(7) implies that the 11 hours is a minimum barrier. So (c) is an optimal schedule and Fin = Opt = 11 hours is the optimal finishing time. Another optimal schedule is (d). Romantic Love A directed graph or digraph for short, is a graph in which the edges have a direction associated with them, typically shown with arrows. Digraphs are particularly useful when we want to describe asymmetric relationships. We have four possible scenarios: Neither loves the other (a), X loves Y but Y doesn’t love X (b), Y loves X but X doesn’t love Y (c), and they love each other (d). blogs.discovermagazine.com Terminology Example If XY is an arc, X is incident to Y or Y is incident from X. The arc YZ is said to by adjacent to XY if YZ starts where XY ends. Ap path from consists of a sequence q of arcs such that each is adjacent to the one before and no arc appears more than once. When the path starts and ends at the same vertex, we call it a cycle of the digraph. The outdegree of vertex X is the number of arcs that start at X (outgoing arcs); the indegree of X is the number of arcs that end at X (incoming arcs). 3 Clicker Quicker Sticker Clicker Quicker Sticker Clicker Quicker Sticker Scheduling with Priority Lists www.gtdtimes.com Priority Lists A priority list is a list of all the tasks prioritized in the order we prefer them. If task X comes before task Y, then X gets priority over Y. So X is executed ahead of Y unless X is not ready for execution, in which case we skip X. Priority List Timelines To keep track on the priority list itself, ready tasks are circled in red, (a). Executed task have a single red slash, (b). Completed tasks have a second slash, (c). Tasks that remain ineligible remain unmarked as shown in (d). 4 Decreasing-Time Algorithm To find a good priority list: (1) Do longer jobs first and (2) Shorter jobs last. A priority list in decreasing order of processing times is called a decreasingtime priority list, and creating a schedule using such a list is called decreasing-time algorithm. Decreasing-Time Algorithm Decreasing-time priority list: AD(8), AP(7), IW(7), AW(6), FW(6), AF(5), IF(5), ID(5), IP(4), HU(4), PU(3), PD(3), EU(2), IC (1) Project Digraph Decreasing-Time Algorithm Clicker Quicker Sticker Clicker Quicker Sticker 5 Clicker Quicker Sticker Clicker Quicker Sticker Clicker Quicker Sticker Critical Paths and Critical Times The critical path for a vertex X is the path from X to END with longest processing time. When we add the processing times of all the tasks along the critical path for a vertex X, we get the critical time for X. (By definition, the critical time of END is 0.) api.ning.com Critical Paths and Critical Times The critical path for a project is the path with longest processing time from START to END. The total processing time for this path is the critical time for the project. The Backflow Algorithm farm4.static.flickr.com Step 1 Find the critical time for every vertex by starting at END and working toward START according to this rule: critical time for X = processing time of X + largest critical time of vertices incident from X. Step 2 Once we have the critical time for every vertex, critical paths are found by just following the path along largest critical times. 6 The Critical Path Algorithm The Critical Path Algorithm Critical paths can be used to create very good schedules using critical times rather than processing times to prioritize the tasks. The priority i it list li t we obtain bt i when h we write it the th tasks t k in decreasing order of critical times (with ties broken randomly) is called the critical-time priority list, and the process of creating a schedule using the critical-time priority list is called the critical-path algorithm. Critical-Path Algorithm Backflow & Critical Path Algorithms Step 1 Find critical times using the backflow algorithm. algorithm Step 2 Create priority list. Step 3 Create schedule. (b) What is the critical path? Clicker Quicker Sticker Clicker Quicker Sticker 7 Scheduling with Independent Tasks What happens to scheduling problems in the special case when there are no precedence relations to worry about tasks that are all independent? There are no efficient optimal algorithms known for scheduling, even when the tasks are all independent. Scheduling with Independent Tasks www.indiana.edu We assign the tasks to the processors as they become free in exactly the order given by the priority list. The critical-path time of a task equals its processing time, meaning the decreasing-time algorithm and the critical-path algorithm become one and the same. ldsfreedom.files.wordpress.com Relative Error Clicker Quicker Sticker If we know the optimal finishing time Opt, we can measure how “close” a particular schedule is p being optimal using the concept of relative error. For a project with finishing time Fin, the relative error is given by ε. renfah.sonance.net ε= Clicker Quicker Sticker Fin − Opt Opt Clicker Quicker Sticker 8 Clicker Quicker Sticker MATHEMATICAL THOUGHT AND PRACTICE Mini-Excursion 2: A Touch of Color Graph Coloring Graph Coloring Can’t We All Get Along? Planning a wedding reception for a contentious family, we need to seat people so that fights don’t break out, unfortunately. mydreamwedding.cn Can’t We All Get Along? Coloring 9 Coloring Complete Graphs Coloring Complete Graphs The only possible way to color is to use a different color for each vertex, as in (b). Thus, we can conclude that X(K5) = 5. We generalize so X(Kn) = n. X(K100) = 100. Greedy Algorithm for Coloring Brook’s Theorem Sudoku Sudoku Each row, column, and block must have 1, 2, 3, 4, 5, 6, 7, 8, and 9 appearing exactly once. (C6) = 2 but X(C5) = 3. If n is odd and greater than 3, X(Cn) = 3. If n is even, even X(Cn) = 2 2. X Each vertex represents a cell, and the cells that cannot have the same numbers are connected with edges. Each of the 81 vertices then has degree 20. 10 Sudoku Four Color Theorem To solve the puzzle, we need only color the graph (Greedy Algorithm) and then replace colors with numbers. Map Coloring Any map (in a plane) can be colored with four colors or less so that no two adjacent countries have the same color. Clicker Quicker Sticker Each vertex is a country and edges show adjacencies. A is adjacent to F, E, and B. Then, color with the Greedy Algorithm. Clicker Quicker Sticker Homework Do online homework Do paper homework Do quiz M t with Meet ith me Prepare group projects Do the final exam review 11
© Copyright 2026 Paperzz