Group 2: Project 2

Project 2: Cookie Cutter



Group 2:

Contents:


Introduction


In our approach to the Cookie Cutter Project, we attempted to make a player that would create as close to optimal cuts as possible. To that end, we did a very respectable job of getting a player that works wll in non-puzzle situations. However, since we were not able to successfully implement and integrate an edge-matching strategy, we were unable to achieve our most primary objective. That said, we did manage to create a player that ran quickly, and perform above-average in all cases.

[ top ]


Initial Strategies


We had two initial approaches to the cookie cutter problem: first, we tried to determine how best to model the human thought process when one goes to place a cookie. Second was to work on the problem using a combination of iterating through a combination of both fixed and random rotations, and then smushing the objects together as best we could.

With regard to the first idea, the most basic aspect of the thought process we could think to model was to place a shape directly adjacent to another copy of it rotated 180 degrees. In particular, we came up with a very compilicated 12-sided shape, and then rotated it around to try and find the optimal shape. We tried to think through what he was looking for to match up sides -- for the first placement, it appeared as though he looked for a long side next to a large angle, or ideally, a 90 degree angle. We also looked to match up the two longest, flattest sides. After that, with a more erratic sides, tried to fit the corners into indentations.

We came up with the idea of simply rotating a given object 180 degrees and then smushing. We thought this would be a good idea becuase it allowed for a reduction in the amount of time taking in figuring out how to rotate, allowing the focus to shift to smushing them together.

We then tried to think through how to best smush the shapes together. We considered leaving rotation out account, and just tried to line up vertices on top of one another, essentially trying to fit corners into holes, forming a new, larger shape. Then, measure the new angles formed, and space wasted. Then, try again, and keep trying until the wasted space is minimized.

click the image for a larger view

We decided to try and stack the cookies in a column, and then line the columns up. We will try and find the optimal column by doing edge matching (iterating through and trying all edge matches). However, it became very clear very quickly that while these intial thoughts may work in some cases, they are not necessarily universal enough to apply to an overarching alogrithm. We found this particular kind of approach to the problem too daunting, and it required such an examination of the human thought process, and it seems, in the runs we did on paper, that much of what allows a person to just eyeball and shape and work through placing it consists both of visual hints, a true sense of positive and negative space, and a clear idea of what the shape actually looks like. Rather than attempt to try and model the latter computationally, we were surprised to find, once we examined Group one's code, that a more simple, direct approach could be used in order to get us on track. This second idea consisted of the aforementioned Group 1 code, with major modifications, including a combination-strategy that included rotating deliberately and randomly, and then pushing the shapes together as best as possible, eventually became our final strategy, and is known as the Bin Player.

[ top ]


The Bin Player


Beginnings of the Player

The code for this final Player originated from the initial framework that Group1 used for their first player, the Pilsbury Doughboy. We are greatly indebted to Group1 for this framework, for it provided a Cookie class, transformation and check methods, and other methods that proved invaluable.

With Group1's inital code as a base, we set about to change their initial strategy. This initial strategy consisted of iterating over 1000 different possibilities for placement, and chose the one with the lowest score. From there, we moved into a more calculating strategy that tried to find the best combination of initial rotation and placement.

Overall Algorithm

The algorithm works as follows: For the first 180 degrees, every one degree rotation is attempted. For each given rotation position, a cookie are either moved to the left and then up, up and to the left, or simply up. The first one third of all 1000 guesses are moved left and then up. The second two thirds of the guesses are moved up and then left. This creates sort of a zig-zagging pattern in the placement possibilities. The final third of the 1000 guesses are placed in a random location towards the top, to try and snuggle in the pieces. At each guess, only a single cookie is being considered,and for this cookie, the score is calculated, and the position is preserved if and only if the newly generated score beats the old best score. After determining the position of the current cookie, its placement with the rest of the cookies placed thus far is considered, in order to form the best "bin" of cookies. Specifically, our strategy moves out of the greedy category by taking advantage of possible combinations of smaller sets.

What we then do is try to place cookies in a minimal area. As more cookies are added it gets harder to place them without collisions, and strategies often lose their compactness over several 'columns' of cookies. We look for all combinations of smaller amounts of cookies, this way, if we pack 1 or 2 columns of cookies well, but not 3 or 4, we just copy the whole original placement and treat that as its own cookie. The picture to the right is a good example of how the algorithm produces three bins of four cookies when there are 12 cookies to be cut.

Overall Algorithm -- Pseudo-code:

The algorithm can be further outlined in natural language as follows:

for each cookie {

   in 1000 tries, find the placement of the cookie that minimizes the width, first moving along the 180° of one open side, then using random moves, all geared to "pack" the cookie into open space

   if after 1000 tries, we for some reason didn't generate a single valid placement (e.g. the cookie was overlapping, etc), then keep trying until the first possible solution is found

   if this is the first cookie, store the placement in a "bin"

   else

        if this placement yields a better score than a combination of previous placements tiled together,

                      then store this placement (of all the laid-out cookies) in a "bin"

       else set the layout for this cookie & previous ones to a "tiled" combination of previous placements that have been store in "bins"

}

return the best layout for the total number of cookies, which might be each cookie having been placed by the "random packer", or it might be repeated sets of cookies whose group placement had been stored in a "bin", or it might be some combination of both techniques.

State Diagrams

[ top ]


Analysis of the Final Player


Strengths

Our player typically came in under the time of the groups that consitently placed above us, namely, groups one and six. An extreme example of this occured in the test run of Group 7's cookies. These cookies were long and thin, and could not be placed vertically. In this case, for 53 copies of the cookie, not only did we place first, but our time, 19.528 seconds, was almost five times faster than our nearest opponent's (group 1's) time of 108.437 seconds. So the bin packing strategy will keep the time limit down as it will repeat the placement once if finds an appropriate bin. We are also very good at placing only one cookie, which is show by our score for one cookie placements in the tournament -- we were first place in 11 out of 20 runs, and average 2.25th place.

Yet another good visual example of the bin strategy occured in the 12 copy test of the person cookie. You can see clearly the repetition of the two people stacked upon on another, with the exceptions of the first and the last cookie. This is yet another example of the speed of our algorithm. Here, we both acheived the best solution and the second best time: our time was 8.344. Our closest competitor, Group1, took over 26 seconds.

Weaknesses

The lack of edge matching code really hurt our placement in the tournament. For shapes such as Group 1's martini style cookie, we averaged only 3.7th place. The algorithm really falls apart when sophisticated placements that would involve lifting the cookie need to be made.

An additional problem arises from a part of our algorithm we thought to always be a feature. Because in every case we try and snug the pieces closer together, we will generally have a more compact use of our space than other players. However, when we would do better to space out and not snug the pieces together, the algorithm loses out, because there is always a degree of pushing left or up that is tried in order to get the most snug fit. But since, as is the case with the Small cookie, pushing certain cookies together may only make them stick out more horizontally, therefore increasing the score and impeding the overall effectiveness of our algorithm.

Overall Comments

This bin strategy had great integration possibilities if we could have successfully combined it with an edge matching strategy. Such a combination of strategies would have meshed well because with a little extra fine tuning, we could have treated two cookies with matched edges as a bin of cookies, and used it along with the current algorithm. As it stands, our algorithm works at least as fast as the two Groups that typically performed better, namely, Groups one and six, but does poorly in cases where puzzle-piece type fitting would benefit the placement.

[ top ]


Tournament Analysis


The results of the tournament, shown below, reveal that our player typically came in between second and third place on average over all cases and all different copy numbers tested.

Taking the dumbell, group1 and small cookie configurations as examples,

Group1 cookie, 5 copies

This cookie required both the ability to fit pieces together, and to recognize that they should fit together vertically. This is a demonstration of the sheer limitations of a bin packing algorithm that does not do extensive edge matching. While we were able to find a fit with the martini style piece into the opening on the other side, the algorithm clearly did not pick up on the best bin placement, which would have been the same as that of the winning placement--two pieces stacked vertically. In theory, our bin packing algorithm should have come up with this as the best placement, but the fact that it did not indicates that there is some kind of bug in the implementation of the algorithm.
Winning Placement Our Placement

Dumbell Cookie, 20 copies

In this case, our testing after the tournament reveals either a mistake in the results or an inconsistency in our bin packing strategy. We suspect it may be a tournament bug, as we have never perceived the bin algorithm producing different output for the same input, though the randomness involed does allow for this possibility. The listed winner of this game, Group 6, as well as the players behind them (Groups 1 and 3) each scored over 3, as did we. But in our test run to grab a screenshot, we discovered that we actually received a better score for this particular number of cookies -- we scored a 2.9808. Click on the image to the right to view the full screen shot and the score.
Winning Placement
Our Placement

Small Cookie, 7 copies

In this case, though we are able to smush together the cookies better than in the winning placement, it is the sheer nature of the pushing the cookies together to try and get a more snug fit that creates a problem. This illustrates a particular case of our player's weakness when the snugging strategy backfires.
Winning Placement Our Placement

Here are the complete results of all of our runs in the tournament:
one cookie
arrow 1
boat 4
dumbell 1
horseshoe 4
H 3
lightening 1
L 4
pacman 1
person 1
P 1
small 1
group1 1
group2 1
group3 3
group4 1
group5 1
group6 4
group7 3
rand-0.1 5
rand-0.2 4
average: 2.25
2 cookies
4
2
1
3
3
4
3
1
3
2
2
3
1
4
2
4
4
3
2
3
average: 2.7
3 cookies
3
4
4
4
3
3
4
4
1
3
2
4
2
3
3
2
3
4
1
6
average: 3.15
4 cookies
6
2
4
4
3
3
3
4
4
3
3
4
2
3
4
3
4
4
1
3
average: 3.35
5 cookies
1
4
4
1
3
3
4
2
2
3
4
5
2
3
3
3
3
1
1
3
average: 2.75
6 cookies
1
2
3
2
3
2
4
2
2
3
4
4
2
3
3
3
3
2
3
3
average: 2.7
7 cookies
3
2
2
4
3
2
3
5
3
3
4
5
2
3
4
3
4
4
2
3
average: 3.2
12 cookies
2
3
3
2
3
2
4
3
1
3
2
4
2
3
3
3
3
3
2
3
average: 2.7
13 cookie
2
3
3
2
3
1
3
2
1
3
2
4
2
3
3
3
4
4
1
3
average: 2.6
20 cookies
3
3
4
2
3
2
2
2
2
3
3
4
4
3
3
3
3
3
2
3
average: 2.85
53 cookies
1
3
2
2
3
2
3
2
2
3
2
3
3
3
3
2
3
1
2
3
average: 2.4

Our player performed quite admirably in the tournament considering that our algorithm ran quickly, and did not quite meet our initial goals. Had we been able to implement an edge-matching strategy in order to fit together appropriate pieces in order to pack them closely in the best way possible, we could likely have done far better. As it stands, the bin algorithm provides the best solution for the company with both time of execution and preservation of dough as considerations.

[ top ]