For Programmers: Free Programming Magazines  


Home > Archive > Prolog > January 2007 > Timetable









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Timetable
Philipp Kraus

2007-01-11, 10:04 pm

Hello,

I must write a Prolog program, which can build a sum over some flights.
My flights are in an Database and Prolog can find the route between
places, but when I try to take the time about all flight, Prolog run
into "out of stack".

My Code:

route(Von, Nach) :-
Time=0,
route(Von, Nach, Time, _),
write('\nGesamtzeit: '), write(Time), write('h'), write('\n').

route( Von, Nach, GTime, [(Von / Nach )] ) :-
flight( Von, Nach, Time),
-->> GTime is GTime + Time,
write('Flug: '), write(Von), write(' -> '), write(Nach),
write(' ('),write(Time), write('h)'), write('\n').

route( Von, Nach, GTime, [ (Von / Via ) | Weitere] ) :-
flight( Von, Via, Time ),
-->> GTime is GTime Time,
write('Flug: '), write(Von), write(' -> '), write(Via),
write(' ('),write(Time), write('h)'), write('\n'),
route( Via, Nach, Time, Weitere ).

If I have the two lines (-->> ) or one of them, my programm wouldn't
work. But why?
my flights are flight( <from>, <to>, <time> )
I try to understand the book Programming for AI (Ivan Bratko).

Can anyone help me?

Thanks a lot

Phil

bart demoen

2007-01-14, 7:04 pm

On Thu, 11 Jan 2007 16:30:37 +0100, Philipp Kraus wrote:


> route( Von, Nach, GTime, [(Von / Nach )] ) :-
> flight( Von, Nach, Time),
> -->> GTime is GTime + Time,


This line basically askes:

compute the result of GTime + Time and
unify that with GTime

I hope you understand that this can only succeed if Time
evaluates to zero.

Arithmetic in Prolog is most conveniently done by ALWAYS having a new
variable at the left hand side of the is/2 operator.



> route( Von, Nach, GTime, [ (Von / Via ) | Weitere] ) :-
> flight( Von, Via, Time ),
> -->> GTime is GTime Time,



This seems a plain syntax error - maybe you meant something else ?

Cheers

Bart Demoen

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com