Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #define N 3
  2.  
  3. mtype = { red , green }
  4. mtype sem1 = red , sem2 = red , sem3 = red ; // three semaphores
  5. bool s0 , s1 , s2 , s3 ; // four presence sensors
  6. bool sensors[4];
  7. byte countZ0 , countZ1 , countZ2 , countZ3 ; // count the vehicles in each zone
  8. mtype sem[3];
  9. int number;
  10. byte countZ[4];
  11. byte ghost1, ghost2,ghost3;
  12.  
  13. ltl mutual_exclusion { []((ghost1+ghost2+ghost3)<2) }
  14. //ltl ficar_verde {<>(sem1==green || sem2==green || sem3==green )}
  15. proctype Sensors () {
  16. do
  17. :: sensors[0] = ( countZ[0] > 0)
  18. :: sensors[1] = ( countZ[1] > 0)
  19. :: sensors[2] = ( countZ[2] > 0)
  20. :: sensors[3] = ( countZ[3] > 0)
  21. od
  22. }
  23.  
  24.  
  25. proctype RoadsideUnit () {
  26. do
  27. ::if
  28. :: (sensors[0] == 0 && sensors[1] == 1 && sensors[2] == 0 && sensors[3] == 0) -> sem3 = red; sem2 = red; sem1 = green
  29. :: (sensors[0] == 0 && sensors[1] == 0 && sensors[2] == 1 && sensors[3] == 0) -> sem1 = red; sem3 = red; sem2 = green
  30. :: (sensors[0] == 0 && sensors[1] == 0 && sensors[2] == 0 && sensors[3] == 1) -> sem2 = red; sem1 = red; sem3 = green
  31.  
  32. :: (sensors[0] == 0 && sensors[1] == 1 && sensors[2] == 1 && sensors[3] == 0) -> sem3 = red; sem2 = red; sem1 = green
  33. :: (sensors[0] == 0 && sensors[1] == 0 && sensors[2] == 1 && sensors[3] == 1) -> sem1 = red; sem3 = red; sem2 = green
  34. :: (sensors[0] == 0 && sensors[1] == 1 && sensors[2] == 0 && sensors[3] == 1) -> sem2 = red; sem1 = red; sem3 = green
  35. :: (sensors[0] == 0 && sensors[1] == 1 && sensors[2] == 1 && sensors[3] == 1) -> sem3 = red; sem2 = red; sem1 = green
  36. fi
  37. od
  38. }
  39.  
  40. proctype Vehicles () {
  41. do
  42. ::if
  43. :: (countZ[0]+countZ[1]+countZ[2]+countZ[3])<N -> select(number: 1 .. 3); countZ[number]++
  44. :: (sem1 == green && countZ[1] > 0 ) -> countZ[1] = countZ[1] - 1; ghost1 = 1; countZ[0] = countZ[0] + 1
  45. :: (sem2 == green && countZ[2] > 0 ) -> countZ[2] = countZ[2] - 1; ghost2 = 1; countZ[0] = countZ[0] + 1
  46. :: (sem3 == green && countZ[3] > 0 ) -> countZ[3] = countZ[3] - 1; ghost3 = 1; countZ[0] = countZ[0] + 1
  47. :: (countZ[0] > 0) -> countZ[0] = countZ[0] - 1 //Rever
  48. :: (countZ[0] == 0) -> ghost1=0; ghost2=0; ghost3=0 // ; sem1=red; sem2=red; sem3=red
  49. ;
  50. fi
  51. od
  52. }
  53. init {
  54.  
  55.  
  56. run Sensors ();
  57. run RoadsideUnit ();
  58. run Vehicles ();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement