/* PLAN - program znajdowania trasy polaczen miedzy miastami */ %%% Przeszukiwanie wgłąb z nawrotami droga(krakow,katowice). droga(katowice,opole). droga(wroclaw,opole). droga(krakow,zakopane). droga(krakow,kielce). droga(krakow,tarnow). droga(kielce,radom). droga(radom,warszawa). droga(warszawa,poznan). droga(warszawa,gdansk). droga(warszawa,lodz). droga(poznan,szczecin). droga(poznan,wroclaw). droga(tarnow,rzeszow). droga(rzeszow,lublin). droga(lublin,bialystok). droga(warszawa,bialystok). droga(szczecin,koszalin). droga(koszalin,gdansk). %%% domknięcie symetryczne relacji droga/2 przejazd(X,Y):- droga(X,Y). przejazd(X,Y):- droga(Y,X). p(X,Y):- przejazd(X,Y). %%% Depth-First Strategy: path(F,F,T,T). %%% A path from F to F is defined the current working path T path(I,F,Path,T):- %%% A path from I to F where Path is the current path p(I,N), %write(N), nl, %%% Find a new node N not(member(N,Path)), %%% Check for ne cycle path(N,F,[N|Path],T). %%% A Path from N to F - the last before F go(I,F,Path):- path(I,F,[I],Path). %%% Depth-First Strategy with calculating the depth path(F,F,T,T,D,D). %%% A path from F to F is defined the current working path T path(I,F,Path,T,L,D):- %%% A path from I to F where Path is the current path p(I,N), %write(N), nl, %%% Find a new node N not(member(N,Path)), %%% Check for ne cycle L1 is L+1, path(N,F,[N|Path],T,L1,D). %%% A Path from N to F - the last before F godc(I,F,Path,D):- path(I,F,[I],Path,1,D).