root/trunk/examples/searching/depth_first1.lgt

Revision 4601, 0.7 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(depth_first(Bound),
3    instantiates(blind_search(Bound))).
4
5
6    :- info([
7        version is 1.2,
8        author is 'Paulo Moura',
9        date is 2008/6/9,
10        comment is 'Depth first state space search strategy.',
11        parnames is ['Bound']]).
12
13
14    :- uses(list, [member/2, reverse/2]).
15
16
17    search(Space, State, Bound, Solution) :-
18        depth(Space, State, Bound, [], Path),
19        reverse(Path, Solution).
20
21
22    depth(Space, State, _, Path, [State| Path]) :-
23        Space::goal_state(State).
24
25    depth(Space, State, Bound, Path, Solution) :-
26        Bound > 0,
27        Space::next_state(State, Next),
28        \+ Space::member_path(Next, [State| Path]),
29        Bound2 is Bound - 1,
30        depth(Space, Next, Bound2, [State| Path], Solution).
31
32
33:- end_object.
Note: See TracBrowser for help on using the browser.