Assignment 4


Bonus point opportunity: In this assignment, you can either

  1. Create a simple "OK" algorithm that does reasonably in solving the problem. This algorithm should produce better results than the "naive" algorithm described below (NaiveBoxAlgorithm.java). This is relatively easy to do, as you'll see when you read the problem.
  2. Spend a bit more time and compete to get more points that can then be applied to recover points lost from a previous assignment. Your algorithm will be compared to that of every other solution proposed by students in the course. There will be extra points for devising an algorithm that outperforms the algorithms of most other students. Also, you will be able to create and submit box-problem instances to challenge other students in the class.

You will solve an "unsolved" problem, one that does not have a name yet, even if it's similar to some other problems we've seen. We'll call it the "Box Problem." You will be given a box and a bunch of items with the goal of placing as many items as possible into the box.

The problem is easily described with a picture:

Here we have a two-dimensional box of width 5 and height 5. (In general, width and height can be different.) This one already has items (six of them numbered 0 to 5, and each with a color) placed in the box, showing a solution. The grid lines are drawn for convenience so that one can view each item as consisting of a group of cells in a fixed geometric pattern (such as the L-shaped item #1), and one can see the whole box as a grid. Item placements need to respect cell boundaries: we can't, for example, place item 0 so that its left edge starts in the middle of a cell.

In a particular instance of the problem, you will be given the box dimensions and the list of items in a plain text file. For instance the above problem is in the text file testproblem2.txt, which looks like this:

5 5
#item 0
 0 0 0 1 1 0 1 1
#item 1
 0 0 0 1 2 2 1 2 0 2
#item 2
 0 0 1 0 2 0 3 0 4 0
#item 3
 1 0 0 3 0 2 0 1 0 0
#item 4
 0 0 0 1 1 1 2 1
#item 5
 1 0 0 0
  
Let's explain: To understand cell coordinates, let's draw the 5x5 grid:

Your main goal is to write code to solve the problem of deciding which items go into the box, the orientation for each item, and where they are placed (the translation for each item) so that as many items as possible are packed and the as much of the box as possible is used. You will do that by creating a class that implements the BoxProblemAlgorithm interface, which has two methods: To see an example, take a look at NaiveBoxAlgorithm.java, which implements the interface and features a simple but somewhat ineffective algorithm. To see how it runs, examine the code in TestBoxAlgorithm.java, then compile and run TestBoxAlgorithm.

Start by downloading and unpacking boxproblem.jar. The relevant javadocs:

Now let's consider some of the details: This should be enough to get started. However, there are some additional tools that you may find useful:

The competition:

Submission: