You are on page 1of 8

Simply Logical Chapter 6 p.

117-8

Peter Flach, 2000

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

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 1 2 4 5 6 8 9 10 12 13 15 9 9 8 7 7 6 4 4 3 2 1 0

0 1 3 4 6 8 9 11 12 14

12 10 9 7 7 4 4 3 2 0

0 1 3 4 6 7 8 9 10 12 13 15

18 15 13 11 8 7 7 6 6 2 2 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 estimate of cost to reach goal from n

actual cost to reach n

A algorithm

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


start 1 0 p r q s goal 1 2 3

Peter Flach, 2000

[start-3]
start 1 p r 0 q s goal 1 2 3

start

3
1 0 p q

start

s goal start 1 p

[p-2,r-3]

p r 2
0 q

3 1 r 2 0 q p

start

s goal start 1 0 p

s goal

[q-2,r-3]

q
q

3 1 r 2 0 q p

start

[r-3,s-4]

s goal

1
1 0 p q

goal start 3 1 r 2 0 s 1 q p

start

[s-3,s-4]

s goal

goal
1 0 p q

goal start 3 1 r 2 0 s goal 1 q p

start

[goal-3,s-4]

s goal

Non-monotonic heuristic

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(Goal). search_hc([Current|_],Goal):children(Current,Children), add_bstf(Children,[],NewAgenda), search_hc(NewAgenda,Goal).

Hill-climbing

You might also like