Title: A Mathematical View of Our World
1A Mathematical View of Our World
- 1st ed.
- Parks, Musser, Trimpe, Maurer, and Maurer
2Chapter 7
3Section 7.1Basic Concepts of Scheduling
- Goals
- Study project scheduling
- Study tasks
- Find finishing times
- Study weighted digraphs
- Study maximal paths
- Find critical times
47.1 Initial Problem
- A model railroad club is preparing for an open
house. - Estimate the minimum preparation time required.
- The solution will be given at the end of the
section.
5Tasks
- A project consists of 2 or more smaller
activities called tasks. - A task cannot be broken into smaller jobs.
- A task is done by 1 machine or 1 person.
- The amount of time needed to complete a project
depends on - How many people or machines are available to do
the work. - How the tasks are assigned.
6Example 1
- A group of college students are making lasagna.
- Divide the project into tasks.
7Example 1, contd
- Solution A possible list of tasks is given.
8Tasks, contd
- The people or machines performing the tasks are
called processors. - The amount of time it takes to perform a task is
called its completion time.
9Tasks, contd
- If one task must be completed before another task
can be started, we say the tasks have a
precedence relation or order requirement between
them. - Tasks that may be done in any order are called
independent. - One way to represent a precedence relation
between 2 tasks is to use points to denote the
tasks and an arrow to indicate the relationship.
10Example 2
- The tasks of putting on socks and putting on
shoes have a preference relation.
11Example 2, contd
- The tasks of putting on a hat and putting on a
coat do not have a preference relation. These
are independent tasks.
12Question
- Choose the list of tasks that has no preference
relations. - a. bake the pizza, grate some cheese, make pizza
sauce - b. fold some clothes, wash some clothes, hang
clothes on the line to dry - c. bake the cake, toss the green salad, set the
table - d. frost the cake, bake the cake, set the table
13Digraphs
- A collection of points (tasks) and straight or
curved arrows (precedence relations) connecting
them is called a directed graph or digraph. - A point in a digraph is called a vertex.
- An arrow in a digraph is called an arc.
14Example 3
- Use a digraph to represent the precedence
relations for a man dressing to go for a run in
the summer. - The tasks consist of putting on
- A Shirt
- Shoes
- Shorts
- Socks
15Example 3, contd
- Solution Determine if there are any order
requirements among the tasks. - Socks must be put on before shoes.
- It is much easier to put on shorts before shoes.
- The shirt can be put on at any point in the
process.
16Example 3, contd
- Solution, contd A possible digraph is shown
below.
17Digraphs, contd
- A digraph that contains at least one precedence
relation is called an order-requirement digraph. - A vertex in a digraph with no arcs attached to it
is said to be isolated.
18Digraphs, contd
- Example
- The digraph from the previous example problem is
an order-requirement digraph. - Vertex put on shirt is isolated.
19Example 4
- Construct an order-requirement digraph for the
tasks of - Making blackberry jam
- Making blackberry cobbler
- Picking blackberries
20Example 4, contd
- Solution
- The berries must be picked first.
- The jam and cobbler can be made in any order.
21Example 5
- Construct an order-requirement digraph for the
tasks of - Putting on socks
- Putting on a sweatshirt
- Putting on snow pants
- Putting on a hat
- Putting on boots
- Strapping on a snowboard
22Example 5, contd
- Solution
- The socks probably go on before the pants.
- The pants go on before the boots.
- The boots go on before the snowboard.
- The sweatshirt goes on before the coat.
- The hat can be put on at any point.
23Example 5, contd
- Solution, contd The digraph is shown below.
24Paths
- Any list of 2 or more vertices connected by
arrows such that the list goes in the same
direction as the arcs in the corresponding
digraph is called a directed path. - Because we consider only directed paths, we
simply call the list a path.
25Example 6
- Identify all possible paths in the
order-requirement digraph representing a simple
version of the project of replacing old brake
shoes.
26Example 6, contd
- Solution There are 6 possible paths.
-
-
-
-
-
-
27Paths, contd
- A path that cannot be extended by adding a vertex
at either end is called a maximal path. - In the previous example, the maximal paths were
-
-
28Sources and Sinks
- A vertex in a digraph that is at the end of no
arc is called a source. - A vertex in a digraph that is at the start of no
arc is called a sink. - An isolated vertex is both a source and a sink.
- A maximal path starts at a source and ends at a
sink.
29Sources and Sinks, contd
- In this digraph from the previous example,
- Vertex T1 is a source.
- Vertex T4 is a sink.
30Question
- Identify all sources and sinks.
- a. Sources put on socks Sinks put on hat
- b. Sources put on hat, put on coat, strap on
- snowboard Sinks put on socks, put on sweatshirt
- c. Sources put on hat Sinks put on socks
- d. Sources put on socks, put on sweatshirt
- Sinks put on hat, put on coat, strap on
snowboard
31Finding all Maximal Paths
- To find all maximal paths in a digraph
- Locate all the sinks that are not isolated
vertices. - Locate all the sources that are not isolated
vertices.
32Finding Maximal Paths, contd
- For each source, follow the arcs until you reach
a sink. - If there is more than one arc at any vertex along
the path formed in Step 3, start again at the
same source and choose a different route.
33Question
- Which path listed below is not a maximal path?
- a. put on hat
- b. put on pants, put on boots
- c. put on sweatshirt, put on coat
- d. put on socks, put on pants, put on boots,
strap on snowboard
34Example 7
- Identify all maximal paths in the digraph.
35Example 7, contd
- Solution
- There is only one sink T6
- There is only one source T1
36Example 7, contd
- Solution, contd
- A maximal path from T1 to T6 is
- Another maximal path from T1 to T6 is
37Example 8
- Identify all maximal paths in the digraph.
38Example 8, contd
- Solution
- There is only one sink T10
39Example 8, contd
- Solution, contd
- There are 4 sources T1, T4 , T6, and T8.
40Example 8, contd
- Solution, contd
- There are 4 maximal paths
-
-
-
-
-
-
41Weighted Digraphs
- The completion time associated with a vertex
(task) is the weight of the vertex. - A digraph with weights at each vertex is called a
weighted digraph. - For example This weighted digraph shows that it
takes 20 seconds to put on sock and 25 seconds to
put on shoes.
42Example 9
- Construct a weighted digraph.
43Example 9, contd
44Project Finishing Time
- The time from the beginning of a project until
the end of the project is called the finishing
time for the project. - The finishing time depends on
- The task completion times.
- The number of processors available.
- How the processors are scheduled.
- Whether or not some tasks can be done at the same
time.
45Example 10
- If only one processor works on the lasagna
project, what is the finishing time?
46Example 10, contd
- Solution We assume the processor can only
perform one task at a time. - Add up all the task completion times 10 5
30 10 10 2 6 7 8 30 118
minutes. - It will take one processor almost 2 hours to
finish the project.
47Weighted Digraphs, contd
- The weight of a path in a weighted
order-requirement digraph is the sum of the
weights at the vertices on the path. - A critical path in an order-requirement digraph
is a path having the largest possible weight. - The weight of a critical path is called the
critical time for the project.
48Weighted Digraphs, contd
- Any critical path must be a maximal path.
- To find the critical paths
- Find all the maximal paths.
- Select the maximal path(s) with the largest
weight.
49Example 11
- Find a critical path in the lasagna project
digraph.
50Example 11, contd
- Solution Previously we found 4 maximal paths.
-
-
-
-
-
-
51Example 11, contd
52Example 11, contd
- Solution, contd The largest weight for any
maximal path is 83. - The one critical path is
- The critical time for the project is 83 minutes.
- It will take a minimum of 83 minutes, with enough
processors, to make the lasagna. - This example illustrates the fact that the
finishing time of a project is always greater
than or equal to its critical time.
537.1 Initial Problem Solution
- A model railroad club is preparing for an open
house. - What is the minimum completion time?
54Initial Problem Solution, contd
- The first 6 tasks need to be done first and in
order. - Task 7 must be done before task 8.
- Everything else must be done before task 10.
55Initial Problem Solution, contd
- A weighted digraph is created.
56Initial Problem Solution, contd
- Find all maximal paths, along with their weights.
57Initial Problem Solution, contd
- The critical time of the project is 52 hours.
- The finishing time is greater than or equal to
the critical time, so it will take at least 52
hours to prepare for the open house.
58Section 7.2List-Scheduling Algorithm
- Goals
- Study project scheduling
- Study priority lists
- Use the list-scheduling algorithm
- Create and read Gantt charts
- Study optimal schedules
597.2 Initial Problem
- Suppose 2 students will make the lasagna in the
project examined in Section 7.1. - What is a good way for the 2 students to divide
the work and how long will it take? - The solution will be given at the end of the
section.
60Priority Lists
- A priority list is an ordered list of all the
tasks in a project. - When tasks are performed, precedence relations
override a priority list. - A priority list tells you which task to do first
among those you can do at a certain point in time.
61Example 1
- A woodworking project consists of 7 tasks.
62Example 1, contd
- The weighted digraph above represents the
project, with completion times in minutes. - Determine the critical time.
- Create a priority list based on completion time,
from shortest to longest.
63Example 1, contd
- Solution The 3 maximal paths, and their weights,
are listed.
64Example 1, contd
- Solution, contd The largest weight of a maximal
path in this case is 90 minutes. - The critical time is 90 minutes.
65Example 1, contd
- Solution, contd The tasks are placed in a
priority list according to their completion
times. - The priority list is T1, T5, T2, T3, T6, T7, and
T4.
66Priority Lists, contd
- A priority list in which tasks are arranged from
shortest completion time to longest completion
time is called an increasing-time priority list. - A priority list in which tasks are arranged from
longest completion time to shortest completion
time is called a decreasing-time priority list
67Question
- Create the decreasing-time priority list for the
project whose digraph is shown below. - a.
- b.
- c.
- d.
68Example 2
- How would one processor finish the woodworking
project from the previous example using the
increasing-time priority list T1, T5, T2, T3, T6,
T7, and T4?
69Example 2, contd
- Solution Use the precedence relations and the
priority list to determine the order of the
tasks. - Task T1 is a source and is first on the list, so
it will be done first. - Next, either T2 or T3 could be done. Choose T2
because it is first in the list. - At this point, the tasks that can be done are T3
or T5. According to the priority list, choose T5.
70Example 2, contd
- Solution, contd The order of the rest of the
tasks is determined in the same manner. - The priority list is T1, T5, T2, T3, T6, T7, T4.
- The order in which the tasks will be completed is
T1, T2, T5, T3, T6, T4, T7 .
71Gantt Charts
- We can keep track of the order in which tasks are
done and how long it takes using a diagram called
a Gantt chart. - Numbers at the bottom of the chart show the
elapsed time. - The boxes represent the tasks.
72Gantt Charts, contd
- A Gantt chart for the woodworking project in the
previous example is shown below.
73Definitions
- A task T will be called ready if all tasks
required to begin T have been completed. - A processor that has not yet been assigned a task
and is not working on a task will be called idle. - At the beginning of a project we assume all
processors are idle and at least 1 task is ready.
74List-Processing Algorithm
- The lowest-numbered idle processor is assigned to
the highest-priority ready task until either all
processors are assigned or all ready tasks have
been assigned.
75List-Processing Algorithm, contd
- When a processor completes a task, that processor
becomes idle. One of 3 cases will occur. - If there are ready tasks, repeat Step 1.
- If there are no ready tasks but not every task
has been done, the processor remains idle until
more tasks are completed. - If all tasks have been completed, the project is
finished.
76Example 3
- Apply the algorithm to the wood-working project
using 2 processors and the increasing-time
priority list T1, T5, T2, T3, T6, T7, T4.
77Example 3, contd
- Solution Step 1
- P1 is assigned to T1.
- P2 remains idle.
78Example 3, contd
- Solution, contd At 5 minutes, Step 2, Case A.
- Ready T2, T3.
- Not completed T2, T3, T4, T5, T6, T7.
- Priority list T1, T5, T2, T3, T6, T7, T4.
79Example 3, contd
- Solution, contd Step 1
- P1 and P2 are idle.
- P1 is assigned to T2.
- P2 is assigned to T3.
80Example 3, contd
- Solution, contd At 20 minutes, Step 2, Case A.
- Ready T5.
- Not completed T3, T4, T5, T6, T7.
- Priority list T1, T5, T2, T3, T6, T7, T4.
81Example 3, contd
- Solution, contd Step 1
- P1 is idle.
- P1 is assigned to T5.
82Example 3, contd
- Solution, contd At 25 minutes, Step 2, Case A.
- Ready T4, T6.
- Not completed T4, T5, T6, T7.
- Priority list T1, T5, T2, T3, T6, T7, T4.
83Example 3, contd
- Solution, contd Step 1
- P2 is idle.
- P2 is assigned to T6.
84Example 3, contd
- Solution, contd At 30 minutes, Step 2, Case A.
- Ready T4.
- Not completed T4, T6, T7.
- Priority list T1, T5, T2, T3, T6, T7, T4.
85Example 3, contd
- Solution, contd Step 1
- P1 is idle.
- P1 is assigned to T4.
86Example 3, contd
- Solution, contd At 50 minutes, Step 2, Case B.
- Ready none.
- Not completed T4, T7.
- Priority list T1, T5, T2, T3, T6, T7, T4.
87Example 3, contd
- Solution, contd Step 1
- P2 remains idle.
88Example 3, contd
- Solution, contd At 65 minutes, Step 2, Case A.
- Ready T7.
- Not completed T7.
- Priority list T1, T5, T2, T3, T6, T7, T4.
89Example 3, contd
- Solution, contd Step 1
- P1 and P2 are idle.
- P1 is assigned to T7.
90Example 3, contd
- Solution, contd At 95 minutes, Step 2, Case C.
- Ready none.
- Not completed none.
- The finishing time with 2 processors is 95
minutes. - This is less than 140 minutes for 1 processor,
but more than the critical time of 90 minutes.
91Example 4
- Apply the algorithm to the wood-working project
using 3 processors and the increasing-time
priority list T1, T5, T2, T3, T6, T7, T4.
92Example 4, contd
- Solution Step 1
- P1 is assigned to T1.
- P2 and P3 remain idle.
93Example 4, contd
- Solution, contd At 5 minutes Step 2 and Step 1
- P1, P2 and P3 are idle.
- T2 and T3 are ready.
- P1 is assigned to T2.
- P2 is assigned to T3.
- P3 remains idle.
94Example 4, contd
- Solution, contd At 20 minutes Step 2 and Step
1 - P1 and P3 are idle.
- T5 is ready.
- P1 is assigned to T5.
- P3 remains idle.
95Example 4, contd
- Solution, contd At 25 minutes Step 2 and Step
1 - P2 and P3 are idle.
- T6 and T4 are ready.
- P2 is assigned to T6.
- P3 is assigned to T4.
96Example 4, contd
- Solution, contd At 30 minutes Step 2 and Step
1 - P1 is idle.
- No tasks are ready.
- P1 remains idle.
97Example 4, contd
- Solution, contd At 50 minutes Step 2 and Step
1 - P1 and P2 are idle.
- No tasks are ready.
- P1 and P2 remain idle.
98Example 4, contd
- Solution, contd At 60 minutes Step 2 and Step
1 - P1, P2 and P3 are idle.
- T7 is ready.
- P1 is assigned to T7.
99Example 4, contd
- Solution, contd At 90 minutes Step 2 and Step
1 - P1, P2 and P3 are idle.
- No tasks are ready.
- All tasks have been completed.
100Example 4, contd
- The completion time with 3 processors is 90
minutes, the critical time. - The project completion is summarized in the Gantt
chart.
101Example 5
- Apply the algorithm to the wood-working project
using 2 processors and the decreasing-time
priority list T4, T7, T6, T3, T2, T5, T1.
102Example 5, contd
- Solution Step 1
- P1 is assigned to T1.
- P2 remains idle.
103Example 5, contd
- Solution, contd At 5 minutes Step 2 and Step 1
- P1 and P2 are idle.
- T2 and T3 are ready.
- P1 is assigned to T3.
- P2 is assigned to T2.
104Example 5, contd
- Solution, contd At 20 minutes Step 2 and Step
1 - P2 is idle.
- T5 is ready.
- P2 is assigned to T5.
105Example 5, contd
- Solution, contd At 25 minutes Step 2 and Step
1 - P1 is idle.
- T4 and T6 are ready.
- P1 is assigned to T4.
106Example 5, contd
- Solution, contd At 30 minutes Step 2 and Step
1 - P2 is idle.
- T6 is ready.
- P2 is assigned to T6.
107Example 5, contd
- Solution, contd At 55 minutes Step 2 and Step
1 - P2 is idle.
- No tasks are ready.
- P2 remains idle.
108Example 5, contd
- Solution, contd At 60 minutes Step 2 and Step
1 - P1 and P2 are idle.
- T7 is ready.
- P1 is assigned to T7.
- P2 remains idle.
109Example 5, contd
- Solution, contd At 90 minutes Step 2 and Step
1 - P1 and P2 are idle.
- No tasks are ready.
- All tasks are completed.
- The finishing time with the decreasing-time
priority list and 2 processors is 90 minutes.
110Example 5, contd
111Question
- Given the priority list
- and the digraph for the project, which tasks
will be assigned first if there are 3 processors?
112Question contd
- a. Processor 1 Task 4 Processor 2 Task 1
Processor 3 Task 8 - b. Processor 1 Task 1 Processor 2 Task 4
Processor 3 Task 6 - c. Processor 4 Task 1 Processor 2 Task 1
Processor 3 Task 6 - d. Processor 1 Task 1 Processor 2 Task 4
Processor 3 Task 8
113Optimal Schedules
- An optimal schedule is a schedule assigning
processors to tasks in such a way that it results
in the shortest possible finishing time for that
project with that number of processors.
114Optimal Schedules, contd
- If the finishing time is equal to the critical
time, we know the schedule is optimal. - If the finishing time is more than the critical
time, the schedule may or may not be optimal. - Typically, the decreasing-time priority list
gives a better finishing time than does the
increasing-time priority list.
115Decreasing-Time Algorithm
- Form a decreasing-time priority list.
- Apply the list-processing algorithm.
- If 2 or more tasks have the same completion time,
they may be chosen in any order.
1167.2 Initial Problem Solution
- Determine a schedule and the finishing time for
the lasagna project with 2 processors.
117Initial Problem Solution, contd
- Use a decreasing-time priority list T3, T10, T1,
T4, T5, T9, T8, T7, T2, T6. - The Gantt chart that results from applying the
algorithm is shown next.
118Initial Problem Solution, contd
- The finishing time for this project with 2
processors and a decreasing-time priority list is
90 minutes. - The critical time was 83 minutes.
- This may or may not be an optimal schedule.
119Section 7.3The Critical-Path Algorithm
- Goals
- Study the critical-path priority list algorithm
- Create the critical-path priority list
- Schedule tasks according to the critical-path
priority list
1207.3 Initial Problem
- Find an optimal schedule for the lasagna project
using 2 processors. - The solution will be given at the end of the
section.
121Example 1
- A digraph for the project of making sandwiches is
shown below. - Two processors will be assigned.
122Example 1, contd
- Apply the decreasing-time algorithm to create a
schedule and find the finishing time. - Find the critical path and the critical time.
- Find the finishing time when one processor is
assigned to the tasks in the critical path and
one to the other tasks.
123Example 1, contd
- Solution The decreasing-time priority list is
T1, T2, T3, T4, T5, T6, T7. - The Gantt chart shows a finishing time of 39
minutes.
124Example 1, contd
- Solution The maximal paths and their weights are
shown below. - The critical time is 30 minutes.
125Example 1, contd
- Solution Instead of using a priority list, all
tasks in the critical path are assigned to one
processor. - The Gantt chart shows a finishing time of 30
minutes.
126Critical-Path Priority List
- List all the maximal paths and isolated vertices.
- Find the greatest of all the weights of the
maximal paths and isolated vertices. - If the weight belongs to a maximal path, the task
at the head of the path goes next in the priority
list. - If the weight belongs to an isolated vertex, that
task goes next in the priority list.
127Critical-Path Priority List, contd
- Remove the task selected in Step 2 and all
attached edges from the digraph. - Using the new digraph, repeat Step 1 and Step 2.
128Example 2
- Find the critical-path priority list.
129Example 2, contd
- Solution The maximal paths are listed. There
are no isolated vertices. - The greatest weight is 42, so the first task in
the list is T2.
130Example 2, contd
- Solution, contd The task and all attached edges
are removed from the digraph.
131Example 2, contd
- Solution, contd The maximal paths are listed.
There are no isolated vertices. - The greatest weight is 38, so the next task in
the list is T1.
132Example 2, contd
- Solution, contd Remove T1 and create a new
digraph and table. - The greatest weight is 30, so the next task in
the list is T5.
133Example 2, contd
- Solution, contd Remove T5 and create a new
digraph and table. - The greatest weight is 22, so the next task in
the list is T6.
134Example 2, contd
- Solution, contd Remove T6 and create a new
digraph and table. - The greatest weight is 20, so the next task in
the list is T3.
135Example 2, contd
- Solution, contd Remove T3 and create a new
digraph and table. - The greatest weight is 15, so the next task in
the list is T7.
136Example 2, contd
- Solution, contd Remove T7 and create a new
digraph and table. - The greatest weight is 11, so the next task in
the list is T4.
137Example 2, contd
- Solution, contd Remove T4 and create a new
digraph and table. - The next task in the list is T8, followed by T9.
- The priority list is T2, T1, T5, T6, T3, T7, T4,
T8, T9.
138Question
- Find the critical-path priority list for the
project. - a.
- b.
- c.
- d.
139Critical-Path Scheduling Algorithm
- Determine the critical-path priority list.
- Apply the list-processing algorithm.
140Question
- Suppose the critical-path algorithm is being
used to schedule a project using 3 processors.
The priority list is . At 2 minutes, the
status is that Processors 1 and 2 are both
working on task, while Processor 3 is idle. What
should happen at this point? - a. Processor 3 is assigned
- Task 8.
- b. Processor 3 is assigned
- Task 2.
- c. Processor 3 is assigned
- Task 5.
- d. Processor 3 remains idle.
141Example 3
- Apply the critical-path scheduling algorithm
using 2 processors.
142Example 3, contd
- Solution The critical-path priority list was
found in the last example T2, T1, T5, T6, T3,
T7, T4, T8, T9. - The Gantt chart is shown below.
143Example 3, contd
- Solution, contd The finishing time with 2
processors using the critical-path priority list
is 42 minutes. - There were 2 periods of time during which
Processor 2 had to remain idle.
1447.3 Initial Problem Solution
- Two processors will complete the lasagna project.
145Initial Problem Solution, contd
- We will use the critical-path priority list.
- The maximal paths are listed, with their weights.
- The greatest weight is 83, so the first task in
the list is T1.
146Initial Problem Solution, contd
- Remove T1.
- The maximal paths are listed, with their weights.
- The greatest weight is 73, so the next task in
the list is T2.
147Initial Problem Solution, contd
- Remove T2.
- The maximal paths are listed, with their weights.
- The greatest weight is 68, so the next task in
the list is T3.
148Initial Problem Solution, contd
- Remove T3.
- The maximal paths are listed, with their weights.
- The greatest weight is 58, so the next task in
the list is T4.
149Initial Problem Solution, contd
- Remove T4.
- The maximal paths are listed, with their weights.
- The greatest weight is 48, so the next task in
the list is T5.
150Initial Problem Solution, contd
- Remove T5.
- The maximal paths are listed, with their weights.
- The greatest weight is 46, so the next task in
the list is T6.
151Initial Problem Solution, contd
- Remove T6.
- The maximal paths are listed, with their weights.
- The greatest weight is 45, so the next task in
the list is T8.
152Initial Problem Solution, contd
- Remove T8.
- The maximal paths are listed, with their weights.
- The task are assigned in the order T7, T9, T10.
- The critical-path priority list is T1, T2, T3,
T4, T5, T6, T8, T7, T9 , T10 .
153Initial Problem Solution, contd
- The Gantt chart is shown above.
- The finishing time is equal to the critical time
of 83 minutes, so we know the schedule is
optimal.