AIML Modue2
AIML Modue2
AIML Modue2
21CS54
Module 2
Solving Problems by Searching
• Heuristic function
h(n) = estimated cost of the cheapest path from the state at node n
to a goal state.
• For example, in route-finding problems, we can estimate the distance
from the current state to a goal by computing the straight-line
distance on the map between the two points.
July 25, 2024 2
July 25, 2024 3
Greedy best-first search
f (n) = h(n).
• Because tiles cannot move along diagonals, the distance is the sum
of the horizontal and vertical distances— sometimes called the city-
block distance or Manhattan distance.
• h2 is also admissible because all any move can do is move one tile
one step closer to the goal. Tiles 1 to 8 in the start state of Figure
3.25 give a Manhattan distance of
h2 = 3+1+2+2+2+3+3+2= 18.
true depth.
• This means that the total search cost is O(b d−k ) compared to
h
• If the rules of the 8-puzzle were changed so that a tile could move
anywhere instead of just to the adjacent empty square, then h1 would
give the exact length of the shortest solution.
• Similarly, if a tile could move one square in any direction, even onto an
occupied square, then h2 would give the exact length of the shortest
solution.
• A problem with fewer restrictions on the actions is called a relaxed
problem.
• The state-space graph of the relaxed problem is a supergraph of the
original state space because the removal of restrictions creates added
edges in the graph.
July 25, 2024 25
• Because the relaxed problem adds edges to the state-space graph, any
optimal solution in the original problem is, by definition, also a solution in
the relaxed problem; but the relaxed problem may have better solutions if
the added edges provide shortcuts.
• If a problem definition is written down in a formal language, it is possible
to construct relaxed problems automatically. For example, if the 8-puzzle
actions are described as
A tile can move from square X to square Y if X is adjacent to Y and Y is
blank,
we can generate three relaxed problems by removing one or both of the
conditions:
a) A tile can move from square X to square Y if X is adjacent to Y.
b) A tile can move from square X to square Y if Y is blank.
c) A tile can move from square X to square Y.
July 25, 2024 26
• A program called ABSOLVER can generate heuristics automatically from
• ABSOLVER generated a new heuristic for the 8-puzzle that was better
than any preexisting heuristic and found the first useful heuristic for the
famous Rubik’s Cube puzzle.
and none of them is clearly better than the others, which should we
choose?