SHARE
TWEET

Untitled

a guest Jun 18th, 2019 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #const bound = 14.
  2. time(1..bound).
  3.  
  4. % hay 5 acciones posibles
  5. action(up).
  6. action(down).
  7. action(left).
  8. action(right).
  9. action(wait).
  10.  
  11.  
  12. %exec(R,A,T) significa que R ejecuta la accion A en T
  13.  
  14. %R está en (X,Y) en tiempo T si es que R está en Xp,Yp en T-1 y
  15. %ejecutas A y X,Y se obtiene del delta
  16. on(R,X-1,Y,T) :- exec(R,left,T-1),on(R,X,Y,T-1),time(T),rangeX(X),rangeY(Y).
  17. on(R,X+1,Y,T) :- exec(R,right,T-1),on(R,X,Y,T-1),time(T),rangeX(X),rangeY(Y).
  18. on(R,X,Y+1,T) :- exec(R,up,T-1),on(R,X,Y,T-1),time(T),rangeX(X),rangeY(Y).
  19. on(R,X,Y-1,T) :- exec(R,down,T-1),on(R,X,Y,T-1),time(T),rangeX(X),rangeY(Y).
  20. on(R,X,Y,T)   :- exec(R,wait,T-1),on(R,X,Y,T-1),time(T),rangeX(X),rangeY(Y).
  21.  
  22. %up(X,Y,T) :- on(R,X,Y,T), on(R,X,Y+1,T+1).
  23. %down(X,Y,T) :- on(R,X,Y,T), on(R,X,Y-1,T+1).
  24. %left(X,Y,T) :- on(R,X,Y,T), on(R,X-1,Y,T+1).
  25. %right(X,Y,T) :- on(R,X,Y,T), on(R,X+1,Y,T+1).
  26. %stay(X,Y,T) :- on(R,X,Y,T), on(R,X,Y,T+1).
  27.  
  28. up(X,Y,T) :- exec(R,up,T), on(R,X,Y,T).
  29. down(X,Y,T) :- exec(R,down,T), on(R,X,Y,T).
  30. left(X,Y,T) :- exec(R,left,T),on(R,X,Y,T).
  31. right(X,Y,T) :- exec(R,right,T),on(R,X,Y,T).
  32. stay(X,Y,T) :- exec(R,wait,T), on(R,X,Y,T).
  33.  
  34. % Cada robot ejecuta una acción en cada instante de tiempo en 0..bound-1
  35. 1 {exec(R,A,T-1) : action(A)} 1 :- robot(R),time(T).
  36.  
  37. % no hay dos robots en la misma ubicación (R1: MODIFICAR PARTE 1)
  38.  
  39. %:- on(R,X,Y,T),on(Rp,X,Y,T),R!=Rp.
  40.  
  41. :- stay(X,Y,T), right(X-1, Y, T).
  42. :- stay(X,Y,T), left(X+1, Y, T).
  43. :- stay(X,Y,T), down(X, Y+1, T).
  44. :- stay(X,Y,T), up(X, Y-1, T).
  45.  
  46. :- right(X,Y,T), up(X+1,Y-1,T).
  47. :- right(X,Y,T), down(X+1,Y+1,T).
  48. :- right(X,Y,T), left(X+2,Y,T).
  49.  
  50. :- left(X,Y,T), up(X-1,Y-1,T).
  51. :- left(X,Y,T), down(X-1,Y+1,T).
  52.  
  53. :- up(X,Y,T), down(X,Y+2, T).
  54.  
  55.  
  56. % dos robots no se pueden 'intercambiar' (R2: MODIFICAR PARTE 1) (NUEVO)
  57. %:- on(R1,X1+1,Y1,T-1), on(R2,X1,Y1,T-1), on(R1,X1,Y1,T), on(R2,X1+1,Y1,T).
  58. %:- on(R1,X1,Y1+1,T-1), on(R2,X1,Y1,T-1), on(R1,X1,Y1,T), on(R2,X1,Y1+1,T).
  59.  
  60. :- up(X,Y,T), down(X, Y+1, T).
  61. :- left(X,Y,T), right(X-1, Y, T).
  62.  
  63. % no hay un robot sobre un obstáculo
  64. :- on(R,X,Y,T),obstacle(X,Y).
  65.  
  66. % no hay robots fuera de la grilla
  67. %rangeX(X), rangeY(Y):- on(R,X,Y,T).
  68. :- on(R,X,Y,T),not rangeX(X).
  69. :- on(R,X,Y,T),not rangeY(Y).
  70.  
  71. % goal_achieved(R,T): robot R está en su objetivo en el tiempo T (NUEVO)
  72. goal_achieved(R,T) :- on(R,X,Y,T),goal(R,X,Y).
  73.  
  74. % pedimos que todo robot haya llegado al objetivo (NUEVO)
  75. :- robot(R),not goal_achieved(R,bound).
  76.  
  77.  
  78. % los siguientes predicados es necesario mostrarlos para el visualizador
  79. #show on/4.
  80. #show obstacle/2.
  81. #show rangeX/1.
  82. #show rangeY/1.
  83. #show exec/3.
  84. #show goal/3.
  85.  
  86. %%%%% Definición del problema
  87.  
  88. % entre que valores se mueven X e Y
  89. rangeX(0..6).
  90. rangeY(0..7).
  91.  
  92. %% obstacle(X,Y): celda (X,Y) es un obstáculo
  93. obstacle(1,1..6).
  94. obstacle(3,1..6).
  95. obstacle(5,1..6).
  96.  
  97. %% definimos los robots
  98. robot(1..12).
  99.  
  100. % la posición inicial (tiempo 0) de cada robot
  101. on(1,0,0,0).
  102. on(2,2,0,0).
  103. on(3,4,0,0).
  104. on(4,6,0,0).
  105. on(5,0,7,0).
  106. on(6,2,7,0).
  107. on(7,4,7,0).
  108. on(8,6,7,0).
  109. on(9,0,3,0).
  110. on(10,0,4,0).
  111. on(11,6,3,0).
  112. on(12,6,4,0).
  113.  
  114. % goal(R,X,Y): el robot R debe llegar a (X,Y)
  115. goal(1,0,7).
  116. goal(2,2,7).
  117. goal(3,4,7).
  118. goal(4,6,7).
  119. goal(5,0,0).
  120. goal(6,2,0).
  121. goal(7,4,0).
  122. goal(8,6,0).
  123. goal(9,6,3).
  124. goal(10,6,4).
  125. goal(11,0,3).
  126. goal(12,0,4).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top