COS 226 Programming Assignment #3

Checklist

Goals

Here are the main goals of the assignment.

Frequently Asked Questions

My program doesn't compile when I hit the Run Script button on the whiteboard submission system.  Is this OK?  No. You will lose a substantial number of points if your code does not compile.

Do I need to use a binary heap?  No, that's just a suggestion, but probably a good one.  However, you should be able to handle the large instances (a million weights).

Can I use the Java library LinkedList or ArrayList?  No, you should not use any library functions on this assignment, except that you can use Java's system sort for IntegerSorter.java.

Am I required to format the list of file sizes exactly as in the reference solution? No, this is not a requirement, but if you wish, you can use the Java library DecimalFormat.

Do I need to implement a full blown version of a linked list data type?  No. We recommend defining an inner class for your linked data structure inside Disk.java, similar to the way we implemented Queue.java in COS 126.

Why doesn't Disk d = pq.delMax(); work?  The method delMax returns an Object. You need an explicit cast to convert from the more general type Object to the more specific type Disk.  The cast is not needed (or recommended) with insert since you are converting from a more specific type to a more general type.

Input, Output, Testing, Submitting

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.

Program report.  You also need to submit a brief written report on what you did for this assignment that answers these questions.  Besides providing details about your implementation which are not clear from the comments within your source code, your program report should also contain an empirical comparison of the heuristics and a discussion of their effectiveness.  This report should be submitted electronically using whiteboard with your source code files.  You can submit either plain text or pdf.  The submitted program report file should be called either report.txt or report.pdf.  See the assignments page for more details on how to submit.

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.