Logtalk 2.26.2 files.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1487 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura
2005-12-24 18:07:41 +00:00
parent 9f1b358c04
commit 3455276aa2
55 changed files with 6535 additions and 0 deletions

View File

@@ -0,0 +1,211 @@
% Planner
:- 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.
% Abstractions of City, Airport, and Flight
:- 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.
:- object(airport).
:- public(fly/1).
:- mode(fly(?), zero_or_more).
:- public(airport/1).
:- mode(airport(?), zero_or_more).
airport(Airport) :-
self(Airport).
:- end_object.
:- object(fly).
:- public(step/3).
:- mode(step(+, +, -), zero_or_more).
step(From, To, fly(From, To)) :-
From::fly(To).
:- end_object.
% Edinburgh locations
:- object(edinburgh,
extends(city)).
airport(edin).
:- end_object.
:- object(edin,
extends(edinburgh)).
:- end_object.
:- object(castle,
extends(edinburgh)).
:- end_object.
:- object(aiai,
extends(edinburgh)).
:- end_object.
% Glasgow locations
:- object(glasgow,
extends(city)).
airport(renfrew).
:- end_object.
% London locations
:- object(london,
extends(city)).
airport(lhr).
:- end_object.
:- object(albert_hall,
extends(london)).
:- end_object.
:- object(imperial,
extends(london)).
:- end_object.
% Manchester locations
:- object(manchester,
extends(city)).
airport(ringway).
:- end_object.
:- object(victoria,
extends(manchester)).
:- end_object.
% Airports
:- object(aberdeen_air,
extends(airport)).
fly(renfrew).
:- end_object.
:- object(lhr,
extends(airport)).
fly(edin).
fly(ringway).
:- end_object.
:- object(renfrew,
extends(airport)).
fly(aberdeen_air).
fly(ringway).
:- end_object.
:- object(ringway,
extends(manchester, airport)).
fly(lhr).
fly(renfrew).
:- end_object.

View File

@@ -0,0 +1,153 @@
:- 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.
:- 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.
:- 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.
:- 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.
:- 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

@@ -0,0 +1,351 @@
:- 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.']).
:- 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.
:- object(aberdeen,
extends(location(194, 340))).
links([
(edinburgh, 115),
(glasgow, 142)]).
:- end_object.
:- object(aberystwyth,
extends(location(126, 102))).
links([
(birmingham, 114),
(liverpool, 100),
(swansea, 75)]).
:- end_object.
:- object(birmingham,
extends(location(192, 106))).
links([
(aberystwyth, 114),
(bristol, 86),
(cambridge, 97),
(liverpool, 99),
(nottingham, 48),
(oxford, 63),
(sheffield, 75)]).
:- end_object.
:- object(brighton,
extends(location(248, 10))).
links([
(dover, 81),
(portsmouth, 49),
(london, 52)]).
:- end_object.
:- object(bristol,
extends(location(168, 47))).
links([
(cardiff, 44),
(exeter, 76),
(oxford, 71),
(birmingham, 86)]).
:- end_object.
:- object(cambridge,
extends(location(254, 92))).
links([
(nottingham, 82),
(oxford, 80),
(london, 54),
(birmingham, 97)]).
:- end_object.
:- object(cardiff,
extends(location(148, 56))).
links([
(bristol, 44),
(swansea, 45)]).
:- end_object.
:- object(carlisle,
extends(location(166, 226))).
links([
(glasgow, 94),
(leeds, 117),
(newcastle, 58)]).
:- end_object.
:- object(dover,
extends(location(292, 38))).
links([
(brighton, 81),
(london, 71)]).
:- end_object.
:- object(edinburgh,
extends(location(162, 282))).
links([
(aberdeen, 115),
(glasgow, 44),
(newcastle, 104)]).
:- end_object.
:- object(exeter,
extends(location(138, 18))).
links([
(bristol, 76),
(penzance, 112),
(portsmouth, 126)]).
:- end_object.
:- object(glasgow,
extends(location(132, 273))).
links([
(aberdeen, 142),
(carlisle, 94),
(edinburgh, 44)]).
:- end_object.
:- object(hull,
extends(location(240, 168))).
links([
(leeds, 58),
(sheffield, 65),
(york, 37)]).
:- end_object.
:- object(leeds,
extends(location(208, 170))).
links([
(carlisle, 117),
(hull, 58),
(sheffield, 34),
(manchester, 41),
(york, 23)]).
:- end_object.
:- object(liverpool,
extends(location(164, 150))).
links([
(aberystwyth, 100),
(birmingham, 99),
(manchester, 35),
(sheffield, 70)]).
:- end_object.
:- object(london,
extends(location(244,54))).
links([
(brighton, 52),
(dover, 71),
(cambridge, 54),
(oxford, 57),
(portsmouth, 72)]).
:- end_object.
:- object(manchester,
extends(location(180, 156))).
links([
(leeds, 41),
(liverpool, 35),
(sheffield, 38)]).
:- end_object.
:- object(newcastle,
extends(location(210, 230))).
links([
(edinburgh, 104),
(carlisle, 58),
(york, 80)]).
:- end_object.
:- object(nottingham,
extends(location(216, 128))).
links([
(birmingham, 48),
(cambridge, 82),
(sheffield, 38)]).
:- end_object.
:- object(oxford,
extends(location(214, 66))).
links([
(bristol, 71),
(birmingham, 63),
(cambridge, 80),
(london, 57)]).
:- end_object.
:- object(penzance,
extends(location(10, 0))).
links([(
exeter, 112)]).
:- end_object.
:- object(portsmouth,
extends(location(216, 22))).
links([
(brighton, 49),
(exeter, 126),
(london, 72)]).
:- end_object.
:- object(sheffield,
extends(location(208, 142))).
links([
(birmingham, 75),
(hull, 65),
(leeds, 34),
(liverpool, 70),
(manchester, 38),
(nottingham, 38)]).
:- end_object.
:- object(swansea,
extends(location(126, 66))).
links([
(cardiff, 45),
(aberystwyth, 75)]).
:- end_object.
:- object(york,
extends(location(218, 184))).
links([
(leeds, 23),
(hull, 37),
(newcastle, 80)]).
:- end_object.