Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. rGraph(Orig,[[Orig,Z]|R],R2):-!,
  2. reorderGraph([[Orig,Z]|R],R2).
  3. rGraph(Orig,R,R3):-
  4. member([Orig,X],R),!,
  5. delete(R,[Orig,X],R2),
  6. reorderGraph([[Orig,X]|R2],R3).
  7. rGraph(Orig,R,R3):-
  8. member([X,Orig],R),
  9. delete(R,[X,Orig],R2),
  10. reorderGraph([[Orig,X]|R2],R3).
  11.  
  12.  
  13. reorderGraph([],[]).
  14. reorderGraph([[X,Y],[Y,Z]|R],[[X,Y]|R1]):-
  15. reorderGraph([[Y,Z]|R],R1).
  16. reorderGraph([[X,Y],[Z,W]|R],[[X,Y]|R2]):-
  17. Y\=Z,
  18. reorderGraph2(Y,[[Z,W]|R],R2).
  19.  
  20. reorderGraph2(_,[],[]).
  21. reorderGraph2(Y,R1,[[Y,Z]|R2]):-
  22. member([Y,Z],R1),!,
  23. delete(R1,[Y,Z],R11),
  24. reorderGraph2(Z,R11,R2).
  25. reorderGraph2(Y,R1,[[Y,Z]|R2]):-
  26. member([Z,Y],R1),
  27. delete(R1,[Z,Y],R11),
  28. reorderGraph2(Z,R11,R2).
  29.  
  30. getCoordenadas(C, L):-
  31. city(C, L1, L2),
  32. L=(L1,L2).
  33.  
  34. segmentation([_], []).
  35. segmentation([H|T], L):-
  36. segmentation(T, LA),
  37. T=[A|_],
  38. append([[H, A]], LA, L).
  39.  
  40. modificarCusto([P1, Q1], [P2, Q2], T, R, CI, CF):-
  41. append([[P2, P1], [Q2, Q1]], T, R),
  42. dist_cities(P1, Q1, C1),
  43. dist_cities(P2, Q2, C2),
  44. dist_cities(P2, P1, C3),
  45. dist_cities(Q2, Q1, C4),
  46. CF is CI - (C1 + C2) + (C3 + C4).
  47.  
  48. elimIntersection([H|T], CI, R, CF):-
  49. elimIntersection_(H, T, R, CI, CF).
  50.  
  51. elimIntersection_(S, [], [S], C, C).
  52. elimIntersection_([P1,Q1], [[P2,Q2]|T], R, CI, CF):-
  53. getPosition(P1,L1),
  54. getPosition(Q1,L2),
  55. getPosition(P2,L3),
  56. getPosition(Q2,L4),
  57. P1\==Q1,
  58. P1\==Q2,
  59. P2\==Q1,
  60. P2\==Q2,
  61. doIntersect(L1, L2, L3, L4),
  62. modificarCusto([P1,Q1], [P2,Q2], T, R, CI, CF).
  63.  
  64. elimIntersection(S, [H|T], R, CI, CF):-
  65. findIntersection(S, T, R1, CI, CF),
  66. append([H], R1, R).
  67.  
  68. tsp3(Orig,Cam,Custo):-
  69. tsp2_(Orig,(_,0,[Orig]),Cam1,Custo1),
  70. segmentation(Cam1, S),
  71. elimIntersection(S, Custo1, R, Custo),
  72. rGraph(Orig, R, Cam),
  73. !.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement