a mathematical view of our world 1 st ed. parks, musser, trimpe, maurer, and maurer

153
A Mathematical A Mathematical View of Our View of Our World World 1 1 st st ed. ed. Parks, Musser, Parks, Musser, Trimpe, Maurer, and Trimpe, Maurer, and Maurer Maurer

Upload: lisa-kennedy

Post on 23-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

A Mathematical View A Mathematical View of Our Worldof Our World

11stst ed. ed.

Parks, Musser, Trimpe, Parks, Musser, Trimpe, Maurer, and MaurerMaurer, and Maurer

Page 2: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Chapter 7Chapter 7

SchedulingScheduling

Page 3: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Section 7.1Section 7.1

Basic Concepts of SchedulingBasic Concepts of Scheduling• GoalsGoals

• Study project schedulingStudy project scheduling• Study tasksStudy tasks• Find finishing timesFind finishing times

• Study weighted digraphsStudy weighted digraphs• Study maximal pathsStudy maximal paths• Find critical timesFind critical times

Page 4: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

7.1 Initial Problem7.1 Initial Problem

• A model railroad club is preparing for an open A model railroad club is preparing for an open house.house.

• Estimate the minimum preparation time required. Estimate the minimum preparation time required. • The solution will be given at the end of the section.The solution will be given at the end of the section.

Page 5: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

TasksTasks• A project consists of 2 or more smaller A project consists of 2 or more smaller

activities called activities called taskstasks. . • A task cannot be broken into smaller jobs.A task cannot be broken into smaller jobs.

• A task is done by 1 machine or 1 person.A task is done by 1 machine or 1 person.

• The amount of time needed to complete a The amount of time needed to complete a project depends on: project depends on: • How many people or machines are available to How many people or machines are available to

do the work.do the work.

• How the tasks are assigned. How the tasks are assigned.

Page 6: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1Example 1• A group of college students are making A group of college students are making

lasagna.lasagna.• Divide the project into tasks.Divide the project into tasks.

Page 7: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’d

• Solution: A possible list of tasks is given.Solution: A possible list of tasks is given.

Page 8: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Tasks, cont’dTasks, cont’d

• The people or machines performing the The people or machines performing the tasks are called tasks are called processorsprocessors..

• The amount of time it takes to perform The amount of time it takes to perform a task is called its a task is called its completion timecompletion time..

Page 9: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Tasks, cont’dTasks, cont’d• If one task must be completed before If one task must be completed before

another task can be started, we say the another task can be started, we say the tasks have a tasks have a precedence relationprecedence relation or or order order requirementrequirement between them. between them.• Tasks that may be done in any order are called Tasks that may be done in any order are called

independentindependent..

• One way to represent a precedence relation One way to represent a precedence relation between 2 tasks is to use points to denote the between 2 tasks is to use points to denote the tasks and an arrow to indicate the relationship.tasks and an arrow to indicate the relationship.

Page 10: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2Example 2

a)a) The tasks of putting on socks and The tasks of putting on socks and putting on shoes have a preference putting on shoes have a preference relation.relation.

Page 11: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

b)b) The tasks of putting on a hat and The tasks of putting on a hat and putting on a coat do not have a putting on a coat do not have a preference relation. These are preference relation. These are independent tasks.independent tasks.

Page 12: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question:Question:Choose the list of tasks that has no Choose the list of tasks that has no preference relations. preference relations.

a. bake the pizza, grate some cheese, a. bake the pizza, grate some cheese, make pizza saucemake pizza sauceb. fold some clothes, wash some b. fold some clothes, wash some clothes, hang clothes on the line to dryclothes, hang clothes on the line to dryc. bake the cake, toss the green salad, c. bake the cake, toss the green salad, set the tableset the tabled. frost the cake, bake the cake, set the d. frost the cake, bake the cake, set the table table

Page 13: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

DigraphsDigraphs

• A collection of points (tasks) and A collection of points (tasks) and straight or curved arrows (precedence straight or curved arrows (precedence relations) connecting them is called a relations) connecting them is called a directed graphdirected graph or or digraphdigraph..• A point in a digraph is called a A point in a digraph is called a vertexvertex..

• An arrow in a digraph is called an An arrow in a digraph is called an arcarc..

Page 14: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3Example 3

• Use a digraph to represent the Use a digraph to represent the precedence relations for a man precedence relations for a man dressing to go for a run in the summer.dressing to go for a run in the summer.

• The tasks consist of putting on:The tasks consist of putting on:• A ShirtA Shirt

• ShoesShoes

• ShortsShorts

• SocksSocks

Page 15: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution: Determine if there are any Solution: Determine if there are any order requirements among the tasks.order requirements among the tasks.• Socks must be put on before shoes.Socks must be put on before shoes.

• It is much easier to put on shorts before It is much easier to put on shorts before shoes.shoes.

• The shirt can be put on at any point in the The shirt can be put on at any point in the process. process.

Page 16: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: A possible digraph is shown Solution, cont’d: A possible digraph is shown

below.below.

Page 17: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Digraphs, cont’dDigraphs, cont’d

• A digraph that contains at least one A digraph that contains at least one precedence relation is called an precedence relation is called an order-order-requirement digraphrequirement digraph..

• A vertex in a digraph with no arcs A vertex in a digraph with no arcs attached to it is said to be attached to it is said to be isolatedisolated..

Page 18: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Digraphs, cont’dDigraphs, cont’d• Example: Example:

• The digraph from the previous example problem The digraph from the previous example problem is an order-requirement digraph.is an order-requirement digraph.

• Vertex “put on shirt” is isolated.Vertex “put on shirt” is isolated.

Page 19: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4Example 4

