COS 226 Programming Assignment Checklist: Bin Packing

Corrections

Print the bins in decreasing order or remaining space when N is small. This should be easier.

Frequently Asked Questions

My program doesn't compile when I hit the Compile button on the Web submission system. Is this OK? No. You will lose a substantial number of points if you don't follow the instructions. We will compile your programs with the following commands:

gcc worstfit.c pq.c item.c
gcc bestfit.c st.c item.c
Even if you don't use priority queues or symbol tables, use these file names or risk angering your grader!

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

With the data file input5.txt (and others), my computer believes that the three values 0.7, 0.15, and 0.15 sum to a value greater than 1.0. What is going on?   Your program should only need 1 bin to store these three values. You are encountering common issues involving the representation of real numbers on binary computers. To effectively handle double precision numbers, you should define a constant, say EPS = 0.00000001, and modify your comparison functions so that a bin can store weight up to 1.0 + EPS.

My program prints -0.000000. What is this? It a very small negative number that when truncated looks like -0. Again, floating-point precision is the culprit.

Input, Output, and Testing

Input.   Your program should read in a sequence of real numbers between 0.0 and 1.0 separated by whitespace from standard input. Here are some sample input files. You may also use generator.c to generate random test instances. It takes 4 command line inputs N, l, u, and s and generate N pseudorandom real numbers between l and u using the seed s. The fourth command line input is optional: if it is not supplied the seed is set arbitrarily via the system clock.

Reference solutions.   For reference, we provide our executable code for the two heuristics on Windows, Solaris, and OS X.

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:

  • For the analysis, generate some input files with random weights between 0.0 and 0.2, and between 0.1 and 0.7 using generate.c. Create two tables (one for each class of inputs) as follows: for each value of N = 100, 1000, 10000, 100000, 1000000, print the total of the weights, the number of bins used by worst-fit, worst-fit decreasing, best-fit, and best-fit decreasing (even better if you report the average over several random trials for each value of N). Print the running time in seconds for worst-fit and best-fit.

  • Discuss the relative effectiveness of the heuristics. The number of bins is the most important factor, but you should also comment the running time.
  • Possible Progress Steps

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

  • Download the directory bins to your system. It contains a number of sample input files, a problem instance generator, a priority queue ADT, and a symbol table ADT.

  • Before writing code, think carefully about the data structures and operations that you will need to support.

  • Test your programs on lots of input data.
  • 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.


    cos226 Home Page
    rs@cs.princeton.edu
    Last modified: February 6, 2001