Heuristic Search

Heuristic Search
Blai Bonet
Search trees and basic concepts
Universidad Sim´
on Bol´ıvar, Caracas, Venezuela
c 2015 Blai Bonet
Goals for the lecture
Lecture 3
Exploring a graph: search trees
Every search algorithm generates a tree when exploring a graph. Such
a tree is called a search tree
• Learn what is the search tree associated to a graph
The shape of the tree depends on the algorithm, and the order in
which the children of nodes are explored
• Learn how the search tree is stored in memory
• Basic concepts of generation and expansion of nodes, and
branching factor
The search algorithm can either:
• Illustrate search tree and branching factor for the 15-puzzle
– store the complete tree in memory,
• Present canonical search trees as tool for analysis
– store only the current branch of the search, or
– store partial information about the tree
c 2015 Blai Bonet
Lecture 3
c 2015 Blai Bonet
Lecture 3
Representation of search trees: nodes
Search tree: example
3
4
6
Search trees are comprised of nodes that represent states
2
As in all trees, a node only needs to store a pointer to its unique
parent (the root is the only node that has no parent)
5
1
1
1
1
1
1
2
2
2
5
3
2
5
5
4
5
3
4
5
2
4
4
4
5
3
4
3 6 3 6 3
5
2
4
5
We also store in nodes:
4
4
3 6 3 6
– the label of the edge connecting the parent with the node
4
3
6
3
6
2
4
2
4
– the cost of the unique path from the root to the node
The nodes in the search tree represent states and paths
1 2 5 3 5 4 4 2 4 4 3 6 3 6 3 5 3 6 3 6 2 4 2 4 2 4 4 2 4 2 4 3 5 3 6 3 5 3 6
c 2015 Blai Bonet
Lecture 3
c 2015 Blai Bonet
Node: data structure and basic manipulation
struct Node {
AbstractState
Node
Action
unsigned
state
parent
action
g
%
%
%
%
Lecture 3
Generation and expansion of nodes
pointer to state represented by node
parent of node (null if root)
action mapping state to node (-1 if root)
cost of path: root -> node
A node is generated when a data structure for it is created in memory
Node(AbstractState s, Node p, Action a, unsigned gcost)
: state(s), parent(p), action(a), g(gcost)
A node is expanded when all its children are generated
Node make-node(AbstractState state, Action action)
return new Node(state, this, action, g + c(state, action))
Critical operations that are performed thousands/millions of times
extract-path(vector<Action> &reversed-path)
Node node = this
while node != 0 && node.parent != 0
reversed-path.push-back(node.action)
node = node.parent
The number of nodes generated per second is frequently used
as a measure of efficiency
}
Node make-root-node(AbstractState state)
return new Node(state, null, -1, 0)
c 2015 Blai Bonet
Lecture 3
c 2015 Blai Bonet
Lecture 3
15-puzzle: complete search tree
depth
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#nodes
emp. branching factor
1
2
6
18
58
186
602
1, 946
6, 298
20, 378
65, 946
213, 402
690, 586
2, 234, 778
7, 231, 898
23, 402, 906
75, 733, 402
245, 078, 426
793, 090, 458
2, 566, 494, 618
8, 305, 351, 066
2.00000000
3.00000000
3.00000000
3.22222222
3.20689655
3.23655913
3.23255813
3.23638232
3.23563035
3.23613701
3.23601128
3.23608026
3.23606038
3.23606998
3.23606693
3.23606828
3.23606783
3.23606802
3.23606795
3.23606798
3.23606797
c 2015 Blai Bonet
15-puzzle: formal analysis of branching factor
It can be shown that the number dn of nodes at depth n in the
complete search tree for the 15-puzzle is
1
n−2
2
(φ1 + 2)2 × φn−2
+
(φ
+
2)
×
φ
+
2
dn =
2
1
2
5
√
√
where φ1 = 1 + 5 ≈ 3.23 and φ2 = 1 − 5 ≈ −1.23
The asymptotic branching factor, if it exists, is limn→∞ dn+1 /dn
For the complete 15-puzzle, the limit exists and it is equal to
√
dn+1
= φ1 = 1 + 5 ≈ 3.23606797
n→∞ dn
lim
At depth 27, number of nodes in search tree exceed total
number of states in problem!
Lecture 3
Foundation for analysis: canonical search trees
c 2015 Blai Bonet
Lecture 3
Canonical search tree: number of nodes
depth
0
1
2
3
4
5
..
In order to analyse search algorithms, we need to assume a nice and
regular structure for search trees
Otherwise the analysis is too complex (e.g. 15-puzzle)
A canonical search tree T satisfies:
#nodes
1
b
b2
b3
b4
b5
..
root
T
n
bn
leaves
– T is a full tree (meaning that all leaves appear at same depth)
– T has a regular branching factor b across all internal nodes
Canonical search tree T of depth n and branching factor b:
Recall: branching factor of node n is its number of children
– Number of nodes at depth d is bd , and number of leaves is bn
n+1
. P
– Total number of nodes is N (b, n) = nk=0 bk = b b−1−1 = O(bn )
– Ratio N (b, n)/bn =
c 2015 Blai Bonet
Lecture 3
c 2015 Blai Bonet
bn+1
bn (b−1)
−
1
bn (b−1)
<
bn b
bn b−1
=
b
b−1
Lecture 3
Canonical search tree: number of nodes
depth
0
1
2
3
4
5
..
#nodes
1
b
b2
b3
b4
b5
..
root
T
n
Canonical search tree: goal depth and cost
b
leaves
depth
b
b/(b − 1)
bn+1
bn (b−1)
2
2.00
−
3
1.50
1
bn (b−1)
<
4
1.33
bn b
bn b−1
5
1.25
goal
n
leaves
=
6
1.20
Canonical search tree T of depth n and branching factor b:
– Goal at depth d with cost c∗
b
b−1
– If all costs are equal to 1, then d = c∗
7
1.16
c 2015 Blai Bonet
– If all costs are positive ≥ cmin > 0, then d ≤ c∗ /cmin
Lecture 3
Summary
• Complete search tree associated with a graph
• Data structure and basic operations for nodes (search tree)
• Concepts: generation, expansion, branching factor
• Complete search tree for the 15-puzzle
• Canonical search trees: full tree of given depth with constant
branching factor
c 2015 Blai Bonet
cost
c∗
d
Canonical search tree T of depth n and branching factor b:
– Ratio N (b, n)/bn =
root
Lecture 3
c 2015 Blai Bonet
Lecture 3