• Construct an order-requirement digraph Construct an order-requirement digraph for the tasks of:for the tasks of:• Making blackberry jamMaking blackberry jam

• Making blackberry cobblerMaking blackberry cobbler

• Picking blackberriesPicking blackberries

Page 20: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d• Solution: Solution:

• The berries must be picked first.The berries must be picked first.

• The jam and cobbler can be made in any order. The jam and cobbler can be made in any order.

Page 21: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5Example 5• Construct an order-requirement digraph Construct an order-requirement digraph

for the tasks of:for the tasks of:• Putting on socksPutting on socks

• Putting on a sweatshirtPutting on a sweatshirt

• Putting on snow pantsPutting on snow pants

• Putting on a hatPutting on a hat

• Putting on bootsPutting on boots

• Strapping on a snowboardStrapping on a snowboard

Page 22: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution: Solution: • The socks probably go on before the The socks probably go on before the

pants.pants.

• The pants go on before the boots.The pants go on before the boots.

• The boots go on before the snowboard.The boots go on before the snowboard.

• The sweatshirt goes on before the coat.The sweatshirt goes on before the coat.

• The hat can be put on at any point. The hat can be put on at any point.

Page 23: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: The digraph is shown Solution, cont’d: The digraph is shown below. below.

Page 24: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

PathsPaths

• Any list of 2 or more vertices connected Any list of 2 or more vertices connected by arrows such that the list goes in the by arrows such that the list goes in the same direction as the arcs in the same direction as the arcs in the corresponding digraph is called a corresponding digraph is called a directed pathdirected path..• Because we consider only directed paths, Because we consider only directed paths,

we simply call the list a we simply call the list a pathpath. .

Page 25: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 6Example 6• Identify all possible paths in the order-Identify all possible paths in the order-

requirement digraph representing a simple requirement digraph representing a simple version of the project of replacing old brake version of the project of replacing old brake shoes.shoes.

Page 26: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 6, cont’dExample 6, cont’d• Solution: There are 6 Solution: There are 6

possible paths.possible paths.

1 3T T1 2T T

2 4T T

3 4T T

1 2 4T T T

1 3 4T T T

Page 27: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Paths, cont’dPaths, cont’d• A path that cannot be extended by adding A path that cannot be extended by adding

a vertex at either end is called a a vertex at either end is called a maximal maximal pathpath..• In the previous example, the maximal paths In the previous example, the maximal paths

were:were:•

1 2 4T T T

1 3 4T T T

Page 28: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Sources and SinksSources and Sinks

• A vertex in a digraph that is at the end A vertex in a digraph that is at the end of no arc is called a of no arc is called a sourcesource..

• A vertex in a digraph that is at the A vertex in a digraph that is at the start of no arc is called a start of no arc is called a sinksink. . • An isolated vertex is both a source and a An isolated vertex is both a source and a

sink.sink.

• A maximal path starts at a source and A maximal path starts at a source and ends at a sink.ends at a sink.

Page 29: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Sources and Sinks, cont’dSources and Sinks, cont’d

• In this digraph In this digraph from the previous from the previous example,example,

• Vertex Vertex TT11 is a is a

source.source.

• Vertex Vertex TT44 is a is a

sink.sink.

Page 30: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question:Question:Identify all sources and sinks. Identify all sources and sinks.

a. Sources: put on socks; Sinks: put on hata. Sources: put on socks; Sinks: put on hat

b. Sources: put on hat, put on coat, strap on b. Sources: put on hat, put on coat, strap on

snowboard; Sinks: put on socks, put on sweatshirtsnowboard; Sinks: put on socks, put on sweatshirt

c. Sources: put on hat; Sinks: put on socksc. Sources: put on hat; Sinks: put on socks

d. Sources: put on socks, put on sweatshirt; d. Sources: put on socks, put on sweatshirt;

Sinks: put on hat, put on coat, strap on snowboard Sinks: put on hat, put on coat, strap on snowboard

Page 31: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Finding all Maximal PathsFinding all Maximal Paths

• To find all maximal paths in a To find all maximal paths in a digraph:digraph:

1)1) Locate all the sinks that are not Locate all the sinks that are not isolated vertices.isolated vertices.

2)2) Locate all the sources that are not Locate all the sources that are not isolated vertices.isolated vertices.

Page 32: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Finding Maximal Paths, cont’dFinding Maximal Paths, cont’d

3)3) For each source, follow the arcs until For each source, follow the arcs until you reach a sink.you reach a sink.

4)4) If there is more than one arc at any If there is more than one arc at any vertex along the path formed in Step vertex along the path formed in Step 3, start again at the same source and 3, start again at the same source and choose a different route. choose a different route.

Page 33: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question:Question:Which path listed below is Which path listed below is notnot a maximal a maximal path? path?

a. put on hata. put on hat

b. put on pants, put on bootsb. put on pants, put on boots

c. put on sweatshirt, put on coatc. put on sweatshirt, put on coat

d. put on socks, put on pants, put on boots, d. put on socks, put on pants, put on boots, strap on snowboard strap on snowboard

Page 34: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 7Example 7

• Identify all maximal paths in the digraph.Identify all maximal paths in the digraph.

Page 35: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 7, cont’dExample 7, cont’d

• Solution:Solution:

1)1) There is only one sink: There is only one sink: TT66

2)2) There is only one source: There is only one source: TT11

Page 36: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 7, cont’dExample 7, cont’d

• Solution, cont’d:Solution, cont’d:

3)3) A maximal path from A maximal path from TT1 1 to to TT6 6 is is

4)4) Another maximal path from Another maximal path from TT1 1 to to TT6 6 isis

1 2 3 5 6T T T T T

1 2 4 5 6T T T T T

Page 37: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 8Example 8• Identify all maximal paths in the digraph.Identify all maximal paths in the digraph.

Page 38: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 8, cont’dExample 8, cont’d

• Solution:Solution:

1)1) There is only one sink: There is only one sink: TT1010

Page 39: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 8, cont’dExample 8, cont’d

• Solution, cont’d:Solution, cont’d:

2)2) There are 4 sources: There are 4 sources: TT11, , TT4 4 , , TT66, and , and TT8.8.

Page 40: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 8, cont’dExample 8, cont’d• Solution, cont’d:Solution, cont’d:

3)3) There are 4 maximal paths:There are 4 maximal paths:•

1 2 3 9 10T T T T T

8 9 10T T T

6 7 9 10T T T T

4 5 9 10T T T T

Page 41: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Weighted DigraphsWeighted Digraphs• The completion time associated with a The completion time associated with a

vertex (task) is the vertex (task) is the weightweight of the vertex. of the vertex.• A digraph with weights at each vertex is A digraph with weights at each vertex is

called a called a weighted digraphweighted digraph..• For example: This weighted digraph shows that For example: This weighted digraph shows that

it takes 20 seconds to put on sock and 25 it takes 20 seconds to put on sock and 25 seconds to put on shoes.seconds to put on shoes.

Page 42: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 9Example 9• Construct a weighted digraph. Construct a weighted digraph.

Page 43: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 9, cont’dExample 9, cont’d• Solution: Solution:

Page 44: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Project Finishing TimeProject Finishing Time• The time from the beginning of a project until The time from the beginning of a project until

the end of the project is called the the end of the project is called the finishing finishing timetime for the project. for the project.

• The finishing time depends on:The finishing time depends on:• The task completion times.The task completion times.

• The number of processors available.The number of processors available.

• How the processors are scheduled.How the processors are scheduled.

• Whether or not some tasks can be done at the Whether or not some tasks can be done at the same time.same time.

Page 45: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 10Example 10• If only one processor works on the lasagna If only one processor works on the lasagna

project, what is the finishing time?project, what is the finishing time?

Page 46: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 10, cont’dExample 10, cont’d

• Solution: We assume the processor can Solution: We assume the processor can only perform one task at a time.only perform one task at a time.• Add up all the task completion times: Add up all the task completion times:

10 + 5 + 30 + 10 + 10 + 2 + 6 + 7 + 8 + 30 10 + 5 + 30 + 10 + 10 + 2 + 6 + 7 + 8 + 30 = 118 minutes.= 118 minutes.

• It will take one processor almost 2 hours It will take one processor almost 2 hours to finish the project.to finish the project.

Page 47: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Weighted Digraphs, cont’dWeighted Digraphs, cont’d• The The weightweight of a path in a weighted of a path in a weighted

order-requirement digraph is the sum of order-requirement digraph is the sum of the weights at the vertices on the path.the weights at the vertices on the path.

• A A critical pathcritical path in an order-requirement in an order-requirement digraph is a path having the largest digraph is a path having the largest possible weight.possible weight.• The weight of a critical path is called the The weight of a critical path is called the

critical timecritical time for the project. for the project.

Page 48: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Weighted Digraphs, cont’dWeighted Digraphs, cont’d

• Any critical path must be a maximal Any critical path must be a maximal path.path.

• To find the critical paths:To find the critical paths:• Find all the maximal paths.Find all the maximal paths.

• Select the maximal path(s) with the largest Select the maximal path(s) with the largest weight.weight.

Page 49: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 11Example 11• Find a critical path in the lasagna project Find a critical path in the lasagna project

digraph. digraph.

Page 50: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 11, cont’dExample 11, cont’d• Solution: Previously we found 4 Solution: Previously we found 4

maximal paths.maximal paths.•

1 2 3 9 10T T T T T

8 9 10T T T

6 7 9 10T T T T

4 5 9 10T T T T

Page 51: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 11, cont’dExample 11, cont’d

• Solution, cont’d:Solution, cont’d:

Page 52: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 11, cont’dExample 11, cont’d• Solution, cont’d: The largest weight for any Solution, cont’d: The largest weight for any

maximal path is 83.maximal path is 83.• The one critical path isThe one critical path is

• The critical time for the project is 83 minutes.The critical time for the project is 83 minutes.

• It will take a minimum of 83 minutes, with It will take a minimum of 83 minutes, with enough processors, to make the lasagna.enough processors, to make the lasagna.

• This example illustrates the fact that the This example illustrates the fact that the finishing time of a project is always greater finishing time of a project is always greater than or equal to its critical time.than or equal to its critical time.

1 2 3 9 10T T T T T

Page 53: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

7.1 Initial Problem Solution7.1 Initial Problem Solution• A model railroad club is preparing for an open house. A model railroad club is preparing for an open house. • What is the minimum completion time?What is the minimum completion time?

Page 54: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• The first 6 tasks need to be done first and in The first 6 tasks need to be done first and in order.order.

• Task 7 must be done before task 8.Task 7 must be done before task 8.• Everything else must be done before task 10. Everything else must be done before task 10.

Page 55: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d• A weighted digraph is created. A weighted digraph is created.

Page 56: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Find all maximal paths, along with their Find all maximal paths, along with their weights.weights.

Page 57: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• The critical time of the project is 52 The critical time of the project is 52 hours.hours.

• The finishing time is greater than or The finishing time is greater than or equal to the critical time, so it will take at equal to the critical time, so it will take at least 52 hours to prepare for the open least 52 hours to prepare for the open house.house.

Page 58: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Section 7.2Section 7.2

List-Scheduling AlgorithmList-Scheduling Algorithm

• GoalsGoals

