- Timestamp:
- 06/09/08 11:40:36 (3 months ago)
- Location:
- trunk
- Files:
-
- 7 modified
-
examples/searching/best_first1.lgt (modified) (2 diffs)
-
examples/searching/breadth_first1.lgt (modified) (4 diffs)
-
examples/searching/depth_first1.lgt (modified) (2 diffs)
-
examples/searching/hill_climbing1.lgt (modified) (2 diffs)
-
examples/searching/salt3.lgt (modified) (4 diffs)
-
examples/searching/state_space.lgt (modified) (3 diffs)
-
RELEASE_NOTES.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/searching/best_first1.lgt
r2383 r4307 5 5 6 6 :- info([ 7 version is 1. 1,7 version is 1.2, 8 8 author is 'Paulo Moura', 9 date is 200 5/10/22,9 date is 2008/6/9, 10 10 comment is 'Best first heuristic state space search strategy.', 11 11 source is 'Example adopted from the book "Prolog Programming for Artificial Intelligence" by Ivan Bratko.', … … 34 34 F =< Threshold, 35 35 (bagof(Next/Cost2, 36 (Space::next_state(State, Next, Cost2), \+ member(Next, Path)),36 (Space::next_state(State, Next, Cost2), \+ Space::member_path(Next, Path)), 37 37 Successors) -> 38 38 succlist(G, Successors, Trees, Threshold, Space), -
trunk/examples/searching/breadth_first1.lgt
r2383 r4307 5 5 6 6 :- info([ 7 version is 1. 1,7 version is 1.2, 8 8 author is 'Paulo Moura', 9 date is 200 5/10/22,9 date is 2008/6/9, 10 10 comment is 'Breadth first state space search strategy.', 11 11 source is 'Example adopted from the book "Prolog Programming for Artificial Intelligence" by Ivan Bratko.', … … 23 23 breadt(Space, Tree, Bound, Solution) :- 24 24 expand([], Tree, Tree2, Solved, Solution, Space, Bound), 25 ( Solved ->25 ( Solved -> 26 26 true 27 ;28 breadt(Space, Tree2, Bound, Solution)).27 ; breadt(Space, Tree2, Bound, Solution) 28 ). 29 29 30 30 … … 34 34 expand(Path, l(State), t(State, Subs), fail, _, Space, Bound) :- 35 35 Bound > 0, 36 bagof(l(Next), 37 (Space::next_state(State, Next), 38 \+ member(Next, [State| Path])), 39 Subs). 36 bagof(l(Next), (Space::next_state(State, Next), \+ Space::member_path(Next, [State| Path])), Subs). 40 37 41 38 expand(Path, t(State,Subs), t(State, Subs2), Solved, Solution, Space, Bound) :- … … 49 46 Bound2 is Bound -1, 50 47 expand(Path, Tree, Tree2, Solved2, Solution, Space, Bound2), 51 ( Solved2 ->48 ( Solved2 -> 52 49 Solved = true 53 ;54 expandall(Path, Trees, [Tree2| Trees2], Subs2, Solved, Solution, Space, Bound))50 ; expandall(Path, Trees, [Tree2| Trees2], Subs2, Solved, Solution, Space, Bound) 51 ) 55 52 ; 56 53 expandall(Path, Trees, Trees2, Subs2, Solved, Solution, Space, Bound). -
trunk/examples/searching/depth_first1.lgt
r2383 r4307 5 5 6 6 :- info([ 7 version is 1. 1,7 version is 1.2, 8 8 author is 'Paulo Moura', 9 date is 200 5/10/22,9 date is 2008/6/9, 10 10 comment is 'Depth first state space search strategy.', 11 11 parnames is ['Bound']]). … … 26 26 Bound > 0, 27 27 Space::next_state(State, Next), 28 \+ member(Next, [State| Path]),28 \+ Space::member_path(Next, [State| Path]), 29 29 Bound2 is Bound - 1, 30 30 depth(Space, Next, Bound2, [State| Path], Solution). -
trunk/examples/searching/hill_climbing1.lgt
r1401 r4307 5 5 6 6 :- info([ 7 version is 1. 1,7 version is 1.2, 8 8 author is 'Paulo Moura', 9 date is 200 4/8/15,9 date is 2008/6/9, 10 10 comment is 'Hill climbing heuristic state space search strategy.', 11 11 parnames is ['Threshold']]). 12 12 13 13 14 :- uses(list, 15 [member/2, reverse/2, sort/2]). 16 17 :- private(hill/7). 14 :- uses(list, [member/2, reverse/2, sort/2]). 18 15 19 16 … … 30 27 (Estimate, Cost, Next), 31 28 (Space::next_state(State, Next, Cost), 32 \+ member(Next, [State| Path]),29 \+ Space::member_path(Next, [State| Path]), 33 30 Space::heuristic(Next, Guess), 34 31 Estimate is Guess + Cost), -
trunk/examples/searching/salt3.lgt
r2738 r4307 28 28 instantiates(state_space)). 29 29 30 31 30 :- info([ 32 version is 1. 0,31 version is 1.1, 33 32 author is 'Paula Marisa Sampaio', 34 date is 200 5/06/08,33 date is 2008/6/9, 35 34 comment is 'Salt state-space search problem.']). 36 35 37 38 36 % each state is represented by a compound term with four arguments: (Acumulator, Measure1, Measure2, Step) 39 40 37 initial_state(initial, (0, 0, 0, all_empty)). 41 38 42 43 39 % the intended salt quantity must end up on the acumulator 44 45 40 goal_state(acumulator, (Acumulator, _, _, _)) :- 46 41 parameter(1, Acumulator). 47 42 48 49 43 % state transitions: 50 44 51 52 45 % emptying a measure into the accumulator 53 54 46 next_state((Acc, X, Y, _), (NewAcc, 0, Y, transfer(m1, acc))) :- 55 47 X > 0, 56 48 NewAcc is Acc + X. 57 58 49 next_state((Acc, X, Y, _), (NewAcc, X, 0, transfer(m2, acc))) :- 59 50 Y > 0, 60 51 NewAcc is Acc + Y. 61 62 52 63 53 % filling up of one of the measures 64 65 54 next_state((Acc, X, Y, Step), (Acc, MaxX, Y, fill(m1))) :- 66 55 parameter(2, MaxX), 67 56 X < MaxX, 68 57 Step \= empty(m1). 69 70 58 next_state((Acc, X, Y, Step), (Acc, X, MaxY, fill(m2))) :- 71 59 parameter(3, MaxY), … … 73 61 Step \= empty(m2). 74 62 75 76 63 % either pouring of a measure into the other till it is filled up 77 64 % or all content of a measure into the other one 78 79 65 next_state((Acc, X, Y, _), (Acc, W, Z, transfer(m2, m1))) :- 80 66 parameter(2, MaxX), … … 88 74 Z = 0 89 75 ). 90 91 76 next_state((Acc, X, Y, _), (Acc, W, Z, transfer(m1, m2))) :- 92 77 parameter(3, MaxY), … … 101 86 ). 102 87 103 104 88 % throwing out the contents of a measure; does not afect the accumulator 105 106 next_state((Acc, X, Y, Step), (Acc, 0, Y, empty(m1))) :- 89 next_state((Acc, X, Y, Step), (Acc, 0, Y, empty(m1))) :- 107 90 X > 0, 108 91 Step \= fill(m1). 109 110 next_state((Acc, X, Y, Step), (Acc, X, 0, empty(m2))) :- 92 next_state((Acc, X, Y, Step), (Acc, X, 0, empty(m2))) :- 111 93 Y > 0, 112 94 Step \= fill(m2). 113 95 96 member_path((Acc, X, Y, _), [(Acc, X, Y, _)| _]) :- 97 !. 98 member_path(State, [_| Path]) :- 99 member_path(State, Path). 114 100 115 101 print_state((Acc, X, Y, Step)) :- 116 102 write('('), write((Acc, X, Y)), write(') '), write(Step), nl. 117 103 118 119 104 :- end_object. -
trunk/examples/searching/state_space.lgt
r2381 r4307 6 6 7 7 :- info([ 8 version is 1. 0,8 version is 1.1, 9 9 author is 'Paulo Moura', 10 date is 1998/3/23,10 date is 2008/6/9, 11 11 comment is 'State space description predicates.']). 12 12 … … 42 42 argnames is ['Name', 'State']]). 43 43 44 :- public(member_path/2). 45 :- mode(member_path(+nonvar, +list), zero_or_one). 46 :- info(member_path/2, 47 [comment is 'True if a state is member of a list of states.', 48 argnames is ['State', 'Path']]). 49 44 50 :- public(print_state/1). 45 51 :- mode(print_state(+nonvar), one). … … 67 73 68 74 75 member_path(State, [State| _]) :- 76 !. 77 member_path(State, [_| Path]) :- 78 member_path(State, Path). 79 80 69 81 print_path([]). 70 82 -
trunk/RELEASE_NOTES.txt
r4306 r4307 43 43 Added missing implementation of the predicate as_dictionary/2 to the 44 44 "bintree" library object. Thanks to Victor Noel for the bug report. 45 46 Updated all the search methods in the "searching" example to delegate 47 checking for cycles to the state space being searched (thus allowing 48 state descriptions to carry additional information that should not be 49 taken into account when comparing states). 45 50 46 51 Updated the syntax coloring support for the Vim text editor to properly
