scheduling two people are camping out and wish to cook a simple supper consisting of soup and...

38
Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks must be performed. T1: Go to the store to buy matches – 10 minutes T2: Collect firewood– 8 minutes T3: Light the fire– 6 minutes T4: Get water from a well– 12 minutes T5: Cook soup (requires constant stirring)– 15 minutes T6: Make hamburger patties – 9 minutes T7: Cook hamburgers– 7 minutes Each task requires only one of the campers and once a task is begun it cannot be interrupted. Some of the tasks can be done simultaneously, but some cannot be done until others are completed. What is the shortest amount of time it will take for all of the tasks to be completed? How should the work be divided between the two campers?

Upload: norma-russell

Post on 17-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Scheduling Two people are camping out and wish to cook a simple supper consisting of

soup and hamburgers. In order to prepare the supper, several tasks must be performed. T1: Go to the store to buy matches – 10 minutes T2: Collect firewood– 8 minutes T3: Light the fire– 6 minutes T4: Get water from a well– 12 minutes T5: Cook soup (requires constant stirring)– 15 minutes T6: Make hamburger patties – 9 minutes T7: Cook hamburgers– 7 minutes Each task requires only one of the campers and once a task is begun it

cannot be interrupted. Some of the tasks can be done simultaneously, but some cannot be done

until others are completed. What is the shortest amount of time it will take for all of the tasks to be

completed? How should the work be divided between the two campers?

Page 2: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Chapter 3: Planning and SchedulingLesson Plan Scheduling Tasks

Assumptions and Goals List-Processing Algorithm Optimal Schedules Strange Happenings

Critical-Path Schedules Independent Tasks

Decreasing-Time-List Algorithm

Bin Packing Bin-Packing Heuristics Decreasing-Time Heuristics

Resolving Conflict via Coloring Vertex Coloring and Chromatic Number

2

Mathematical Literacy in Today’s World, 8th

ed.

For All Practical Purposes

© 2009, W.H. Freeman and Company

Page 3: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Chapter 3: Planning and SchedulingScheduling Tasks

3

Planning and Scheduling Accurate planning and scheduling is required of both people and

machines. Examples: Around-the-clock scheduling of doctors and nurses,

scheduling equipment (X-rays, MRI scans) for maximum efficiency

Processors A person, machine, robot, operating

room, or runway (for airplanes) whose time must be scheduled.

Machine-Scheduling Problem The problem of deciding how the

tasks should be scheduled so the entire job is completed as early as possible.

Page 4: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Assumptions When a processor starts a task, it will be completed without

interruption. Any processor can work on any of the tasks. No processor stays idle voluntarily. Order-requirement digraph is used to show the task order and has

the task times highlighted within each vertex. Priority lists arrange the tasks in order, independent of the order

requirements. Used to “break ties” if more than one task is ready.

Goals to Consider Minimize the completion time of the job. Minimize the total time the processors are idle. Find the minimum number of processors necessary to finish the

job by a specified time.

Chapter 3: Planning and SchedulingScheduling Tasks

4

Page 5: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

5

Chapter 3: Planning and SchedulingScheduling Tasks

Order-Requirement Digraph For the next example, tasks are

labeled as T1–T8. The length of time for each task

is indicated in a colored circle. At the beginning (time = 0),

tasks T1, T7, T8 are ready to be scheduled on machines.

Processors For this example, tasks will be scheduled on two machines

according to the order-requirement digraph and priority list.

Priority List A list that ranks the tasks in some criterion of importance. For the problem, the priority list is T1, T2, T3, T4, T5, T6, T7, T8.

Order Requirement Digraph — Example

Ready task – A task is ready if its predecessors have been completed by that time as given by the order-requirement digraph.

Page 6: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

6

Chapter 3: Planning and SchedulingScheduling Tasks

List Processing Algorithm At a given time, assign to the

lowest numbered free machine (or processor) the first task on the priority list that is ready at that time (and not already been assigned).

Summary of Steps1. Look at timeline for available

machine. If more than one is free, use the lower-number machine—the top machine.

2. Use order-requirement digraph to choose the ready tasks.

3. When there is a tie (two or more tasks ready), use priority list to break ties and assign the ready tasks in order.

Order-Requirement Digraph

Priority List: T1, T2, T3, T4, T5,T6, T7, T8

Schedule Tasks on Machines

Page 7: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

7

Chapter 3: Planning and SchedulingScheduling Tasks

When is the schedule optimal? From Chapter 2, remember the longest path in an order

requirement is the critical path. The earliest time for the job made up of all the tasks is the length

of the longest path (critical path) in the order-requirement digraph.

Referring to the previous example: The critical path is T1, T2, T3, T4 = 8 + 6 + 9 + 4 = 27. If the job is completed in the same time as the length of the

critical path, this is the earliest completion time possible and it is an optimal schedule.

If the schedule completion time = the length of critical path,

then the schedule is optimal (earliest completion time).

Page 8: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

8

Chapter 3: Planning and SchedulingScheduling Tasks

Strange Happenings Four factors affect the final schedule:

1. Times of the tasks

2. Number of processors

3. Order-requirement diagram

4. Ordering of the tasks on the priority list

While keeping the priority list constant, you would expect the following strategies would make the completion time earlier:

1. Reduce task times.

2. Use more processors.

3. “Loosen” the constraints of the order-requirement digraph.

However, with a constant priority list, applying one of these strategies may

not always make the completion time shorter — strange happenings.

Page 9: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExampleSchedule the tasks in the digraph on two processors with priority list T1, T4 , T5 , T6 ,T 7, T8, T9, T10, T2, T3. What is the completion time?

Page 10: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks
Page 11: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExampleUsing the same digraph, schedule the tasks on three processors with priority listT 1, T 2, T3 , T 4, T 5, T6, T 7, T8, T9, T10. What is the completion time?

Page 12: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks
Page 13: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

13

Chapter 3: Planning and SchedulingCritical Path Schedules Critical-Path Schedules

A systematic method of choosing/creating a priority list, L, that yields optimal, or nearly optional, schedules.

Critical-Path Scheduling Algorithm (to create priority list L)1. Find a task that heads a critical (longest) path in the order-requirement

digraph. If a tie, choose the lowest-number task.2. Place the task found in step 1 next on the list L (the first time through

the process this task will head the list).3. Remove the task found in step 1 and the edges attached to it from the

current order-requirement digraph, obtaining a new (modified) order-requirement digraph.

4. If there are no vertices left in the new order-requirement digraph, the procedure is complete; if there are vertices left, go to step 1.

This procedure will terminate when all the tasks in the original order-requirement digraph have been placed on the list L (example on next slide).

Page 14: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

14

Chapter 3: Planning and SchedulingCritical Path Schedules Example of Critical-Path Scheduling Algorithm

For this order-requirement digraph, there are two critical paths of length 64: T1, T2, T3 and T1, T4, T3. Place T1 on the list L.

With T1 “gone,” there is a new critical path of length 60: T5, T6, T4, T3. Place T5 next on the list L.

With T1 and T5 “gone,” the next longest path would be 56: T6, T4, T3. Place T6 next on the list L. (Continue the algorithm until list is complete.)

The new priority list would be: L = T1, T5, T6, T2, T4, T3, T8, T9, T7, T10.

Using the list-processing algorithm with the original order-requirement digraph and the new priority list L, the following schedule is obtained:

Page 15: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExampleDetermine the earliest completion time for the order-requirement digraph. Use critical-pathscheduling to construct a priority list for the tasks.

Page 16: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

16

Chapter 3: Planning and SchedulingIndependent Tasks Independent Tasks

Tasks that are independent of each other if they can be performed in any order (no edges in the order-requirement digraph).

Label the tasks by their task times rather than their task number. The list-processing algorithm can be used to schedule the tasks onto

machines using the given list but may not be efficient.

Decreasing-Time List Algorithm First put the tasks in decreasing order by time, then apply the list

processing algorithm. This will help pack the longest tasks first, so they do not “stick out” on the right end.

Example: Apply decreasing-time list algorithm on independent tasks 10, 9, 7, 7, 5, 4 (already in order)

This result is an optimal schedule!

Page 17: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

When a path is not given you can add up the TOTAL amount of time of tasks and divide that number by the number of processors.

Example from previous page: 10, 9, 7, 7, 5, 4

10+9+7+7+5+4= 42 42/2= 21 The minimum time required to complete the given tasks

on two processors is 21 minutes.

Page 18: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Example 2: What is the minimum time required to complete nine independent tasks on three processors when the sum of all the times of the nine tasks is 72 minutes?

Example 3: What is the minimum time required to complete 12 independent tasks on two processors when the sum of all the times of the 12 tasks is 84 minutes?

Example 4: What is the minimum time required to perform eight independent tasks with a total task time of 48 minutes on four machines?

Page 19: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

19

Chapter 3: Planning and SchedulingBin Packing

Bin Packing The problem of finding the minimum number of bins into which

the weight can be packed. Find the minimum number of bins (containers) of capacity, W. Where weights w1, w2, …,wn are packed into the bins.

Each weight of object is less than or equal to W (wi W).

Instead of fixing the number of machines and finding a minimum completion time, we want to find the minimum number of machines (bins), each with a fixed capacity W .

Heuristic Algorithms Methods that can be carried out quickly but cannot guarantee to

produce optimal results. Once again, there is no fast or optimal algorithm, so we will look

at several methods and compare them.

Page 20: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

20

Chapter 3: Planning and SchedulingBin Packing Bin Packing — Six Methods

