CS 371 - Introduction to Artificial Intelligence
Homework #2


Due at the beginning of class 6
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.

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.

2. Grid Navigation: Implement GridNavigationNode.java according to this specification. You may test your code using these test files.

In this exercise, you'll create a heuristic search node that, given a start and goal position (row and column) and a 2D array indicating when grid positions are blocked from entry, will enable an A* search to find an optimal path according to the Euclidean distances traveled by horizontal, vertical, and diagonal moves. Furthermore, for this problem, you will perform full repeated state checking, preventing the revisiting of the same row and column in search.

The provided test code generates a maze image, and removes black wall pixels at random. This allows multiple goal paths. Two PNG images are generated, a maze mutilated thus (example), and an image showing in green the path found from the upper-left entrance to the lower-right exit (example).

Todd Neller