Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. // Example of logic programming Petri net (LPPN)
  3. /////////////////////////////////////////////////////////////////////////////////////////
  4. //
  5. // e2 c1(A) e1(A) c2(A) c5(A)
  6. // [ t2 ]<----( p1 )---->[ t1 ]---->( p2 )---->[*dt1*]---->( p5 )
  7. // |
  8. // v
  9. // (*dp1*)
  10. // |
  11. // v
  12. // ( p4 )---->[ t3 ]---->( p3 )
  13. // c4(B) e3(A) c3(A, B)
  14. //
  15. //
  16. // with only c1(a) in p1
  17. // expected execution paths:
  18. // c1(a) --e2--> not c1(a)
  19. // c1(a) --e1(a)--> not c1(a), c2(a), c5(a)
  20. //
  21. // with also c4(b) in p4
  22. // c1(a) --e2--> not c1(a)
  23. // c1(a) --e1(a), e3(a)--> not c1(a), c2(a), c5(a), not c4(b), c3(a, b)
  24. //
  25. /////////////////////////////////////////////////////////////////////////////////////////
  26.  
  27. // define a temporal range for the execution
  28. time(0..1).
  29.  
  30. #domain fluent(F), event(E), time(N), time(N1), time(N2), time(N3).
  31. #domain place(P), trans(T), trans(T1), trans(T2).
  32.  
  33. holdsAt(F, P, N) :-
  34. initially(F, P),
  35. not clipped(0, F, P, N).
  36. holdsAt(F, P, N2) :- firesAt(E, T, N1), N1 < N2,
  37. initiates(T, F, P, N1),
  38. not clipped(N1, F, P, N2).
  39. clipped(N1, F, P, N2) :- firesAt(E, T, N), N1 <= N, N < N2,
  40. terminates(T, F, P, N).
  41.  
  42. // execution semantics
  43. {prefiresAt(T, N)} :- enabled(T, N), safe(T).
  44. someTransitionPrefiresAt(N) :- prefiresAt(T, N).
  45. :- N > 0, not someTransitionPrefiresAt(N-1).
  46. :- prefiresAt(T1, N), prefiresAt(T2, N), T1 != T2.
  47.  
  48. #domain a(A), b(B).
  49.  
  50. // for each positive literal for place labels, type it as fluent (condition)
  51. fluent(c1(A)).
  52. fluent(c2(A)).
  53. fluent(c3(A, B)).
  54. fluent(c4(B)).
  55. fluent(c5(A)).
  56.  
  57. // for each positive literal for event labels, type it as event
  58. event(e1(A)).
  59. event(e2).
  60. event(e3(A)).
  61.  
  62. // for each place, type it and say how it is initially filled, type the identifiers
  63. place(p1). initially(c1(a), p1). a(a).
  64. place(p2).
  65. place(p3).
  66. place(p4). initially(c4(b), p4). b(b).
  67.  
  68. // for each place, type it and say if it is safe or not
  69. trans(t1). safe(t1).
  70. trans(t2). safe(t2).
  71. trans(t3).
  72.  
  73. // for each place with more than one input,
  74. // you cannot consume more than the only available token
  75. :- 2{terminates(t1, c1(A), p1, N), terminates(t2, c1(A), p1, N)}.
  76.  
  77. // for each transition,
  78. // define the conditions for being enabled
  79. enabled(t1, N) :- holdsAt(c1(A), p1, N).
  80. enabled(t2, N) :- holdsAt(c1(A), p1, N).
  81. enabled(t3, N) :- holdsAt(c4(B), p4, N).
  82.  
  83. // for each transition,
  84. // define how the substitution is decided
  85. appliesAt(t1, subs(A), N) :- holdsAt(c1(A), p1, N), firesAt(e1(A), t1, N).
  86. appliesAt(t2, subs(A), N) :- holdsAt(c1(A), p1, N), firesAt(e2, t2, N).
  87. appliesAt(t3, subs(A, B), N) :- holdsAt(c4(B), p4, N), firesAt(e3(A), t3, N).
  88.  
  89. // for each safe transition,
  90. // define the conditions for transforming the prefiring in firing
  91. firesAt(e1(A), t1, N) :- holdsAt(c1(A), p1, N), prefiresAt(t1, N).
  92. firesAt(e2, t2, N) :- holdsAt(c1(A), p1, N), prefiresAt(t2, N).
  93.  
  94. // for each transition,
  95. // define how to create tokens in the output places
  96. initiates(t1, c2(A), p2, N) :- appliesAt(t1, subs(A), N).
  97. initiates(t3, c3(A, B), p3, N) :- appliesAt(t3, subs(A, B), N).
  98.  
  99. // for each transition, define how to consume tokens in the output places
  100. terminates(t1, c1(A), p1, N) :- appliesAt(t1, subs(A), N).
  101. terminates(t2, c1(A), p1, N) :- appliesAt(t2, subs(A), N).
  102. terminates(t3, c4(B), p4, N) :- appliesAt(t3, subs(A, B), N).
  103.  
  104. // for each logic operator on places, specify the constraint
  105. holdsAt(c5(A), p5, N) :- holdsAt(c2(A), p2, N).
  106.  
  107. // for each logic operator on transitions, specify the constraint
  108. firesAt(e3(A), t3, N) :- holdsAt(c4(B), p4, N), firesAt(e1(A), t1, N).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement