Course Home | Homework | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science A220/P126
Data Structures and Object-Oriented Programming

Michael Goldwasser

Spring 2005

Dept. of Math & Computer Science

Programming Assignment 08

Arithmetic Expressions

Due: Friday, 29 April 2005, 8pm

Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.

Collaboration Policy

For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners. You will note that there are two distinct implementation approaches required for this assignment. It may be that the partnership divides the work by having one person do one implementation, and one person another (with consultation as needed). Alternatively both pieces could be developed side-by-side.

Please make sure you adhere to the policies on academic integrity in this regard.

Contents:


Preface

Although each individual part of this assignment may not be so difficult, you should expect that the 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.

This assignment will involve several programming techniques which we have not yet used in earlier assignments. Namely,


Overview

You have just taken an internship with an online grocer (Please Note: I had originally written this assignment at a time when I thought online grocers might be viable -- who knew?). 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.

For example, the execution of the program might be started as:

Binpack 20 0.2 0 1

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

One of the challenges of this program is simply the many required tasks. Here is our suggested approach for the development cycle:


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, Heuristic.cpp, SlowPQ.h, SlowPQ.tcc, FastPQ.h and FastPQ.tcc. However, if you find need to create any additional files, please make sure to submit those as well, along with an updated makefile, if necessary.


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):


Michael Goldwasser
CS A220/P126, Spring 2005
Last modified: Sunday, 24 April 2005
Course Home | Homework | Programming | Schedule & Lecture Notes | Submit