1% ***************************************************************
    2% The following defines the graph with cycles of Figure 4.5 in
    3% Computational Intelligence: A Logical Approach
    4% Copyright, Poole, Mackworth, Goebel, and Oxford University Press, 1997. 
    5
    6
    7% A search is carried out by using something like:
    8%  ask hsearch(astar,[node(o103,[],0,0)],P).
    9%    (try a depth-bound of 200).
   10
   11% neighbours(N,NN) is true if NN is the list of neighbours of node N
   12neighbours(o103,[ts,l2d3,o109]).
   13neighbours(ts,[mail,o103]).
   14neighbours(mail,[ts]).
   15neighbours(o109,[o103,o111,o119]).
   16neighbours(o111,[o109]).
   17neighbours(o119,[storage,o123,o109]).
   18neighbours(storage,[o119]).
   19neighbours(o123,[r123,o125,o119]).
   20neighbours(o125,[o123]).
   21neighbours(l2d1,[l3d2,l2d2,l3d3]).
   22neighbours(l2d2,[l2d1,l2d4]).
   23neighbours(l2d3,[l2d1,l2d4]).
   24neighbours(l2d4,[l2d3,l2d2,o109]).
   25neighbours(l3d2,[l3d3,l3d1]).
   26neighbours(l3d1,[l3d3,l3d2]).
   27neighbours(l3d3,[l3d1,l3d2]).
   28neighbours(r123,[o123]).
   29
   30
   31% is_goal(N) is true if N is a goal node.
   32is_goal(r123).
   33
   34% cost(N,M,C) is true if C is the arc cost for the arc from node N to node M
   35cost(N,M,C) <-
   36   neighbours(N,NN) &
   37   member(M,NN) &
   38   position(N,NX,NY) &
   39   position(M,MX,MY) &
   40   C is abs(NX-MX)+abs(NY-MY).                  % `Manhattan distance'
   41%   C is sqrt((NX-MX)*(NX-MX)+(NY-MY)*(NY-MY)). % Euclidean Distance
   42
   43% N.B. the cost database in the book is obtained by the instances of the query
   44% ? cost(A,B,C).
   45
   46% h(N,C) is true if C is the heuristic cost of node N
   47%  This assumes that there is only one goal node.
   48h(N,C) <-
   49   position(N,NX,NY) &
   50   is_goal(G) &
   51   position(G,GX,GY) &
   52   C is abs(NX-GX)+abs(NY-GY).
   53
   54% position(N,X,Y) is true if node X is at position (X,Y)
   55
   56position(mail,17,43).
   57position(ts,23,43).
   58position(o103,31,43).
   59position(o109,43,43).
   60position(o111,47,43).
   61position(o119,42,58).
   62position(o123,33,58).
   63position(o125,29,58).
   64position(r123,33,62).
   65position(l2d1,33,49).
   66position(l2d2,39,49).
   67position(l2d3,32,46).
   68position(l2d4,39,46).
   69position(l3d1,34,55).
   70position(l3d2,33,52).
   71position(l3d3,39,52).
   72position(storage,45,62).
   73
   74member(A,[A|_]).
   75member(A,[_|T])