• Study project schedulingStudy project scheduling• Study priority listsStudy priority lists• Use the list-scheduling algorithmUse the list-scheduling algorithm• Create and read Gantt chartsCreate and read Gantt charts• Study optimal schedulesStudy optimal schedules

Page 59: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

7.2 Initial Problem7.2 Initial Problem

• Suppose 2 students will make the lasagna in the Suppose 2 students will make the lasagna in the project examined in Section 7.1.project examined in Section 7.1.

• What is a good way for the 2 students to divide the What is a good way for the 2 students to divide the work and how long will it take? work and how long will it take? • The solution will be given at the end of the section.The solution will be given at the end of the section.

Page 60: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Priority ListsPriority Lists

• A A priority listpriority list is an ordered list of all the is an ordered list of all the tasks in a project.tasks in a project.• When tasks are performed, precedence When tasks are performed, precedence

relations override a priority list.relations override a priority list.

• A priority list tells you which task to do first A priority list tells you which task to do first among those you can do at a certain point among those you can do at a certain point in time.in time.

Page 61: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1Example 1• A woodworking project consists of 7 tasks.A woodworking project consists of 7 tasks.

Page 62: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’d

• The weighted digraph above represents the The weighted digraph above represents the project, with completion times in minutes.project, with completion times in minutes.

• Determine the critical time.Determine the critical time.• Create a priority list based on completion time, Create a priority list based on completion time,

from shortest to longest. from shortest to longest.

Page 63: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’d• Solution: The 3 Solution: The 3

maximal paths, maximal paths, and their weights, and their weights, are listed.are listed.

Page 64: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’d

• Solution, cont’d: The largest weight of Solution, cont’d: The largest weight of a maximal path in this case is 90 a maximal path in this case is 90 minutes.minutes.• The critical time is 90 minutes.The critical time is 90 minutes.

Page 65: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’d• Solution, cont’d: Solution, cont’d:

The tasks are The tasks are placed in a priority placed in a priority list according to list according to their completion their completion times.times.

• The priority list is The priority list is TT11, ,

TT55, T, T22, T, T33, T, T66, T, T77,, and and

TT44..

Page 66: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Priority Lists, cont’dPriority Lists, cont’d• A priority list in which tasks are A priority list in which tasks are

arranged from shortest completion arranged from shortest completion time to longest completion time is time to longest completion time is called an called an increasing-time priority listincreasing-time priority list..

• A priority list in which tasks are A priority list in which tasks are arranged from longest completion arranged from longest completion time to shortest completion time is time to shortest completion time is called a called a decreasing-time priority listdecreasing-time priority list

Page 67: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question:Question:

Create the decreasing-time priority list Create the decreasing-time priority list for the project whose digraph is shown for the project whose digraph is shown below. below.

a.a.

b.b.

c.c.

d.d.

7 56 2 8 9 1 4 3 10, , , , , , , , ,T T T T T T T T T T

1 2 3 4 5 6 7 8 9 10, , , , , , , , ,T T T T T T T T T T

10 3 5 4 1 9 8 7 2 6, , , , , , , , ,T T T T T T T T T T

10 9 8 7 6 5 4 3 2 1, , , , , , , , ,T T T T T T T T T T

Page 68: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2Example 2• How would one processor finish the How would one processor finish the

woodworking project from the previous woodworking project from the previous example using the increasing-time priority example using the increasing-time priority list list TT11, T, T55, T, T22, T, T33, T, T66, T, T77, and , and TT44??

Page 69: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d• Solution: Use the precedence relations Solution: Use the precedence relations

and the priority list to determine the order and the priority list to determine the order of the tasks.of the tasks.

• Task Task TT11 is a source and is first on the list, so it is a source and is first on the list, so it

will be done first.will be done first.

• Next, either Next, either TT22 or or TT33 could be done. Choose could be done. Choose TT22

because it is first in the list.because it is first in the list.

• At this point, the tasks that can be done are At this point, the tasks that can be done are TT33

or or TT55. According to the priority list, choose . According to the priority list, choose TT55..

Page 70: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: The order of the rest of Solution, cont’d: The order of the rest of the tasks is determined in the same the tasks is determined in the same manner.manner.

• The priority list is The priority list is TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T4.4.

• The order in which the tasks will be completed The order in which the tasks will be completed is is TT11, T, T22, T, T55, T, T33, T, T66, T, T44, T, T77 . .

Page 71: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Gantt ChartsGantt Charts

• We can keep track of the order in We can keep track of the order in which tasks are done and how long it which tasks are done and how long it takes using a diagram called a takes using a diagram called a Gantt Gantt chartchart..

• Numbers at the bottom of the chart show Numbers at the bottom of the chart show the elapsed time.the elapsed time.

• The boxes represent the tasks.The boxes represent the tasks.

Page 72: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Gantt Charts, cont’dGantt Charts, cont’d

• A Gantt chart for the woodworking project A Gantt chart for the woodworking project in the previous example is shown below.in the previous example is shown below.

Page 73: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

DefinitionsDefinitions• A task A task TT will be called will be called readyready if all if all

tasks required to begin tasks required to begin TT have been have been completed.completed.

• A processor that has not yet been A processor that has not yet been assigned a task and is not working on assigned a task and is not working on a task will be called a task will be called idleidle..

• At the beginning of a project we assume At the beginning of a project we assume all processors are idle and at least 1 task all processors are idle and at least 1 task is ready.is ready.

Page 74: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

List-Processing AlgorithmList-Processing Algorithm

1)1) The lowest-numbered idle processor The lowest-numbered idle processor is assigned to the highest-priority is assigned to the highest-priority ready task until either all processors ready task until either all processors are assigned or all ready tasks have are assigned or all ready tasks have been assigned.been assigned.

Page 75: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

List-Processing Algorithm, cont’dList-Processing Algorithm, cont’d

2)2) When a processor completes a task, that When a processor completes a task, that processor becomes idle. One of 3 cases processor becomes idle. One of 3 cases will occur.will occur.

A.A. If there are ready tasks, repeat Step 1.If there are ready tasks, repeat Step 1.

B.B. If there are no ready tasks but not every task If there are no ready tasks but not every task has been done, the processor remains idle has been done, the processor remains idle until more tasks are completed.until more tasks are completed.

C.C. If all tasks have been completed, the project If all tasks have been completed, the project is finished.is finished.

Page 76: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3Example 3• Apply the algorithm to the wood-working Apply the algorithm to the wood-working

project using 2 processors and the project using 2 processors and the increasing-time priority list increasing-time priority list TT11, T, T55, T, T22, T, T33, T, T66, ,

TT77, T, T44..

Page 77: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution: Step 1:Solution: Step 1:

• PP11 is assigned to is assigned to

TT11..

• PP22 remains idle. remains idle.

Page 78: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 5 minutes, Step 2, Solution, cont’d: At 5 minutes, Step 2, Case A.Case A.

• Ready: Ready: TT22, T, T33. .

• Not completed: Not completed: TT22, T, T33, T, T44, T, T55, T, T66, T, T77..

• Priority list: Priority list: TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T44..

Page 79: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: Step 1:Solution, cont’d: Step 1:

• PP11 and and PP22 are idle. are idle.

• PP11 is assigned to is assigned to TT22..

• PP22 is assigned to is assigned to TT33..

Page 80: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 20 minutes, Step Solution, cont’d: At 20 minutes, Step 2, Case A.2, Case A.

• Ready: Ready: TT55. .

• Not completed: Not completed: TT33, T, T44, T, T55, T, T66, T, T77..

• Priority list: Priority list: TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T4.4.

Page 81: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: Step 1:Solution, cont’d: Step 1:

• PP11 is idle. is idle.

• PP11 is assigned to is assigned to TT55..

Page 82: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 25 minutes, Step Solution, cont’d: At 25 minutes, Step 2, Case A.2, Case A.

• Ready: Ready: TT44, T, T66. .

• Not completed: Not completed: TT44, T, T55, T, T66, T, T77..

• Priority list: Priority list: TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T44..

Page 83: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: Step 1:Solution, cont’d: Step 1:

• PP22 is idle. is idle.

• PP22 is assigned to is assigned to TT66..

Page 84: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 30 minutes, Step Solution, cont’d: At 30 minutes, Step 2, Case A.2, Case A.

• Ready: Ready: TT44. .

• Not completed: Not completed: TT44, T, T66, T, T77..

• Priority list: Priority list: TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T4.4.

Page 85: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: Step 1:Solution, cont’d: Step 1:

• PP11 is idle.is idle.

• PP11 is assigned to is assigned to TT44..

Page 86: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 50 minutes, Step Solution, cont’d: At 50 minutes, Step 2, Case B.2, Case B.

• Ready: none. Ready: none.

• Not completed: Not completed: TT44, T, T77..

• Priority list: Priority list: TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T44..

Page 87: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: Step 1:Solution, cont’d: Step 1:

• PP22 remains idle. remains idle.

Page 88: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 65 minutes, Step Solution, cont’d: At 65 minutes, Step 2, Case A.2, Case A.

• Ready: Ready: TT77. .

• Not completed: Not completed: TT77..

• Priority list: Priority list: TT11, T, T55, T, T22, T, T33, T, T66, T, T77, T, T4.4.

Page 89: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: Step 1:Solution, cont’d: Step 1:

• PP11 and and PP22 are idle. are idle.

• PP11 is assigned to is assigned to TT77..

Page 90: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d

• Solution, cont’d: At 95 minutes, Step 2, Solution, cont’d: At 95 minutes, Step 2, Case C.Case C.

• Ready: none. Ready: none.

• Not completed: none.Not completed: none.

• The finishing time with 2 processors is 95 The finishing time with 2 processors is 95 minutes.minutes.

• This is less than 140 minutes for 1 processor, This is less than 140 minutes for 1 processor, but more than the critical time of 90 minutes.but more than the critical time of 90 minutes.

Page 91: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4Example 4• Apply the algorithm to the wood-working Apply the algorithm to the wood-working

project using 3 processors and the project using 3 processors and the increasing-time priority list increasing-time priority list TT11, T, T55, T, T22, T, T33, T, T66, ,

TT77, T, T44..

Page 92: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution: Step 1:Solution: Step 1:

• PP11 is assigned to is assigned to TT11..

• PP22 and and PP3 3 remain idle.remain idle.

Page 93: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 5 minutes: Step 2 Solution, cont’d: At 5 minutes: Step 2 and Step 1and Step 1

• PP11, P, P22 and and PP33 are idle.are idle.

• TT22 and and TT33 are ready.are ready.

• PP11 is assigned to is assigned to T T22..

• PP22 is assigned to is assigned to TT33..

• PP33 remains idle.remains idle.

Page 94: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 20 minutes: Step Solution, cont’d: At 20 minutes: Step 2 and Step 12 and Step 1

• PP11 and and PP33 are idle.are idle.

• TT55 is ready.is ready.

• PP11 is assigned to is assigned to TT55..

• PP33 remains idle.remains idle.

Page 95: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 25 minutes: Step Solution, cont’d: At 25 minutes: Step 2 and Step 12 and Step 1

• PP22 and and PP33 are idle.are idle.

• TT66 and and TT4 4 are ready.are ready.

• PP22 is assigned to is assigned to TT66..

• PP33 is assigned to is assigned to TT44..

Page 96: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 30 minutes: Step Solution, cont’d: At 30 minutes: Step 2 and Step 12 and Step 1

• PP11 is idle.is idle.

• No tasksNo tasks are ready.are ready.

• PP11 remains idle. remains idle.

Page 97: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 50 minutes: Step Solution, cont’d: At 50 minutes: Step 2 and Step 12 and Step 1

• PP11 and and PP22 are idle.are idle.

• No tasksNo tasks are ready.are ready.

• PP11 and and PP22 remain idle. remain idle.

Page 98: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 60 minutes: Step Solution, cont’d: At 60 minutes: Step 2 and Step 12 and Step 1

• PP11, P, P22 and and PP3 3 are idle.are idle.

• TT77 is ready.is ready.

• PP11 is assigned to is assigned to TT77..

Page 99: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d

• Solution, cont’d: At 90 minutes: Step Solution, cont’d: At 90 minutes: Step 2 and Step 12 and Step 1

• PP11, P, P22 and and PP33 are idle.are idle.

• No tasks are ready.No tasks are ready.

• All tasks have been completed.All tasks have been completed.

Page 100: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 4, cont’dExample 4, cont’d• The completion time with 3 processors is The completion time with 3 processors is

90 minutes, the critical time.90 minutes, the critical time.• The project completion is summarized in the The project completion is summarized in the

Gantt chart.Gantt chart.

Page 101: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5Example 5• Apply the algorithm to the wood-working Apply the algorithm to the wood-working

project using 2 processors and the project using 2 processors and the decreasing-time priority list decreasing-time priority list TT44, T, T77, T, T66, T, T33, ,

TT22, T, T55, T, T11..

Page 102: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution: Step 1:Solution: Step 1:

• PP11 is assigned to is assigned to TT11..

• PP22 remains idle.remains idle.

Page 103: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 5 minutes: Step 2 Solution, cont’d: At 5 minutes: Step 2 and Step 1and Step 1

• PP11 and and PP2 2 are idle.are idle.

• TT22 and and TT33 are ready.are ready.

• PP11 is assigned to is assigned to TT33..

• PP22 is assigned to is assigned to TT22..

Page 104: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 20 minutes: Step Solution, cont’d: At 20 minutes: Step 2 and Step 12 and Step 1

• PP2 2 is idle.is idle.

• TT55 is ready.is ready.

• PP22 is assigned to is assigned to TT55..

Page 105: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 25 minutes: Step Solution, cont’d: At 25 minutes: Step 2 and Step 12 and Step 1

• PP1 1 is idle.is idle.

• TT4 4 and and TT66 are ready.are ready.

• PP11 is assigned to is assigned to T T44..

Page 106: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 30 minutes: Step Solution, cont’d: At 30 minutes: Step 2 and Step 12 and Step 1

• PP22 is idle.is idle.

• TT66 is ready. is ready.

• PP22 is assigned to is assigned to TT66..

Page 107: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 55 minutes: Step Solution, cont’d: At 55 minutes: Step 2 and Step 12 and Step 1

• PP22 is idle.is idle.

• No tasks are ready.No tasks are ready.

• PP22 remains idle.remains idle.

Page 108: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 60 minutes: Step Solution, cont’d: At 60 minutes: Step 2 and Step 12 and Step 1

• PP11 and and PP2 2 are idle.are idle.

• TT77 is ready. is ready.

• PP11 is assigned to is assigned to TT77..

• PP22 remains idle.remains idle.

Page 109: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d: At 90 minutes: Step 2 and Solution, cont’d: At 90 minutes: Step 2 and Step 1Step 1

• PP11 and and PP22 are idle.are idle.

• No tasks are ready.No tasks are ready.

• All tasks are completed.All tasks are completed.

• The finishing time with the decreasing-time The finishing time with the decreasing-time priority list and 2 processors is 90 minutes.priority list and 2 processors is 90 minutes.

Page 110: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 5, cont’dExample 5, cont’d

• Solution, cont’d:Solution, cont’d:

Page 111: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question:Question:Given the priority list Given the priority list

and the digraph for the project, and the digraph for the project, which tasks will be assigned first if which tasks will be assigned first if there are 3 processors?there are 3 processors?

10 3 5 4 1 9 8 7 2 6, , , , , , , , ,T T T T T T T T T T

Page 112: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question cont’dQuestion cont’d

a. Processor 1: Task 4; Processor 2: a. Processor 1: Task 4; Processor 2: Task 1; Processor 3: Task 8Task 1; Processor 3: Task 8

b. Processor 1: Task 1; Processor 2: b. Processor 1: Task 1; Processor 2: Task 4; Processor 3: Task 6Task 4; Processor 3: Task 6

c. Processor 4: Task 1; Processor 2: c. Processor 4: Task 1; Processor 2: Task 1; Processor 3: Task 6Task 1; Processor 3: Task 6

d. Processor 1: Task 1; Processor 2: d. Processor 1: Task 1; Processor 2: Task 4; Processor 3: Task 8Task 4; Processor 3: Task 8

Page 113: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Optimal SchedulesOptimal Schedules

• An An optimal scheduleoptimal schedule is a schedule is a schedule assigning processors to tasks in such assigning processors to tasks in such a way that it results in the shortest a way that it results in the shortest possible finishing time for that project possible finishing time for that project with that number of processors. with that number of processors.

Page 114: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Optimal Schedules, cont’dOptimal Schedules, cont’d

• If the finishing time is equal to the critical If the finishing time is equal to the critical time, we know the schedule is optimal.time, we know the schedule is optimal.

• If the finishing time is more than the critical If the finishing time is more than the critical time, the schedule may or may not be time, the schedule may or may not be optimal.optimal.

• Typically, the decreasing-time priority list gives Typically, the decreasing-time priority list gives a better finishing time than does the a better finishing time than does the increasing-time priority list.increasing-time priority list.

Page 115: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Decreasing-Time AlgorithmDecreasing-Time Algorithm

1)1) Form a decreasing-time priority list.Form a decreasing-time priority list.

2)2) Apply the list-processing algorithm.Apply the list-processing algorithm.• If 2 or more tasks have the same If 2 or more tasks have the same

completion time, they may be chosen in completion time, they may be chosen in any order.any order.

Page 116: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

7.2 Initial Problem Solution7.2 Initial Problem Solution• Determine a schedule and the finishing time Determine a schedule and the finishing time

for the lasagna project with 2 processors.for the lasagna project with 2 processors.

Page 117: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Use a decreasing-time priority list: Use a decreasing-time priority list: TT33, T, T1010, ,

TT11, T, T44, T, T55, T, T99, T, T88, T, T77, T, T22, T, T66..

• The Gantt chart that results from applying The Gantt chart that results from applying the algorithm is shown next. the algorithm is shown next.

Page 118: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• The finishing time for this project with 2 The finishing time for this project with 2 processors and a decreasing-time processors and a decreasing-time priority list is 90 minutes.priority list is 90 minutes.• The critical time was 83 minutes.The critical time was 83 minutes.

• This may or may not be an optimal This may or may not be an optimal schedule.schedule.

Page 119: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Section 7.3Section 7.3

The Critical-Path AlgorithmThe Critical-Path Algorithm• GoalsGoals

• Study the critical-path priority list Study the critical-path priority list algorithmalgorithm

• Create the critical-path priority listCreate the critical-path priority list• Schedule tasks according to the critical-Schedule tasks according to the critical-

path priority listpath priority list

Page 120: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

7.3 Initial Problem7.3 Initial Problem

• Find an optimal schedule for the lasagna Find an optimal schedule for the lasagna project using 2 processors. project using 2 processors. • The solution will be given at the end of the section.The solution will be given at the end of the section.

Page 121: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1Example 1• A digraph for the project of making A digraph for the project of making

sandwiches is shown below.sandwiches is shown below.• Two processors will be assigned.Two processors will be assigned.

Page 122: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’d

a)a) Apply the decreasing-time algorithm to Apply the decreasing-time algorithm to create a schedule and find the finishing create a schedule and find the finishing time.time.

b)b) Find the critical path and the critical time.Find the critical path and the critical time.

c)c) Find the finishing time when one processor Find the finishing time when one processor is assigned to the tasks in the critical path is assigned to the tasks in the critical path and one to the other tasks.and one to the other tasks.

Page 123: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’da)a) Solution: The decreasing-time priority list is Solution: The decreasing-time priority list is

TT11, T, T22, T, T33, T, T44, T, T55, T, T66, T, T77..

• The Gantt chart shows a finishing time of 39 The Gantt chart shows a finishing time of 39 minutes.minutes.

Page 124: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’db)b) Solution: The maximal paths and their Solution: The maximal paths and their

weights are shown below.weights are shown below.

• The critical time is 30 minutes.The critical time is 30 minutes.

Page 125: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 1, cont’dExample 1, cont’dc)c) Solution: Instead of using a priority list, all tasks in Solution: Instead of using a priority list, all tasks in

the critical path are assigned to one processor.the critical path are assigned to one processor.

• The Gantt chart shows a finishing time of 30 minutes.The Gantt chart shows a finishing time of 30 minutes.

Page 126: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Critical-Path Priority List Critical-Path Priority List 1)1) List all the maximal paths and isolated List all the maximal paths and isolated

vertices.vertices.

2)2) Find the greatest of all the weights of the Find the greatest of all the weights of the maximal paths and isolated vertices.maximal paths and isolated vertices.

A.A. If the weight belongs to a maximal path, the If the weight belongs to a maximal path, the task at the head of the path goes next in the task at the head of the path goes next in the priority list.priority list.

B.B. If the weight belongs to an isolated vertex, that If the weight belongs to an isolated vertex, that task goes next in the priority list.task goes next in the priority list.

Page 127: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Critical-Path Priority List, cont’d Critical-Path Priority List, cont’d

3)3) Remove the task selected in Step 2 Remove the task selected in Step 2 and all attached edges from the and all attached edges from the digraph.digraph.

• Using the new digraph, repeat Step 1 and Using the new digraph, repeat Step 1 and Step 2. Step 2.

Page 128: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2Example 2• Find the critical-path priority list.Find the critical-path priority list.

Page 129: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution: The maximal paths are listed. Solution: The maximal paths are listed. There are no isolated vertices.There are no isolated vertices.• The greatest weight is 42, so the first task in the The greatest weight is 42, so the first task in the

list is list is TT22..

Page 130: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: The task and all attached Solution, cont’d: The task and all attached edges are removed from the digraph.edges are removed from the digraph.

Page 131: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: The maximal paths are Solution, cont’d: The maximal paths are listed. There are no isolated vertices.listed. There are no isolated vertices.• The greatest weight is 38, so the next task in the The greatest weight is 38, so the next task in the

list is list is TT11..

Page 132: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: Remove Solution, cont’d: Remove TT11 and create a new and create a new

digraph and table. digraph and table. • The greatest weight is 30, so the next task in the The greatest weight is 30, so the next task in the

list is list is TT55..

Page 133: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: Remove Solution, cont’d: Remove TT55 and create a new and create a new

digraph and table. digraph and table. • The greatest weight is 22, so the next task in the The greatest weight is 22, so the next task in the

list is list is TT66..

