Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- route(dublin, cork, 200, 'fct').
- route(cork, dublin, 200, 'fct').
- route(cork, corkAirport, 20, 'fc').
- route(corkAirport, cork, 25, 'fc').
- route(dublin, dublinAirport, 10, 'fc').
- route(dublinAirport, dublin, 20, 'fc').
- route(dublinAirport, corkAirport, 225, 'p').
- route(corkAirport, dublinAirport, 225, 'p').
- % String code values for each mode of transport. I needed to use the string code values as when
- % the string is split into a list it converts the individual letters into
- % their string code counterparts
- mode(102, 5).
- mode(99, 80).
- mode(116, 100).
- mode(112, 500).
- % Used this function to get a path from Beginning to end of the journey
- path(Begin, End, Path) :-
- path(Begin, End, [Begin], Path).
- % Upon reaching the target, the list is reversed
- path(End, End, RPath, Path) :-
- reverse(RPath, Path).
- % take an edge and check if we have already visited before use
- % Use of memberchk implemented below
- path(Begin, End, Visited, Path) :-
- route(Begin, Next, _, _),
- \+ memberchk(Next, Visited),
- path(Next, End, [Next|Visited], Path).
- % Use of string_to_list to convert the mode string and placed in List_input, which is then reversed and put in Rev_input
- journey(A, B, Input_mode) :- path(A, B, X),
- string_to_list(Input_mode, List_input),
- reverse(List_input, Rev_input),
- Y is 0,
- L = X,
- lis(X, Rev_input, Y, X, L),
- nl.
- % Used this function to calculate time it takes for mode to reach destination
- timeCalc(Velocity, Dist, TMP) :- TMP is ((Dist / Velocity) * 60).
- % Used this function to add time taken by different modes together
- addTime(TMP, Y, Time) :- Time is TMP + Y.
- % This is where I formatted my output, 'L' are the source and destinations and 'H' is the lenght of time it took in minutes.
- lis([_|[]], _, _, [H|_], L) :- output(L), write(' would take '), write(H), write(' minutes to travel to.'), !.
- lis([H1, H2|T], Rev_input, Y, X, L) :- route(H1, H2, Dist, Mode),
- modeFind(H1, H2, Dist, Mode, Rev_input, Transport),
- mode(Transport, Velocity),
- timeCalc(Velocity, Dist, TMP),
- addTime(TMP, Y, Time),
- lis([H2|T], Rev_input, Time, [Time|X], L).
- modeFind(_, _, _, Mode, Rev_input, Transport) :- string_to_list(Mode, Mode_L),
- modeCheck(Rev_input, Mode_L, Transport).
- modeCheck([H|_], R_mode, Transport) :- member(H, R_mode), !, Transport is H.
- modeCheck([_|T], R_mode, Transport) :- modeCheck(T, R_mode, Transport).
- output([]).
- output([H|[]]) :-
- write(H), !.
- output([H|T]) :-
- write(H),
- write(' --> '),
- output(T).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement