2. Different Scheduling Problem
Have collection of idpt tasks (all task
times ≤ 10). Instead of asking how
long to finish job with 3 processors,
instead ask,
“What is fewest number of processors
need to finish job in under 20 min?”
A very different question!
Example of a bin-packing problem.
3. The Bin Packing Problem
Assume have:
identical “bins” fixed capacity, and
objects (“weights”) of various sizes
that must be packed in bins.
How can we do this most efficiently
(i.e., with fewest bins)?
4. Example
A company buys bulk wire in 100 ft
spools. They use the wire in a variety of
lengths in their product. How should
they cut the wire so as to use the
fewest spools?
5. Example
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 9ft lengths.
How should we cut the boards so as to
minimize the cost of material?
6. Variants
Two possibilities:
1. Only know next weight to pack.
(Think assembly line.)
2. Have full knowledge of all needed
sizes/weights.
(E.g., a work order that lists everything
that is needed.)
7. Variants
Two possibilities:
1. Only know next wt to pack.
2. Full knowledge all weights.
In (2), it makes sense to first sort the
weights in a decreasing list. (Why?)
Leads to two variants of every bin-
packing algorithm.
9. The Bin Packing Problem
Pack wts w1, w2, …,wn into bins.
Each bin has fixed capacity.
Use as few bins as possible.
A scheduling problem in disguise!
unlimited # of procs each with fixed
capacity (Goal: minimize # procs)
11. The Algorithms
Heuristic Algorithms
• NF – Next Fit
• FF – First Fit
• WF – Worst Fit
In last 2, bins stay
open until they are
completely full.
Decreasing Versions
• NFD – Next Fit D
• FFD – First Fit D
• WFD – Worst Fit D
With these first sort
wts into decreasing
order, then pack.
12. Next Fit Packing Algortihm
Only one bin open at a time!
Pack item in current bin.
If item will not fit in current bin:
close this bin & open a new bin.
Continue until all items packed.
13. Example using Next Fit Packing
Wts 6, 6, 5, 5, 5, 4, 4, 4, 4, 2, 2, 2, 2, 3, 3, 7, 7, 5, 5, 8, 8, 4, 4, 5
14. Next Fit Packing Algortihm
Advantages – Do not need to know 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.
15. First Fit & Worst Fit Packing
Keep all bins open until full. Then close.
To pack an item, look at open bins.
FF Place item in first bin in which it fits.
WF Place item in bin with the most space
(and into which item fits) .
Only open new bin if item will not fit in any
of the already open bins.
16. Bin Packing Methods
Next Fit & First Fit & Worst 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.
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.
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.
17. Bin Packing Methods
Next Fit Decreasing (NFD)
First Fit Decreasing(FFD)
Worse Fit Decreasing(WFD)
Decreasing-Time Heuristics
NFD, FFD, WFD – Create the priority list by
listing the weights in order of decreasing size
before applying selected bin-packing
method.
18. Example: Next Fit
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 9' lengths(!). How should you cut the boards
so as to minimize the cost of material? Use (1) NF and (2) NFD.
Next Fit: 6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
8
4 6
5
4
5 2
2
3
7
5 5
8
4
4
3 1 3 1 1
4 4
0 2
2
19. Example: Next Fit
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 9' lengths(!). How should you cut the boards
so as to minimize the cost of material? Use (1) NF and (2) NFD.
Next Fit Decreasing: 8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 2, 2
8
4 8 7
6 5 5 5 5 4
4
4
3
2
2
2
1 1
0
2 3 4 4 4 0
20. Example
8
4 6
5
7
4
6
5
3
4
2
8
4 7 2
Pack the following weights: 6, 5, 7, 3, 4, 2 in bins of size 10 using
(1) NF and (2) NFD.
Next Fit: NFD: 7, 6, 5, 4, 3, 2
3
21. Example: First Fit
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 9' lengths(!). How should you cut the boards
so as to minimize the cost of material? Use (1) FF and (2) FFD.
First Fit: 6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
8
4 8
7
5 5
5
4
4 4
3 2
2
2
6
5
1
0 0
0 0 0 0
22. Example: First Fit
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 91 lengths(!). How should you cut the boards
so as to minimize the cost of material? Use (1) FF and (2) FFD.
First Fit Decreasing: 8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 2, 2
8
4 8
1
7
6 5 5 5 5
4 4 4
3
2 2
2
0 0 0 0 0 0
23. Example
4
Pack the following weights: 6, 5, 7, 3, 4, 2 in bins of size 10 using
(1) FF and (2) FFD.
First Fit: FFD: 7, 6, 5, 4, 3, 2
1 1 1 0 0 3
8 8
4
3 4 2
7
6
5
3 4
7 2
6
5
24. Example: Worst Fit
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 9' lengths(!). How should you cut the boards
so as to minimize the cost of material? Use (1) WF and (2) WFD.
Worst Fit: 6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
8
4
6 5
4
0
4
2
1
2
2
1
3
7
5
2
8
1
5 4
0
5
5
0
25. Example: Worst Fit
A wall unit requires boards of lengths:
6, 5, 4, 5, 3, 2, 2, 2, 7, 5, 5, 8, 4, 4
Stock boards come in 91 lengths(!). How should you cut the boards
so as to minimize the cost of material? Use (1) WF and (2) WFD.
Worst Fit Decreasing: 8, 7, 6, 5, 5, 5, 5, 4, 4, 4, 3, 2, 2, 2
8
4 8
1
7
6 5 5 5 5
4
0
4
0
4
0
3
2
2
2
7
1
1
0
26. Example
4
Pack the following weights: 6, 5, 7, 3, 4, 2 in bins of size 10 using
(1) WF and (2) WFD.
Worst Fit: WFD: 7, 6, 5, 4, 3, 2
0 2 1 1 1 1
8 8
4
4
2
3
5
7
6
2 3 4
7
6
5
27. Exercise
Find a question of the form:
Use indicated bin-packing algorithm to
place given weight in the supplied,
already partially filled, bins.
Place wts in the bins and select the
next wt to be added in such a way that
each of the 3 algorithms (NF, FF, WF)
will place the wt in a different bin.