Page 134: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: Remove Solution, cont’d: Remove TT66 and create a new and create a new

digraph and table. digraph and table. • The greatest weight is 20, so the next task in the The greatest weight is 20, so the next task in the

list is list is TT33..

Page 135: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: Remove Solution, cont’d: Remove TT33 and create a new and create a new

digraph and table. digraph and table. • The greatest weight is 15, so the next task in the The greatest weight is 15, so the next task in the

list is list is TT77..

Page 136: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: Remove Solution, cont’d: Remove TT77 and create a new and create a new

digraph and table. digraph and table. • The greatest weight is 11, so the next task in the The greatest weight is 11, so the next task in the

list islist is T T44..

Page 137: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 2, cont’dExample 2, cont’d

• Solution, cont’d: Remove Solution, cont’d: Remove TT44 and create a new and create a new

digraph and table.digraph and table.

• The next task in the list is The next task in the list is TT88, followed by , followed by TT99. .

• The priority list is The priority list is TT22, T, T11, T, T55, T, T66, T, T33, T, T77, T, T44, T, T88, T, T99..

Page 138: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Question:Question:

Find the critical-path priority list for Find the critical-path priority list for the project. the project.

a. a.

b. b.

c. c.

d.d.

10 9 8 7 6 5 4 3 2 1, , , , , , , , ,T T T T T T T T T T

1 2 3 4 5 6 7 8 9 10, , , , , , , , ,T T T T T T T T T T

1 4 8 6 5 7 2 3 9 10, , , , , , , , ,T T T T T T T T T T

1 2 3 4 5 6 8 7 9 10, , , , , , , , ,T T T T T T T T T T

Page 139: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Critical-Path Scheduling AlgorithmCritical-Path Scheduling Algorithm

1)1) Determine the critical-path priority list.Determine the critical-path priority list.

2)2) Apply the list-processing algorithm.Apply the list-processing algorithm.

Page 140: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

QuestionQuestionSuppose the critical-path algorithm is being used to Suppose the critical-path algorithm is being used to schedule a project using 3 processors. The priority list is schedule a project using 3 processors. The priority list is

. At 2 minutes, the status is that . At 2 minutes, the status is that Processors 1 and 2 are both working on task, while Processors 1 and 2 are both working on task, while Processor 3 is idle. What should happen at this point? Processor 3 is idle. What should happen at this point?

a. Processor 3 is assigned a. Processor 3 is assigned

Task 8.Task 8.

b. Processor 3 is assigned b. Processor 3 is assigned

Task 2.Task 2.

c. Processor 3 is assigned c. Processor 3 is assigned

Task 5.Task 5.

d. Processor 3 remains idle.d. Processor 3 remains idle.

1 2 3 4 5 6 8 7 9 10, , , , , , , , ,T T T T T T T T T T

Page 141: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3Example 3• Apply the critical-path scheduling algorithm Apply the critical-path scheduling algorithm

using 2 processors.using 2 processors.

Page 142: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution: The critical-path priority list was Solution: The critical-path priority list was

found in the last example: found in the last example: TT22, T, T11, T, T55, T, T66, T, T33, ,

TT77, T, T44, T, T88, T, T99..

• The Gantt chart is shown below.The Gantt chart is shown below.

Page 143: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Example 3, cont’dExample 3, cont’d• Solution, cont’d: The finishing time with 2 Solution, cont’d: The finishing time with 2

processors using the critical-path priority list is 42 processors using the critical-path priority list is 42 minutes.minutes.

• There were 2 periods of time during which There were 2 periods of time during which Processor 2 had to remain idle.Processor 2 had to remain idle.

Page 144: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

7.3 Initial Problem Solution7.3 Initial Problem Solution• Two processors will complete the lasagna Two processors will complete the lasagna

project.project.

Page 145: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• We will use the critical-path priority list.We will use the critical-path priority list.• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.

• The greatest weight is 83, so the first task in the list is The greatest weight is 83, so the first task in the list is TT11..

Page 146: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT11..

• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.• The greatest weight is 73, so the next task in the list is The greatest weight is 73, so the next task in the list is

TT22..

Page 147: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT22..

• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.• The greatest weight is 68, so the next task in the list is The greatest weight is 68, so the next task in the list is

TT33..

Page 148: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT33..

• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.• The greatest weight is 58, so the next task in the list is The greatest weight is 58, so the next task in the list is

TT44..

Page 149: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT44..

• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.• The greatest weight is 48, so the next task in the list is The greatest weight is 48, so the next task in the list is

TT55..

Page 150: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT55..

• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.• The greatest weight is 46, so the next task in the list is The greatest weight is 46, so the next task in the list is

TT66..

Page 151: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT66..

• The maximal paths are listed, with their weights.The maximal paths are listed, with their weights.• The greatest weight is 45, so the next task in the list is The greatest weight is 45, so the next task in the list is

TT88..

Page 152: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• Remove Remove TT88..

• The maximal paths are listed, with their The maximal paths are listed, with their weights.weights.

• The task are assigned in the order The task are assigned in the order TT77, T, T99, T, T1010. .

• The critical-path priority list is The critical-path priority list is TT11, T, T22, T, T33, T, T44, T, T55, ,

TT66, T, T88, T, T77, T, T9 9 , T, T10 .10 .

Page 153: A Mathematical View of Our World 1 st ed. Parks, Musser, Trimpe, Maurer, and Maurer

Initial Problem Solution, cont’dInitial Problem Solution, cont’d

• The Gantt chart is shown above.The Gantt chart is shown above.• The finishing time is equal to the critical The finishing time is equal to the critical

time of 83 minutes, so we know the time of 83 minutes, so we know the schedule is optimal. schedule is optimal.