Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
49 views6 pages

Rec2 Sol

The document describes a recitation for an AI course that discusses heuristics and search algorithms. Students are asked to work in pairs to design admissible and consistent heuristics for a graph. They then use their heuristics with A* search and answer questions about the path found. Additional problems ask students to run depth-first search, breadth-first search, uniform-cost search, greedy search, and A* search on a treasure hunting graph and report the results. The recitation concludes with true/false questions about search algorithms and heuristics.

Uploaded by

m22ai569
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

Rec2 Sol

The document describes a recitation for an AI course that discusses heuristics and search algorithms. Students are asked to work in pairs to design admissible and consistent heuristics for a graph. They then use their heuristics with A* search and answer questions about the path found. Additional problems ask students to run depth-first search, breadth-first search, uniform-cost search, greedy search, and A* search on a treasure hunting graph and report the results. The recitation concludes with true/false questions about search algorithms and heuristics.

Uploaded by

m22ai569
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

15-281: AI: Representation and Problem Solving Spring 2020

Recitation 2 Jan 24

1 Designing & Understanding Heuristics


Today, we will be taking a closer look at how the performance of A∗ is affected by the heuristics it uses. To
do this, we’ll be using the graph below. You may have noticed that no heuristic values have been provided
(Recall: What is A∗ without heuristic values?). This is because we’ll be working in pairs to come up with
heuristics ourselves!

Please find someone next to you to work with, and decide between yourselves who will design an admis-
sible heuristic and who will design a consistent heuristic. Then, independently create these heuristics for the
given graph by annotating each node with a heuristic value. (Note: you do NOT need to find a closed form
way to represent the heuristic function.)

When you have completed your heuristic, exchange papers with your partner, and work together to an-
swer the questions below.

A 4
C

5
6
9
S 2
3 G
4
B
1
D

(a) Write down the path found by running A∗ using your heuristic on the graph above.

This will depend on the provided heuristic. Recall that A∗ expands the node in its frontier that has the
lowest f (n) = g(n) + h(n) value.

(b) Work with your partner to come up with a heuristic that’s admissible but not consistent.

Heuristics will vary from team to team, and there may be many correct solutions. Feel free to come to
OH or post on Piazza if you’re unsure about a particular answer.

(c) (Bonus) Explain why a consistent heuristic must also be admissible. You may assume that the heuristic
value at a goal node is always 0.

Recall the definitions of admissibility and consistency.

A heuristic is admissible if it never overestimates the true cost to a nearest goal.


A heuristic is consistent if, when going from neighboring nodes a to b, the heuristic difference/step cost
never overestimates the actual step cost. This can also be re-expressed as the triangle inequality men-
tioned in Lecture 3.

Let h(n) be the heuristic value at node n and c(n, n + 1) be the cost from node n to n + 1. We’re
given the assumption that h(ng ) = 0, where ng is a goal node. Informally, we want to backtrack from the

1
15-281: AI: Representation and Problem Solving Spring 2020

Recitation 2 Jan 24

goal node, showing that if we start with an admissible node (which h(ng ) = 0 is by default), its parent
nodes will be admissible through the rule of consistency, and this pattern continues.

Consider some node n and assume the heuristic value at n is admissible. We want to show that any of
its parent nodes, say n − 1, will also be admissible by the definition of consistency.

By consistency, we get that:


h(n − 1) − h(n) ≤ c(n − 1, n)
= h(n − 1) ≤ c(n − 1, n) + h(n)
c(n − 1, n) is the actual path cost from n − 1 to n. Since we know h(n) is admissible, we know that h(n)
has to be less than or equal to the path cost from n to goal node ng .

Thus, h(n − 1) ≤ the path cost from (n − 1 to n) + h(n).


Since h(n) is less than or equal to path cost from (n to ng ),
h(n − 1) ≤ path cost from (n − 1 to ng ).

This by definition is admissible.

Formal proof (for students interested):


Assume we have some consistent heuristic h. Also assume h(ng ) = 0, where ng is a goal node. By
definition of consistency, h(n) ≤ c(n, n + 1) + h(n + 1) for all nodes n in the graph. We want to show
that for all n, h(n) ≤ h∗ (n) (the definition of admissibility) also holds.
Base Case: We begin by considering the ng − 1th node in any path where ng denotes the goal state.

h(ng − 1) ≤ c(ng − 1, ng ) + h(ng ) (1)


Because ng is the goal state, by assumption, h(ng ) = h∗ (ng ). Therefore, we can rewrite the above as
h(ng − 1) ≤ c(ng − 1, ng ) + h∗ (ng )
and given that c(ng − 1, ng ) + h∗ (ng ) = h∗ (ng − 1), we can see:
h(ng − 1) ≤ h∗ (ng − 1)
as desired.

Inductive Hypothesis: Assume that for some arbitrary node (which lies on a path from start to
goal) ng − k that h(ng − k) ≤ h∗ (ng − k).

Inductive Step: To see if this is always the case, we consider the ng − k − 1th node in any of the
paths we considered above (e.g. where there is precisely one node between it and the goal state). The
cost to get from this node to the goal state can be written as
h(ng − k − 1) ≤ c(ng − k − 1, ng − k) + h(ng − k)
From our base case above, we know that
h(ng − k − 1) ≤ c(ng − k − 1, ng − k) + h(ng − k) ≤ c(ng − k − 1, ng − k) + h∗ (ng − k)
h(ng − k − 1) ≤ c(ng − k − 1, ng − k) + h∗ (ng − k)
And again, we know that c(ng − k − 1, ng − k) + h∗ (ng − k) = h∗ (ng − k − 1), so we can see:
h(ng − k − 1) ≤ h∗ (ng − k − 1)
By the inductive hypothesis, this holds for all nodes, proving that consistency does imply admissibility!

2
15-281: AI: Representation and Problem Solving Spring 2020

Recitation 2 Jan 24

2 Treasure Hunting
We are lost at sea, trying to find a hidden treasure. We have a treasure map that tells us which paths we
can take and approximately how far away the treasure is but it’s not very accurate. We do know that the
map will never overestimate the distance to the treasure. There is treasure on two different islands (but we
only need to reach one of them).

A is the the island where we are currently and the shaded (red) states are the locations of the treasure. Ar-
rows encode possible actions from each island, and numbers by the arrows represent action costs. Note that
arrows are directed; for example, A → C is a valid action, but C → A is not. Numbers shown in diamonds
are heuristic values that estimate the optimal (minimal) cost to get from that island to any treasure.

Run each of the following search algorithms with graph search and write down the nodes that are added
to the explored set during the course of the search, as well as the final path returned and the correspond-
ing cost of the final path, if applicable. When popping off of the frontier, assume that ties are broken
alphabetically.

(a) Depth-First Search

Explored set:

A, C, F, B, G

Path returned:

A, C, G

(b) Breadth-First Search

Explored set:

3
15-281: AI: Representation and Problem Solving Spring 2020

Recitation 2 Jan 24

A, C, D, E

Path returned:

A, E

(c) Uniform-Cost Search

Explored set:

A, D, C, G

Path returned and cost:

A, D, G with a cost of 2

(d) Greedy Search

Explored set:

A, E

Path returned and cost:

A, E with a cost of 3

(e) A∗ Search

Explored set:

A, D, G

Path returned and cost:

A, D, G with a cost of 2

4
15-281: AI: Representation and Problem Solving Spring 2020

Recitation 2 Jan 24

3 True/False Section
For each of the following questions, answer true or false and provide a brief explanation (or counterexample,
if applicable).
(a) Depth-first search always expands at least as many nodes as A∗ search with an admissible heuristic.

False: If the minimum goal path consists of d nodes, a lucky DFS might expand exactly those d nodes
to reach the goal. A∗ could potentially expand some other nodes before finding that path (those nodes
would have a lower f (n) value than the final goal’s).

(b) Assume that for a single move, a rook can move any number of squares on a chessboard in a straight line,
either vertically or horizontally, but cannot jump over other pieces. Manhattan distance is an admissible
heuristic for the smallest number of moves to move the rook from square A to square B.

False: A rook can move from one corner to the opposite corner across a 4x4 board in two moves, although
the Manhattan distance from start to finish is 6.

(c) Euclidean distance is an admissible heuristic for Pacman path-planning problems.

True: Euclidean distance is the minimum distance to travel between any two points. Thus, it will always
be less than or equal to Pacman’s (who only moves horizontally or vertically) actual cost to travel along
some path, making it admissible (0 ≤ h(n) ≤ h∗ (n)).

More specifically, if the goal is either vertical or horizontal to Pacman’s current position, then the
Euclidean distance will be the true distance. Otherwise, if the goal is diagonally away from Pacman’s
current position, then the Euclidean distance will be less than the true distance. In both scenarios,
Euclidean distance is a lower bound on the true distance.

(d) The sum of several admissible heuristics is still an admissible heuristic.

False:

4 6
S A B

h1 (S)=7 h1 (A)=4

h2 (S)=8 h2 (A)=5

Both of these heuristics (h1 and h2 ) are admissible, but if we sum them, we find that h3 (S) = 15 and
h3 (A) = 9. This is not admissible.

However, notice that taking the maximum of two admissible heuristics will result in an admissible heuris-
tic.

(e) Admissibility of a heuristic for A∗ search implies consistency as well.

False:

1 3
S A B

h(S)=4 h(A)=1

5
15-281: AI: Representation and Problem Solving Spring 2020

Recitation 2 Jan 24

Heuristic h is admissible since it never overestimates the true cost to the goal. However, it is not consistent
since the step cost (between states S and A) is overestimated by the heuristics. The estimated step cost
is h(S) − h(A) = 4 − 1 = 3, while the true step cost between S and A is 1.
Another way of looking at it is h(S) > cost(S, A) + h(A), which violates the triangle inequality.

(f) A∗ with graph search is always optimal with an admissible heuristic.

False:

h(S)=4

3
1

1 2
A B C

h(A)=3 h(B)=0

The optimal path from S to C is S − A − B − C with a total cost of 4. However, with A* graph search:

• After starting from S, the options on the frontier are S − A with a cost plus heuristic of 1+3=4, or
S − B with a cost plus heuristic of 3+0=3. So, we choose to explore S − B.
• Next, the options on the frontier are S − A with a cost plus heuristic of 1+3=4, or B − C with a
backward path cost of 5. So, we choose to explore S − A.
• We’ve already reached B from the earlier path, so we don’t consider edge A − B. Thus, our only
option is to explore B − C for a cost of 5.
• So, we will choose the path S − B − C with a total cost of 5, which is not optimal.

Note that there is a distinction here between tree search and graph search: A∗ with tree search is
guaranteed to be optimal if the heuristic is admissible, but A∗ with graph search is only guaranteed to
be optimal if the heuristic is consistent.

You might also like