SHARE
TWEET

Untitled

a guest Feb 17th, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. route(a,d,1).
  2. route(a,h,1).
  3. route(a,b,1).
  4. route(b,e,1).
  5. route(b,c,1).
  6. route(c,f,1).
  7. route(c,e,1).
  8. route(f,i,1).
  9. route(f,h,1).
  10. route(e,d,1).
  11. route(d,g,1).
  12. route(g,j,1).
  13. route(g,l,1).
  14. route(h,k,1).
  15. route(i,k,1).
  16. route(i,l,1).
  17. route(j,m,1).
  18. route(j,o,1).
  19. route(k,n,1).
  20. route(l,m,1).
  21. route(l,o,1).
  22. route(m,n,1).
  23. route(n,o,1).
  24.  
  25. ha_path(A, B) :-route(A, B, _), !.
  26. ha_path(A, B) :-route(A, X, _), ha_path(X, B).
  27.  
  28. %--------------------------------------------------------
  29.  
  30. crossing(A, B,Visited,[B|Visited]) :-route(A, B,_).
  31. crossing(A, B, Visited, Cam) :-route(A, C, _),
  32.                              C == B,
  33.                              + member(C, Visited),
  34.                              crossing(C, B, [C|Visited], Cam).
  35.  
  36. %------------------------------------------------
  37.  
  38. %Find the ways and the cost between two nodes.
  39.  
  40. path(A, B, Cam) :- crossing(A, B, [A], Cam).
  41. paths(A, B, Lc) :-setof(Cam, path(A, B, Cam), Lc), !.
  42. paths(_,_,[]).
  43.  
  44. costPath(A, B, Cam, Cost) :-crossingCost(A, B, [A], Cam, Cost).
  45. crossingCost(A, B, Visited,[B|Visited],Cost1) :-route(A, B, Cost1).
  46. crossingCost(A, B, Visited, Cam, Cost) :-route(A, C, Cost2)
  47.                                        ,C == B,+ member(C, Visited)
  48.                      ,crossingCost(C, B, [C|Visited], Cam, CostResto)
  49.                      ,Cost is Cost2 + CostResto.
  50.    
  51. %----------------------------------------------------
  52. %Find the paths and cost between two points.
  53.  
  54. costPaths(A, B, Lc) :-
  55. setof(Cam/Cost,costPath(A,B,Cam,Cost), Lc), !.
  56. costPaths(_,_,[]).
  57.  
  58. %---------------------------------------------------
RAW Paste Data
Top