This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/lo/travellers/driving.lgt
vsc fd048651b6 Logtalk files
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@55 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2001-06-06 20:07:01 +00:00

53 lines
961 B
Plaintext

:- object(driving,
extends(salesman)).
:- info([
authors 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.