Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1.  
  2. ultimoDaLista([A],A).
  3. ultimoDaLista([_|L], R):- ultimoDaLista(L,R).
  4.  
  5. listIsEmpty([]):-true.
  6. listIsEmpty([_|_]):-false.
  7.  
  8. % pesquisa termina quando a lista de novos elementos estiver vazia (só resta a cidade vizinha)
  9. bnb(A,Cam,Custo):-
  10. %findall(city(B,_,_), (B\==A), New),
  11. city(A,_,_),
  12. bnb2(A,[(0,[A])],Cam,Custo).
  13.  
  14.  
  15. bnb2(A,[(Custo,[A|T])|T2],Cam,Custo):-
  16. Custo > 0,
  17. L = [A|T],
  18. reverse(L,Cam).
  19.  
  20. bnb2(A,[(Ca,LA)|Outros],Cam,Custo):-
  21. %procura todas as cidades q conectam ao destino atual
  22. LA = [X|_],
  23. findall((CaX,[NovaCidade|LA]),(city(NovaCidade,_,_),\+member(NovaCidade, LA),dist_cities(NovaCidade,X, Ca2), CaX is Ca + Ca2),Novos),
  24. ultimoDaLista(LA,U),
  25. (listIsEmpty(Novos),dist_cities(X,U, Dist),Cax2 is Ca+Dist, Novos2 = [(Cax2,[U|LA])], append(Outros,Novos2,Todos);\+listIsEmpty(Novos),append(Outros,Novos,Todos)),
  26. sort(Todos,TodosOrd),
  27. bnb2(A,TodosOrd,Cam,Custo).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement