CS 371 - Introduction to Artificial Intelligence Homework #2

Due: Thursday 2/9 at the beginning of class
Note: Work is to be done in pairs

# Informed Search

1. Pancake Sorting with Flip Costs:  For this exercise, we will work with a variant of the "Pancake Sorting Problem".  A stack of pancakes with different sizes is represented as a permutation of p integers {0, ... , p-1}.  A "flip" of n pancakes reverses the order of the first n pancakes, and incurs a cost of n.  Our goal is to seek a minimal total cost sequence of flips to sort a given pancake permutation.  Consider the following example optimal solution for pancake sequence {5, 2, 7, 4, 1, 3, 6, 0}:

```         5 2 7 4 1 3 6 0 cost: 0
flip 2: 2 5 7 4 1 3 6 0 cost: 2
flip 4: 4 7 5 2 1 3 6 0 cost: 6
flip 3: 5 7 4 2 1 3 6 0 cost: 9
flip 2: 7 5 4 2 1 3 6 0 cost: 11
flip 6: 3 1 2 4 5 7 6 0 cost: 17
flip 3: 2 1 3 4 5 7 6 0 cost: 20
flip 2: 1 2 3 4 5 7 6 0 cost: 22
flip 7: 6 7 5 4 3 2 1 0 cost: 29
flip 2: 7 6 5 4 3 2 1 0 cost: 31
flip 8: 0 1 2 3 4 5 6 7 cost: 39
```
With the initial sequence, no cost is incurred.  After flipping (reversing) the first 2 pancakes {5, 2}, a cost of 2 is accumulated.  After next flipping the first 4 pancakes {2, 5, 7, 4}, the cumulative cost is then 6.  Continuing on through all 10 flips, we reach a goal node with optimal (minimal) cost 39.  (Optimal flip sequences may not be unique.)

Implement HPancakeSortNode.java according to this specification.  Have all the following necessary supporting classes (developed and/or specified in class) available in the same directory when you submit your work.

• AStarComparator.java
• BestFirstSearcher.java
• HSearcher.java
• HSearchNode.java
• Searcher.java
• SearchNode.java

Pancake Sorting History: First discussed by mathematician Jacob Goodman, the Pancake Sorting Problem in its original form (with cost equal to depth of search, i.e. number of flips regardless of flip sizes) was of great interest to a sophomore at Harvard College who took on the research challenge and dropped out a year later.  That sophomore's pancake sorting algorithm held the record for being the best for more than 30 years when it was bested in 2008 by researchers at UT Dallas.  That Harvard sophomore dropout was Bill Gates.

This variant is my own design.