You are lost but fortunately you have Leonid Shamis's A* framework which you can use to find your way home.
In this assignment, you will devise an algorithm for plotting a course home, minimizing the total cost of the path and the amount of time spent searching.
In this assignment, you'll first work with the TerrainMap class, a class encapsulating a two-dimensional world layered on top of a rectangular grid. Each point in the world has a height, represented by an integer value between 0 and 255. Depending on the selected movement type, you can either move to any of the eight squares adjacent to your own location (e.g. the four cardinal directions and the diagonals) or just the cardinal directions. As you would expect, the cost to traverse between tiles is dependent on the differences in height between the tiles. Below are different const functions for you to experiment with.
The TerrainMap class also keeps track of which tiles your algorithm visits as it looks for an optimal path home. Part of your grade on this assignment will be determined by how many tiles your algorithm visited. For example, if two different algorithms each yield the optimal path, but one accomplishes this task and only considers 10% of the number of squares as the other, the algorithm that visited fewer squares would be considered superior to the other. Interestingly, many of the better search algorithms that visit fewer squares also run in considerably less time, so you'll have a dual incentive to keep your search space small. Please note that this is still secondary to finding the shortest path.
Your assignment is to create an implementation of the AIModule interface that computes a path from the start location to the end location while minimizing the total search space. Once you've written this function, you can plug it in to the existing starter code by compiling your module and specifying it as a command-line parameter to the main program. For example, if you've written an AI module called PerfectAI, you can see the result by running "java Main PerfectAI". This will run your AI, print its score and number of visited squares to stdout, and will create a display window showing the terrain, the path you've taken, and the squares your AI module visited.
To help test your implementation, we've provided a working Dijkstra's algorithm AI class called DijkstraAI. As you've learned in class, Dijkstra's algorithm always yields the optimal path, so you can compare your own AI against the DijkstraAI module to see if your path is indeed optimal. The starter code is designed such that you can have several different AI modules each plot a path over the terrain. You can do this by specifying multiple parameters to the main program, as in "java Main PerfectAI DijkstraAI". Because you can interface with the starter code directly from the command line, you do not need to make any changes to the provided starter code.
Your submission for this assignment should consist of a single .java file containing your AIModule implementation, and it will be run using a clean copy of the starter code. If you have any extensions to the project that require changes to the starter code, please let us know before you begin making changes.
// Exponential of the height difference
public double getCost(final Point p1, final Point p2)
{
return Math.exp(getTile(p2) - getTile(p1));
}
// New height divided by old height
public double getCost(final Point p1, final Point p2)
{
return getTile(p2) / (getTile(p1) + 1);
}
You may cut and paste them into
TerrainMap.java over the
current getCost function. Note that the second cost function involves
integer math and can return 0 despite the function return type. You
can interpret it as though there is a floor
function around the entire expression. However, don't place a floor
function around the expression as we found there are some bugs in the
floor function for some Java VM.
For each cost function above and for each movement type (cardinal
neighbors or all eight neighbors), do the following:
a)
Create an admissible heuristic, document the exact form of the
heuristic and prove it is admissable. (6 points per cost
function and movement type)
Submission Requirements: For
questions a) submit a detailed writeup.
For implementation purposes only consider chess (eight option)
movement with the built cost functions.
a) You
will now implement your own version of A*. Look at the DirectAI and
StupidAI classes to get an idea
of how to search the state space. (20 points)
b) To implement
the heuristic, write valid java code in the form of: (5 points)
private double getHeuristic(final TerrainMap map, final Point pt1, final Point pt2)
{
...
}
Submission Requirements: For questions a) and b) submit an
java module labeled as AStarExp_<your-student-id>.java for the
first cost function and
AStarDiv_<your-student-id>.java for
the second cost function.
Try out your heuristic functions with the appropriate cost
function on 500x500 maps with random seeds 1, 2, 3, 4 and 5.
Submission Requirements (one for each cost function): For
each execution record the cost of the shortest path and the number of
nodes expanded
as per the output of the program.
5
points per cost function for getting the shortest path. Non-optimal
paths will get
5 * (shortest path cost) / (your path cost)
For
all students who get the shortest path: we will rank your performance
and you shall receive bonus marks of:
5*(Number of Qualified
Students + 1 - Your Rank) / (Number of Qualified Students) for each
cost function.
Answer this question ONLY for the “Exponential of the height difference” cost function.
Go to
http://tahoe.usgs.gov/viewers.html
and download the Dem3D viewer. This will allow you to view the file
in MtAftDem.zip which is in the old USGS DEM format of the Mount
Saint Helens after the eruption.
There are better DEM viewers
you could use that allows fly throughs etc, but this one works with a
standards graphics card and will help them understand the terrain you
are navigating.
This is a much larger grid and hence you
.will have to more cleverly implement your algorithm and/or use a
clever variation. Your aim is to modify both your A* algorithm and
admissible heuristic so as to find the optimal path in this new
environment in the least possible time. You can use any
valid technique to improve the performance of the algorithm. By this,
I mean any clever modification of the base algorithm (such as
waypoints) but NOT say writing the A* algorithm in assembler or
memorizing paths etc. If you have any doubts about the validity of
your approach then first consult me. The algorithm must still be
guaranteed to find the global optima.
Use the following
command to run this part of the assignment: "java Main
YourAIModule -load MTAFT.XYZ".
Submission
Requirements:
a) A clear and concise description of your
modified A* and admissible heuristic.(10 points)
b) The
implementation of your modified A* and admissible heuristic in the
file MtStHelensExp_<your-student-id>.java and
MtStHelensDiv_<your-student-id>.java (10 points)
c) The
cost of your shortest path, number of nodes expanded and time to find
it.