Project 1: Heuristic Search
Part A
Memphis has been hit with a freak snowstorm and the Rhodes campus is
buried in snow. This has made normal navigation of campus impossible
because Campus Safety has only managed to shovel out a few paths between buildings.
Fortunately, they have printed up maps of campus showing the paths
and estimates of how long it will take to walk
between buildings.
Your job is to write a program using the A* algorithm to find the fastest way to walk between
two locations on campus using only the paths on the map.
Input
You will be supplied with various files describing locations on campus, their
(x, y) coordinates in a grid system, and their "effective" distances between each
other.
A sample file might look like this:
location rat 0 0
location ohlendorf 2 0
location library 0 2
location rhodes_tower 2 2
distance rat ohlendorf 5
distance rat library 6
distance ohlendorf rhodes_tower 4
distance library rhodes_tower 2
It is assumed that a path may be traversed in either direction, and that if there is no
distance given for a pair of locations, no direct path exists between those locations.
Distances are guaranteed to be positive integers, and will not be less than the
Euclidean distance between the pair of cities.
Your program should accept three things on the command line or ask the user
to type them in: the filename of a map file,
followed by two locations (start and finish).
Example: astar_parta.py mapfile.txt rat rhodes_tower
Output
Your program should print out the best path from the start to the finish location,
the path cost, and the number of states on the explored list at the end of the algorithm (the number of states
"expanded").
Example:
Best path is:
rat
library
rhodes_tower
for a path cost of 8.
There were 3 states that were expanded.
Part B
You've finished your program for Part A and are about to use it to
figure out the best way to get to your first class when it is reported
that the campus has closed for the day. However, all your teachers still
want their homework assignments turned in today, so you'll still need to
make a trip out of your dorm and visit all your teacher's offices to
drop off your assignments.
Your job is to write a program (again, using A*) to find the fastest way to make a tour
of campus, starting at your dorm, visiting a certain set of buildings
on campus in any order you choose, and returning to your dorm.
Input
Your program will accept on the command line (or ask the user to type in) a filename referencing a map file, followed
by a starting location, then a list of locations that must be visited in an arbitrary order.
Example: astar_partb.py mapfile.txt rat library ohlendorf
(This means you start at the rat, then must visit the library and ohlendorf in any order,
and return to the rat.)
Output
Your program should print out the best tour of campus that begins at the starting location,
visits all of the other locations listed, and ends at the starting location. Be sure to print
all of the intermediate locations passed through, even if they weren't in the list of
buildings to visit (you may need to visit some locations more than once).
Also print the total cost of the tour, and the total number of states expanded.
Example:
Best path is:
rat
ohlendorf
rhodes_tower
library
rat
for a path cost of 17.
There were XYZ states that were expanded.
What to turn in
Through Moodle, turn in your code. On paper, turn in a short writeup explaining for each
of parts (a) and (b): how you chose to represent a "state," and what your heuristic function
does.
Grading
You will be graded on correctness of your program (whether it gives the best path or tour),
and also the quality of your heuristics (measured by how many states need to be expanded to find
the best solution).
Sample Output
You can use these map files: very simplified map of campus used in the
examples earlier, and more complicated map used in class as a
demonstration of A*.
Sample runs using these maps and various start and ending locations.