COMP9414: Artificial Intelligence Informed Search - Sorry
COMP9414: Artificial Intelligence Informed Search - Sorry
COMP9414: Artificial Intelligence Informed Search - Sorry
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>COMP9414</strong>, Wednesday 23 March, 2005 <strong>Informed</strong> <strong>Search</strong> 12<br />
<strong>COMP9414</strong>, Wednesday 23 March, 2005 <strong>Informed</strong> <strong>Search</strong> 14<br />
A ∗ <strong>Search</strong><br />
% extend path by each node in Succs and insert into Paths in order of costs<br />
extend_path([], _, _, Paths, Paths).<br />
% no more paths<br />
2 8 3<br />
(1+5=6)<br />
1 6 4<br />
7 5<br />
2<br />
1<br />
7<br />
8<br />
6<br />
3<br />
4<br />
5<br />
2 8 3<br />
1 4<br />
7 6 5<br />
(0+4=4)<br />
(1+3=4)<br />
2 8 3<br />
(1+5=6)<br />
1 6 4<br />
7 5<br />
extend_path([S|Succs], Path, Cost, Paths, Paths2) :-<br />
Path = [LastNode|_],<br />
s(LastNode, S, C),<br />
NewCost is Cost + C,<br />
% g(S) = NewCost<br />
h(S, H),<br />
% h(S) = estimate S->Soln<br />
NewEst is NewCost + H,<br />
% f(S) = estimate of node’s value<br />
insert([S|Path], NewCost, NewEst, Paths, Paths1),<br />
extend_path(Succs, Path, Cost, Paths1, Paths2).<br />
% insert path in order in the list of paths<br />
insert(Path, Cost, Estimate, [], [[Path, Cost]]).<br />
8 3<br />
2 1 4<br />
7 6 5<br />
(3+3=6)<br />
2 8 3<br />
1 4<br />
7 6 5<br />
2 8 3<br />
7 1 4<br />
6 5<br />
(2+3=5)<br />
(3+4=7)<br />
2 3<br />
1 8 4<br />
7 6 5<br />
2 3<br />
1 8 4<br />
7 6 5<br />
(3+2=5)<br />
(2+3=5)<br />
2 3<br />
1 8 4<br />
7 6 5<br />
(3+4=7)<br />
2 8 3<br />
1 4<br />
7 6 5<br />
(2+4=6)<br />
insert(Path, Cost, Estimate, Paths, [[Path, Cost]|Paths]) :-<br />
Paths = [Path1|_],<br />
Path1 = [[Last1|_], Cost1],<br />
h(Last1, H),<br />
Estimate1 is Cost1 + H,<br />
Estimate1 > Estimate.<br />
% new path is better<br />
1<br />
7<br />
2<br />
8<br />
6<br />
3<br />
4<br />
5<br />
(4+1=5)<br />
insert(Path, Cost, Estimate, [Path1|Paths], [Path1|Paths1]) :-<br />
insert(Path, Cost, Estimate, Paths, Paths1).<br />
1 2 3<br />
(5+0=5)<br />
8 4<br />
7 6 5<br />
1 2 3<br />
(5+2=7)<br />
7 8 4<br />
6 5<br />
<strong>COMP9414</strong> c○UNSW, 2005 Generated: 24 March 2005<br />
<strong>COMP9414</strong> c○UNSW, 2005 Generated: 24 March 2005<br />
<strong>COMP9414</strong>, Wednesday 23 March, 2005 <strong>Informed</strong> <strong>Search</strong> 13<br />
A ∗ <strong>Search</strong><br />
<strong>COMP9414</strong>, Wednesday 23 March, 2005 <strong>Informed</strong> <strong>Search</strong> 15<br />
A ∗ <strong>Search</strong> — Analysis<br />
% Best-First <strong>Search</strong><br />
% A simplified version of Bratko Fig. 12.3<br />
% Store paths and costs g(n) in a list of paths, ordered according to f(n)<br />
% Nodes in a path are listed in reverse order, i.e. list [t,g,f,e,s]<br />
% represents path s->e->f->g->t<br />
% <strong>Search</strong> from the start node Start for path Solution, call ?- bestfirst(Start, Solution)<br />
bestfirst(Start, Solution) :-<br />
astar([[[Start], 0]], Solution).<br />
astar([BestPath|Paths], Path) :-<br />
BestPath = [Path, Cost],<br />
Path = [LastNode|_],<br />
goal(LastNode).<br />
astar([BestPath|Paths], Solution) :-<br />
BestPath = [Path, Cost],<br />
Path = [LastNode|_],<br />
extend(Path, Cost, Paths, NewPaths),<br />
astar(NewPaths, Solution).<br />
Optimal (optimally efficient)<br />
Complete<br />
Number of nodes searched (and stored) still exponential in the worst<br />
case<br />
It has been shown that this will be the case unless the error in the<br />
heuristic grows no faster than the actual path cost<br />
|h(n) − h ∗ (n)| ≤ O(log h ∗ (n))<br />
For many heuristics, this error is at least proportional to the path cost!<br />
% extend best path by successors of last node<br />
extend(Path, Cost, Paths, NewPaths) :-<br />
Path = [LastNode|_],<br />
findall(S, s(LastNode, S, _), Succs),<br />
not(Succs = []),<br />
extend_path(Succs, Path, Cost, Paths, NewPaths).<br />
<strong>COMP9414</strong> c○UNSW, 2005 Generated: 24 March 2005