L04 Problem Solving As Search Informed
L04 Problem Solving As Search Informed
Semester I, 2024-25
1
Outline
• Last Class
• Uninformed Search
• This Class
• Informed Search
• Key idea behind Informed Search
• Best First Search
• Greedy Best First Search
• A* Search: evaluation Function
• Reference Material
• AIMA Ch. 3
2
Acknowledgement
These slides are intended for teaching purposes only. Some material
has been used/adapted from web sources and from slides by Doina
Precup, Dorsa Sadigh, Percy Liang, Mausam, Dan Klein, Nicholas Roy
and others.
3
Informed Search … c1
c2
c3
• Uniform Cost Search
• Expand the lowest cost path
• Complete
• Optimal
• Problem
• Explores options in every “direction”
• No information about goal location
• Informed Search
• Use problem-specific knowledge beyond the
definition of the problem to guide the search
towards the goal.
4
What other knowledge can be leveraged during
search?
2D route finding problem: (left) uninformed search (right) an approach that uses approx. distance to goal
5
information.
Recall: Tree Search
Note: Central to tree search is how nodes (partial plans) are kept in the frontier are expanded (prioritized)
Prioritization essentially means among many partial plans which one we should search first (over other
options we have in the frontier).
6
Evaluation of a node during search
• Best First Search
• Always choose the node from frontier that has the best evaluation (according
to a function).
• The search orders nodes in the frontier (via priority queue) for expansion using
this evaluation.
• Central Idea
• To evaluate a need we need two things: cost so far and cost to go.
• Uninformed search methods expand nodes based on the cost (or distance) from the
start state to the the current state, d(s0, s)
• Evaluation based on the exact cost so far.
• Informed search methods additionally estimate of the cost (or distance) from the
current state to the goal state, d(s, sg) and use it in deciding which node to expand next.
• Evaluation based on the exact cost so far + an estimate of cost to go
• Note: What if we knew the exact distance to goal d(s, s g)?
• Then there is no need to search, we could just be greedy! In practice, we do not know that exactly
and must make an “estimate”.
8
A heuristic approximates the cost to goal
• An intuition about “approximate cost to goal”
• Even if we do not know d(s, sg) exactly, we often have some intuition about
this distance. This intuition is called a heuristic, h(n).
• Heuristic function h(n)
• Assigns an estimate of the actual cost to go for each state.
• Formally, h(n) = estimated cost of the cheapest path from the state at node n to a goal
state.
• Heuristic function can be arbitrary, non-negative, problem-specific functions.
• Constraint, h(n) = 0 if n is a goal. If you are at the goal, then there is no more cost to be
incurred.
9
Example Heuristic – Path Planning
• Consider a path along a road
system
• What is a reasonable heuristic?
• The straight-line Euclidean distance
from one place to another
• Is it exact?
• Not always. Actual paths are rarely
straight.
h(x)
10
Example Heuristic – 8 Puzzle
Intuitively, heuristics are trying to
estimate how much more effort is needed
from the current state to the goal.
11
Greedy Best-First Search (only guided by
heuristic)
• Best-First Search
• At any time, expand the most promising node on the frontier according to the
evaluation function f(n).
12
Greedy Best-First Search
• Which path does Greedy Best-First Search return?
13
A* Search
• Core Idea
• Combine the greedy search (the estimated cost to go) with the uniform-search
strategy (the cost incurred so far).
• Minimize estimated path costs. Avoid expanding paths that are already
expensive.
• Always expand node with lowest f(n) first, where
• g(n) = actual cost from the initial state to n.
• h(n) = estimated cost from n to the next goal.
• f(n) = g(n) + h(n), the estimated cost of the cheapest solution through n.
• Can I use any heuristic?
• Any heuristic will not work. [properties soon]
Example: UCS , Greedy and A* Search
• Uniform-cost orders by path cost, or backward cost g(n)
• Greedy orders by goal proximity, or forward cost h(n)
8 g=0
S h=6
h=1 g=1
e
1 h=5 a
1 3 2 g=2 g=9
S a d G
h=6 b d g=4 e h=1
h=6 h=5 h=2
1 h=2 h=0
1 g=3 g=6
c b g = 10
h=7 c G h=0 d
h=2
h=7 h=6
g = 12
G h=0
• A* Search orders by the sum: f(n) = g(n) + h(n)
• Let h∗(n) be the actual shortest path from n to any goal state.
• Heuristic h is called admissible if h(n) ≤ h∗(n) ∀n.
• Admissible heuristics are optimistic, they often think that the cost to
the goal is less than the actual cost.
• If h is admissible, then h(g) = 0, ∀g ∈ G
• A trivial case of an admissible heuristic is h(n) = 0, ∀n.
Admissible or not admissible?
Using an inadmissible h
Search with original heuristic
Straight line
heuristic, we
change one value.
Search with heuristic value changed.
A* Tree Search with Admissible Heuristic leads to an optimal path
• Property
• If h is a consistent heuristic and all costs are non-zero, then f values cannot decrease
along any path:
• Claim f(n’)>= f(n), where n’ is the successor of n.
• g(n’) = g(n) + c(n, a, n’)
• f(n’) = g(n) + c(n, a, n’) + h(n’) >= f(n)
Admissibility and Consistency
A
1 • Main idea: estimated heuristic costs ≤ actual costs
h=4 C h=1 • Admissibility: heuristic cost ≤ actual cost to goal
h=2
h(A) ≤ actual cost from A to G
3 • Consistency: heuristic “arc” cost ≤ actual cost for each arc
G
Consistency (monotonicity)
Search proceeds as f-value contours
Optimality of A* Graph Search
A* Search Properties
• Optimality
• Tree search version of A* optimal if the heuristic is admissible.
• Graph search version of A* is optimal if the heuristic is consistent.
• Completeness
• If a solution exists, A* will find it provided that:
• Every node has a finite number of successor nodes (b is finite).
• There exists a positive constant > 0 such that every step has at least cost
• Then there exists only a finite number of nodes with cost less than or equal to C*.
30
How heuristics effect nodes searched
b
…
Start Goal
b
…
Start Goal
32
Effective branching factor
34
Reference: AIMA
Ways to design heuristics
• Constructing Relaxations
• Examples:
• If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then h1 gives the
shortest solution
• If the rules are relaxed so that a tile can move to any adjacent square, then h2 gives the shortest
solution
• Exact solution cost of a relaxed version of the problem
• Combining heuristics
• Prior experience in terms of seeing plans for problems encountered in the past
35
Method I: Creating admissible heuristics from
relaxed problems
• Relaxation
• Ignore constraints/rules. 366
• Increase possibilities for actions.
• State space graph for the relaxed
problem is a super-graph of the original
state space Permitting straight line movement adds edges to
the graph.
• The removal of restrictions adds more edges.
• Hope is that in the relaxed graph, it is easier
to find a solution.
36
Admissible Heuristics from Relaxed Problems
• Optimal solution in the original problem is also a solution for the relaxed
problem.
• Cost of the optimal solution in the relaxed problem is an admissible
heuristic in the original problem.
• Finding the optimal solution in the relaxed problem should be “easy”
• Without performing search.
• If decomposition is possible, it is easier to directly solve the problem.
37
Comparing heuristics: dominance
• Heuristic function h2 (strictly) dominates h1 if
• Both are admissible and
• for every node n, h 2(n) is (strictly) greater than h 1(n).
38
Method II: Combining admissible heuristics
• Heuristic design process
• We may have a set of heuristics but not a single
“clearly best” heuristic.
• Have a set of heuristics for a problem and none of
them dominates any of the other.
• Combining heuristics
• Can use a composite heuristic
• Max of admissible heuristics is admissible when the
component heuristics are admissible.
• The composite heuristic dominates the component
heuristic.
39
Slide adapted from Dan Klein
Combining admissible heuristics
• Fundamentally, heuristic functions form a semi-
lattice structure
• Some heuristics can be compared to others via
dominance.
• There may be others not comparable.
• Can create composites by combining component
heuristics.
• Bottom of lattice is the zero heuristic
• No or little computation effort
• Not useful during search
• Top of lattice is the exact heuristic
• A lot of computation effort
• Really useful during search (give the exact cost)
40
Slide adapted from Dan Klein
Trade-off in heuristic design
41
Slide adapted from Mausam
Pattern Databases
Optimally solve a sub-problem.
In the tiles example, mask out
certain numbers. Consider a smaller-
sized pattern.
43
Slide from Kalev Kask
A* Search: Other Properties
• Exponential worst-case time and space complexity
• Let e = (h* - h)/h* (relative error)
• Complexity O(bed) where be is the effective branching factor.
• With a good heuristic complexity is often sub-exponential
• Optimally efficient
• With a given h, no other search algorithm will be able to expand fewer nodes
• If an algorithm does not expand all nodes with f(n) < C* (the cost of the optimal
solution) then there is a chance that it will miss the optimal solution.
• Main Limitation: Space Requirement!
• The number of states within the goal contour search space is still exponential
in the length of the solution.
- The memory needed is O(total number of states). The frontier is O(b^d). Despite using
the heuristic, it may be difficult to store the frontier.
- How to reduce memory requirement for A*?
45
Adapted from Maxim Likhachev
Iterative Deepening A* (IDA*)
• Key Idea
• A* uses a lot of memory. Alternative: Don’t’ keep all the nodes, recompute them. Borrow
idea from iterative deepening search (discussed before).
• IDA*
• Use an f-value limit, rather than a depth limit for search.
• Expand all nodes up to f1, f2, . . . . .
• Keep track of the next limit to consider
• so we will search at least one more node next time.
• If the depth-bounded search fails, then the next bound is the minimum of the f-values
that exceeded the previous bound.
• IDA* checks the same nodes as A* but recomputes them using a depth-first search (DFS)
instead of storing them.
46
Iterative Deepening A* (IDA*)
IDA* example
• If f1 = 4, then which nodes are searched?
• If f2 = 8, then which nodes are searched?
47
Iterative Deepening A* (IDA*)
• Key Idea: DFS in the inner loop is giving the space advantage. The depth is
decided by the f value.
• Like A*, IDA* is guaranteed to find the shortest path leading from the given start
node to any goal node in the problem graph, if the heuristic
function h is admissible.
48
History of A* Search
• Origin
• Shakey Experiment (AI Center at Stanford
Research Institute)
• https://www.youtube.com/watch?v=GmU7SimF
kpU
• Peter Hart, Nils Nilsson and Bertram
Raphael first published the algorithm in 1968.
• Djikstra was too slow for path finding.
• https://ieeexplore.ieee.org/stamp/stamp.jsp?tp
=&arnumber=4082128
49