Simply Logical Ð Chapter 6 p.117-8 search_bstf([Goal|Rest],Goal):goal(Goal). search_bstf([Current|Rest],Goal):children(Current,Children), add_bstf(Children,Rest,NewAgenda), search_bstf(NewAgenda,Goal). % add_bstf(A,B,C) <- C contains the elements of A and B % (B and C sorted according to eval/2) add_bstf([],Agenda,Agenda). add_bstf([Child|Children],OldAgenda,NewAgenda):add_one(Child,OldAgenda,TmpAgenda), add_bstf(Children,TmpAgenda,NewAgenda). % add_one(S,A,B) <- B is A with S inserted acc. to eval/2 add_one(Child,OldAgenda,NewAgenda):eval(Child,Value), add_one(Value,Child,OldAgenda,NewAgenda). Best-first search © Peter Flach, 2000 Simply Logical Ð Chapter 6 p.120 © Peter Flach, 2000 % tiles_a(A,M,V0,V) <- goal position can be reached from % one of the positions on A with last % move M (best-first strategy) tiles_a([v(V,LastMove)|Rest],LastMove,Visited,Visited):goal(LastMove). tiles_a([v(V,LastMove)|Rest],Goal,Visited0,Visited):show_move(LastMove,V), setof0(v(Value,NextMove), ( move(LastMove,NextMove), eval(NextMove,Value) ), Children), % Children sorted on Value merge(Children,Rest,NewAgenda), % best-first tiles_a(NewAgenda,Goal,[LastMove|Visited0],Visited). Solving a puzzle Simply Logical Ð Chapter 6 p.123 © Peter Flach, 2000 outOfPlace bLeftOfw ➂ ➁ ➀ ➀ ➁ ➂ ➃ ➂ ➁ ➁ ➂ ➃ 0 9 0 12 0 18 1 9 1 10 1 15 2 8 3 9 3 13 4 7 4 7 4 11 5 7 6 7 6 8 6 6 8 4 7 7 8 4 9 4 8 7 9 4 11 3 9 6 10 3 12 2 10 6 12 2 14 0 12 2 13 1 13 2 15 0 15 0 Comparing heuristics Simply Logical Ð Chapter 6 p.124 © Peter Flach, 2000 ☞ An A algorithm is a best-first search algorithm that aims at minimising the total cost along a path from start to goal. f(n) = g(n) + h(n) estimate of total cost along path through n A algorithm actual cost to reach n estimate of cost to reach goal from n Simply Logical Ð Chapter 6 p.125 © Peter Flach, 2000 ☞ A heuristic is (globally) optimistic or admissible if the estimated cost of reaching a goal is always less than the actual cost. h(n) ² h*(n) estimate of cost to reach goal from n actual (unknown) cost to reach goal from n ☞ A heuristic is monotonic (locally optimistic) if the estimated cost of reaching any node is always less than the actual cost. h(n1)Ð h(n2)² h*(n1)Ðh*(n2) Global and local optimism Simply Logical Ð Chapter 6 p.126 © Peter Flach, 2000 start 3 1 p 0 q r s 2 [start-3] 1 goal start 3 start 3 1 p r 0 p 1 r 0 2 goal q 1 0 q r 2 1 goal goal start 3 p 1 p 0 q r 2 q s 1 goal goal start 3 q goal 1 1 p 0 q r 2 s goal 2 [s-3,s-4] 1 start 3 p 2 [r-3,s-4] s 1 start 3 s Non-monotonic heuristic p 2 [q-2,r-3] goal 1 [p-2,r-3] 1 start 3 r 0 r goal s 1 q s q goal 0 start 3 r 0 p 1 p 1 1 2 2 1 start 3 s s r goal r 0 q start 3 s 1 0 s p q p 1 r 0 1 2 q s 1 start 3 1 2 [goal-3,s-4] Simply Logical Ð Chapter 6 p.127 © Peter Flach, 2000 search_beam(Agenda,Goal):search_beam(1,Agenda,[],Goal). search_beam(D,[],NextLayer,Goal):D1 is D+1, search_beam(D1,NextLayer,[],Goal). search_beam(D,[Goal|Rest],NextLayer,Goal):goal(Goal). search_beam(D,[Current|Rest],NextLayer,Goal):children(Current,Children), add_beam(D,Children,NextLayer,NewNextLayer), search_beam(D,Rest,NewNextLayer,Goal). ☞ Here, the number of children to be added to the beam is made dependent on the depth D of the node ✓ in order to keep depth as a ÔglobalÕ variable, search is layer-by-layer Beam search Simply Logical Ð Chapter 6 p.128 © Peter Flach, 2000 search_hc(Goal,Goal):goal(Goal). search_hc(Current,Goal):children(Current,Children), select_best(Children,Best), search_hc(Best,Goal). % hill_climbing as a variant of best-first search search_hc([Goal |_],Goal Goal):):search_hc([Goal|_], goal(Goal ). goal(Goal). search_hc([Current |_],Goal):search_hc([Current|_],Goal):children(Current ,Children), children(Current, Children), add_bstf(Children ,[],NewAgenda NewAgenda), ), add_bstf(Children,[], search_hc(NewAgenda ,Goal). search_hc(NewAgenda,Goal). Hill-climbing
© Copyright 2025 Paperzz