Artificial Intelligence Heuristic (Informed) Search
Artificial Intelligence Heuristic (Informed) Search
Artificial Intelligence Heuristic (Informed) Search
Algorithms
1) Greedy (Best-First) Search
2) A* and IDA*
3) Bidirectional Search
Optional reading:
– R. C. Holte, A. Felner, G. Sharon, N. R. Sturtevant: Bidirectional
Search That Is Guaranteed to Meet in the Middle, AAAI-2016
3 Artificial Intelligence: Heuristic Search © JK
How to Determine the next Node for Expansion?
Uninformed Search
– rigid procedure, no knowledge of the cost from a node to
the goal
– e.g. FIFO, LIFO queues
Informed Search
– "value" of expanding a node (state) used as guidance
that steers the search algorithm through the search
space
– evaluation function f(s) assigns a number to each state
0, if 𝑠𝑠 is a goal state
ℎ 𝑠𝑠 = �
> 0, otherwise
ℎ∗ 𝑠𝑠 = ∞ for dead-end states, from which the goal is unreachable
ℎ∗ 𝑠𝑠 is also called the goal distance of 𝑠𝑠
The value of ℎ depends only on the state 𝑠𝑠, not on the path that we
followed so far to construct the partial solution (and the costs 𝑔𝑔 of this
path)
6 © JK
Artificial Intelligence: Heuristic Search
Desirable Properties of Heuristic Function 𝒉𝒉(𝒔𝒔)
1) Efficient to compute (ℎ 𝑠𝑠 = 0 as extreme case)
2) Informative (ℎ(𝑠𝑠) = ℎ∗ (𝑠𝑠) as extreme case)
0, if 𝑠𝑠 is a goal state
3) ℎ 𝑠𝑠 = �
> 0, otherwise
4) ℎ is admissible
5) ℎ 𝑠𝑠𝑑𝑑 = ∞ for dead-end states 𝑠𝑠𝑑𝑑
6) ℎ is consistent
GOOD heuristics should satisfy a balanced compromise of properties (1)
to (4) at least, better of all 6
Properties (5) ensures effective dead-end recognition and (6) is a
prerequisite for algorithms to guarantee minimal-cost (optimal) solutions
7 Artificial Intelligence: Heuristic Search © JK
Admissiblity of 𝒉𝒉(𝒔𝒔)
The value 𝑐𝑐 𝑠𝑠, 𝑎𝑎 is the action cost of getting from 𝑠𝑠 to 𝑠𝑠𝑠 with action 𝑎𝑎.
We reformulate the inequality from above to: ℎ 𝑠𝑠 ≤ 𝑐𝑐 𝑠𝑠, 𝑎𝑎 + ℎ(𝑠𝑠𝑠).
𝑠𝑠
𝑐𝑐(𝑠𝑠, 𝑎𝑎) Triangle inequality: The sum of the lengths of
any two sides of a triangle must be greater or
equal than the length of the remaining side.
𝑠𝑠𝑠
ℎ(𝑠𝑠)
ℎ(𝑠𝑠𝑠) Applying an action 𝑎𝑎 to the state 𝑠𝑠, the
heuristic value cannot decrease by more
than the cost 𝑐𝑐 𝑠𝑠, 𝑎𝑎 of 𝑎𝑎.
goal state
9 Artificial Intelligence: Heuristic Search © JK
Consistency ⟹ Admissibility
Let Π be a problem with state space Θ and let ℎ be a heuristic function forΘ.
If ℎ is consistent, then ℎ is admissible.
𝑎𝑎
To show: ℎ 𝑠𝑠 − ℎ 𝑠𝑠 ≤ 𝑐𝑐 𝑠𝑠, 𝑎𝑎 , ∀𝑠𝑠 → 𝑠𝑠 ′ ⟹ ℎ(𝑠𝑠) ≤ ℎ∗ (𝑠𝑠), ∀𝑠𝑠 ∈ 𝑆𝑆.
′
Base case: 𝑠𝑠 is a goal state, so 𝑠𝑠 ∈ 𝒮𝒮0 (𝑘𝑘 = 0). By the definition of heuristic functions
then ℎ(𝑠𝑠) = 0 and so ℎ(𝑠𝑠) ≤ ℎ∗ (𝑠𝑠) = 0 as required.
Inductive step: Let 𝑠𝑠 ∈ 𝒮𝒮𝑘𝑘+1 . Then the cheapest path from 𝑠𝑠 to a goal state has length
𝑎𝑎
𝑘𝑘 + 1. Let 𝑠𝑠𝑠 be the successor state of 𝑠𝑠 in this cheapest path, so 𝑠𝑠 → 𝑠𝑠𝑠. We thus know
that 𝑠𝑠𝑠 ∈ 𝒮𝒮𝑘𝑘 and therefore
1) By the consistency of ℎ we have: ℎ 𝑠𝑠 − ℎ 𝑠𝑠 ′ ≤ 𝑐𝑐(𝑠𝑠, 𝑎𝑎)
2) By the Inductive Hypothesis: ℎ 𝑠𝑠 ′ ≤ ℎ∗ 𝑠𝑠′
3) Since the cheapest path has the cheapest costs: ℎ∗ 𝑠𝑠 = ℎ∗ 𝑠𝑠 ′ + 𝑐𝑐(𝑠𝑠, 𝑎𝑎)
Combining these three statements, we get
𝒉𝒉 𝒔𝒔 ≤ ℎ 𝑠𝑠 ′ + 𝑐𝑐 𝑠𝑠, 𝑎𝑎 ≤ ℎ∗ 𝑠𝑠′ + 𝑐𝑐 𝑠𝑠, 𝑎𝑎 = 𝒉𝒉∗ (𝒔𝒔)
QED
11
1) 2) 3) © JK
(1) Greedy Best-First Search
Uses only the heuristic part of the evaluation function
𝑓𝑓(𝑠𝑠) = ℎ(𝑠𝑠)
Not optimal
http://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html
gives a good introduction
A* is optimal
– first solution found has minimum path cost if ℎ is
admissible (on trees) or if ℎ is consistent (on graphs)
• under an admissible heuristics on graphs, A* needs to expand all
nodes with 𝑓𝑓(𝑛𝑛) ≤ 𝐶𝐶 ∗ (the cost of an optimal solution), called
“re-opening”
• For any path, re-opening checks if it is the cheapest to a state 𝑠𝑠
and puts explored states back into the frontier if a cheaper path
was found
19 Artificial Intelligence: Heuristic Search © JK
Properties of A*
S,T,Z
R,F,T,Z,O
F,P,T,Z,C,O
P,T,Z,B,C´,O
Bucharest is inserted
after Pitesti in the
frontier!
B´,T,Z,C´,O
700 = 400 - (2200 - 2500) 150 = 650 - (2200 -1700) 250 = 1950 - (1700 - 0)
𝑎𝑎1 𝑎𝑎𝑛𝑛
Proof: Let 𝑠𝑠0 𝑠𝑠1 , … , 𝑠𝑠𝑛𝑛−1 𝑠𝑠𝑛𝑛 be any state path in Θ. The 𝑔𝑔 + ℎ value,
used by A*, is ∑𝑛𝑛𝑖𝑖=1 𝑐𝑐(𝑠𝑠𝑖𝑖−1 , 𝑎𝑎𝑖𝑖 ) + ℎ(𝑠𝑠𝑛𝑛 ). The 𝑔𝑔 value in Θℎ , used by
uniform-cost search on Θℎ , is ∑𝑛𝑛𝑖𝑖=1 𝑐𝑐(𝑠𝑠𝑖𝑖−1 , 𝑎𝑎𝑖𝑖 ) − ℎ 𝑠𝑠0 + ℎ(𝑠𝑠𝑛𝑛 ) (see Proof
of Lemma A). The difference −ℎ(𝑠𝑠0 ) is constant, so the ordering of the
frontier (open list) is the same. As the duplicate elimination is identical,
the assumption is shown.
400+2500 650+1700
650+1950+0
IDA* is optimal. The first solution found has minimal path costs if ℎ is
admissible (tree) or consistent (graph)
Initial state
A C
G I
Goal state
D K
H J
First letter indicates the distance from start (N=near, F=far, R=remote)
and the second letter indicates the distance from goal (N=near, F=far)
NN includes only those states at the exact midpoint of optimal
solutions
MM is complete
Superscripts:
Where: a for finite state spaces
𝑑𝑑 depth of solution b with duplicate elimination
𝑚𝑚 maximum depth of the search space c if every node has a finite number of
successor nodes
d if each action has positive and finite costs
e 1st solution found has minimal path costs if ℎ
is admissible (tree) or consistent (graph)
f for non-negative action costs
39
g with backtracking search, else 𝑂𝑂(𝑏𝑏𝑏𝑏) © JK
Designing Heuristic Functions
The informedness of the heuristic is critical for the success
of the search algorithm
– steer the algorithm towards the most promising parts of
the search space
– recognize dead ends early
– find a near-optimal solution under practical conditions
h2 = 3 + 1 + 2 + … = 18
current position
LC: 2 + 2 = 4
MH: 2 + 0 = 2
Two tiles 𝑡𝑡𝑗𝑗 and 𝑡𝑡𝑘𝑘 are in a linear conflict if 𝑡𝑡𝑗𝑗 and 𝑡𝑡𝑘𝑘 are in
the same line, the goal positions of 𝑡𝑡𝑗𝑗 and 𝑡𝑡𝑘𝑘 are both in that
line, 𝑡𝑡𝑗𝑗 is to the right of 𝑡𝑡𝑘𝑘 and the goal position of 𝑡𝑡𝑗𝑗 is to the
left of the goal position of 𝑡𝑡𝑘𝑘
– LC will add a cost of 2 moves for each pair of conflicting
tiles to the Manhattan Distance
– Motivation: Tiles need to surround one another
LC is consistent and more informative than MH
44 Artificial Intelligence: Heuristic Search © JK
Gaschnig's Heuristic
transform 724596831
into 912345678
724596831
Move(t, y, z)
preconditions : ON(t, y) & CLEAR(z) & ADJ(y, z)
effects : ON(t, z) & CLEAR(y) &
NOT ON(t, y) & NOT CLEAR(z)