Solutions-Heuristic Search
Solutions-Heuristic Search
1) Solve Problem ?? for A* with a) the Manhattan distance heuristic and b) the
straight line distance heuristic. The Manhattan distance heuristic between two
grid cells (x1 , y1 ) and (x2 , y2 ) is |x1 − x2 | + |y1 − y2 | (the length of a shortest
path between the two cells, assuming that there are no obstacles on the grid).
For instance, the Manhattan distance between A1 and E3 is |1 − 5| + |1 − 3| = 6.
Answer:
Manhattan distance heuristic:
A B C D E
1 2 3 4 5 6
2 3 5
3 g 1 2 4
4 1 2 3 5
5 2 3 4 5 6
Expansion order (with f values): E1 (6), D1 (6), C1 (6), B1 (6), A1 (6), C2 (6),
C3 (6), B3 (6), A3 (6)
Straight-line distance heuristic (approximately):
A B C D E
1 2 2.2 2.8 3.6 4.5
2 2.2 4.1
3 g 1 2 4
4 1 1.4 2.2 4.1
5 2 2.2 2.8 3.6 4.5
Expansion order (with f values): E1 (4.5), D1 (4.6), C1 (4.8), E2 (5.1), B1 (5.2),
C2 (5.2), A1 (6), C3 (6), B3 (6), A3 (6).
2) We are given a sequence of integers and want to sort them in ascending order.
The only operation available to us is to reverse the order of the elements in
some prefix of the sequence. For instance, by reversing the first three elements
of (1 2 3 4), we get (3 2 1 4). This problem is also known as the “pancake
flipping” problem. We model this problem as a search problem, where each
state corresponds to a different ordering of the elements in the sequence. Given
an initial sequence (2 4 1 3), in which order does A* expand the states, using the
breakpoint heuristic described below? Assume that ties are broken toward states
with larger g-values, and, if there are still ties, they are broken in lexicographic
order. That is, (2 1 4 3) is preferred to (2 4 1 3).
Breakpoint heuristic: A breakpoint exists between two consecutive integers if
their difference is more than one. Additionally, a breakpoint exists after the
last integer in the sequence if it is not the largest integer in the sequence. For
instance, in (2 1 4 3), there are two breakpoints: one between 1 and 4 (since
their difference is more than 1), the other after 3 (since it is at the end and of
the sequence and is not the largest integer in the sequence). The breakpoint
heuristic is the number of breakpoints in a given sequence. (Bonus question: Is
this heuristic a) admissible and b) consistent? Why?)
Answer:
We start with the sequence (2.4.1.3.) which has 4 breakpoints (dots represent
the breakpoints). We have only three actions available to us: reverse the order
of the first two elements, first three elements, or all the elements (reversing the
order of only the first element is pointless). The search tree is given below:
2.4.1.3. (4)
(a) (2.4.1.3.) 4
(b) (1.4.2 3.) 4
(c) (4.1 2 3.) 4
(d) (3 2 1.4 ) 4
(e) (1 2 3 4 ) 4
The breakpoint heuristic is consistent (and therefore admissible). The goal state
(1 2 3 4) has no breakpoints, therefore h(goal) = 0. Each action can change the
number of breakpoints by at most 1 (reversing the first i elements can only effect
the breakpoint after i). Therefore, for any edge (s, s0 ), 0 ≤ h(s) ≤ 1 + h(s0 )
holds.
We get:
8) Give a simple example that shows that A* with inconsistent but admissible
heuristic values is not guaranteed to find a cost-minimal path if it expands
every state at most once.
Answer:
S h(S) = 4
1 2
h(A) = 3 A B h(B) = 1
1 1
C h(C) = 0
G h(G) = 0
In this example (where the heuristic is admissible but not consistent), when
searching for a path from S to G, the states are expanded in the following order
(parentheses show f-values):
S (0 + 4 = 4)
B (2 + 1 = 3)
C (3 + 0 = 3)
A (1 + 3 = 4)
G (5 + 0 = 5)
Note that expanding A finds a shorter path from S to C, but this is not re-
flected in the solution since C was expanded before A and we are not allowed
to expand a state more than once.