Assignment Two: Search: Question One
Assignment Two: Search: Question One
Question One
Define two non-trivial admissible heuristics functions for the coffee shop domain described in ques-
tion 1 of the previous assignment. Your first heuristic, h1, should not take into account the locations
of the coffee shops or the blocked squares. The second heuristic, h2, should take into account the
locations of the coffee shops, but not locations of the blocked squares.
Hint: a useful concept is the Manhattan distance between two points (x1 , y1 ) and (x2 , y2 ) which
is |x1 − x2 | + |y1 − y2 |. The Python function abs finds the absolute value of a number.
For each heuristic (as well as the trivial heuristic, h = 0), report on the number of paths
expanded by A∗ , both with and without multiple-path pruning, to find an optimal solution.
Thus complete the following table:
A∗ without MPP A∗ with MPP
h=0 1365747 81
h1
h2
where the h = 0 entries are from the posted problem representation. You may have different
numbers.
We recommend that you use the Python implementation, but you don’t have to if you can
answer the question in another way (e.g., by writing the searcher in another language). You
can start with coffee.py at http://www.cs.ubc.ca/~poole/cs322/2020/as1/coffee.py, which
should be added to the directory containing the other python files. You need to explain how you
got your answers (and include any code that you used beyond what was provided, and the relavant
output from the program).
Question Two
Sam was very puzzled as to why there was a minus (“−”) in the second element of the tuple added
to the heap in add in FrontierPQ in searchGeneric.py.
Chris suggested the following example would demonstrate the importance of the minus. Con-
sider an infinite integer grid, where the states are pairs of integers, the start is (0,0), and the goal
is (10,10). The neighbours of (i , j ) are (i + 1, j ) and (i , j + 1). Consider the heuristic function
h((i , j )) = |10 − i | + |10 − j |. Chris suggested you compare how many paths are expanded with the
minus and without the minus.
1
Explain to Sam what the minus does and why it is there. Give evidence for your claims. It
might be useful to refer to other search strategies in your explanation. As part of your explanation,
explain what is special about Chris’s example.
Question Three
For each of the following, give a graph that is a tree (there is at most one arc into any node),
contains at most 15 nodes, and has at most two arcs out of any node.
(a) Give a graph where depth-first search expands fewer nodes than breadth-first search.
(b) Give a graph where breadth-first search expands fewer nodes than depth-first search.
(c) Give a graph where A∗ search expands fewer nodes than either depth-first search or breadth-
first search.
(d) Give a graph where depth-first search and breadth-first search both expand fewer nodes than
A∗ search.
You must draw the graph and show the order of the neighbors (this is needed for the depth-first
search). Either give the arc costs and heuristic function or state explicitly that you are drawing
the graph to scale and are using Euclidean distance for the arc costs and the heuristic function.
Explain why the graph you give is a solution to the problem.
Question Four
For each question, specify how long you spend on it, and what you learned. How was the work in
the team allocated? Was the question reasonable? (This questions is worth marks, so please do
it!)