1 / 8

Best-first search

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

tbower
Download Presentation

Best-first search

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Simply Logical – Chapter 6 p.120 % 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 Valuemerge(Children,Rest,NewAgenda), % best-firsttiles_a(NewAgenda,Goal,[LastMove|Visited0],Visited). Solving a puzzle

  3. Simply Logical – Chapter 6             0 12 0 9 0 18 1 10 1 9 1 15 3 9 2 8 3 13 4 7 4 7 4 11 6 7 5 7 6 8 8 4 6 6 7 7 9 4 8 4 8 7 11 3 9 4 9 6 12 2 10 3 10 6 p.123 14 0 12 2 12 2 13 1 13 2 15 0 15 0 outOfPlace bLeftOfw Comparing heuristics

  4. Simply Logical – Chapter 6 estimate of total cost along path through n estimate of cost to reach goal from n actual cost to reach n p.124 • 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) A algorithm

  5. Simply Logical – Chapter 6 estimate of cost to reach goal from n actual (unknown) cost to reach goal from n p.125 • 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) • 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

  6. Simply Logical – Chapter 6 start 3 p 1 r 2 q 0 s 1 goal start 3 start 3 start 3 p p 1 1 r r 2 2 q q 0 0 s 1 s 1 p goal goal 1 start 3 start 3 p p 1 1 r r 2 2 r 2 q q 0 0 s 1 s 1 q 0 goal goal start 3 start 3 p p 1 1 r r 2 2 q q 0 0 s 1 s 1 s 1 goal goal start 3 start 3 p p 1 1 r r 2 2 q q 0 0 p.126 s 1 s 1 goal goal goal start 3 start 3 p p 1 1 r r 2 2 q q 0 0 s 1 s 1 goal goal [start-3] [p-2,r-3] [q-2,r-3] [r-3,s-4] [s-3,s-4] [goal-3,s-4] Non-monotonic heuristic

  7. Simply Logical – Chapter 6 p.127 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

  8. Simply Logical – Chapter 6 p.128 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(Goal). search_hc([Current|_],Goal):-children(Current,Children),add_bstf(Children,[],NewAgenda),search_hc(NewAgenda,Goal). Hill-climbing

More Related