% iterative deepening

% works in SWI-Prolog.  
% Written by Tim Finin, http://umbc.edu/~finin/, finin@Umbc.edu

:- ensure_loaded(showPath).

id :-
 id(Path),
 showPath(Path).

id(Path) :-
  start(S),
  id(S,Path).

id(S,Path) :-
  from(Limit,1,5),
  id1(S,0,Limit,Path).

id1(S,Depth,Limit,[S]) :-
  Depth<Limit,
  goal(S).

id1(S,Depth,Limit,[S|Rest]) :-
  Depth<Limit,
  Depth2 is Depth+1,
  arc(S,S2),
  id1(S2,Depth2,Limit,Rest).

% from(-Var,+Val,+Inc) senerates a stream of integers starting with
% the first argument by instantiates Var to integers beginning 
% with Val and incrementing each time by Inc.
% e.g., from(X,10,2) -> 10,12,14,16,18,...

from(X,X,_).
from(X,N,Inc) :- N2 is N+Inc, from(X,N2,Inc).
