Professional Documents
Culture Documents
Chapter2 Part2
Chapter2 Part2
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting nodes to the search tree
end
A state is a physical configuration
7 8 3
Depth = 3
2 1 Path_Cost = 3
4 5 6
Children
State Node
Expand Function : creates new nodes, filling in the various
fields and using the Successor_Function of the problem to
create the corresponding new states
function Tree-Search (problem) returns a solution, or failure
loop do
if List_toExplore is empty then return failure
node ← Remove(List_toExplore)
successors←
N← new Node
Parent [N] ← node;
Action[N]←action;
State[N]←result
Path_Cost[N]←Path-Cost[node] + Step_Cost(State[node], action, result)
Depth[N]←Depth[node] + 1
add N to successors
return successors
A strategy is defined by picking the order of
node expansion
Breadth-first search
Depth-first search
Depth-limited search
Iterative deepening search
Basic Idea: Priority to expand the least recently
(shallowest) generated nodes
List_toExplore : C D E List_toExplore : D E F G
Expanding Order : A B C D E F G
Complete ??
Time ??
Space ??
Optimal ??
Complete ? Yes (if b is finite)
Time ?? 1 + b + b2 + b3 + … + bd = O(bd) (exp.
In d)
Space ?? O(bd) (each expanded node must be
kept in memory)
Optimal ?? Yes (if cost = 1 per step); not
optimal in general
1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
1 2 3
8 6 Initial State
7 5 4
(0)
1 2 1 2 3 1 2 3
(1) 8 6 3 (2) 8 6 4 (3) 8 6
7 5 4 7 5 7 5 4
1 2 1 2 2 1 3 1 2 2 1 2 2
(4) 8 6 3 (5) 8 6 4 (6) 8 2 6 (7) 8 5 6 (8) 8 6
7 5 4 7 5 7 5 4 7 4 7 5 4
1 6 2 1 2 1 2 3
57
Basic Idea : Expand the deepest unexpanded
node
Implementation: List_toExplore is LIFO queue,
i.e., put successors at front
1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
1 2 3
8 6 Initial State
7 5 4
(0)
1 2 1 2 3
(1) 8 6 3 (5) 8 6 4
7 5 4 7 5
1 2 1 2 2
(2) 8 6 3 6
(6) 8 4
7 5 4 7 5
1 6 2 1 2 2 3
(3) 1
8 3 (4) 8 6 3 (7) 8 4
7 5 4 7 5 4 7 6 5
Goal State
Basic Idea :
The problem of Depth Limited Search is : How to define
the good value of L ?
Space ?? O(b * d)
Special cases:
◦ greedy search
◦ A∗ search
Use of a criterion to reorder any nodes to be
explored (instead of a LIFO or a FIFO list)
⇨ Heuristic
⇨ Evaluation Function f
The search is guided by the the best node
according to the evaluation function
1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
Initial State Final State
f(n)=h(n)
h ???
1 2 1 2 3 1 2 3
8 6 3 8 6 4 8 6
7 5 4 7 5 (2) 7 5 4
(3)
8 6 4
7 5 f(n)= h(n) =1
1 2 3
f*(n) n Node n
h*(n)
Goal
B State
⇨ f*(n) represents the ideal cost (best cost) of the path crossing a
node n to reach the goal
g*(n): the cost of the best path already
crossed from the initial state to the state n
Example : Puzzle
g(n) : the number of moved tokens
→ the length of path from the root to n
By using A* Algo. f(n)=g(n) +h(n)
with :
◦ g : number of moved tokens de jetons déplacés
◦ h: number of misplaced tokens
1 2 3 1 2 3
8 6 8 4
7 5 4 7 6 5
Initial Configuration Final Configuration
Initial State Final State
1 2 3
1 2 1 2 3 1 2 3
8 6 3 8 6 4 8 6
(1+4) 7 5 4 7 5 (1+2) 7 5 4
(1+3)
1 2 2
8 6 4
(2+1)
7 5
1 2 3
(3+0)
Goal State 8 4
7 6 5
2 8 3 1 2 3
1 6 4 8 4
7 5 7 6 5
Initial Configuration Final Configuration
Path ???
91
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 925 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 935 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 945 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 955 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 965 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 975 6 5
puzzle with A* Algorithm 2 8 3
m(A) d(x)
1 6 4
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x) 1 4
m(E)
=3
1 8 4
m(F)
=3
1 4
m(G) d(x)
=4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 985 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 6 995 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 61005 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
7 6 5
1 2 3 1 2 3
m(M) m(N) d(x)
8 4 7 8 4
=0 =2 =5
7 61015 6 5
puzzle with A* Algorithm 2
1
8
6
3
4
m(A) d(x)
=4 =0
7 5
A, ..., N: states
2 8 3 2 8 3 2 8 3
m = misplaced tokens m(B) m(C) m(D) d(x)
1 6 4 1 4 1 6 4
=5 =3 =5 =1
7 5 7 6 5 7 5
d = depth or number
of moved tokens
2 8 3 2 3 2 8 3
f(x) = m(x) + d(x)
m(E) m(F) m(G) d(x)
1 4 1 8 4 1 4
=3 =3 =4 =2
7 6 5 7 6 5 7 6 5
8 3 2 8 3 2 3 2 3
m(H) m(I) m(J) m(K) d(x)
2 1 4 7 1 4 1 8 4 1 8 4
=3 =4 =2 =4 =3
7 6 5 6 5 7 6 5 7 6 5
1 2 3
m(L) d(x)
8 4
=1 =4
Final
7 6 5
State 1
8
2 3
4
m(M)
=0
1
7
2
8
3
4
m(N) d(x)
=2 =5
7 61025 6 5
Assume a postman initially in the city of Arad in
Romania
the goal is to attain Bucharest with the minimal
cost path
The shortest path ???
Greedy Search ?
A* Algorithm ?
Romania Step Straight-line
Cost in Km distance to
Bucharest