Artifical Intelligence

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

CS 510: Introduction to Artificial Intelligence

Written Problems
1. Algorithm A* (8-Puzzle)

DT (node) counts “direct tile reversals” – in which two adjacent tiles must be exchanged
to be in their respective proper positions (DT (node) =2 for sample state B, since 1-2 and
5-6 are direct reversals.)

In the 8-puzzle problem 8 differently numbered tiles are fitted into 9 spaces on a 3x3 grid. One
space has no tile so that any tile adjacent to the empty space can be moved to occupy it by
sliding from its original position. For instance, here is an initial and a goal state:
initial state goal state
281 123
4 6 456
753 78

Here are some different heuristic functions:

 h1 (n) = number of misplaced tiles


 h2(n) = P(n) + 2 * R(n) where P(n) is the sum of the Manhattan distances that each tile is
from home, and R(n) is the number of direct tile reversals (when two adjacent tiles must
be exchanged to be in the order of the goal).
 h3 (n) = P (n) + 3 * S (n) where P (n) is the sum of the Manhattan distances that each tile
is from home, and S (n) is a sequence score obtained by counting 1 for the central tile (if
not empty) and counting 2 for each tile on the board perimeter that is not followed (in
clockwise order) by its correct successor.

A solution to the problem may be found by using a best-first search where the heuristic is used to
choose which position to search next. (Don’t forget to exclude loops from the search).
S(node) is a “sequence score” – for every tile around the edge, count 2 for every tile not
followed by its proper successor and 0 for every other tile. If there is a piece in the center,
add 1.

 Sequence Score: h(n) = P(n) + 3 S(n)

P(n) is the distance of each tile from its proper position.

"The quantity S(n) is a sequence score obtained by checking around the non-centrally
squares in turn, allotting 2 for every tile not followed by its proper successor and 0 for
every other tile, except that a piece in the center scores 1."

This might be easier to understand if you know that the goal state that Nilsson uses is
represented by: (1 2 3 8 space 4 7 6 5). This heuristic is not admissible.

 X-Y: decompose the problem into two one dimensional problems where the "space" can
swap with any tile in an adjacent row/column. Add the number of steps from the two
subproblems.
 Number of tiles out of row plus number of tiles out of column.
 n-MaxSwap: assume you can swap any tile with the "space". Use the number of steps it
takes to solve this problem as the heuristic value.
 n-Swap: represent the "space" as a tile and assume you can swap any two tiles. Use the
number of steps it takes to solve this problem as the heuristic value.

Note that some of these heuristics involve performing a search to find the value of the heuristic.
In these cases, you want the additional time spent evaluating the heuristic to be more than offset
by the decrease in the effective branching factor.

You could create the "perfect" heuristic by having it perform an A* search to find the exact number
of steps to reach the goal, but that would not be a good solution to this problem!
For each of these heuristics, determine whether it is admissible, and justify your answer

A heuristic function hh is admissible, if it never overestimates the cost for any given node.
Formally speaking, let h∗h∗ map each node to its true cost of reaching the goal. The heuristic
function hh is admissible, if for all nodes nn in the search tree the following inequality holds:

h(n)≤h∗(n).(⋆)(⋆)h(n)≤h∗(n).

That means for checking whether a given heuristic function hh is admissible, we have to verify
that the inequality (⋆)(⋆) holds by either for admissible order:

h0(node): 0 h1(node): number of tiles out of place  Least admissible

h2(node): sum of distances out of place  Least admissible

h3(node): 2*DT(node) – defined below  Least admissible

h4(node): h2(node) + 3*S(node)  admissible

h5(node): h1(node) + h3(node)  admissible

h6(node): h2(node) + h3(node)  admissible

h7(node): maximum of all admissible heuristics in {h1(node), h2(node) ... h6(node)}


admissible

a. calculating the real cost h∗h∗ for each node and comparing the values, proving it by using
additional information available of the heuristic.

For example, we know that the eucledian distance is admissible for searching the shortest path (in
terms of actual distance, not path cost). Note also that any consistent heuristic is admissible (but
not always vice-versa).

For your example, there is no additional information available regarding the two heuristics. Thus
you have to calculate the real cost h∗h∗ for each node, and then check whether the
inequality (⋆)(⋆) holds (I leave this task to you).
By checking the total cost you can neither prove that a heuristic is admissible nor that a heuristic
is not admissible. The problem with this idea is that on the one hand you sum up the costs of the
edges, but on the other hand you sum up the path cost (the heuristic values). For example, consider
the following search tree with start node AA and goal node C

For the admissible heuristics above, show the precedence from least to most informed¸ e.g.,
hi(node) ≤ hj(node) ≤ …

A heuristic function is said to be admissible if it never overestimates the cost of reaching the goal,
i.e. the cost it estimates to reach the goal is not higher than the lowest possible cost from the current
point in the path. If the heuristic function, h always underestimates the true cost (h (n) is smaller
than h*(n)), then A* is guaranteed to find an optimal solution
h0(node) ≤ h1(node) ≤ h7(node) ≤ h3(node) ≤ h5(node) ≤ h4(node) ≤ h2(node) ≤ h6(node)

h0 and h1 are least informed as it gives only number of tiles out of place and h6 is most informed
as it gives as heuristic functions at h1 and h3 nodes
2. Minimax, Alpha-Beta (from Tanimoto)

You might also like