Programming Assignment

Due:

Please make sure you adhere to the policies on academic honesty.

Please see the general programming webpage for details about the programming environment for this course, and specifically for directions in how to submit your programming assignment electronically.

The files you need for this assignment can be downloaded here.


Contents:

  • Preface
  • Overview
  • Heuristics
  • The Driver
  • Your Tasks
  • Recommended Steps for Progress
  • Files you will need
  • Files to Submit
  • Grading Standards
  • Useful Java hints

  • Preface

    Although each individual task we ask of you might not be so difficult, this assignment as a whole will be the most involved programming assignment as of yet. Needless to say, please start early and tackle the program in stages.


    Overview

    You have just taken an internship with an online grocer. You will be responsible for packing an order of groceries into 'bins' which will then get loaded onto a truck for delivery. Of course, the goal is to be able to pack the order into as few bins as possible. At the same time, you do not want to pack bins so heavily that they cannot be easily carried. In order to try to find a good solution for packing items, we will have you write a computer program. We will abstract the problem with the following model:

    This setup can actually be used in modeling a variety of different applications, and it has been given the name "Bin Packing" in the literature. Unfortunately, minimizing the number of bins appears to be a very difficult problem to solve efficiently (there are too many possibilities!). Fortunately a number of heuristics have been studied, and some of these seem to get quite good results.


    Heuristics

    In this program, we ask you to implement two particular heuristics. The first heuristic, called "worst-fit," proceeds as follows. Items are considered one-at-a-time (in the original order presented). When an item is being considered, we look at the existing bin with the most available room. If the new item fits in this bin, we place it there; if it does not fit in this bin then it will not fit in any bin, so we place the item into a newly created bin. For example, on an instance with weights .29, .11, .81 and .68, this algorithm would pack the items into three bins (note that this is not the best possible).

    A second heuristic is known as "worst-fit-decreasing." This heuristics considers items one-at-a-time, again placing each considered item into the bin with the most remaining space (if such a bin will hold the item). The difference between this heuristic and the last is that items are considered in order of decreasing weight, rather than in the original order. To do this, all items are initially placed into a priority queue and at each step the item with largest remaining weight is removed from this queue and then placed into a bin. (note that for this to work, you will have to adjust your view of priorities so that the "minKey" is the one with the largest weight). Looking at our previous example, the items would get considered in the order .81, .68, .29 and .11, and thus packed into two bins. By no means are these the only two approaches to bin packing. If anyone is interested in the history of the problem, we will be happy to provide references. But for this assignment, we will focus on these two heuristics.


    The Driver

    In order to test your program and evaluate the bin packing heuristics, we are providing you with a driver which does the following. Given an integer N and a floating-point value u in [0...1], the driver generates N weights each chosen at random in the range [0...u). These weights are stored in an array of double-precision floating point numbers. The driver calculates S, the sum of all of the weights, and reports that any solution will require at least S* bins, where S* is the smallest integer at least as great as S. For example, if the weights sum to 20.3, then we know that no solution can pack these items into 20 bins or less. (Please note: this does not mean that there always exists a solution using exactly S* bins - but it gives us a reasonable bound for which to aim when evaluating the heuristics' results.)

    The driver accepts the following five command line arguments, as specified by the user. The first four of these are required; the fifth is optional.

    At this point, the driver calls a routine worstFit which is written by you to simulate the worst-fit heuristic. This routine returns the overall number of bins used. Secondly, the driver calls a routine worstFitDecreasing written by you to simulate the worst-fit-decreasing heuristic.

    Finally, although generating random data is useful for experiments, it is troublesome when developing and testing your program. The difficulty is that when a bug arises, you generally want to fix the bug and then re-test on the same data. But if data is generated at random, you will likely get a different data set when you re-test. For this reason, we will give you a way to set a "seed" which is used by the random number generator. In this way, you can re-test on a previous data set by providing the identical seed.


    Your Tasks


    Recommended Steps for Progress

    This program might seem intimidating because of the many required tasks. Here is our suggestion for getting going:


    Files you will need

    The files you need for this assignment can be downloaded here.


    Files to Submit

    At minimum, you must submit the files: readme, Binpack.java, SlowPQ.java, and FastPQ.java. However, you will most likely need to define some additional classes (such as a Comparator, and an Object representing an individual bin). You may also free to use data structures from earlier in the class.

    Please submit all source code which you use other than those files which were directly provided by us for this assignment.


    Grading Standards

    The assignment is worth 10 points. In general, we will try to apportion the points based on the following break down (though we will use some of our own judgment in the end):


    Useful Java Hints

    Along the way, there will be a few potential difficulties involving detailed use of Java. We will summarize some very useful advice here, and we hope that you will come back to it when needed.


    Last modified: 29 October 2002