Next Fit (NF) Next Fit Decreasing (NFD)First Fit (FF) First Fit Decreasing (FFD)Worse Fit (WF) Worse Fit Decreasing (WFD)

Next Fit (NF) – A new bin is opened if the weight to be packed next will not fit in the bin that is currently being filled; the current bin is then closed.

First Fit (FF) – The next weight to be packed is placed in the lowest-numbered bin already opened into which it will fit. If it does not fit in any open bins, a new bin is opened.

Worse Fit (WF) – The next weight to be packed is placed into the open bin with the largest amount of room remaining. If it does not fit in any bins, open a new bin.

Decreasing-Time Heuristics (NFD, FFD, WFD) – Create the priority list by listing the tasks in order of decreasing size before the bin-packing method.

Page 21: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

21

Chapter 3: Planning and SchedulingBin Packing Next Fit (NF)

Advantages – Does not require knowledge of all the weights in advance; only need to know the remaining space in the bin.

Disadvantages – The bin packed early on may have had room for small items that come later in the list.

Best method for assembly-line packing.

Example Using Next Fit Bin Packing Pack list 6, 6, 5, 5, 5, 4, 4, 4, 4, 2, 2, 2, 2, 3, 3, 7 7, 5, 5, 8, 8, 4, 4, 5

Page 22: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExamplePack boxes of sizes 5, 7, 2, 6, 5, 1, 3, 4, 2,

3, 6, 3 into bins of capacity 10. How many bins are

requireda) using the next-fit algorithm?b) using the first-fit algorithm?c) using the worst-fit algorithm?

Page 23: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

a) There are six bins required.

Page 24: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

b) There are five bins required.

Page 25: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

c) There are five bins required.

Page 26: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExamplePack boxes of sizes 5, 7, 2, 6, 5, 1, 3, 4, 2, 3, 6, 3 into bins of capacity 10. How many bins arerequireda) using the next-fit decreasing algorithm?b) using the first-fit decreasing algorithm?c) using the worst-fit decreasing algorithm?

Page 27: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

SolutionFirst, rearrange the boxes in decreasing order of size.7, 6, 6, 5, 5, 4, 3, 3, 3, 2, 2, 1

a) There are six bins required.

Page 28: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

b) There are five bins required.

Page 29: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

c) There are five bins required.

Page 30: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

30

Chapter 3: Planning and SchedulingResolving Conflict Goals of Three Scheduling Problems

Optimization issues – Try to maximize profit, minimize cost. Example: Scheduling machine time for earliest completion time

Equity – Try to make things fair for all participants. Example: Schedule baseball games (same number home and away

games) Conflict Resolution – Try to prevent conflicts from happening.

Example: Scheduling college final examinations for end of term

Resolving Conflict via Coloring Vertex Coloring – The vertex coloring problem for a graph requires

assigning each vertex of the graph a color (label), such that two vertices joined by an edge are assigned different colors.

Chromatic Number – The chromatic number is the minimum number of colors needed to label the vertices of a graph so that no two vertices of the graph joined by an edge get the same color.

Page 31: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Vertex ColoringColor the vertices of the following graphs in such a way that adjacent vertices have different colors. What is the minimum number of colors required for each graph?

Page 32: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExampleDiscuss the coloring of the following graphs. Can you make any generalizations regarding the chromatic number of such figures?

Page 33: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

In general, any pie chart with an even number of sectors can be colored with 2 colors and with an odd number of sectors (greater than one) requires 3.

Page 34: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

ExampleWhat is the chromatic number for each of the following?

Page 35: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

SOLUTION:

Page 36: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

36

Chapter 3: Planning and SchedulingResolving Conflict Example: Scheduling Exams Using Vertex Coloring

There are eight (8) finals to schedule with only two (2) air-conditioned rooms. (8 courses: French-F, Math-M, History-H, Philosophy-P, English-E, Italian-I, Spanish-S, Chemistry-C).

In the graph, courses are represented by vertices and two course are joined by an edge for every student enrolled in both courses.

a) Represents conflict info about the courses.

b) 8 colors represent 8 time slots — not optimal.

c) 4 colors — 4 time slots but need 3 rooms for time slot 2.

d) 4 colors with 4 time slots — each color appears twice so only need 2 air condition rooms.

The chromatic number is 4 as in d (we scheduled 8 exams in 4 time slots without a conflict).

Page 37: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Conflict ResolutionA man wants to set up an aquarium in his home to contain five different types of fish—A, B, C, D,and E. However, some of these fish will eat other ones and thus cannot share a tank. The chartbelow displays the incompatibilities. (An X indicates that the two species cannot share a tank.)What is the minimum number of tanks required, and which fish go into which tank?

Page 38: Scheduling Two people are camping out and wish to cook a simple supper consisting of soup and hamburgers. In order to prepare the supper, several tasks

Conflict Solution: