As Binpacking
As Binpacking
PROBLEM: You have a set of "bins". Each bin has a capacity of 10 pounds. You are
given items weighing from 1 to 10 pounds each. The goal is to place the items in the bins
such that each bin is packed as close to capacity as possible. For example, if you have
items weighing 4, 3, 7, and 6, you could fit them into 2 bins: 4 + 6 in bin #1, and 3 + 7 in
bin #2. There would be no wasted capacity, as both bins are filled to capacity. However,
if you place 4 +3 in bin #1, you'd need to place 7 and 6 in separate bins, thereby, using 3
bins. There would be 3+3+4=10 pounds of extra capacity. Given 5 algorithms for placing
items in bins, determine the weight of each bin that needs to be used.
1. First Fit – Starting with bin #1, place the items, in the order given, in the first bin in
which they fit.
2. First Fit Increasing – Sort the items from lightest to heaviest. Then place the items,
starting with the lightest and bin #1, in the first bin in which they fit.
3. First Fit Decreasing – Sort the items from heaviest to lightest. Then place the items,
starting with the heaviest and bin #1, in the first bin in which they fit.
4. Best Fit – Starting with bin #1 and using the items in the order given put the items in
the first bin that will come closest to maximizing the load of that bin.
5. Worst Fit – Starting with bin #1 and using the items in the order given put the items
in the lightest non-empty bin in which they fit. Empty bins are used only when no other
bins are available.
INPUT: There will be two input lines. Each line will have a list of item weights. The
list will end with a weight of zero.
OUTPUT: There are 10 outputs. For each line of input print in order, starting with bin
#1, the weight of each non-zero bin used for each of the algorithms. The output lines will
be in the order of the algorithms above unless labeled otherwise.
1. 1, 3, 5, 3, 6, 2, 1, 2, 4, 6, 3, 7, 0 1. 10, 9, 8, 9, 7
2. 9, 10, 5, 6, 6, 7
3. 10, 10, 10, 10, 3
4. 10, 9, 8, 9, 7
5. 9, 9, 9, 9, 7
ACSL
ALL-STAR American Computer Science League Program #5
Bin Packing
TEST DATA
TEST INPUT
1. 2, 9, 4, 7, 1, 3, 2, 6, 8, 1, 4, 2, 5, 3, 4, 0
2. 1, 4, 2, 8, 2, 1, 6, 3, 4, 5, 2, 2, 7, 3, 1, 5, 2, 0
TEST OUTPUT