CS116 - Artificial Intelligence
Spring, 2004
(updated 2/5/2004)

HW 4, Due Wed. Feb. 18 (2:00pm), 2004

For this assignment, submit one lisp file.  Name it "search.lisp".  Submit it to the course WebCT site by 2pm on Wed. (2/11).  Prior to final submission, you will want to test your program on the test structures using the sample evaluation function I've provided in
searchtest.lisp.  The assignment will be graded on correctness, completeness, and coherence (style and elegance).

1.  Write search functions in Lisp for each of the following search methods (and name them as given here with the appropriate inputs):
a. (breadth-first-search graph start goal)
b. (depth-first-search graph start goal)
and your choice of one out of the following two:
c. (best-first-search graph start goal heuristic-f)
d. (hill-climbing graph start goal heuristic-f)

Graph Representation
Your function should expect a graph represented as:
((node1 (n1a c1a) (n1b c1b) ...)
 (node2 (n2a c2a) (n2b c2b) ...)
where directed link exists in the graph from node1 to nodes n1a, n2a, etc., with costs c1a, c1b, etc. respectively.  If we had a graph consisting of a square (with bi-directional edges) with unit-cost edges, we could represent it as:
((n1 (n2 1) (n4 1))
 (n2 (n1 1) (n3 1))
 (n3 (n2 1) (n4 1))
 (n4 (n1 1) (n3 1)))

The start node and goal node are simply atoms (that corresponds to nodes in the input graph structure).

Inputs and Outputs
Your search functions should take as inputs, a graph representation, a start node, and a goal node.  You may assume that inputs are legal and correct (e.g., start and goal nodes exist in the graph, etc.).
  However, there may or may not exist a path between the start and goal nodes; your function should return nil for the path sequence and 0 for the total cost when no path can be found.  For heuristic searches, your function should also take an evaluation function parameter.

All of the functions should return a set of values (use the "values" expression) in the following order:
1. a list corresponding to the sequence of nodes visited in the found path to the goal (starting with the start node)
2. the total cost of the path found
3. the total number of nodes placed on the open list
4. the total number of nodes placed on the closed list

You should expect the heuristic function argument to take two arguements in the following order: a current node and the goal node.  Similarly, you should provide these arguments in that order via a "funcall" to the function argument.  For example:  (funcall evalfuncparameter current goal) could occur in a function foo that was called as (foo start goal #'test-eval).  (If you had looked at this earlier, note the change from three to two arguments to the evaluation function.  It is up to your discretion how to maintain the accumulated cost so far for a candidate path and how to incorporate that value into your score.)

It is important that you follow these instructions carefully because I will be grading your assignments based on a script that will call your functions.  If it doesn't work, you will not get full credit.  I have provided a file, searchtest.lisp, that contains a sample tree, a sample graph, and a sample heuristic function that you can use to test your programs.  However, your functions will be expected to run correctly on arbitrary graphs with arbitrary evaluation functions.