Newbie needs help...

From: Il Capoufficio (ilmagopancione_at_libero.it)
Date: 10/31/04


Date: Sun, 31 Oct 2004 14:48:25 GMT

Hi, I have some problems with this Prolog program. There is a "database"
made up of informations about the flights of an airport. The information
are like this:

flight(FromCity, ToCity, [LeavingTime, ArrivalTime, Id, Days]).

*Id is a number which identifies the flight, while Days can be a list
(like [mon, tue, sun]) or "all_days", which means that the flight occurs
every day.*

flight(rome, london , [h(9,00), h(10,30), 1, all_days]).
flight(rome, london, [h(11,00), h(12,30), 2, [mon, tue, fri, sat]]).
flight(rome, london, [h(11,30), h(13,00), 3, [mon, wed, thu, fri, sun]]).
flight(rome, paris, [h(12,00), h(12,00), 4, all_days]).
flight(rome, paris, [h(12,25), h(13,45), 5, [mon,tue, fri, sat]]).
flight(london, moscow, [h(9,00), h(11,15), 6, [mon,tue, wed, thu]]).
flight(london, moscow, [h(12,05), h(14,20), 7, [fri, sat, sun]]).
flight(paris, tokyo, [h(12, 31), h(14,00), 8, [mon, tue]]).
flight(paris, tokyo, [h(12,10), h(13,50), 9, all_days]).

Then there are the following rules:

flight1(City1, City2, Day, Leave, Arrive, Id):-
        flight(City1, City2, [Leave, Arrive, Id,all_days]).
flight1(City1, City2, Day, Leave, Arrive, Id):-
        flight(City1, City2, [Leave, Arrive, Id|Y]),
        Y = [T|_],
        member(Day, T).

which checks if there is a flight from City1 to City2 in a given Day.

Then:
travel(City1, City2, Day, go(City1, City2, Id, Leave, Arrive)):-
        flight1(City1, City2, Day, Leave, Arrive, Id).
travel(City1, City2, Day, go(City1, City3, Id, Leave, Arrive, Path)):-
        flight1(City1, City3, Day, Leave, Arrive, Id),
        flight1(City3, City2, Day, Leave1, _, _),
        changeFlight(Arrive, Leave1),
        travel(City3, City2, Day, Path).

Travel tells if there is a flight from City1 to City2, but also checks
if there is a path between City1 and City2 going through (City1 ->
City3), (City3 -> City4) (City4 -> City2).

changeFlight(H1, H2):-
        t(H1, H2).
t(h(X,Y),h(Z,W)):-
        (Z*60+W)-(X*60+Y) >= 30.

changeFlight chechks if there is at least 30 minutes between H1 and H2.

And that's all.
Now, if I pose the query "travel(rome, tokyo, mon, J).", the result is
J = go(rome,paris,4,h(12,0),h(12,0),go(paris,tokyo,9,h(12,10),h(13,50)))
J = go(rome,paris,4,h(12,0),h(12,0),go(paris,tokyo,8,h(12,31),h(14,0)))

The second answer is right, but in the first the arrival time of the
rome-paris flight (12,00) and the leaving time of paris-tokyo (12,10)
don't respect the changeFlight rule. Any suggestions?

Thanks to everyone...



Relevant Pages

  • Re: program
    ... > Write a complete Java program that does the following: ... > airline flight. ... > Display the departure time, the arrival time, and the flight time (in ...
    (comp.lang.java.programmer)
  • Time Difference
    ... to enter the local departure time, the departure city and the local ... arrival time and city. ... I assume I will need a flight header ...
    (comp.databases.ms-access)
  • Re: Hide all controls inside another control
    ... Of course it can be done, but where is the flight information coming from? ... > original flight number departure time, arrival time at connecting aiport, ... > connecting flight number, departure time of 2nd flight and arrival time at ...
    (microsoft.public.access.forms)
  • Re: program
    ... > Write a complete Java program that does the following: ... > airline flight. ... > Display the departure time, the arrival time, and the flight time (in ...
    (comp.lang.java.programmer)
  • Re: program
    ... > Write a complete Java program that does the following: ... > airline flight. ... > Display the departure time, the arrival time, and the flight time (in ...
    (comp.lang.java.programmer)