Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flight(singapore,london , 2310, 0520, ba58,1).
- flight(singapore,london , 2310, 0520, ba58,3).
- flight(singapore,london , 2310, 0520, ba58,4).
- flight(singapore,london , 2310, 0520, ba58,6).
- flight(london,singapore , 1000, 1610, ba24,1).
- flight(london,singapore , 1000, 1610, ba24,3).
- flight(london,singapore , 1000, 1610, ba24,4).
- flight(london,singapore , 1000, 1610, ba24,6).
- flight(london,edinburgh , 0940, 1050, ba4732,1).
- flight(london,edinburgh , 0940, 1050, ba4732,2).
- flight(london,edinburgh , 0940, 1050, ba4732,3).
- flight(london,edinburgh , 0940, 1050, ba4732,4).
- flight(london,edinburgh , 0940, 1050, ba4732,5).
- flight(london,edinburgh , 0940, 1050, ba4732,6).
- flight(london,edinburgh , 0940, 1050, ba4732,7).
- % check if an element belongs to a list
- member(Country,[Country|_]).
- member(Country,[_|Tail]):- member(Country,Tail).
- mydiff(X,X) :- !,fail.
- mydiff(X,Y).
- % A: boarding station, B: destination, Path: route from A to B
- path(A,B,Path) :-
- travel(A,B,[A],Q),
- reverse(Q,Path).
- % performs depth first search, member(C,Visited) will check if a station has been visited to avoid looping
- travel(A,B,P,[B|P]) :- flight(A,B,_,_,_,_).
- travel(A,B,Visited,Path) :-
- flight(A,C,_,_,_,_),
- mydiff(C,B),
- \+member(C,Visited),
- travel(C,B,[C|Visited],Path).
- calculate :- possiblePath(X), asserta(pathInformation(X)),fail.
- findpossiblePath([]).
- findpossiblePath([Head|Tail]) :- /*nl,write(Head),*/asserta(possiblePath(Head)),findpossiblePath(Tail).
- start :- nl, write('Please Day of Flight in Numberic format (1 for Mon, 7 for Sun: '),
- read(Day),
- nl, write('Origin Country: '),
- read(Origin), checkOCountry(Origin, 0), nl, write('Dest Country: '),
- read(Dest), checkDCountry(Dest, 1)->
- plane(Board,0),
- plane(Arrive,1),
- computation(Board,Arrive,List), nl,write('ShortestRoute: '),write(List),
- retractall(board(X,Y)),!,fail.
- computation(Start,Destination,List) :- setof(Path,path(Start,Destination,Path),Set), findpossiblePath(Set),
- not(calculate),pathInformation(List),retractall(pathInformation(X)),retractall(possiblePath(W)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement