You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
5.3 KiB

  1. // GRID WORLD MODEL OF ROBOT AND JANITOR
  2. // Hakan Younes/gxn/dxp 04/05/04
  3. // Variant by Sebastian Junges, RWTH Aachen University
  4. // As described in
  5. // Junges, Jansen, Dehnert, Topcu, Katoen:
  6. // Safety Constrained Reinforcement Learning
  7. // Proc. of TACAS16
  8. mdp
  9. // PARAMETERS: Probability that the janitor moves North, South, East or West
  10. const double jProbN;
  11. const double jProbE;
  12. const double jProbS = 1 - jProbN;
  13. const double jProbW = 1 - jProbE;
  14. // CONSTANTS
  15. const int xSize = 6; // size of the grid
  16. const int ySize = 6;
  17. const int jXmin = 1; // janitor area
  18. const int jXmax = 6;
  19. const int jYmin = 1;
  20. const int jYmax = 6;
  21. const int maxSteps = 15;
  22. formula T = (xR = xSize & yR = ySize);
  23. formula C = (xR = xJ & yR = yJ);
  24. module counter
  25. count : [0..maxSteps] init 0;
  26. [forward] (count<maxSteps & !C) -> 1:(count'=count+1);
  27. [turnLeft] (count<maxSteps & !C) -> 1:(count'=count+1);
  28. [turnRight] (count<maxSteps & !C) -> 1:(count'=count+1);
  29. [forward] (count<maxSteps & C) -> 1:(count'=maxSteps);
  30. [turnLeft] (count<maxSteps & C) -> 1:(count'=maxSteps);
  31. [turnRight] (count<maxSteps & C) -> 1:(count'=maxSteps);
  32. [forward] (count=maxSteps) -> 1:true;
  33. [turnLeft] (count=maxSteps) -> 1:true;
  34. [turnRight] (count=maxSteps) -> 1:true;
  35. endmodule
  36. module robot
  37. xR : [1..xSize] init 1;
  38. yR : [1..ySize] init 1;
  39. d: [0..3] init 0;
  40. [forward] (d=0 & yR < ySize & !T) -> 1:(yR'=yR+1);
  41. [forward] (d=2 & yR > 1 & !T) -> 1:(yR'=yR-1);
  42. [forward] (d=1 & xR < xSize & !T) -> 1:(xR'=xR+1);
  43. [forward] (d=3 & xR > 1 & !T) -> 1:(xR'=xR-1);
  44. //[backward] (d=0 & yR > 1 & !T) -> 1:(yR'=yR-1);
  45. //[backward] (d=2 & yR < ySize & !T) -> 1:(yR'=yR+1);
  46. //[backward] (d=1 & xR > 1 & !T) -> 1:(xR'=xR-1);
  47. //[backward] (d=3 & xR < xSize & !T) -> 1:(xR'=xR+1);
  48. [turnLeft] (d>0 & !T) -> 1:(d'=d-1);
  49. [turnLeft] (d=0 & !T) -> 1:(d'=3);
  50. [turnRight] (d=3 & !T) -> 1:(d'=0);
  51. [turnRight] (d<3 & !T) -> 1:(d'=d+1);
  52. // [turnLeft] (d=1) -> 1:(d=0);
  53. // [turnRight] (d=0) -> 1:(d=1);
  54. [done] T -> 1:true;
  55. endmodule
  56. // The Janitor moves probabilistically within the grid.
  57. module janitor
  58. xJ : [jXmin..jXmax] init jXmax; // x position of janitor
  59. yJ : [jYmin..jYmax] init jYmin; // y position of janitor
  60. [forward] (yJ=jYmax & xJ=jXmax) -> 0.5:(yJ'=yJ-1) + 0.5:(xJ'=xJ-1);
  61. [forward] (yJ=jYmax & xJ=jXmin) -> 0.5:(yJ'=yJ-1) + 0.5:(xJ'=xJ+1);
  62. [forward] (yJ=jYmax & xJ<jXmax & xJ > jXmin) -> 0.3333:(yJ'=yJ-1) + 0.6667*jProbW:(xJ'=xJ-1) + 0.6667*jProbE:(xJ'=xJ+1);
  63. [forward] (yJ=jYmin & xJ=jXmax) -> 0.5:(yJ'=yJ+1) + 0.5:(xJ'=xJ-1);
  64. [forward] (yJ=jYmin & xJ=jXmin) -> 0.5:(yJ'=yJ+1) + 0.5:(xJ'=xJ+1);
  65. [forward] (yJ=jYmin & xJ<jXmax & xJ>jXmin) -> 0.3333:(yJ'=yJ+1) + 0.6667*jProbW:(xJ'=xJ-1) + 0.6667*jProbE:(xJ'=xJ+1);
  66. [forward] (yJ<jYmax & yJ>jYmin & xJ=jXmax) -> 0.6667*jProbN:(yJ'=yJ+1) + 0.6667*jProbS:(yJ'=yJ-1) + 0.3333:(xJ'=xJ-1);
  67. [forward] (yJ<jYmax & yJ>jYmin & xJ=jXmin) -> 0.6667*jProbN:(yJ'=yJ+1) + 0.6667*jProbS:(yJ'=yJ-1) + 0.3333:(xJ'=xJ+1);
  68. [forward] (yJ<jYmax & yJ>jYmin & xJ<jXmax & xJ>jXmin) -> 0.5*jProbS:(yJ'=yJ-1) + 0.5*jProbN:(yJ'=yJ+1) + 0.5*jProbW:(xJ'=xJ-1) + 0.5*jProbE:(xJ'=xJ+1);
  69. [turnLeft] (yJ=jYmax & xJ=jXmax) -> 0.5:(yJ'=yJ-1) + 0.5:(xJ'=xJ-1);
  70. [turnLeft] (yJ=jYmax & xJ=jXmin) -> 0.5:(yJ'=yJ-1) + 0.5:(xJ'=xJ+1);
  71. [turnLeft] (yJ=jYmax & xJ<jXmax & xJ > jXmin) -> 0.3333:(yJ'=yJ-1) + 0.6667*jProbW:(xJ'=xJ-1) + 0.6667*jProbE:(xJ'=xJ+1);
  72. [turnLeft] (yJ=jYmin & xJ=jXmax) -> 0.5:(yJ'=yJ+1) + 0.5:(xJ'=xJ-1);
  73. [turnLeft] (yJ=jYmin & xJ=jXmin) -> 0.5:(yJ'=yJ+1) + 0.5:(xJ'=xJ+1);
  74. [turnLeft] (yJ=jYmin & xJ<jXmax & xJ>jXmin) -> 0.3333:(yJ'=yJ+1) + 0.6667*jProbW:(xJ'=xJ-1) + 0.6667*jProbE:(xJ'=xJ+1);
  75. [turnLeft] (yJ<jYmax & yJ>jYmin & xJ=jXmax) -> 0.6667*jProbN:(yJ'=yJ+1) + 0.6667*jProbS:(yJ'=yJ-1) + 0.3333:(xJ'=xJ-1);
  76. [turnLeft] (yJ<jYmax & yJ>jYmin & xJ=jXmin) -> 0.6667*jProbN:(yJ'=yJ+1) + 0.6667*jProbS:(yJ'=yJ-1) + 0.3333:(xJ'=xJ+1);
  77. [turnLeft] (yJ<jYmax & yJ>jYmin & xJ<jXmax & xJ>jXmin) -> 0.5*jProbS:(yJ'=yJ-1) + 0.5*jProbN:(yJ'=yJ+1) + 0.5*jProbW:(xJ'=xJ-1) + 0.5*jProbE:(xJ'=xJ+1);
  78. [turnRight] (yJ=jYmax & xJ=jXmax) -> 0.5:(yJ'=yJ-1) + 0.5:(xJ'=xJ-1);
  79. [turnRight] (yJ=jYmax & xJ=jXmin) -> 0.5:(yJ'=yJ-1) + 0.5:(xJ'=xJ+1);
  80. [turnRight] (yJ=jYmax & xJ<jXmax & xJ > jXmin) -> 0.3333:(yJ'=yJ-1) + 0.6667*jProbW:(xJ'=xJ-1) + 0.6667*jProbE:(xJ'=xJ+1);
  81. [turnRight] (yJ=jYmin & xJ=jXmax) -> 0.5:(yJ'=yJ+1) + 0.5:(xJ'=xJ-1);
  82. [turnRight] (yJ=jYmin & xJ=jXmin) -> 0.5:(yJ'=yJ+1) + 0.5:(xJ'=xJ+1);
  83. [turnRight] (yJ=jYmin & xJ<jXmax & xJ>jXmin) -> 0.3333:(yJ'=yJ+1) + 0.6667*jProbW:(xJ'=xJ-1) + 0.6667*jProbE:(xJ'=xJ+1);
  84. [turnRight] (yJ<jYmax & yJ>jYmin & xJ=jXmax) -> 0.6667*jProbN:(yJ'=yJ+1) + 0.6667*jProbS:(yJ'=yJ-1) + 0.3333:(xJ'=xJ-1);
  85. [turnRight] (yJ<jYmax & yJ>jYmin & xJ=jXmin) -> 0.6667*jProbN:(yJ'=yJ+1) + 0.6667*jProbS:(yJ'=yJ-1) + 0.3333:(xJ'=xJ+1);
  86. [turnRight] (yJ<jYmax & yJ>jYmin & xJ<jXmax & xJ>jXmin) -> 0.5*jProbS:(yJ'=yJ-1) + 0.5*jProbN:(yJ'=yJ+1) + 0.5*jProbW:(xJ'=xJ-1) + 0.5*jProbE:(xJ'=xJ+1);
  87. endmodule
  88. rewards "mvbased"
  89. [forward] true: 5;
  90. //[backward] true: 10;
  91. [turnLeft] true: 25;
  92. [turnRight] true: 28;
  93. endrewards
  94. rewards "mvbased_upper"
  95. [forward] true: 30;
  96. //[backward] true: 35;
  97. [turnLeft] true: 40;
  98. [turnRight] true: 40;
  99. endrewards
  100. rewards "mvbased_lower"
  101. [forward] true: 4;
  102. //[backward] true: 4;
  103. [turnLeft] true: 8;
  104. [turnRight] true: 8;
  105. endrewards
  106. label "Target" = T & (count<maxSteps) & !C;
  107. label "Crash" = C;