Logtalk 2.26.2 files.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1489 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura
2005-12-24 18:34:29 +00:00
parent 60fbc754f9
commit 6d079626af
76 changed files with 0 additions and 1648 deletions

View File

@@ -1,9 +0,0 @@
:- object(aberdeen_air,
extends(airport)).
fly(renfrew).
:- end_object.

View File

@@ -1,6 +0,0 @@
:- object(aiai,
extends(edinburgh)).
:- end_object.

View File

@@ -1,16 +0,0 @@
:- object(airport).
:- public(fly/1).
:- mode(fly(?), zero_or_more).
:- public(airport/1).
:- mode(airport(?), zero_or_more).
airport(Airport) :-
self(Airport).
:- end_object.

View File

@@ -1,6 +0,0 @@
:- object(albert_hall,
extends(london)).
:- end_object.

View File

@@ -1,6 +0,0 @@
:- object(castle,
extends(edinburgh)).
:- end_object.

View File

@@ -1,30 +0,0 @@
:- object(city).
:- public(step/3).
:- mode(step(+, +, -), zero_or_more).
:- public(airport/1).
:- mode(airport(?atom), zero_or_more).
step(X, Y, P1-P-P2) :-
\+ same_city(X, Y), !,
X::airport(XA),
Y::airport(YA),
plan(fly)::from(XA, YA, P),
plan(city)::from(X, XA, P1),
plan(city)::from(YA, Y, P2).
step(X, Y, taxi(X, Y)) :-
same_city(X, Y),
X \= Y.
same_city(X, Y) :-
X::airport(A),
Y::airport(A).
:- end_object.

View File

@@ -1,6 +0,0 @@
:- object(edin,
extends(edinburgh)).
:- end_object.

View File

@@ -1,9 +0,0 @@
:- object(edinburgh,
extends(city)).
airport(edin).
:- end_object.

View File

@@ -1,13 +0,0 @@
:- object(fly).
:- public(step/3).
:- mode(step(+, +, -), zero_or_more).
step(From, To, fly(From, To)) :-
From::fly(To).
:- end_object.

View File

@@ -1,9 +0,0 @@
:- object(glasgow,
extends(city)).
airport(renfrew).
:- end_object.

View File

@@ -1,6 +0,0 @@
:- object(imperial,
extends(london)).
:- end_object.

View File

@@ -1,10 +0,0 @@
:- object(lhr,
extends(airport)).
fly(edin).
fly(ringway).
:- end_object.

View File

@@ -1,9 +0,0 @@
:- object(london,
extends(city)).
airport(lhr).
:- end_object.

View File

@@ -1,9 +0,0 @@
:- object(manchester,
extends(city)).
airport(ringway).
:- end_object.

View File

@@ -1,46 +0,0 @@
:- object(plan(_)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Air-line trip planner.',
parnames is ['Mode'],
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- public(from/3).
:- mode(from(+atom, +atom, -list), zero_or_more).
:- info(from/3,
[comment is 'Plan a trip from Start to Destination.',
argnames is ['Start', 'Destination', 'Plan']]).
from(Start, Destination, Plan) :-
from(Start, Destination, [], Plan).
from(Start, Destination, _, [Step]) :-
parameter(1, Mode),
Mode::step(Start, Destination, Step),
!.
from(Start, Destination, Locations, [Step| Steps]) :-
parameter(1, Mode),
Mode::step(Start, City2, Step),
not_member(City2, Locations),
from(City2, Destination, [Start| Locations], Steps).
not_member(_, []).
not_member(City, [Location| Locations]) :-
City \= Location,
not_member(City, Locations).
:- end_object.

View File

@@ -1,10 +0,0 @@
:- object(renfrew,
extends(airport)).
fly(aberdeen_air).
fly(ringway).
:- end_object.

View File

@@ -1,10 +0,0 @@
:- object(ringway,
extends(manchester, airport)).
fly(lhr).
fly(renfrew).
:- end_object.

View File

@@ -1,6 +0,0 @@
:- object(victoria,
extends(manchester)).
:- end_object.

View File

@@ -1,11 +0,0 @@
:- object(aberdeen,
extends(location(194, 340))).
links([
(edinburgh, 115),
(glasgow, 142)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(aberystwyth,
extends(location(126, 102))).
links([
(birmingham, 114),
(liverpool, 100),
(swansea, 75)]).
:- end_object.

View File

@@ -1,16 +0,0 @@
:- object(birmingham,
extends(location(192, 106))).
links([
(aberystwyth, 114),
(bristol, 86),
(cambridge, 97),
(liverpool, 99),
(nottingham, 48),
(oxford, 63),
(sheffield, 75)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(brighton,
extends(location(248, 10))).
links([
(dover, 81),
(portsmouth, 49),
(london, 52)]).
:- end_object.

View File

@@ -1,13 +0,0 @@
:- object(bristol,
extends(location(168, 47))).
links([
(cardiff, 44),
(exeter, 76),
(oxford, 71),
(birmingham, 86)]).
:- end_object.

View File

@@ -1,13 +0,0 @@
:- object(cambridge,
extends(location(254, 92))).
links([
(nottingham, 82),
(oxford, 80),
(london, 54),
(birmingham, 97)]).
:- end_object.

View File

@@ -1,11 +0,0 @@
:- object(cardiff,
extends(location(148, 56))).
links([
(bristol, 44),
(swansea, 45)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(carlisle,
extends(location(166, 226))).
links([
(glasgow, 94),
(leeds, 117),
(newcastle, 58)]).
:- end_object.

View File

@@ -1,72 +0,0 @@
:- object(circular,
extends(salesman)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- op(400, yfx, ~).
route([Town| Towns], Route) :-
route(Towns, Town~Town, Route).
route([], Route, Route).
route([Town| Towns], Route, Route2) :-
best_place(Route, Town, Best),
split(Best, Route, Town, Split),
route(Towns, Split, Route2).
best_place(Route, Town, Best) :-
best_place(Route, Town, 10000000, 0, 0, Best).
best_place(R~T1~T2, Town, XD, _, I, Best) :-
atom(T1),
atom(T2),
extra(T1, Town, T2, XT),
XT < XD,
I2 is I + 1,
best_place(R~T1, Town, XT, I2, I2, Best).
best_place(R~T1~T2, Town, XD, XI, I, Best) :-
atom(T1),
atom(T2),
I2 is I + 1,
best_place(R~T1, Town, XD, XI, I2, Best).
best_place(T1~T2, Town, XD, _, I, Best) :-
atom(T1),
atom(T2),
extra(T1, Town, T2, XT),
XT < XD,
Best is I + 1.
best_place(_~_, _, _, XI, _, XI).
split(0, Route, Town, Route~Town).
split(IX, Route~Town1, Town, Split~Town1) :-
IX2 is IX - 1,
split(IX2, Route, Town, Split).
split(1, Route, Town, Town~Route).
extra(T1, T, T2, E) :-
T1::crow_flies(T, E1),
T::crow_flies(T2, E2),
T1::crow_flies(T2, E3),
E is E1 + E2 - E3.
:- end_object.

View File

@@ -1,20 +0,0 @@
:- object(descend).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- public(less/2).
less(X, Y):-
X >= Y.
:- end_object.

View File

@@ -1,11 +0,0 @@
:- object(dover,
extends(location(292, 38))).
links([
(brighton, 81),
(london, 71)]).
:- end_object.

View File

@@ -1,52 +0,0 @@
:- object(driving,
extends(salesman)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- op(400, yfx, ~).
route(Towns, Route) :-
presort::route(Towns, Presort),
drive_around(Presort, Route).
drive_around(Route~Town1~Town2, Route1~Route2) :-
!,
drive_around(Route~Town1, Route1),
Town1::drive(Town2, Route2).
drive_around(Town1~Town2, Route) :-
!,
Town1::drive(Town2, Route).
drive_around(Town, Town).
drive_length(Route, Length) :-
drive_length(Route, 0, Length).
drive_length(Route~Town1~Town2, Acc, Length) :-
!,
Town1::road_distance(Town2, Length2),
Acc2 is Acc + Length2,
drive_length(Route~Town1, Acc2, Length).
drive_length(Town1~Town2, Acc, Length) :-
!,
Town1::road_distance(Town2, Length2),
Length is Acc + Length2.
drive_length(_, Length, Length).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(edinburgh,
extends(location(162, 282))).
links([
(aberdeen, 115),
(glasgow, 44),
(newcastle, 104)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(exeter,
extends(location(138, 18))).
links([
(bristol, 76),
(penzance, 112),
(portsmouth, 126)]).
:- end_object.

View File

@@ -1,68 +0,0 @@
:- object(geographic(_OX, _OY)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
parnames is ['OX', 'OY'],
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- public(less/2).
less(Town1, Town2):-
angle(Town1, Angle1),
angle(Town2, Angle2),
Angle1 < Angle2.
angle(Town, Angle) :-
Town::at(X, Y),
parameter(1, OX),
parameter(2, OY),
angle(X, Y, OX, OY, Angle).
angle(X, Y, OX, OY, Angle) :-
X > OX,
Y >= OY,
Angle is atan((Y-OY)/(X-OX)).
angle(X, Y, OX, OY, Angle) :-
X > OX,
Y < OY,
pi(Pi),
Angle is Pi + Pi - atan((OY-Y)/(X-OX)).
angle(X, Y, OX, OY, Angle) :-
X < OX,
Y >= OY,
pi(Pi),
Angle is Pi - atan((Y-OY)/(OX-X)).
angle(X, Y, OX, OY, Angle) :-
X < OX,
Y < OY,
pi(Pi),
Angle is Pi + atan((OY-Y)/(OX-X)).
angle(OX, Y, OX, OY, Angle) :-
Y > OY,
pi(Pi),
Angle is Pi / 2.
angle(OX, Y, OX, OY, Angle) :-
Y =< OY,
pi(Pi),
Angle is 1.5 * Pi.
pi(Pi) :-
Pi is 4.0*atan(1.0).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(glasgow,
extends(location(132, 273))).
links([
(aberdeen, 142),
(carlisle, 94),
(edinburgh, 44)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(hull,
extends(location(240, 168))).
links([
(leeds, 58),
(sheffield, 65),
(york, 37)]).
:- end_object.

View File

@@ -1,91 +0,0 @@
:- object(incremental,
extends(salesman)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- op(400, yfx, ~).
route([Town| Towns], Route) :-
route(Towns, Town, Route).
route([], Route, Route).
route([Town| Towns], Route, Route2) :-
best_place(Route, Town, Best),
split(Best, Route, Town, NewR),
route(Towns, NewR, Route2).
best_place(Route~Town1, Town, Best) :- % try the back first ...
atom(Town1),
Town::crow_flies(Town1, Distance),
best_place(Route~Town1, Town, Distance, 0, 0, Best).
best_place(Town, _, 0) :-
atom(Town).
best_place(R~T1~T2, T, XD, _, I, Best) :-
atom(T1),
atom(T2),
extra(T1, T, T2, XT),
XT < XD,
I2 is I + 1,
best_place(R~T1, T, XT, I2, I2, Best).
best_place(R~T1~T2, T, XD, XI, I, Best) :-
atom(T1),
atom(T2),
I2 is I + 1,
best_place(R~T1, T, XD, XI, I2, Best).
best_place(T1~T2, T, XD, _, I, Best) :-
atom(T1),
atom(T2),
extra(T1, T, T2, XT),
XT < XD,
I2 is I + 1,
best_place(T1, T, XT, I2, I2, Best).
best_place(T1~T2, T, XD, XI, I, Best) :-
atom(T1),
atom(T2),
I2 is I + 1,
best_place(T1, T, XD, XI, I2, Best).
best_place(T1, T, XD, _, I, Best) :-
atom(T1),
T1::crow_flies(T, Distance),
Distance < XD,
Best is I + 1.
best_place(_, _, _, XI, _, XI).
split(0, Route, Town, Route~Town).
split(IX, Route~Town1, Town, S~Town1) :-
IX2 is IX -1,
split(IX2, Route, Town, S).
split(1, Route, Town, Town~Route).
extra(T1, T, T2, XT) :-
T1::crow_flies(T, Distance1),
T::crow_flies(T2, Distance2),
T1::crow_flies(T2, Distance3),
XT is Distance1 + Distance2 - Distance3.
:- end_object.

View File

@@ -1,14 +0,0 @@
:- object(leeds,
extends(location(208, 170))).
links([
(carlisle, 117),
(hull, 58),
(sheffield, 34),
(manchester, 41),
(york, 23)]).
:- end_object.

View File

@@ -1,13 +0,0 @@
:- object(liverpool,
extends(location(164, 150))).
links([
(aberystwyth, 100),
(birmingham, 99),
(manchester, 35),
(sheffield, 70)]).
:- end_object.

View File

@@ -1,83 +0,0 @@
:- object(location(_X, _Y)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
parnames is ['X', 'Y'],
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- op(400, yfx, ~).
:- public(at/2).
:- mode(at(-integer, -integer), one).
:- public(crow_flies/2).
:- mode(crow_flies(+atom, -integer), one).
:- public(drive/2).
:- mode(drive(+atom, -nonvar), zero_or_more).
:- public(links/1).
:- mode(links(-list), one).
:- public(road_distance/2).
:- mode(road_distance(?atom, ?integer), zero_or_more).
at(X, Y) :-
parameter(1, X),
parameter(2, Y).
crow_flies(Town, Distance) :-
::at(X, Y),
Town::at(U, V),
U0 is U-X,
V0 is V-Y,
Distance is sqrt(U0*U0+V0*V0).
road_distance(Town, Distance) :-
::links(Links),
member((Town, Distance), Links).
drive(To, Route) :- % plan a road journey
self(Self),
plan_drive(Self, To, [], _, Route).
% go directly
plan_drive(From, To, _, Distance, From~To):-
To::links(Links),
member((From, Distance), Links).
% go indirectly
plan_drive(From, To, R, D+DI, Route~To):-
To::links(Links),
nearest(Links, From, Int, DI),
\+ member(Int, R),
plan_drive(From, Int, [To| R], D, Route).
nearest(Links, To, Int, Distance):-
quick(metric(To))::sort(Links, Sorted),
member((Int, Distance), Sorted).
member(Head, [Head| _]).
member(Head, [_| Tail]) :-
member(Head, Tail).
:- end_object.

View File

@@ -1,14 +0,0 @@
:- object(london,
extends(location(244,54))).
links([
(brighton, 52),
(dover, 71),
(cambridge, 54),
(oxford, 57),
(portsmouth, 72)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(manchester,
extends(location(180, 156))).
links([
(leeds, 41),
(liverpool, 35),
(sheffield, 38)]).
:- end_object.

View File

@@ -1,24 +0,0 @@
:- object(metric(_Town)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
parnames is ['Town'],
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- public(less/2).
less((Town1, _), (Town2, _)):-
parameter(1, Town),
Town::crow_flies(Town1, Distance1),
Town::crow_flies(Town2, Distance2),
Distance1 < Distance2.
:- end_object.

View File

@@ -1,20 +0,0 @@
:- object(natural).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- public(less/2).
less(X, Y):-
X < Y.
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(newcastle,
extends(location(210, 230))).
links([
(edinburgh, 104),
(carlisle, 58),
(york, 80)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(nottingham,
extends(location(216, 128))).
links([
(birmingham, 48),
(cambridge, 82),
(sheffield, 38)]).
:- end_object.

View File

@@ -1,13 +0,0 @@
:- object(oxford,
extends(location(214, 66))).
links([
(bristol, 71),
(birmingham, 63),
(cambridge, 80),
(london, 57)]).
:- end_object.

View File

@@ -1,10 +0,0 @@
:- object(penzance,
extends(location(10, 0))).
links([(
exeter, 112)]).
:- end_object.

View File

@@ -1,65 +0,0 @@
:- object(permute,
extends(salesman)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- op(400, yfx, ~).
route(Towns, Route) :-
findall(
(Towns2, Length),
(permute(Towns, Towns2), route_length(Towns2, Length)),
List),
shortest(List, Route).
permute([Town], Town).
permute(Towns, Towns2~Town) :-
delete(Towns, Town, Towns3),
permute(Towns3, Towns2).
delete([Head| Tail], Head, Tail).
delete([Head| Tail], Element, [Head| Tail2]):-
delete(Tail, Element, Tail2).
route_length(Town, 0) :-
atom(Town), !.
route_length(Towns~Town1~Town2, Length) :-
!,
route_length(Towns~Town1, Length1),
Town1::crow_flies(Town2, Length2),
Length is Length1 + Length2.
route_length(Town1~Town2, Length) :-
Town1::crow_flies(Town2, Length).
shortest(List, Shortest) :-
shortest(List, null, 1000000, Shortest).
shortest([], Route, Length, (Route, Length)).
shortest([(Route, Length)| Routes], _, LX, Shortest) :-
Length < LX, !,
shortest(Routes, Route, Length, Shortest).
shortest([_| Routes], RX, LX, Shortest) :-
shortest(Routes, RX, LX, Shortest).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(portsmouth,
extends(location(216, 22))).
links([
(brighton, 49),
(exeter, 126),
(london, 72)]).
:- end_object.

View File

@@ -1,43 +0,0 @@
:- object(presort,
extends(incremental)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- uses(quick(_)).
route(Towns, Route) :-
arrange(Towns, Towns2),
^^route(Towns2, Route).
arrange(Towns, Sorted) :-
centre(Towns, X, Y),
quick(geographic(X, Y))::sort(Towns, Sorted).
centre(Towns, X, Y) :-
average(Towns, 0, 0, U, V, 0, L),
X is U/L,
Y is V/L.
average([], U, V, U, V, L, L).
average([Town| Towns], UX, VX, U, V, I, L):-
Town::at(UT, VT),
UX2 is UX+UT,
VX2 is VX+VT,
I2 is I + 1,
average(Towns, UX2, VX2, U, V, I2, L).
:- end_object.

View File

@@ -1,45 +0,0 @@
:- object(quick(_Order)).
:- info([
author is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
parnames is ['Order'],
comment is '.',
source is 'Example adopted from the Francis G. McCabe L&O documentation.']).
:- public(sort/2).
:- mode(sort(+list, -list), one).
sort([], []).
sort([X| L], S):-
split(L, X, L1, L2),
sort(L1, S1),
sort(L2, S2),
app(S1, [X| S2], S).
split([], _, [], []).
split([D| L], X, [D| L1], L2):-
parameter(1, Order),
Order::less(D, X),
!,
split(L, X, L1, L2).
split([D| L], X, L1, [D| L2]):-
split(L, X, L1, L2).
app([], L, L).
app([H| T], L, [H| T2]) :-
app(T, L, T2).
:- end_object.

View File

@@ -1,15 +0,0 @@
:- object(sheffield,
extends(location(208, 142))).
links([
(birmingham, 75),
(hull, 65),
(leeds, 34),
(liverpool, 70),
(manchester, 38),
(nottingham, 38)]).
:- end_object.

View File

@@ -1,11 +0,0 @@
:- object(swansea,
extends(location(126, 66))).
links([
(cardiff, 45),
(aberystwyth, 75)]).
:- end_object.

View File

@@ -1,12 +0,0 @@
:- object(york,
extends(location(218, 184))).
links([
(leeds, 23),
(hull, 37),
(newcastle, 80)]).
:- end_object.