Updated to Logtalk 2.9.1
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@211 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.8.4
|
||||
Release 2.9.1
|
||||
|
||||
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
@@ -12,9 +12,10 @@ You will need to also load the objects in the roots example.
|
||||
|
||||
You will also need to load the following files in the library directory:
|
||||
dates.loader, types.loader, events.loader, metapredicates.loader, and
|
||||
hierarchies.loader.
|
||||
hierarchies.loader. Alternatively, you can just load the all.loader file.
|
||||
|
||||
Some of the code in this folder is adopted from the book "Prolog Programming
|
||||
for Artificial Intelligence" by Ivan Bratko.
|
||||
|
||||
The object "performance" only provides correct results for the first solution.
|
||||
For a description of the search problems, please see a classical AI book
|
||||
(such as the one above) or visit the url <http://www.plastelina.net/games>.
|
||||
|
@@ -1,6 +1,6 @@
|
||||
=================================================================
|
||||
Logtalk - Object oriented extension to Prolog
|
||||
Release 2.8.4
|
||||
Release 2.9.1
|
||||
|
||||
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
|
||||
=================================================================
|
||||
@@ -43,8 +43,8 @@ CC.<__>..........MMMC
|
||||
..........<__>.MMMCCC
|
||||
|
||||
Cost = 15,
|
||||
Path = [((3,3),esq,0,0),((2,2),dir,1,1),((3,2),esq,0,1),((3,0),dir,0,3),((3,1),esq,0,2),((1,1),dir,2,2),((2,2),esq,1,1),((0,2),dir,3,1),((0,3),esq,3,0),((0,1),dir,3,2),((0,2),esq,3,1),((0,0),dir,3,3)],
|
||||
Initial = ((3,3),esq,0,0)
|
||||
Path = [((3,3),left,0,0),((2,2),right,1,1),((3,2),left,0,1),((3,0),right,0,3),((3,1),left,0,2),((1,1),right,2,2),((2,2),left,1,1),((0,2),right,3,1),((0,3),left,3,0),((0,1),right,3,2),((0,2),left,3,1),((0,0),right,3,3)],
|
||||
Initial = ((3,3),left,0,0)
|
||||
yes
|
||||
|
||||
|
||||
@@ -65,16 +65,43 @@ C..........<__>.MMMCC
|
||||
CC.<__>..........MMMC
|
||||
..........<__>.MMMCCC
|
||||
solution length: 12
|
||||
number of state transitions: 27
|
||||
ratio solution length / state transitions: 0.4444444444444444
|
||||
minimum branching degree: 2
|
||||
average branching degree: 2.5555555555555554
|
||||
number of state transitions: 26
|
||||
ratio solution length / state transitions: 0.461538
|
||||
minimum branching degree: 1
|
||||
average branching degree: 2.30769
|
||||
maximum branching degree: 3
|
||||
time: 0.067999999999756255
|
||||
time: 0.02
|
||||
|
||||
Cost = 15,
|
||||
Path = [((3,3),esq,0,0),((2,2),dir,1,1),((3,2),esq,0,1),((3,0),dir,0,3),((3,1),esq,0,2),((1,1),dir,2,2),((2,2),esq,1,1),((0,2),dir,3,1),((0,3),esq,3,0),((0,1),dir,3,2),((0,2),esq,3,1),((0,0),dir,3,3)],
|
||||
Initial = ((3,3),esq,0,0) ?
|
||||
Path = [((3,3),left,0,0),((2,2),right,1,1),((3,2),left,0,1),((3,0),right,0,3),((3,1),left,0,2),((1,1),right,2,2),((2,2),left,1,1),((0,2),right,3,1),((0,3),left,3,0),((0,1),right,3,2),((0,2),left,3,1),((0,0),right,3,3)],
|
||||
Initial = ((3,3),left,0,0) ?
|
||||
|
||||
yes
|
||||
|
||||
|
||||
% bridge problem, solved using a hill climbing strategy
|
||||
|
||||
| ?- performance::init, bridge::initial_state(Initial), hill_climbing(30)::solve(bridge, Initial, Path, Cost), bridge::print_path(Path), performance::report.
|
||||
|
||||
_|____________|_ lamp 1 3 6 8 12
|
||||
1 3 lamp _|____________|_ 6 8 12
|
||||
3 _|____________|_ lamp 1 6 8 12
|
||||
1 3 6 lamp _|____________|_ 8 12
|
||||
3 6 _|____________|_ lamp 1 8 12
|
||||
3 6 8 12 lamp _|____________|_ 1
|
||||
6 8 12 _|____________|_ lamp 1 3
|
||||
1 3 6 8 12 lamp _|____________|_
|
||||
solution length: 8
|
||||
state transitions: 346
|
||||
ratio solution length / state transitions: 0.0231214
|
||||
minimum branching degree: 1
|
||||
average branching degree: 7.42453
|
||||
maximum branching degree: 15
|
||||
time: 0.28
|
||||
|
||||
Initial = [], right, [1, 3, 6, 8, 12]
|
||||
Path = [ ([], right, [1, 3, 6, 8, 12]), ([1, 3], left, [6, 8, 12]), ([3], right, [1, 6, 8, 12]), ([1, 3, 6], left, [8, 12]), ([3, 6], right, [1, 8|...]), ([3, 6|...], left, [1]), ([6|...], right, [...|...]), ([...|...], ..., ...)]
|
||||
Cost = 29
|
||||
|
||||
yes
|
||||
|
||||
@@ -104,11 +131,11 @@ yes
|
||||
|
||||
solution length: 6
|
||||
number of state transitions: 105
|
||||
ratio solution length / state transitions: 0.05714285714285714
|
||||
ratio solution length / state transitions: 0.0571429
|
||||
minimum branching degree: 2
|
||||
average branching degree: 3.6315789473684212
|
||||
average branching degree: 3.63158
|
||||
maximum branching degree: 4
|
||||
time: 0.20000000000027285
|
||||
time: 0.02
|
||||
|
||||
Path = [(0,0),(0,3),(3,0),(3,3),(4,2),(0,2)],
|
||||
Initial = (0,0) ?
|
||||
@@ -144,14 +171,14 @@ yes
|
||||
|
||||
solution length: 8
|
||||
number of state transitions: 12
|
||||
ratio solution length / state transitions: 0.6666666666666666
|
||||
ratio solution length / state transitions: 0.666667
|
||||
|
||||
|
||||
|
||||
minimum branching degree: 1
|
||||
average branching degree: 2.0
|
||||
average branching degree: 2
|
||||
maximum branching degree: 3
|
||||
time: 0.021999999999934516
|
||||
time: 0.00
|
||||
|
||||
Path = [(0,0),(4,0),(4,3),(0,3),(3,0),(3,3),(4,2),(0,2)],
|
||||
Initial = (0,0) ?
|
||||
@@ -190,9 +217,9 @@ solution length: 6
|
||||
number of state transitions: 15
|
||||
ratio solution length / state transitions: 0.4
|
||||
minimum branching degree: 2
|
||||
average branching degree: 3.1333333333333333
|
||||
average branching degree: 3.13333
|
||||
maximum branching degree: 4
|
||||
time: 0.050000000000181899
|
||||
time: 0.01
|
||||
|
||||
Cost = 5,
|
||||
Path = [[2/1,1/2,1/3,3/3,3/2,3/1,2/2,1/1,2/3],[2/2,1/2,1/3,3/3,3/2,3/1,2/1,1/1,2/3],[2/3,1/2,1/3,3/3,3/2,3/1,2/1,1/1,2/2],[1/3,1/2,2/3,3/3,3/2,3/1,2/1,1/1,2/2],[1/2,1/3,2/3,3/3,3/2,3/1,2/1,1/1,2/2],[2/2,1/3,2/3,3/3,3/2,3/1,2/1,1/1,1/2]],
|
||||
@@ -232,9 +259,9 @@ solution length: 6
|
||||
number of state transitions: 15
|
||||
ratio solution length / state transitions: 0.4
|
||||
minimum branching degree: 2
|
||||
average branching degree: 3.1333333333333333
|
||||
average branching degree: 3.13333
|
||||
maximum branching degree: 4
|
||||
time: 0.046000000000276486
|
||||
time: 0.02
|
||||
|
||||
Cost = 5,
|
||||
Path = [[2/1,1/2,1/3,3/3,3/2,3/1,2/2,1/1,2/3],[2/2,1/2,1/3,3/3,3/2,3/1,2/1,1/1,2/3],[2/3,1/2,1/3,3/3,3/2,3/1,2/1,1/1,2/2],[1/3,1/2,2/3,3/3,3/2,3/1,2/1,1/1,2/2],[1/2,1/3,2/3,3/3,3/2,3/1,2/1,1/1,2/2],[2/2,1/3,2/3,3/3,3/2,3/1,2/1,1/1,1/2]],
|
||||
|
@@ -31,8 +31,8 @@
|
||||
|
||||
expand(Path, l(State,F/G), Threshold, Tree, Solved, Solution, Space, Cost) :-
|
||||
F =< Threshold,
|
||||
(bagof(Next/Cost,
|
||||
(Space::next_state(State, Next, Cost), \+ list::member(Next, Path)),
|
||||
(bagof(Next/Cost2,
|
||||
(Space::next_state(State, Next, Cost2), \+ list::member(Next, Path)),
|
||||
Successors) ->
|
||||
succlist(G, Successors, Trees, Threshold, Space),
|
||||
bestf(Trees, F2, Threshold),
|
||||
|
@@ -11,9 +11,6 @@
|
||||
parnames is ['Bound']]).
|
||||
|
||||
|
||||
:- calls(state_space).
|
||||
|
||||
|
||||
:- uses(list).
|
||||
|
||||
|
||||
|
@@ -25,7 +25,6 @@
|
||||
Space::goal_state(State).
|
||||
|
||||
hill(Space, State, Threshold, Path, Solution, SoFar, Total) :-
|
||||
SoFar < Threshold,
|
||||
findall(
|
||||
(Estimate, Cost, Next),
|
||||
(Space::next_state(State, Next, Cost),
|
||||
@@ -34,9 +33,10 @@
|
||||
Estimate is Guess + Cost),
|
||||
States),
|
||||
list::sort(States, SortedStates),
|
||||
list::member((_, Cost, Next), SortedStates),
|
||||
SoFar2 is SoFar + Cost,
|
||||
hill(Space, Next, Threshold, [State| Path], Solution, SoFar2, Total).
|
||||
list::member((_, Cost2, Next2), SortedStates),
|
||||
SoFar2 is SoFar + Cost2,
|
||||
SoFar2 =< Threshold,
|
||||
hill(Space, Next2, Threshold, [State| Path], Solution, SoFar2, Total).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
@@ -66,7 +66,7 @@
|
||||
write('average branching degree: '), write(Average), nl,
|
||||
write('maximum branching degree: '), write(Maximum), nl,
|
||||
write('time: '), write(Time), nl,
|
||||
!.
|
||||
::retractall(transitions(_, _, _)). % clean up for next solution
|
||||
|
||||
|
||||
transitions(Number) :-
|
||||
@@ -87,9 +87,8 @@
|
||||
findall(State2, ::transitions(State1, State2, _), States2),
|
||||
list::length(States2, Length)),
|
||||
Lengths),
|
||||
list::sort(Lengths, SortedLengths),
|
||||
SortedLengths = [Minimum| _],
|
||||
list::reverse(SortedLengths, [Maximum| _]),
|
||||
list::min(Lengths, Minimum),
|
||||
list::max(Lengths, Maximum),
|
||||
numberlist::sum(Lengths, Sum),
|
||||
list::length(Lengths, Length),
|
||||
Average is Sum / Length.
|
||||
@@ -116,12 +115,14 @@
|
||||
before(_, solve(_, _, _), _) :-
|
||||
!,
|
||||
time::cpu_time(Time),
|
||||
::assertz(start_time(Time)).
|
||||
::retractall(start_time(_)),
|
||||
::asserta(start_time(Time)).
|
||||
|
||||
before(_, solve(_, _, _, _), _) :-
|
||||
!,
|
||||
time::cpu_time(Time),
|
||||
::assertz(start_time(Time)).
|
||||
::retractall(start_time(_)),
|
||||
::asserta(start_time(Time)).
|
||||
|
||||
|
||||
after(_, next_state(S1, S2), _) :-
|
||||
@@ -145,7 +146,8 @@
|
||||
after(_, solve(_, _, Solution), _) :-
|
||||
!,
|
||||
time::cpu_time(Time),
|
||||
::assertz(end_time(Time)),
|
||||
::retractall(end_time(_)),
|
||||
::asserta(end_time(Time)),
|
||||
list::length(Solution, Length),
|
||||
::retractall(solution_length(_)),
|
||||
::asserta(solution_length(Length)).
|
||||
@@ -153,11 +155,11 @@
|
||||
after(_, solve(_, _, Solution, _), _) :-
|
||||
!,
|
||||
time::cpu_time(Time),
|
||||
::assertz(end_time(Time)),
|
||||
::retractall(end_time(_)),
|
||||
::asserta(end_time(Time)),
|
||||
list::length(Solution, Length),
|
||||
::retractall(solution_length(_)),
|
||||
::asserta(solution_length(Length)).
|
||||
|
||||
|
||||
:- end_object.
|
||||
|
||||
|
@@ -1,17 +1,18 @@
|
||||
|
||||
:- initialization(
|
||||
logtalk_load([
|
||||
best_first1,
|
||||
state_space,
|
||||
water_jug,
|
||||
farmer,
|
||||
heuristic_state_space,
|
||||
bridge,
|
||||
eight_puzzle,
|
||||
miss_cann,
|
||||
search_strategy,
|
||||
blind_search1,
|
||||
breadth_first1,
|
||||
depth_first1,
|
||||
eight_puzzle,
|
||||
farmer,
|
||||
heuristic_search1,
|
||||
heuristic_state_space,
|
||||
best_first1,
|
||||
hill_climbing1,
|
||||
miss_cann,
|
||||
performance,
|
||||
search_strategy,
|
||||
state_space,
|
||||
water_jug])).
|
||||
performance])).
|
||||
|
@@ -31,7 +31,7 @@
|
||||
|
||||
next_state((X, Y), (Z, 3)) :-
|
||||
X > 0, Y < 3,
|
||||
Aux is X + Y, Aux >= 4,
|
||||
Aux is X + Y, Aux >= 3,
|
||||
Z is X - (3 - Y).
|
||||
|
||||
next_state((X, Y),(Z, 0)) :-
|
||||
|
Reference in New Issue
Block a user