Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Help with basic list functions
Hi,
I am very new to Prolog, and I am having a terrible time getting to grips
with it. If someone coukld please help with this problem I would be
extremely grateful. I think it is reletively simple, so hopefully someone
can explain to me what is going wrong.

Basically, this program is meant to find routes between these places. At
the moment it just needs to check that it is not re-visiting the same
location twice. In the first journey rule I am trying to check that the
destination has not already been visited. In the second journey rule I am
trying to use an accumulator in the form of the list Beenthere, where it
adds each location to the head of the list after it has been visited.
The trip rules are fine, but I think there are a number of problems with
my journey rules.

Can someone please tell me how to get this program to (a) check that it is
not re-visiting any places and (b) add visited places to the list?

------------------------------------------------------

% wessex2.pl

:-use_module(library(lists)).

% road/3

road(budmouth, casterbridge, 5).
road(casterbridge, exonbury, 30).
road(casterbridge, glaston, 30).
road(casterbridge, idmouth, 25).
road(downstaple, exonbury, 20).
road(downstaple, glaston, 40).
road(downstaple, tivworthy, 15).
road(glaston, tivworthy, 30).
road(exonbury, idmouth, 10).
road(exonbury, tivworthy, 10).

% rule 1

trip(Place1, Place2, Dist) :-
road(Place1, Place2, Dist).

% rule 2

trip(Place1, Place2, Dist) :-
road(Place2, Place1, Dist).

% part 2.2

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%

% rule 1

journey(Place1, Place2, Dist, Route, Beenthere) :-
trip(Place1, Place2, Dist),
Route = [Place1, Place2],

\+ (member(Place2, Beenthere)).


 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%

% rule 2

journey(Place1, Place2, Dist, Route, Beenthere) :-

journey(Place1, PLACE3, ADIST, Route1,Beenthere1),
journey(PLACE3, Place2, BDIST, Route2,Beenthere1),
Dist is +(ADIST, BDIST),

append([Place1], Route2, Route),

Beenthere = [Head|Tail],
\+ (member(PLACE3, Beenthere)),
Beenthere1 = [Place1|Beenthere].

-----------------------------------------------------------
Oh, and the \ symbols are actually backslashes, but for some reason they
are not appearing correctly on this pc.

Any help would be greatly appreciated.

Thanks very much.

















Report this thread to moderator Post Follow-up to this message
Old Post
Scaramanga
03-27-04 05:11 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.