Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #include <incmode>.
  2.  
  3. #program base.
  4.  
  5. cargo(c1; c2).
  6.  
  7. plane(p1; p2).
  8.  
  9. airport(jfk; sfo).
  10.  
  11. init(at(c1,sfo)). % il cargo c1 è nell'aereoporto sfo.
  12. init(at(c2,jfk)). % il cargo c2 è nell'aereoporto jfk.
  13. init(at(p1,sfo)). % l'aereo p1 è nell'aereoporto sfo.
  14. init(at(p2,jfk)). % l'aereo p2 è nell'aereoporto jfk.
  15.  
  16. goal(at(c1,jfk)). % il cargo c1 è nell'aereoporto jfk.
  17. goal(at(c2,sfo)). % il cargo c2 è nell'aereporto sfo.
  18.  
  19. holds(F, 0) :- init(F).
  20.  
  21. #program step(t).
  22.  
  23. 1 { load(C, P, A, t): cargo(C), plane(P), airport(A); unload(C, P, A, t): cargo(C), plane(P), airport(A); fly(P, FROM, TO, t): plane(P), airport(FROM), airport(TO), FROM != TO} 1.
  24.  
  25. holds(F, t) :- holds(F, t - 1), not -holds(F, t).
  26. -holds(F, t) :- -holds(F, t - 1), not holds(F, t).
  27.  
  28. % Azione Load.
  29. % Se effettuo una azione di load di un cargo sull'aereoplano, il cargo P si troverà sull'aereo P.
  30. holds(in(C, P), t) :- cargo(C), plane(P), load(C, P, A, t).
  31. -holds(at(C, A), t) :- cargo(C), airport(A), load(C, P, A, t).
  32.  
  33. % Azione Unload.
  34. %
  35. holds(at(C, A), t) :- cargo(C), airport(A), unload(C, P, A, t).
  36. -holds(in(C, P), t) :- cargo(C), plane(P), unload(C, P, A, t).
  37.  
  38. % Azione Fly.
  39. %
  40. holds(at(P, TO), t) :- fly(P, FROM, TO, t).
  41. -holds(at(P, FROM), t) :- fly(P, FROM, TO, t).
  42.  
  43. %% TEST
  44.  
  45. % Constraints su load.
  46. % Escludo l'azione di load al tempo t se il cargo C si trova nell'aereoporto A1 al tempo t - 1 e l'aereo P si trova nell'aereoporto A2 e A1 è diverso da A2.
  47. :- load(C, P, A, t), holds(at(C, A1), t - 1), holds(at(P, A2), t - 1), A1 != A2.
  48. % Escludo l'azione di load al tempo t se il cargo C non si trova nello stesso aereoporto dell'aereo P.
  49. :- load(C, P, A, t), holds(at(C, A1), t - 1), A != A1.
  50. % Escludo l'azione di load al tempo t se l'aereo P non si trova nello stesso aereoporto del cargo C.
  51. :- load(C, P, A, t), holds(at(P, A2), t - 1), A != A2.
  52. % Escludo l'azione di load al tempo t se ho già caricato al tempo t - 1 senza aver prima scaricato.
  53. :- load(C, P, A, t), holds(in(_, P), t - 1).
  54. % Escludo l'azione di load al tempo t se al tempo t - 1 ho caricato lo stesso cargo.
  55. :- load(C, P, A, t), holds(in(C, _), t - 1).
  56.  
  57. % Constraints su unload.
  58. % Escludo l'azione di unload se l'aereo P non si trova nell'aereoporto A.
  59. :- unload(C, P, A, t), not holds(at(P, A), t - 1).
  60. % Escludo l'azione di unload se il cargo C non è un su P.
  61. :- unload(C, P, A, t), not holds(in(C, P), t - 1).
  62.  
  63. % Constraints su fly.
  64. % Se l'aereo P non si trova nell'aereoporto FROM, allora non può volare dall'aereoporto FROM all'aereoporto TO.
  65. :- fly(P, FROM, TO, t), not holds(at(P, FROM), t - 1).
  66.  
  67. #program check(t).
  68.  
  69. :- query(t), goal(F), not holds(F, t).
  70.  
  71. %% OUTPUT
  72.  
  73. #show load/4.
  74. #show fly/4.
  75. #show unload/4.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement