Lecture 08 Informed Search Strategies-I

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

Informed Search Strategies

Lecture # 08
Monday, February 17, 2020
Fall 2020
FAST – NUCES, Faisalabad Campus

Zain Iqbal
[email protected]
Outline
Informed = use problem-specific knowledge
Informed Search Strategies
Which search strategies?
⚫ Best-first search and its variants
Heuristic functions?
⚫ How to invent them
A* Search
A strategy is defined by
picking the order of node
expansion
Limitations of uninformed
search
8-puzzle
⚫ Avg. solution cost is about 22 steps
⚫ branching factor ~ 3
⚫ Exhaustive search to depth 22:
⚫ 3.1 x 1010 states

⚫ E.g., d=12, IDS expands 3.6 million states on average

[24 puzzle has 1024 states (much worse)]


Recall tree search…
Recall tree search…

This “strategy” is what


differentiates different
search algorithms
Search Algorithms
Blind search – BFS, DFS, uniform cost
⚫ no notion concept of the “right direction”
⚫ can only recognize goal once it’s achieved

Heuristic search – we have rough idea of how


good various states are, and use this
knowledge to guide our search
Heuristic
Webster's Revised Unabridged Dictionary (1913) (web1913)
Heuristic \Heu*ris"tic\, a. [Greek. to discover.] Serving to discover
or find out.
The Free On-line Dictionary of Computing (15Feb98)
heuristic 1. <programming> A rule of thumb, simplification or
educated guess that reduces or limits the search for solutions
in domains that are difficult and poorly understood. Unlike
algorithms, heuristics do not guarantee feasible solutions and
are often used with no theoretical guarantee. 2. <algorithm>
approximation algorithm.
From WordNet (r) 1.6
heuristic adj 1: (computer science) relating to or using a heuristic
rule 2: of or relating to a general formulation that serves to
guide investigation [ant: algorithmic] n : a commonsense rule
(or set of rules) intended to increase the probability of solving
some problem [syn: heuristic rule, heuristic program]
Informed Search
Add domain-specific information to select the
best path along which to continue searching
Define a heuristic function, h(n), that
estimates the “goodness” of a node n.
Specifically, h(n) = estimated cost (or
distance) of minimal cost path from n to a
goal state.
The heuristic function is an estimate, based
on domain-specific information that is
computable from the current state
description, of how close we are to a goal
Best-first search
General approach of informed search:
⚫ Best-first search: node is selected for expansion
based on an evaluation function f(n)
The evaluation function is construed as a cost estimate, so the
node with the lowest evaluation is expanded first
Idea: evaluation function measures distance
to the goal.
⚫ Choose node which appears best
Implementation:
⚫ fringe is queue sorted in decreasing order of
desirability.
⚫ Special cases: Greedy search, A* search
Best-first search

18-Feb-20 11
Greedy best-first search
Special case of best-first search
⚫ Uses h(n) = heuristic function as its
evaluation function
⚫ Expand the node that appears closest to
goal
Let us see how this works for route-finding problems
in Romania; we use the straight-line distance
heuristic, which we will call hSLD.
If the goal is Bucharest, we need to know the straight
line distances to Bucharest, which are shown in
Figure
Romania with step costs in km
Greedy best-first search
example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Optimal Path

Now consider Going From Iasi to Fargaras


Properties of greedy best-first search
Complete?
⚫ Not unless it keeps track of all states visited
⚫ Otherwise can get stuck in loops (just like DFS)
Optimal?
⚫ No – we just saw a counter-example
Time?
⚫ O(bm), can generate all nodes at depth m before
finding solution
⚫ m = maximum depth of search space
Space?
⚫ O(bm) – again, worst case, can generate all nodes
at depth m before finding solution
A* Search
Expand node based on estimate of total
path cost through node
Evaluation function f(n) = g(n) + h(n)
⚫ g(n) = cost so far to reach n
⚫ h(n) = estimated cost from n to goal

⚫ f(n) = estimated total cost of path through n


to goal
Efficiency of search will depend on
quality of heuristic h(n)
A* Search
A* Search
A * search example
A * search example
140
A* search example
140

140 80
99 151
A* search example
140

80
220
80
146 97
A* search example
A* search example

220

97
317

138
97
101
Condition’s of A* optimality
Admissible heuristics
A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach the
goal state from n.

An admissible heuristic never overestimates the cost


to reach the goal, i.e., it is optimistic

Example: hSLD(n) is admissible


⚫ never overestimates the actual road distance

Theorem:
If h(n) is admissible, A* using TREE-SEARCH is optimal
Admissibility of a heuristic
Let c(n) denotes the optimal path from
node n to any goal node. A search
heuristic h(n) is called admissible

if h(n) ≤ c(n) for all nodes n, i.e. if for all


nodes it is an underestimate of the cost to
any goal.
Admissibility of a heuristic
Let c(n) denote the cost of the optimal path from node n to any goal node.A
search heuristic h(n) is called
admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an
underestimate of the cost to any goal.

• Example: is the straight-


line distance (SLD)
admissible?

YES

The shortest distance


between two points is a line. 1
Monotonicity of a heuristic
• A second, slightly stronger condition CONSISTENCY called consistency (or
sometimes monotonicity)

• MONOTONICITY is required only for applications of A∗ to graph search.

• h(n) is monotonic if, for every node n and every successor n’ of n generated by
any action a, the estimated cost of reaching the goal from n is no greater than the
step cost of getting to n’ plus the estimated cost of reaching the goal from n’:
• h(n) ≤ c(n,a,n’) +h(n’).

• This implies that f(n) (which equals g(n)+h(n)) never decreases along a path from
the root.

➢ Monotonic heuristic => admissible heuristic.


Consistent heuristic (monotonic)
A heuristic is consistent if for every node n, every successor
n' of n generated by any action a,
h(n) ≤ c(n,a,n') + h(n')
OR
h(n) - h(n') ≤ c(n,a,n')

If h is consistent, we have
f(n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
≥ g(n) + h(n) = f(n)
Because g(n’)=g(n)+c(n,a,n')
i.e., f(n) is non-decreasing along any path

Assuming h is consistence, Meaning


h(n) ≤ c(n,a,n') + h(n')
Monotonicity of a heuristic

For an admissible heuristic, the inequality makes


perfect sense:

if there were a route from n to Gn via n’ that was


cheaper than h(n), that would violate the property that
h(n) is a lower bound on the cost to reach Gn.
Optimality ofA *
A * expands nodes in order of increasing f value
Gradually adds "f-contours" of nodes
Contour i has all nodes with f=fi, where fi < fi+1
Optimality ofA *
If C∗ is the cost of the optimal solution
path, then we can say the following:
⚫ A∗ expands all nodes with f(n) < C∗.
⚫ A∗ might then expand some of the nodes
right on the “goal contour”
(where f(n) = C∗) before selecting a goal
node.
Properties ofA*
Complete? Yes (unless there are
infinitely many nodes with f ≤ f(G) )
Optimal?Yes
Time? Exponential
Space? Keeps all nodes in memory
A* Search – Informedness
• If A 1 and A 2 are two versions of A*, such that A 2 is
more informed than A1,then A 1 expands at least as
many nodes as does A 2
• The closer h is to h*, the fewer extra nodes
that will be expanded
Analysis ofA*
In fact, we can say something even
stronger about A* (when it is admissible)

A* is optimally efficient among the algorithms


that extend the search path from the initial
state
It finds the goal with the minimum no. of expansions
Why A* is Optimally Efficient?
• No other optimal algorithm is guaranteed to
expand fewer nodes than A* (given the same
heuristic function)

• This is because any algorithm that does not


expand every node with f(n) < f(G) (optimal goal)
risks missing the optimal solution
Complete Optimal Time Space

DFS N N O(bm) O(bm)


(Y if no
cycles)
BFS Y Y O(bm) O(bm)
IDS Y Y O(bm) O(bm)
UCS Y Y O(bm) O(bm)
(when arc costs Costs > 0 Costs >=0
available)

Best First N N O(bm) O(bm)


(when h available)

A* Y Y O(bm) O(bm)
(when arc costs > 0
and hadmissible)

21
TASK
Reading Material
Russell & Norvig: Chapter # 3
David Poole: Chapter # 3
George Luger: Chapter # 4
An article: A*’s use of Heuristic
http://theory.stanford.edu/~amitp/GameProgra
mming/Heuristics.html

You might also like