Artificial Intelligence: Informed Search
Artificial Intelligence: Informed Search
Informed Search
• Heuristic Search
• Priority first search (PFS)
• Greedy Best-First Search
• A*
• Conditions for optimality
Introduction
Informed Search Strategies
• Greedy Best First Search
• A*
Explore the state with lowest f(n)
Uniform Cost Search (PFS) f(n)=g(n)
• Bag: Priority Queue
• Priority of a state s = Path cost from start state to s
• Explore the cheapest path first
• Complete and optimal – if there is a solution alg will find the solution,
if multiple solution is there, it will find the optimal solution
• Explores in every “direction” – but expect to focus towards the
solution
• Not in the direction of a goal
PFS Algorithm with Prioirty f(n)=g(n)
def Priority_First_Search (problem):
discovered = priority queue ordered by distance
explored = {}
add start node with distance = 0 to discovered
while discovered is not empty:
u = delete_min (discovered)
if u.state is goal: return Solution (u)
if u is not in explored:
add u to explored
for each v in Successors (u):
if v.state is in discovered with longer path:
replace that node with v
elif v is in explored with longer path
replace that node with v
else:
add v to discovered
return failure
PFS
Greedy BFS
Complete: No?
Optimal: No?
Time and space complexity :
exponential
A*
• Uniform-cost orders by backward path cost, g(n)
• Greedy orders by goal proximity, forward path cost, h(n)
• A* orders by the sum: f(n)=g(n)+h(n)
A* algorithm
def A* (problem):
discovered = priority queue ordered by f(n) = g(n) + h(n)
add start node with f(n) = h(n) to discovered
while discovered is not empty:
u = delete_min (discovered)
if u.state is goal: return Solution (u)
for each v in Successors (u):
g(v) = g(u) + c(u,v)
f(v) = g(v) + h(v)
if v.state is in discovered with longer path:
replace that node with v
else:
add v to discovered
return failure
Example
When should A* terminate
• When we test for goal state
• Entry to the discovered bag (add)
• Selecting a state from the discovered bag for exploration (remove)
Admissible heuristic
S -> G f(n)= 5
S -> A: 1+6 = 7, A - > G : 7+3 = 10
So to G is selected
But actual cost of S-A-G is 4 which is less than S -> G (5)
Thus it is not optimal, this is because the heuristic of A is
greater than the actual cost
Consistent Heuristic
A* is complete
• Branching factor ≈3
• Suppose goal state at depth, solution cost, d=22
• Tree search: 322=3.1×1010 states
• Graph search: 9!/2=181,440 states
• Smaller 170,000 times
• 15-puzzle, 1013 states
•h1= Number of mispplaced tiles, h1=8
•h2= Manhattan distance h2=3+1+2+2+2+3+3+2=18
• Number of nodes N
• Solution depth d
• Effective branching factor b∗ N+1=1+b∗+(b∗)2+…+(b∗)d
• Almost constant for hard problems
• Good heuristic, b∗≈1
•
Comparison of Search Costs and Effective
Branching Factors for 8-Puzzle
• A* with h1 (misplaced tiles)
• A* with h2 (Manhattan distance)
• Data averaged over 100 puzzles for each solution length d from 6 to
28.
• h2(n)≥h1(n), h2 dominates h1, efficient
• All nodes n generated have
f(n)<C∗
g(n)+h(n)<C∗
h(n)<C∗−g(n)
h1(n)≤h2(n)<C∗−g(n)
Generate Admissible Heuristics from Relaxed
Problems
• Relaxed problem, a problem with fewer restrictions on the actions
• Supergraph of the original state space because the removal of
restrictions creates added edges
• May have shortcuts, and hence cheaper solutions
• Cost of an cheapest solution to a relaxed problem is an admissible
heuristic for the original problem.
Relax 8-Puzzle