Project 2: Cookie Cutter

Group 3: Eric Li, Andy Shin, Yuan Zheng

Introduction

The second project, Cookie Cutter, was a game where a specified number of copies of polygonally shaped cookies were to be cut out from a piece of dough 1.0 units in width and infinitely long. The goal of the game was to use a combination of translation and rotation on the cookies so that the length of dough expended was as small as possible.

Aspects of the Problem

Heuristic vs Algorithm

The Cookie Cutter problem has several interesting aspects that should be brought to light before discussing strategies. The first is a choice of a heuristic versus an overall algorithm for attacking the problem. A heuristic involves trying to minimize the amount of dough used with each additionally placed copy while an overall algorithm tries to examine the entire placement configuration, i.e. all copies included. The strength of a heuristic lies in the simplicity of applying it. Once the procedure for placing one cookie has been determined, for all other copies, simply apply the heuristic repeatedly until all copies have been placed. On the contrary, for an algorithm, all cookie positions must be examined together in order to figure out the best possible configuration, and at any point in the midst of the calculation, we cannot assume certain cookies have been set and will remain at their positions. Instead, all cookie positions must be considered with respect to all other cookie positions, and changes in one placement could lead to re-positioning of all other cookies. This can potentially cause performance issues as well since the algorithm might need to re-examine all cookie placements for each change in the placement of one cookie whereas the heuristic only needs to consider the placement of the one cookie with respect to those cookies that act as boundaries for it. This is especially the case when the number of copies to be placed is large.

The advantage of the algorithm over the heuristic is that the former could potentially find the optimal solution that the latter might not be able to. For example, if the optimal placement requires that one of the cookies is not placed to minimize the length of space occupied, i.e. not optimal for that particular cookie, so that additional cookies may be placed in combination with that copy to form the optimal overall placement, then a heuristic will not find that solution. The heuristic will always look for the optimal placement at each step, which precludes solutions that are non-optimal at certain steps along the way.


In the case shown, the placement in the second picture is shorter horizontally than in the first picture. If each shape had been placed optimally at each step, the best that could've been achieved is the first picture.

One possible solution that leverages the advantages of an overall algorithm while avoiding some of its pitfalls is to apply the algorithm at different levels. In order to limit the total number of possible configurations to explore to a manageable size, we could stipulate that only placement of n copies where n is within some reasonable limit, e.g. 20, would use the algorithm. For n greater than 20, we break up the cookies into groups of 20 or less cookies and apply the algorithm separately to each group and then combine them together. The combination step could use either a heuristic or an algorithm. The idea is that we treat the groups of 20 or less cookies as one whole and manipulate each of them as a single cookie making placement much less complex. In most cases, the combination step would involve simply pushing one group into the other as far as possible. One drawback of this solution is that it might not find the absolute optimal solution for all copies since it does not examine all copies with respect to each other. Thus, in essence this solution omits some small portions of the search space for a sizable gain in efficiency. The use of an efficient algorithm over an heuristic could also be considered a meta-strategy, a class of strategies we discuss in more detail below.

Efficiency

Speaking of efficiency, one aspect of the problem worth considering is whether or not a complex strategy is worth implementing. As we worked through this project, we noticed that some complex strategies required as much time as brute force searches did but took much longer to implement because of its complexity. In those cases, the question must be asked whether or not its worth it to go with the complex strategy. In computer science, where the three primary factors governing the measurement of efficiency - time, space, and cognitive strain - come into play, it would not be worth the added time and cognitive strain requirements to implement a high complexity algorithm over a brute force one, especially if it can be shown that the former has no clear advantage over the latter. However, if the algorithm does have some advantage, then it would probably be better to choose it over the brute force algorithm, which even though is much simpler and avoids issues like emergent properties of complex systems or excessive cognitive strain and development time, has the crucial flaw of lacking scalability.

Cookie Shapes

Another aspect of the Cookie Cutter problem is that different classes of strategies seem to work better for different classes of cookie shapes. One class of strategies based on simulating real physical interactions between cookies as objects, which we will call physics strategies, seem to work quite well for convex shapes. But when dealing with concave shapes where a protrusion on the shape fits well with an indentation in another part of the shape, physics strategies seem to have trouble finding this fit. One situation that exemplifies this predicament is that if you randomly place jigsaw puzzle pieces on a flat surface and then compress them from all sides, it's very unlikely that the pieces will fall into a configuration of occupying minimal area. That can only be done by matching the pieces with the slots they are suppose to fit in deliberately. One the other hand, a strategy that matches sides of similar length and pairs of angles that add up to 360 degrees will be much better suited for dealing with cookies of the puzzle type. But this strategy will not perform as well as a physics strategy when placing convex shapes. A potential solution to this problem is to determine the type of the cookie before choosing the method to apply. However, determining cookie type is not necessarily trivial. One way around this is to simply run all the methods on the cookies and choose the one that performs the best. The only problem with this solution is that it is potentially very expensive in terms of computation time.

Primary Strategies

These are various strategies we brainstormed and analyzed and tried to implement. Due to time constraints, we weren't able to produce completed versions of all of them. Nevertheless, it was a valuable learning experience for us to have looked at various strategies and their respective strengths and weaknesses, and we have documented our finds below.

Hybrid Strategies

Hybrid strategies use a combination of the strategies we documented above. In reality, most complex strategies are hybrid strategies employing numerous strategies to conquer different sub-problems. Below, we elaborate on some of the hybrid strategies we devised and implemented. One note about hybrid strategies is that there are many ways to combine multiple strategies. Even the same two strategies can be hybridized in a variety of ways with differing levels of effectiveness.

Note: A concluding remark we want to make about hybridizing strategies is that the simplest way to combine any number of strategies is to run them all and select the best placement. However, this is not truly combining methods since each method is applied on the entire set of cookie copies. Each method is not applied to individual copies where appropriate to achieve a best overall placement.

Meta-Strategies

Some strategies we came upon apply on a higher level than the detailed strategies enumerated above. These meta-strategies can be applied to any regular strategies to increase effectiveness and therefore are just as important if not more so.

Group3 Player

The final submission of our player consisted of three players combined, a rectangular/rotation/compaction player, a more efficient version of a pure sampling player, and a compaction/sampling player. Some of our other players were omitted due to bugs and excessive computation time of combining all methods.

Tournament Results Analysis

We tallied the rankings of our player in all games played in the tournament and reorganized it into a matrix in order to facilitate identifying relationships between the various types of cookies played and the strengths and weaknesses of our player. The chart is separated and color coded into three sections based on the source of the cookie shapes. Each box contains our ranking for the tournament round using the shape specified at the left and the number of copies indicated at the top. The average ranking over all different copies of the same shape is calculated and shown at the right. The overall average ranking is displayed at the bottom right. The results are also sorted by average rankings.

# of Cookie Copies
Cookie Shape 1 2 3 4 5 6 7 12 13 20 53   Average Rank     
L.out.game 3 2 1 1 1 2 2 2 2 1 1   1.636363636    
small.out.game 2 1 1 1 1 1 1 7 6 6 3   2.727272727    
dumbbell.game 6 6 1 2 2 4 4 2 2 3 4   3.272727273    
horseshoe.game 3 4 3 2 4 4 3 4 4 4 4   3.545454545    
pacman.out.game 4 4 3 5 4 4 4 4 3 4 3   3.818181818    
lightening.game 5 3 5 2 4 5 5 4 4 4 4   4.090909091    
person.out.game 5 2 5 5 4 4 4 4 4 4 4   4.090909091    
arrow.game 4 2 6 4 5 6 5 4 4 4 3   4.272727273    
H.out.game 4 5 5 4 5 4 4 4 4 4 4   4.272727273    
P.out.game 4 6 4 5 4 4 4 4 4 4 4   4.272727273    
boat.game 5 6 5 6 5 5 5 7 4 4 6   5.272727273    
Group2Tournament.game 5 4 5 4 4 5 4 4 4 2 2   3.909090909    
Group1Tournament.game 4 6 5 5 3 5 3 3 3 3 5   4.090909091    
Group3Tournament.game 4 2 5 5 5 5 5 4 4 4 4   4.272727273    
Group7Tournament.game 4 4 1 5 5 5 5 5 5 4 4   4.272727273    
Group5Tournament.game 5 2 5 4 5 5 6 4 5 4 4   4.454545455    
Group4Tournament.game 5 6 5 5 5 5 5 4 4 4 4   4.727272727    
Group6Tournament.game 6 6 6 6 5 5 5 5 5 4 4   5.181818182    
rand-0.1.game 3 4 5 4 5 5 4 4 4 4 4   4.181818182    
rand-0.2.game 1 5 3 6 6 6 4 4 4 4 5   4.363636364    
Overall Average Rank 4.036363636  

[1]
 :

Our player seems to have performed best when placing the extremely large L-shaped cookie and the extremely small cookie. Closer inspection of the small cookie case reveals that a bug in our player caused our cookie placement to be invalid for some of the rounds, and that we could've performed much better for that cookie otherwise. It's not apparent from the data why we performed much better for shapes of extreme sizes. We surmise that the other players probably spent a large amount of time optimizing for the typical shapes and devised algorithms that perform well when searching various orientations given enough freedom to move but have a more difficult time with oversized shapes that have very limited ranges of movements and combination possibilities. Aside from those observations, we note that our player consistently ranks in the exact middle of the pack, averaging an overall rank of 4 out of 7 players.

Conclusion

In comparison with project one, this project was definitely different in its focus. Our analyses and approaches were much more heavily mathematically based. Also, the set of potentially good solutions seemed at first very limited, but as we delved into the project, we discovered there were many layers to the problem, and it had a hidden complexity that was not at all trivial. We tried to mine the complexity of the problem and use it to our advantage through implementing various intuitive and counter-intuitive algorithms. However, the more we did so, the more we realized that we have to look past the complexity and explore the problem from a higher level of abstraction to make considerable progress. That's when we moved from developing and testing strategies to categorizing strategies by similarities, identifying common strengths and weaknesses, and formulating meta-strategies. Time constraints limited us from going further down that path, but we feel that it is an important conclusion that perhaps future groups might find useful.

Suggestions

While working on this project, we spent the majority of our time coming up with and implementing solutions to sub-problems, most of them mathematical in nature. It would, therefore, probably benefit future groups working on this particular problem, if it's to be ever used again, to have access to a larger library of functions for manipulating cookies and performing various calculations on them. Most of these can probably be found in people's code submissions. If groups are given more tools to work with, they could focus more on exploring various strategies.