1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| % ligne(Nom, Liste_des_stations).
ligne(m1, [a1,b1,c1,d1,e1,f1]).
ligne(m2, [a2,b2,c2,d2,e2,f2,g2,h2]).
ligne(m3, [a3,b3,c3,c1,d3,e3,f2,f3,g3,h3,i3]).
% predicat qui recherche la jonction entre deux lignes
jonction(Ligne_1, Ligne_2, Station) :-
ligne(Ligne_1, Stations_1),
ligne(Ligne_2, Stations_2),
Ligne_1 \= Ligne_2,
member(Station, Stations_1),
member(Station, Stations_2).
% predicat qui indique si une Station
% est desservie par une Ligne
dessert(Station, Ligne) :-
ligne(Ligne,Stations),
member(Station, Stations).
% predicat de lancement de recherche
trajet(A, B, P) :-
dessert(B, Ligne),
trajet(A, B, [[Ligne, B]], P).
% predicat effectif de la recherche
% on va de A à B, sachant qu'on a déjà visité
% les stations décrites dans Chemin
%
% Attention, dans la recherche on est en B
% et on veut arriver à A
% En fait la recherche se fait de la fin vers le début
%
% Premier cas les stations sont sur la même ligne
trajet(A, B, Chemin, [[Ligne, A] | Chemin]) :-
Chemin = [[Ligne, B] | _R],
dessert(A, Ligne),
dessert(B, Ligne),
!.
% ici on recherche une jonction entre deux lignes
trajet(A, B, Chemin, Chemin_terminal) :-
Chemin = [[Ligne, B] | _R],
jonction(Ligne, Ligne_1, S),
\+ member([Ligne, S], Chemin),
trajet(A, S, [[Ligne_1, S], [Ligne, S] | Chemin], Chemin_terminal). |
Partager