dslreports logo
site
 
    All Forums Hot Topics Gallery
spc

spacer




how-to block ads


Search Topic:
uniqs
949
share rss forum feed

giuprolog

join:2012-09-04

Help me program in prolog!

I am not an expert in logic programming and Prolog and I'm struggling with this project to make the university "taking pleasure in a domain, write two programs that make, one depth-first search and another in breadth" ... I have chosen as domain a journey through the various Italian cities, place the following code:
arc_weighed(roma,firenze,3).
arc_weighed(firenze,genova,3).
arc_weighed(genova,torino,2).
arc_weighed(torino,milano,2).
arc_weighed(torino,aosta,1).
arc_weighed(firenze,bologna,2).
arc_weighed(bologna,venezia,2).
arc_weighed(venezia,trento,2).
arc_weighed(venezia,trieste,2).
arc_weighed(napoli,potenza,2).
arc_weighed(palermo,cagliari,9).
arc_weighed(potenza,bari,2).
arc_weighed(potenza,catanzaro,4).
arc_weighed(catanzaro,palermo,5).
arc_weighed(roma,laquila,1).
arc_weighed(laquila,campobasso,3).
arc_weighed(laquila,ancona,2).
arc_weighed(campobasso,napoli,2).
 
calculated_route:- write('Hi, welcome we give in to our travel agency virtuale.Le propose, starting from Rome an interesting tourist route.'), write('Enter capital of arrival:'),nl, read(X), search_loc('roma',X).
 
search_loc(X,X):-  write('Already here, good sightseeing!'),nl.
 
search_loc(X,Y):-search(X,Y,L,[X],Costo), reverse_append(L,_),write('. To take this route:'), write(Costo), write(' hours.') .
 
search(X,X,L,L,0).
search(X,Y,L,P,O):- arc_weighed(X,W,C),ricerca(W,Y,L,[W|P],K),weighted_path(C,K,O).
 
reverse_append([],[]).
reverse_append([A|C],Q):-reverse_append(C,K),
append(K,[A],Q),write(A), write(' ').
 
weighted_path(A,C,Costo):- Costo is C+A.
 
not(X):- X,!,fail.
not(_).
 :uhh:
 

with this code I do I make a journey .. how can I make the two different research?
Can you help me in writing algorithms? thank you! :)