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:
parent
60fbc754f9
commit
6d079626af
Logtalk/examples
errors
lo
planner
aberdeen_air.lgtaiai.lgtairport.lgtalbert_hall.lgtcastle.lgtcity.lgtedin.lgtedinburgh.lgtfly.lgtglasgow.lgtimperial.lgtlhr.lgtlondon.lgtmanchester.lgtplan1.lgtrenfrew.lgtringway.lgtvictoria.lgt
travellers
aberdeen.lgtaberystwyth.lgtbirmingham.lgtbrighton.lgtbristol.lgtcambridge.lgtcardiff.lgtcarlisle.lgtcircular.lgtdescend.lgtdover.lgtdriving.lgtedinburgh.lgtexeter.lgtgeographic2.lgtglasgow.lgthull.lgtincremental.lgtleeds.lgtliverpool.lgtlocation2.lgtlondon.lgtmanchester.lgtmetric1.lgtnatural.lgtnewcastle.lgtnottingham.lgtoxford.lgtpenzance.lgtpermute.lgtportsmouth.lgtpresort.lgtquick1.lgtsheffield.lgtswansea.lgtyork.lgt
poem
shapes
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(lgtredef).
|
|
||||||
|
|
||||||
current_object(_).
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
:- object(misspell).
|
|
||||||
|
|
||||||
output(A) :-
|
|
||||||
writr(A).
|
|
||||||
|
|
||||||
:- end_object.
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
:- object(plredef).
|
|
||||||
|
|
||||||
write(_).
|
|
||||||
|
|
||||||
:- end_object.
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
:- object(portability).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(predicate/0).
|
|
||||||
|
|
||||||
|
|
||||||
predicate :-
|
|
||||||
compare(Result, first, second),
|
|
||||||
retractall(result(Result, _)),
|
|
||||||
sort([], []),
|
|
||||||
consult(file).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
:- object(singletons(L)).
|
|
||||||
|
|
||||||
predicate(A) :-
|
|
||||||
write(C).
|
|
||||||
|
|
||||||
:- end_object.
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
:- object(unknownrefs,
|
|
||||||
implements(protocol),
|
|
||||||
imports(category),
|
|
||||||
extends(object)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
:- object(aberdeen_air,
|
|
||||||
extends(airport)).
|
|
||||||
|
|
||||||
|
|
||||||
fly(renfrew).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(aiai,
|
|
||||||
extends(edinburgh)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(albert_hall,
|
|
||||||
extends(london)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(castle,
|
|
||||||
extends(edinburgh)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(edin,
|
|
||||||
extends(edinburgh)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
:- object(edinburgh,
|
|
||||||
extends(city)).
|
|
||||||
|
|
||||||
|
|
||||||
airport(edin).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
:- object(glasgow,
|
|
||||||
extends(city)).
|
|
||||||
|
|
||||||
|
|
||||||
airport(renfrew).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(imperial,
|
|
||||||
extends(london)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
:- object(lhr,
|
|
||||||
extends(airport)).
|
|
||||||
|
|
||||||
|
|
||||||
fly(edin).
|
|
||||||
fly(ringway).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
:- object(london,
|
|
||||||
extends(city)).
|
|
||||||
|
|
||||||
|
|
||||||
airport(lhr).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
:- object(manchester,
|
|
||||||
extends(city)).
|
|
||||||
|
|
||||||
|
|
||||||
airport(ringway).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
:- object(renfrew,
|
|
||||||
extends(airport)).
|
|
||||||
|
|
||||||
|
|
||||||
fly(aberdeen_air).
|
|
||||||
fly(ringway).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
:- object(ringway,
|
|
||||||
extends(manchester, airport)).
|
|
||||||
|
|
||||||
|
|
||||||
fly(lhr).
|
|
||||||
fly(renfrew).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
:- object(victoria,
|
|
||||||
extends(manchester)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
:- object(aberdeen,
|
|
||||||
extends(location(194, 340))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(edinburgh, 115),
|
|
||||||
(glasgow, 142)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(aberystwyth,
|
|
||||||
extends(location(126, 102))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(birmingham, 114),
|
|
||||||
(liverpool, 100),
|
|
||||||
(swansea, 75)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(brighton,
|
|
||||||
extends(location(248, 10))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(dover, 81),
|
|
||||||
(portsmouth, 49),
|
|
||||||
(london, 52)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
:- object(bristol,
|
|
||||||
extends(location(168, 47))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(cardiff, 44),
|
|
||||||
(exeter, 76),
|
|
||||||
(oxford, 71),
|
|
||||||
(birmingham, 86)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
:- object(cambridge,
|
|
||||||
extends(location(254, 92))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(nottingham, 82),
|
|
||||||
(oxford, 80),
|
|
||||||
(london, 54),
|
|
||||||
(birmingham, 97)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
:- object(cardiff,
|
|
||||||
extends(location(148, 56))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(bristol, 44),
|
|
||||||
(swansea, 45)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(carlisle,
|
|
||||||
extends(location(166, 226))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(glasgow, 94),
|
|
||||||
(leeds, 117),
|
|
||||||
(newcastle, 58)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -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.
|
|
@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
:- object(dover,
|
|
||||||
extends(location(292, 38))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(brighton, 81),
|
|
||||||
(london, 71)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(edinburgh,
|
|
||||||
extends(location(162, 282))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(aberdeen, 115),
|
|
||||||
(glasgow, 44),
|
|
||||||
(newcastle, 104)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(exeter,
|
|
||||||
extends(location(138, 18))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(bristol, 76),
|
|
||||||
(penzance, 112),
|
|
||||||
(portsmouth, 126)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(glasgow,
|
|
||||||
extends(location(132, 273))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(aberdeen, 142),
|
|
||||||
(carlisle, 94),
|
|
||||||
(edinburgh, 44)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(hull,
|
|
||||||
extends(location(240, 168))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(leeds, 58),
|
|
||||||
(sheffield, 65),
|
|
||||||
(york, 37)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
:- object(leeds,
|
|
||||||
extends(location(208, 170))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(carlisle, 117),
|
|
||||||
(hull, 58),
|
|
||||||
(sheffield, 34),
|
|
||||||
(manchester, 41),
|
|
||||||
(york, 23)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
:- object(liverpool,
|
|
||||||
extends(location(164, 150))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(aberystwyth, 100),
|
|
||||||
(birmingham, 99),
|
|
||||||
(manchester, 35),
|
|
||||||
(sheffield, 70)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,14 +0,0 @@
|
|||||||
|
|
||||||
:- object(london,
|
|
||||||
extends(location(244,54))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(brighton, 52),
|
|
||||||
(dover, 71),
|
|
||||||
(cambridge, 54),
|
|
||||||
(oxford, 57),
|
|
||||||
(portsmouth, 72)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(manchester,
|
|
||||||
extends(location(180, 156))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(leeds, 41),
|
|
||||||
(liverpool, 35),
|
|
||||||
(sheffield, 38)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -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.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(newcastle,
|
|
||||||
extends(location(210, 230))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(edinburgh, 104),
|
|
||||||
(carlisle, 58),
|
|
||||||
(york, 80)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(nottingham,
|
|
||||||
extends(location(216, 128))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(birmingham, 48),
|
|
||||||
(cambridge, 82),
|
|
||||||
(sheffield, 38)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,13 +0,0 @@
|
|||||||
|
|
||||||
:- object(oxford,
|
|
||||||
extends(location(214, 66))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(bristol, 71),
|
|
||||||
(birmingham, 63),
|
|
||||||
(cambridge, 80),
|
|
||||||
(london, 57)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
:- object(penzance,
|
|
||||||
extends(location(10, 0))).
|
|
||||||
|
|
||||||
|
|
||||||
links([(
|
|
||||||
exeter, 112)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(portsmouth,
|
|
||||||
extends(location(216, 22))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(brighton, 49),
|
|
||||||
(exeter, 126),
|
|
||||||
(london, 72)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -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.
|
|
@ -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.
|
|
@ -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.
|
|
@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
:- object(swansea,
|
|
||||||
extends(location(126, 66))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(cardiff, 45),
|
|
||||||
(aberystwyth, 75)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
:- object(york,
|
|
||||||
extends(location(218, 184))).
|
|
||||||
|
|
||||||
|
|
||||||
links([
|
|
||||||
(leeds, 23),
|
|
||||||
(hull, 37),
|
|
||||||
(newcastle, 80)]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,33 +0,0 @@
|
|||||||
|
|
||||||
/* Circle is a special form of ellipse */
|
|
||||||
/* Subclasses ('circle' here) must have the same number of arguments */
|
|
||||||
/* as their superclass ('ellipse') for the superclass predicates to */
|
|
||||||
/* be applicable. The arguments may be renamed for clarity. */
|
|
||||||
|
|
||||||
:- object(circle(Center, Radius),
|
|
||||||
extends(ellipse(Center, Radius, Radius))).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2000/4/22,
|
|
||||||
comment is 'Parametric object for representing geometric circles.',
|
|
||||||
parnames is ['Center', 'Radius'],
|
|
||||||
source is 'Example adopted from the POEM system by Ben Staveley-Taylor.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(circumference/1).
|
|
||||||
:- mode(circumference(-number), one).
|
|
||||||
|
|
||||||
|
|
||||||
circumference(Circumference) :-
|
|
||||||
pi(Pi),
|
|
||||||
parameter(2, Radius),
|
|
||||||
Circumference is 2*Pi*Radius.
|
|
||||||
|
|
||||||
|
|
||||||
pi(3.14196).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
/* Ellipses are defined by centre and semi-axes */
|
|
||||||
|
|
||||||
:- object(ellipse(_Center, _A, _B)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2000/4/22,
|
|
||||||
comment is 'Parametric object for representing geometric ellipses.',
|
|
||||||
parnames is ['Center', 'Rx', 'Ry'],
|
|
||||||
source is 'Example adopted from the POEM system by Ben Staveley-Taylor.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(area/1).
|
|
||||||
:- mode(area(-number), one).
|
|
||||||
|
|
||||||
|
|
||||||
area(Area) :-
|
|
||||||
pi(Pi),
|
|
||||||
parameter(2, A),
|
|
||||||
parameter(3, B),
|
|
||||||
Area is Pi*A*B.
|
|
||||||
|
|
||||||
|
|
||||||
pi(3.14196).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,92 +0,0 @@
|
|||||||
|
|
||||||
/* A line is defined by its end points. */
|
|
||||||
/* This class shows examples of calling its own and other class */
|
|
||||||
/* predicates. */
|
|
||||||
|
|
||||||
:- object(line(_Point1, _Point2)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2000/4/22,
|
|
||||||
comment is 'Parametric object for representing geometric lines.',
|
|
||||||
parnames is ['Point1', 'Point2'],
|
|
||||||
source is 'Example adopted from the POEM system by Ben Staveley-Taylor.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(length/1).
|
|
||||||
:- mode(length(-number), one).
|
|
||||||
|
|
||||||
:- public(intersects/1).
|
|
||||||
:- mode(intersects(+nonvar), one).
|
|
||||||
|
|
||||||
:- public(signed_distance/2).
|
|
||||||
:- mode(signed_distance(+nonvar, -number), one).
|
|
||||||
|
|
||||||
:- public(distance/2).
|
|
||||||
:- mode(distance(+nonvar, -number), one).
|
|
||||||
|
|
||||||
|
|
||||||
length(Length) :-
|
|
||||||
/* sets Len to the length of the owner line */
|
|
||||||
parameter(1, P1),
|
|
||||||
parameter(2, P2),
|
|
||||||
P1::distance(P2, Length).
|
|
||||||
|
|
||||||
|
|
||||||
intersects(Line2) :-
|
|
||||||
/* succeeds if Line2 intersects the owner line. */
|
|
||||||
/* this isn't necessarily a good method, but shows how to */
|
|
||||||
/* call class procedures from within the class definition. */
|
|
||||||
parameter(1, P1),
|
|
||||||
parameter(2, P2),
|
|
||||||
Line1 = line(P1, P2),
|
|
||||||
Line2 = line(P3, P4),
|
|
||||||
Line2::signed_distance(P1, D1),
|
|
||||||
Line2::signed_distance(P2, D2),
|
|
||||||
opposite_signs(D1, D2),
|
|
||||||
Line1::signed_distance(P3, D3),
|
|
||||||
Line1::signed_distance(P4, D4),
|
|
||||||
opposite_signs(D3, D4).
|
|
||||||
|
|
||||||
|
|
||||||
signed_distance(Point, Dist) :-
|
|
||||||
/* finds the perpendicular distance from point to line. */
|
|
||||||
/* the sign of the answer depends on which side of the */
|
|
||||||
/* line the point is on. */
|
|
||||||
parameter(1, P1),
|
|
||||||
parameter(2, P2),
|
|
||||||
P1 = point(X1, Y1),
|
|
||||||
P2 = point(X2, Y2),
|
|
||||||
Point = point(X3, Y3),
|
|
||||||
A is X2-X1,
|
|
||||||
B is Y1-Y2,
|
|
||||||
C is X1*Y2-X2*Y1,
|
|
||||||
Dist is (A*Y3+B*X3+C)/sqrt(A*A+B*B).
|
|
||||||
|
|
||||||
|
|
||||||
distance(Point, Dist) :-
|
|
||||||
/* as 'signed_distance', but Dist always >= 0 */
|
|
||||||
parameter(1, P1),
|
|
||||||
parameter(2, P2),
|
|
||||||
line(P1, P2)::signed_distance(Point, Temp),
|
|
||||||
Dist is abs(Temp).
|
|
||||||
|
|
||||||
|
|
||||||
/* 'opposite_signs' succeeds if its arguments are of opposite signs. */
|
|
||||||
/* It has a feature in that 'opposite_signs(0,0)' succeeds: this is */
|
|
||||||
/* because 0 is treated as having optional sign. */
|
|
||||||
|
|
||||||
opposite_signs(A, B) :-
|
|
||||||
o_s_aux(A, B).
|
|
||||||
|
|
||||||
opposite_signs(A, B) :-
|
|
||||||
o_s_aux(B, A).
|
|
||||||
|
|
||||||
o_s_aux(A, B) :-
|
|
||||||
A >= 0,
|
|
||||||
B =< 0.
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
/* Points are going to be the fundamental quantity. */
|
|
||||||
/* These will be defined in Cartesian co-ordinates. */
|
|
||||||
|
|
||||||
:- object(point(_X, _Y)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2000/4/22,
|
|
||||||
comment is 'Parametric object for representing geometric points.',
|
|
||||||
parnames is ['X', 'Y'],
|
|
||||||
source is 'Example adopted from the POEM system by Ben Staveley-Taylor.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(identical/1).
|
|
||||||
:- mode(identical(+nonvar), one).
|
|
||||||
|
|
||||||
:- public(distance/2).
|
|
||||||
:- mode(distance(+nonvar, -number), one).
|
|
||||||
|
|
||||||
|
|
||||||
identical(point(X1, Y1)) :-
|
|
||||||
/* succeeds if the argument and owner points are the same. */
|
|
||||||
parameter(1, X),
|
|
||||||
parameter(2, Y),
|
|
||||||
X1 = X,
|
|
||||||
Y1 = Y.
|
|
||||||
|
|
||||||
|
|
||||||
distance(point(X1, Y1), Distance) :-
|
|
||||||
/* finds the distance between argument and owner points. */
|
|
||||||
parameter(1, X),
|
|
||||||
parameter(2, Y),
|
|
||||||
Distance is sqrt((X1-X)*(X1-X)+(Y1-Y)*(Y1-Y)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,40 +0,0 @@
|
|||||||
:- object(polygon,
|
|
||||||
instantiates(abstract_class),
|
|
||||||
specializes(shape)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.1,
|
|
||||||
date is 2004/1/8,
|
|
||||||
comment is 'Generic polygon.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(nsides/1).
|
|
||||||
|
|
||||||
:- mode(nsides(?integer), zero_or_one).
|
|
||||||
|
|
||||||
:- info(nsides/1, [
|
|
||||||
comment is 'Polygon number of sides.',
|
|
||||||
argnames is ['Number']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(area/1).
|
|
||||||
|
|
||||||
:- mode(area(-float), zero_or_one).
|
|
||||||
|
|
||||||
:- info(area/1, [
|
|
||||||
comment is 'Polygon area.',
|
|
||||||
argnames is ['Area']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(perimeter/1).
|
|
||||||
|
|
||||||
:- mode(perimeter(?atom), zero_or_one).
|
|
||||||
|
|
||||||
:- info(perimeter/1, [
|
|
||||||
comment is 'Polygon perimeter.',
|
|
||||||
argnames is ['Perimeter']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,4 +0,0 @@
|
|||||||
:- object(q1,
|
|
||||||
instantiates(square)).
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,14 +0,0 @@
|
|||||||
:- object(q2,
|
|
||||||
instantiates(square)).
|
|
||||||
|
|
||||||
|
|
||||||
position(2, 3).
|
|
||||||
|
|
||||||
|
|
||||||
color(blue).
|
|
||||||
|
|
||||||
|
|
||||||
side(3).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
:- object(regular_polygon,
|
|
||||||
instantiates(abstract_class),
|
|
||||||
specializes(polygon)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.1,
|
|
||||||
date is 2004/1/8,
|
|
||||||
comment is 'Generic regular polygon.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(side/1).
|
|
||||||
|
|
||||||
:- mode(side(?atom), zero_or_one).
|
|
||||||
|
|
||||||
:- info(side/1, [
|
|
||||||
comment is 'Regular polygon side length.',
|
|
||||||
argnames is ['Length']]).
|
|
||||||
|
|
||||||
|
|
||||||
side(1). % default side length
|
|
||||||
|
|
||||||
|
|
||||||
perimeter(Perimeter) :-
|
|
||||||
::nsides(Number),
|
|
||||||
::side(Side),
|
|
||||||
Perimeter is Number*Side.
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,37 +0,0 @@
|
|||||||
:- object(shape,
|
|
||||||
instantiates(abstract_class),
|
|
||||||
specializes(object)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2003/2/3,
|
|
||||||
comment is 'Generic geometric shape.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(color/1).
|
|
||||||
|
|
||||||
:- mode(color(?atom), zero_or_one).
|
|
||||||
|
|
||||||
:- info(color/1, [
|
|
||||||
comment is 'Shape color.',
|
|
||||||
argnames is ['Color']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(position/2).
|
|
||||||
|
|
||||||
:- mode(position(?integer, ?integer), zero_or_one).
|
|
||||||
|
|
||||||
:- info(position/2, [
|
|
||||||
comment is 'Shape position.',
|
|
||||||
argnames is ['X', 'Y']]).
|
|
||||||
|
|
||||||
|
|
||||||
color(red). % default shape color
|
|
||||||
|
|
||||||
|
|
||||||
position(0, 0). % default shape position
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,21 +0,0 @@
|
|||||||
:- object(square,
|
|
||||||
instantiates(class),
|
|
||||||
specializes(regular_polygon)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2003/2/3,
|
|
||||||
comment is 'Geometric square.']).
|
|
||||||
|
|
||||||
|
|
||||||
nsides(4).
|
|
||||||
|
|
||||||
|
|
||||||
area(Area) :-
|
|
||||||
::side(Side),
|
|
||||||
Area is Side*Side.
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,39 +0,0 @@
|
|||||||
:- object(polygon,
|
|
||||||
extends(shape)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.1,
|
|
||||||
date is 2004/1/8,
|
|
||||||
comment is 'Generic polygon.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(nsides/1).
|
|
||||||
|
|
||||||
:- mode(nsides(?integer), zero_or_one).
|
|
||||||
|
|
||||||
:- info(nsides/1, [
|
|
||||||
comment is 'Polygon number of sides.',
|
|
||||||
argnames is ['Number']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(area/1).
|
|
||||||
|
|
||||||
:- mode(area(-float), zero_or_one).
|
|
||||||
|
|
||||||
:- info(area/1, [
|
|
||||||
comment is 'Polygon area.',
|
|
||||||
argnames is ['Area']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(perimeter/1).
|
|
||||||
|
|
||||||
:- mode(perimeter(?atom), zero_or_one).
|
|
||||||
|
|
||||||
:- info(perimeter/1, [
|
|
||||||
comment is 'Polygon perimeter.',
|
|
||||||
argnames is ['Perimeter']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,5 +0,0 @@
|
|||||||
:- object(q1,
|
|
||||||
extends(square)).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,14 +0,0 @@
|
|||||||
:- object(q2,
|
|
||||||
extends(square)).
|
|
||||||
|
|
||||||
|
|
||||||
position(2, 3).
|
|
||||||
|
|
||||||
|
|
||||||
color(blue).
|
|
||||||
|
|
||||||
|
|
||||||
side(3).
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
:- object(regular_polygon,
|
|
||||||
extends(polygon)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.1,
|
|
||||||
date is 2004/1/8,
|
|
||||||
comment is 'Generic regular polygon.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(side/1).
|
|
||||||
|
|
||||||
:- mode(side(?atom), zero_or_one).
|
|
||||||
|
|
||||||
:- info(side/1, [
|
|
||||||
comment is 'Regular polygon side length.',
|
|
||||||
argnames is ['Length']]).
|
|
||||||
|
|
||||||
|
|
||||||
side(1). % default side length
|
|
||||||
|
|
||||||
|
|
||||||
perimeter(Perimeter) :-
|
|
||||||
::nsides(Number),
|
|
||||||
::side(Side),
|
|
||||||
Perimeter is Number*Side.
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,35 +0,0 @@
|
|||||||
:- object(shape).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2003/2/3,
|
|
||||||
comment is 'Generic geometric shape.']).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(color/1).
|
|
||||||
|
|
||||||
:- mode(color(?atom), zero_or_one).
|
|
||||||
|
|
||||||
:- info(color/1, [
|
|
||||||
comment is 'Shape color.',
|
|
||||||
argnames is ['Color']]).
|
|
||||||
|
|
||||||
|
|
||||||
:- public(position/2).
|
|
||||||
|
|
||||||
:- mode(position(?integer, ?integer), zero_or_one).
|
|
||||||
|
|
||||||
:- info(position/2, [
|
|
||||||
comment is 'Shape position.',
|
|
||||||
argnames is ['X', 'Y']]).
|
|
||||||
|
|
||||||
|
|
||||||
color(red). % default shape color
|
|
||||||
|
|
||||||
|
|
||||||
position(0, 0). % default shape position
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
@ -1,21 +0,0 @@
|
|||||||
|
|
||||||
:- object(square,
|
|
||||||
extends(regular_polygon)).
|
|
||||||
|
|
||||||
|
|
||||||
:- info([
|
|
||||||
author is 'Paulo Moura',
|
|
||||||
version is 1.0,
|
|
||||||
date is 2003/2/3,
|
|
||||||
comment is 'Geometric square.']).
|
|
||||||
|
|
||||||
|
|
||||||
nsides(4).
|
|
||||||
|
|
||||||
|
|
||||||
area(Area) :-
|
|
||||||
::side(Side),
|
|
||||||
Area is Side*Side.
|
|
||||||
|
|
||||||
|
|
||||||
:- end_object.
|
|
Reference in New Issue
Block a user