Download presentation
Presentation is loading. Please wait.
Published byRobert Whitehead Modified over 9 years ago
1
D1: Bin Packing Algorithms
2
D1: Bin-Packing Algorithms Bin-packing algorithms can be used to find ways to complete a number of tasks in given time slots, provided the tasks can be done in any order. Say that you are a journalist. There are 5 days until deadline day (so there are 5 bins). Each day contains 7 working hours (so each bin has a capacity of 7 hours). You then have a number of articles to write, each of which take a certain number of hours and must all be completed for deadline day. A bin-packing algorithm can help you to find a good order in which to do the tasks! Nothing to do with actual bins, you may be pleased to know!
3
There are three sorts of bin-packing algorithm. The first is the first-fit algorithm. Example 1:Jayme is a journalist. The articles she has left to write before deadline day will take 32421532 hours. Each working day lasts 7 hours. Apply the first-fit bin-packing algorithm to the list to determine the number of days it will take Jayme to write the articles. D1: Bin-Packing Algorithms
4
The first-fit bin-packing algorithm means that you put each item in the first bin that has the free capacity to take it. Let’s see how this works. Working 3242153232421532 Bin 1 3 2 Bin 2 4 2 1 Bin 3 5 Bin 4 3 2 Using the first-fit algorithm, Jayme will need 4 working days to write her articles. D1: Bin-Packing Algorithms
5
The second sort of bin-packing algorithm is the first-fit decreasing algorithm. Example 2:Sandrine is a joiner. She needs the following lengths of wood, in metres, for a project. 0.42.521.631.20.9 The wood she needs is sold in 4 metre lengths. a) Carry out a quick sort to produce a list of the lengths needed in descending order. Identify your pivots clearly. b) Apply the first-fit decreasing bin-packing algorithm to your ordered list to determine the total number of 4m lengths needed. D1: Bin-Packing Algorithms
6
32.521.61.20.90.4 This algorithm works by using a sorting algorithm on the data to get it into decreasing order, and then using the first-fit idea with the sorted list. WorkingThe correctly ordered list is Bin 1 3 Bin 2 2.5 Bin 3 2 Using the first-fit decreasing algorithm, Sandrine will only need 3 of the 4m lengths of wood to complete her project. 1.6 1.2 0.9 0.4 D1: Bin-Packing Algorithms
7
What would have happened if you had used the first-fit algorithm? Example 2A:Sandrine is a joiner. She needs the following lengths of wood, in metres, for a project. 0.42.521.631.20.9 The wood she needs is sold in 4 metre lengths. Apply the first-fit bin-packing algorithm to the data to determine the total number of 4m lengths needed. D1: Bin-Packing Algorithms
8
D1: Bin-Packing There is another way to pack bins… use your own judgement! This is the full bin algorithm. The signal that tells you to do this is when a question begins with “Use the full bin algorithm to…” If that is the case, check through the list and make as many full bins as possible out of the numbers that you have (see Q3 of D1 January 2010 for an example of this).
9
There is another calculation related to bin-packing that you can be asked to perform: the lower bound. Example 2B:Sandrine is a joiner. She needs the following lengths of wood, in metres, for a project. 0.42.521.631.20.9 The wood she needs is sold in 4 metre lengths. Calculate a lower bound for the total number of 4 metre lengths that Sandrine will need. Add together all the values in the list, divide the total by the size of the bin (4, here) and round up (ALWAYS up!). 11.6 ÷ 4 = 2.9 3 bins minimum D1: Bin-Packing Algorithms
10
Notes The first-fit decreasing bin-packing algorithm is generally more efficient than the first-fit bin-packing algorithm. However, neither of these algorithms is guaranteed to give the best solution! There is no true algorithm that will always produce the best solution to bin-packing problems. Whenever an algorithm is not guaranteed to give the best solution possible, it is called a heuristic algorithm. D1: Bin-Packing Algorithms
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.