COS 226 Programming Assignment Checklist: Bin Packing

Under a bit of construction, especially the part dealing with the best-fit heuristic.

Goals

Here are the main goals of the assignment.

Frequently Asked Questions

Do I need to use a binary heap for worst-fit and a binary search tree for best-fit? No, these are just a suggestion, but probably good ones. However, you should be able to handle the large instances (a million weights).

Can I use an Iterable collection such as Queue or java.util.LinkedList to store the list of files associated with each disk? Absolutely. Now that you know how to implement it, we encourage you to take advantage of Java's foreach loops.

Am I required to format the list of file sizes exactly as in the reference solution? No, this is not a requirement, but we recommend using StdOut.printf() and String.format().

My Disk data type is mutable, but I am using it as the key in a priority queue or symbol table. Will that create a problem? No, provided you are careful not to mutate a Disk while it is on the data structure. Instead, remove it from the data structure, mutate it, and then reinsert it.

How should I implement the ceiling function for the best-fit heuristic? To do it efficiently, use a (balanced) binary search tree. The sorted symbol table and sorted set data types (ST.java and SET.java) provide this functionality. However, these data structures prohibit duplicate keys, e.g., two disks with the same remaining capacity. There are a number of work-a-rounds. One approach is to modify the compareTo() method in Disk to use a unique id field to break ties when two Disk objects have the same remaining capacity. Another approach is to create a separate data structure, say MultiSET.java, that allows duplicate keys.

I get the error "foreach not applicable to expression type" when I compile SET.java. What am I doing wrong? There was a bug in an early version of DrJava. Try compiling from the command-line or downloading the latest version of DrJava.

How do I ask Java for more memory? Use the -Xmx flag. For example, the following asks Java for 100MB of space.

% java -Xmx100m BestFit < input20.txt

Is there an input on which best-fit decreasing will give a suboptimal solution? Yes, there are many. Here's a short one { 400000, 400000, 300000, 300000, 300000, 300000}.

Input, Output, and Testing

Input.   Your program should read in a sequence of integers between 0 and 1000000 separated by whitespace from standard input. Here are some sample input files. You may also use Generator.java to generate random test instances. It takes 3 command line inputs N, L, and U, and generates N pseudorandom integers between L and U.

Reference solutions.   For reference, we provide our executable code for the two heuristics on Windows, Solaris, and OS X. Choose the version of worstfit226 for your operating system and execute with worstfit226 < input.txt. Note that these programs were written in C, so you may see slightly different behavior, e.g., the formatting of the numbers. Also, the priority queue is not "stable", so although the remaining capacities of all the disk should match, you may get different file sizes on some disks.

readme.txt

You may use the following readme file template. Besides providing details about your implementation which are not clear from the comments within your source code, your readme.txt file should also contain:

Possible Progress Steps

These are purely suggestions for how you might make progress. You do not have to follow these steps.

Enrichment Section

Researchers have proved some amazing things about bin packing heuristics. For example, if the optimal packing uses B bins then the best-fit decreasing algorithm is guaranteed to use no more than 11B/9 + 1 bins (within 22% of best possible). The original proof of this result (for the first-fit decreasing heuristic) required over 70 pages of analysis! The file worstcase30.txt gives a worst-case instance where the best-fit decreasing algorithm uses 11 bins even though the weights fit snugly into 9 bins.