Introduction to Artificial Intelligence
Informed Search
Bernhard Beckert
UNIVERSITÄT KOBLENZ-LANDAU
Winter Term 2004/2005
Outline
Best-first search
Review: Tree search
function TREE-SEARCH(problem, fringe) returns a solution or failure
fringe
←
INSERT(MAKE-NODE(INITIAL-STATE[problem]),fringe)loop do
if fringe is empty then return failure
node
←
REMOVE-FIRST(fringe)if GOAL-TEST[problem] applied to STATE(node) succeeds then
return node else
fringe
←
INSERT-ALL(EXPAND(node,problem),fringe)end
Strategy
Defines the order of node expansion
Best-first search
Idea
Use an evaluation function for each node (estimate of “desirability”) Expand most desirable unexpanded node
Implementation
fringe is a queue sorted in decreasing order of desirability
Special cases
Romania with step costs in km
Rimnicu Vilcea
Vaslui Iasi
Straight−line distance to Bucharest
0
Sibiu Fagaras
Pitesti
Vaslui Iasi
Rimnicu Vilcea
Greedy search
Heuristic
Evaluation function
h
(
n
)
=
estimate of cost fromn
togoal
Greedy search expands the node that appears to be closest to goal
Example
h
SLD(
n
)
=
straight-line distance fromn
to BucharestNote
Greedy search: Example Romania
Arad 366
Greedy search: Example Romania
Zerind Arad
Sibiu Timisoara
Greedy search: Example Romania
Rimnicu Vilcea
Zerind Arad
Sibiu
Arad Fagaras Oradea
Timisoara
329 374
366 176 380 193
Greedy search: Example Romania
Rimnicu Vilcea
Zerind Arad
Sibiu
Arad Fagaras Oradea
Timisoara
Sibiu Bucharest
329 374
366 380 193
Greedy search: Properties
Complete
Time
Space
Optimal
Greedy search: Properties
Complete No
Can get stuck in loops Example: Iasi to Oradea
Iasi
→
Neamt→
Iasi→
Neamt→ · · ·
Complete in finite space with repeated-state checking
Time
Space
Greedy search: Properties
Complete No
Can get stuck in loops Example: Iasi to Oradea
Iasi
→
Neamt→
Iasi→
Neamt→ · · ·
Complete in finite space with repeated-state checking
Time
O
(
b
m)
Space
Optimal
Greedy search: Properties
Complete No
Can get stuck in loops Example: Iasi to Oradea
Iasi
→
Neamt→
Iasi→
Neamt→ · · ·
Complete in finite space with repeated-state checking
Time
O
(
b
m)
Space
O
(
b
m)
Greedy search: Properties
Complete No
Can get stuck in loops Example: Iasi to Oradea
Iasi
→
Neamt→
Iasi→
Neamt→ · · ·
Complete in finite space with repeated-state checking
Time
O
(
b
m)
Space
O
(
b
m)
Optimal No
Greedy search: Properties
Complete No
Can get stuck in loops Example: Iasi to Oradea
Iasi
→
Neamt→
Iasi→
Neamt→ · · ·
Complete in finite space with repeated-state checking
Time
O
(
b
m)
Space
O
(
b
m)
Optimal No
Note
Worst-case time same as depth-first search, Worst-case space same as breadth-first
A
∗
search
Idea
Avoid expanding paths that are already expensive
Evaluation function
f
(
n
)
=
g
(
n
) +
h
(
n
)
where
g
(
n
) =
cost so far to reachn
h
(
n
) =
estimated cost to goal fromn
f
(
n
) =
estimated total cost of path throughn
to goalA
∗
search: Admissibility
Admissibility of heuristic
h
(
n
)
is admissible ifh
(
n
)
≤
h
∗(
n
)
for alln
A
∗
search: Admissibility
Admissibility of heuristic
h
(
n
)
is admissible ifh
(
n
)
≤
h
∗(
n
)
for alln
where
h
∗(
n
)
is the true cost fromn
to goalAlso required
h
(
n
)
≥
0
for alln
In particular:
h
(
G
) =
0
for goalG
A
∗
search: Admissibility
Admissibility of heuristic
h
(
n
)
is admissible ifh
(
n
)
≤
h
∗(
n
)
for alln
where
h
∗(
n
)
is the true cost fromn
to goalAlso required
h
(
n
)
≥
0
for alln
In particular:
h
(
G
) =
0
for goalG
Example
A
∗
search: Admissibility
Theorem
A∗ search with admissible heuristic is optimal
A
∗
search example
A
∗
search example
Zerind Arad
Sibiu Timisoara
447=118+329 449=75+374 393=140+253
A
∗
search example
Zerind Arad
Sibiu
Arad
Timisoara
Rimnicu Vilcea
Fagaras Oradea
447=118+329 449=75+374
A
∗
search example
Zerind Arad
Sibiu
Arad
Timisoara
Fagaras Oradea
447=118+329 449=75+374
646=280+366 415=239+176
Rimnicu Vilcea
Craiova Pitesti Sibiu 526=366+160 417=317+100 553=300+253 671=291+380
A
∗
search example
Zerind Arad
Sibiu
Arad
Timisoara
Sibiu Bucharest
Rimnicu Vilcea
Fagaras Oradea
Craiova Pitesti Sibiu
447=118+329 449=75+374
646=280+366
A
∗
search example
Sibiu Bucharest
Rimnicu Vilcea
Fagaras Oradea
Craiova Pitesti Sibiu
Bucharest Craiova Rimnicu Vilcea
418=418+0
447=118+329 449=75+374
646=280+366
591=338+253 450=450+0 526=366+160 553=300+253
615=455+160 607=414+193 671=291+380
A
∗
search:
f
-contours
A∗ gradually adds “
f
-contours” of nodesOptimality of A
∗
search: Proof
Suppose a suboptimal goal
G
2 has been generatedLet
n
be an unexpanded node on a shortest path to an optimal goalG
f
(
G
2) =
g
(
G
2)
sinceh
(
G
2) =
0
>
g
(
G
)
sinceG
2 suboptimal=
g
(
n
) +
h
∗(
n
)
≥
g
(
n
) +
h
(
n
)
sinceh
is admissible=
f
(
n
)
Thus, A∗ never selects
G
2 for expansion
A
∗
search: Properties
Complete
Time
Space
A
∗
search: Properties
Complete Yes
(unless there are infinitely many nodes
n
withf
(
n
)
≤
f
(
G
)
)Time
Space
Optimal
A
∗
search: Properties
Complete Yes
(unless there are infinitely many nodes
n
withf
(
n
)
≤
f
(
G
)
)Time Exponential in
[relative error in
h
×
length of solution]Space
A
∗
search: Properties
Complete Yes
(unless there are infinitely many nodes
n
withf
(
n
)
≤
f
(
G
)
)Time Exponential in
[relative error in
h
×
length of solution]Space Same as time
Optimal
A
∗
search: Properties
Complete Yes
(unless there are infinitely many nodes
n
withf
(
n
)
≤
f
(
G
)
)Time Exponential in
[relative error in
h
×
length of solution]Space Same as time
A
∗
search: Properties
Complete Yes
(unless there are infinitely many nodes
n
withf
(
n
)
≤
f
(
G
)
)Time Exponential in
[relative error in
h
×
length of solution]Space Same as time
Optimal Yes
Note
A∗ expands all nodes with
f
(
n
)
<
C
∗ A∗ expands some nodes withf
(
n
) =
C
∗ A∗ expands no nodes withf
(
n
)
>
C
∗Admissible heuristics: Example 8-puzzle
2
Start State Goal State
5
Addmissible heuristics
h
1(
n
)
= number of misplaced tilesh
2(
n
)
= total ˘Manhattan distanceAdmissible heuristics: Example 8-puzzle
2
Start State Goal State
5
Addmissible heuristics
h
1(
n
)
= number of misplaced tilesh
2(
n
)
= total ˘Manhattan distance(i.e., no. of squares from desired location of each tile)
In the example
h
1(
S
)
=h
2(
S
)
=Admissible heuristics: Example 8-puzzle
2
Start State Goal State
5
Addmissible heuristics
h
1(
n
)
= number of misplaced tilesh
2(
n
)
= total ˘Manhattan distance(i.e., no. of squares from desired location of each tile)
In the example
h
1(
S
)
= 6Admissible heuristics: Example 8-puzzle
2
Start State Goal State
5
Addmissible heuristics
h
1(
n
)
= number of misplaced tilesh
2(
n
)
= total ˘Manhattan distance(i.e., no. of squares from desired location of each tile)
In the example
h
1(
S
)
= 6h
2(
S
)
= 2 + 0 + 3 + 1 + 0 + 1 + 3 + 4 = 14Dominance
Definition
h
1,
h
2 two admissible heuristicsh
2 dominatesh
1 ifDominance
Definition
h
1,
h
2 two admissible heuristicsh
2 dominatesh
1 ifh
2(
n
)
≥
h
1(
n
)
for alln
Theorem
If
h
2 dominatesh
1, thenh
2 is better for search thanh
1.Dominance: Example 8-puzzle
Typical search costs
d
=
14
IDS 3,473,941 nodesA∗
(
h
1
)
539 nodesA∗
(
h
2
)
113 nodesd
=
24
IDS too many nodesA∗
(
h
1
)
39,135 nodesA∗
(
h
2
)
1,641 nodesd
: depth of first solutionRelaxed problems
Finding good admissible heuristics is an art!
Deriving admissible heuristics
Admissible heuristics can be derived from the exact
solution cost of a relaxed version of the problem
Relaxed problems
Finding good admissible heuristics is an art!
Deriving admissible heuristics
Admissible heuristics can be derived from the exact
solution cost of a relaxed version of the problem
Example
If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then we get heuristic
h
1Relaxed problems
Finding good admissible heuristics is an art!
Deriving admissible heuristics
Admissible heuristics can be derived from the exact
solution cost of a relaxed version of the problem
Example
If the rules of the 8-puzzle are relaxed so that a tile can move anywhere, then we get heuristic
h
1If the rules are relaxed so that a tile can move to any adjacent square, then we get heuristic
h
2Key point
The optimal solution cost of a relaxed problem is not greater than the optimal solution cost of the real problem