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.

659 lines
47 KiB

10 months ago
10 months ago
10 months ago
10 months ago
  1. #include "PrismModulesPrinter.h"
  2. #include <map>
  3. #include <string>
  4. #define NOFAULT -1
  5. #define LEFT 0
  6. #define RIGHT 1
  7. #define FORWARD 2
  8. std::string northUpdate(const AgentName &a) { return "(row"+a+"'=row"+a+"-1)"; }
  9. std::string southUpdate(const AgentName &a) { return "(row"+a+"'=row"+a+"+1)"; }
  10. std::string eastUpdate(const AgentName &a) { return "(col"+a+"'=col"+a+"+1)"; }
  11. std::string westUpdate(const AgentName &a) { return "(col"+a+"'=col"+a+"-1)"; }
  12. namespace prism {
  13. PrismModulesPrinter::PrismModulesPrinter(std::ostream& os, const ModelType &modelType, const coordinates &maxBoundaries, const cells &boxes, const cells &balls, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const AgentNameAndPositionMap &agentNameAndPositionMap, std::vector<Configuration> config, const float probIntended, const float faultyProbability, const bool anyLava, const bool anyGoals)
  14. : os(os), modelType(modelType), maxBoundaries(maxBoundaries), boxes(boxes), balls(balls), lockedDoors(lockedDoors), unlockedDoors(unlockedDoors), keys(keys), slipperyTiles(slipperyTiles), agentNameAndPositionMap(agentNameAndPositionMap), configuration(config), probIntended(probIntended), faultyProbability(faultyProbability), anyLava(anyLava), anyGoals(anyGoals) {
  15. numberOfPlayer = agentNameAndPositionMap.size();
  16. size_t index = 0;
  17. for(auto begin = agentNameAndPositionMap.begin(); begin != agentNameAndPositionMap.end(); begin++, index++) {
  18. agentIndexMap[begin->first] = index;
  19. }
  20. }
  21. void PrismModulesPrinter::printModelType(const ModelType &modelType) {
  22. switch(modelType) {
  23. case(ModelType::MDP):
  24. os << "mdp";
  25. break;
  26. case(ModelType::SMG):
  27. os << "smg";
  28. break;
  29. }
  30. os << "\n\n";
  31. }
  32. std::ostream& PrismModulesPrinter::print() {
  33. for(const auto [agentName, initialPosition] : agentNameAndPositionMap) {
  34. agentNameActionMap[agentName] = {};
  35. }
  36. for(const auto &key : keys) {
  37. printPortableObjectModule(key);
  38. }
  39. for(const auto &ball : balls) {
  40. printPortableObjectModule(ball);
  41. }
  42. for(const auto &box : boxes) {
  43. printPortableObjectModule(box);
  44. }
  45. for(const auto &door : unlockedDoors) {
  46. printDoorModule(door, true);
  47. }
  48. for(const auto &door : lockedDoors) {
  49. printDoorModule(door, false);
  50. }
  51. for(const auto [agentName, initialPosition] : agentNameAndPositionMap) {
  52. printRobotModule(agentName, initialPosition);
  53. }
  54. if(agentNameAndPositionMap.size() > 1) {
  55. printMoveModule();
  56. }
  57. if(faultyBehaviour()) {
  58. for(const auto [agentName, initialPosition] : agentNameAndPositionMap) {
  59. printFaultyMovementModule(agentName);
  60. }
  61. }
  62. if(agentNameAndPositionMap.size() > 1) {
  63. for(const auto [agentName, index] : agentIndexMap) {
  64. printPlayerStruct(agentName);
  65. }
  66. }
  67. if (!configuration.empty()) {
  68. printConfiguration(configuration);
  69. }
  70. return os;
  71. }
  72. void PrismModulesPrinter::printConfiguration(const std::vector<Configuration>& configurations) {
  73. for (auto& configuration : configurations) {
  74. if (configuration.overwrite_ || configuration.type_ == ConfigType::Module) {
  75. continue;
  76. }
  77. os << configuration.expression_ << std::endl;
  78. }
  79. }
  80. void PrismModulesPrinter::printConstants(const std::vector<std::string> &constants) {
  81. for (auto& constant : constants) {
  82. os << constant << std::endl;
  83. }
  84. }
  85. void PrismModulesPrinter::printPortableObjectModule(const cell &object) {
  86. std::string identifier = capitalize(object.getColor()) + object.getType();
  87. os << "\nmodule " << identifier << std::endl;
  88. os << "\tx" << identifier << " : [-1.." << maxBoundaries.second << "] init " << object.column << ";\n";
  89. os << "\ty" << identifier << " : [-1.." << maxBoundaries.first << "] init " << object.row << ";\n";
  90. os << "\t" << identifier << "PickedUp : bool;\n";
  91. os << "\n";
  92. for(const auto [name, position] : agentNameAndPositionMap) {
  93. printPortableObjectActions(name, identifier);
  94. }
  95. os << "endmodule\n\n";
  96. }
  97. void PrismModulesPrinter::printPortableObjectActions(const std::string &agentName, const std::string &identifier) {
  98. std::string actionName = "[" + agentName + "_pickup_" + identifier + "]";
  99. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  100. os << "\t" << actionName << " true -> (x" << identifier << "'=-1) & (y" << identifier << "'=-1) & (" << identifier << "PickedUp'=true);\n";
  101. actionName = "[" + agentName + "_drop_" + identifier + "_north]";
  102. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  103. os << "\t" << actionName << " " << " true -> (x" << identifier << "'=x" << agentName << ") & (y" << identifier << "'=y" << agentName << "-1) & (" << identifier << "PickedUp'=false);\n";
  104. actionName = "[" + agentName + "_drop_" + identifier + "_west]";
  105. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  106. os << "\t" << actionName << " " << " true -> (x" << identifier << "'=x" << agentName << "-1) & (y" << identifier << "'=y" << agentName << ") & (" << identifier << "PickedUp'=false);\n";
  107. actionName = "[" + agentName + "_drop_" + identifier + "_south]";
  108. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  109. os << "\t" << actionName << " " << " true -> (x" << identifier << "'=x" << agentName << ") & (y" << identifier << "'=y" << agentName << "+1) & (" << identifier << "PickedUp'=false);\n";
  110. actionName = "[" + agentName + "_drop_" + identifier + "_east]";
  111. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  112. os << "\t" << actionName << " " << " ttrue -> (x" << identifier << "'=x" << agentName << "+1) & (y" << identifier << "'=y" << agentName << ") & (" << identifier << "PickedUp'=false);\n";
  113. }
  114. void PrismModulesPrinter::printDoorModule(const cell &door, const bool &opened) {
  115. std::string identifier = capitalize(door.getColor()) + door.getType();
  116. os << "\nmodule " << identifier << std::endl;
  117. os << "\t" << identifier << "Open : bool init false;\n";
  118. os << "\n";
  119. if(opened) {
  120. for(const auto [name, position] : agentNameAndPositionMap) {
  121. printUnlockedDoorActions(name, identifier);
  122. }
  123. } else {
  124. for(const auto [name, position] : agentNameAndPositionMap) {
  125. printLockedDoorActions(name, identifier);
  126. }
  127. }
  128. os << "endmodule\n\n";
  129. }
  130. void PrismModulesPrinter::printLockedDoorActions(const std::string &agentName, const std::string &identifier) {
  131. std::string actionName = "[" + agentName + "_unlock_" + identifier + "]";
  132. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  133. os << "\t" << actionName << " !" << identifier << "Open -> (" << identifier << "Open'=true);\n";
  134. actionName = "[" + agentName + "_close_" + identifier + "]";
  135. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  136. os << "\t" << actionName << " " << identifier << "Open -> (" << identifier << "Open'=false);\n";
  137. }
  138. void PrismModulesPrinter::printUnlockedDoorActions(const std::string &agentName, const std::string &identifier) {
  139. std::string actionName = "[" + agentName + "_open_" + identifier + "]";
  140. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  141. os << "\t !" << identifier << "Open -> (" << identifier << "Open'=true);\n";
  142. actionName = "[" + agentName + "_close_" + identifier + "]";
  143. agentNameActionMap.at(agentName).insert({NOFAULT, actionName});
  144. os << "\t" << agentName << " " << identifier << "Open -> (" << identifier << "Open'=false);\n";
  145. }
  146. void PrismModulesPrinter::printRobotModule(const AgentName &agentName, const coordinates &initialPosition) {
  147. os << "\nmodule " << agentName << std::endl;
  148. os << "\tcol" << agentName << " : [1.." << maxBoundaries.second << "] init " << initialPosition.second << ";\n";
  149. os << "\trow" << agentName << " : [1.." << maxBoundaries.first << "] init " << initialPosition.first << ";\n";
  150. os << "\tview" << agentName << " : [0..3] init 1;\n";
  151. printTurnActionsForRobot(agentName);
  152. printMovementActionsForRobot(agentName);
  153. if(slipperyBehaviour()) printSlipperyMovementActionsForRobot(agentName);
  154. for(const auto &door : unlockedDoors) {
  155. std::string identifier = capitalize(door.getColor()) + door.getType();
  156. printUnlockedDoorActionsForRobot(agentName, identifier);
  157. }
  158. for(const auto &door : lockedDoors) {
  159. std::string identifier = capitalize(door.getColor()) + door.getType();
  160. std::string key = capitalize(door.getColor()) + "Key";
  161. printLockedDoorActionsForRobot(agentName, identifier, key);
  162. }
  163. for(const auto &key : keys) {
  164. std::string identifier = capitalize(key.getColor()) + key.getType();
  165. os << "\t" << agentName << "Carrying" << identifier << " : bool init false;\n";
  166. printPortableObjectActionsForRobot(agentName, identifier);
  167. }
  168. for(const auto &ball : balls) {
  169. std::string identifier = capitalize(ball.getColor()) + ball.getType();
  170. os << "\t" << agentName << "Carrying" << identifier << " : bool init false;\n";
  171. printPortableObjectActionsForRobot(agentName, identifier);
  172. }
  173. for(const auto &box : boxes) {
  174. std::string identifier = capitalize(box.getColor()) + box.getType();
  175. os << "\t" << agentName << "Carrying" << identifier << " : bool init false;\n";
  176. printPortableObjectActionsForRobot(agentName, identifier);
  177. }
  178. os << "\n" << actionStream.str();
  179. actionStream.str(std::string());
  180. os << "endmodule\n\n";
  181. }
  182. void PrismModulesPrinter::printPortableObjectActionsForRobot(const std::string &a, const std::string &i) {
  183. actionStream << "\t[" << a << "_pickup_" << i << "] " << " !" << a << "IsCarrying & " << a << "CannotMove" << i << " -> (" << a << "Carrying" << i << "'=true);\n";
  184. actionStream << "\t[" << a << "_drop_" << i << "_north]\t" << a << "Carrying" << i << " & view" << a << "=3 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveNorthWall -> (" << a << "Carrying" << i << "'=false);\n";
  185. actionStream << "\t[" << a << "_drop_" << i << "_west] \t" << a << "Carrying" << i << " & view" << a << "=2 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveWestWall -> (" << a << "Carrying" << i << "'=false);\n";
  186. actionStream << "\t[" << a << "_drop_" << i << "_south]\t" << a << "Carrying" << i << " & view" << a << "=1 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveSouthWall -> (" << a << "Carrying" << i << "'=false);\n";
  187. actionStream << "\t[" << a << "_drop_" << i << "_east] \t" << a << "Carrying" << i << " & view" << a << "=0 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveEastWall -> (" << a << "Carrying" << i << "'=false);\n";
  188. actionStream << "\n";
  189. }
  190. void PrismModulesPrinter::printUnlockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier) {
  191. actionStream << "\t[" << agentName << "_open_" << identifier << "] " << agentName << "CannotMove" << identifier << " -> true;\n";
  192. actionStream << "\t[" << agentName << "_close_" << identifier << "] " << agentName << "IsNextTo" << identifier << " -> true;\n";
  193. actionStream << "\n";
  194. }
  195. void PrismModulesPrinter::printLockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier, const std::string &key) {
  196. actionStream << "\t[" << agentName << "_unlock_" << identifier << "] " << agentName << "CannotMove" << identifier << " & " << agentName << "Carrying" << key << " -> true;\n";
  197. actionStream << "\t[" << agentName << "_close_" << identifier << "] " << agentName << "IsNextTo" << identifier << " & " << agentName << "Carrying" << key << " -> true;\n";
  198. actionStream << "\n";
  199. }
  200. void PrismModulesPrinter::printTurnActionsForRobot(const AgentName &a) {
  201. actionStream << printTurnGuard(a, "right", RIGHT, "true") << printTurnUpdate(a, {1.0, "(view"+a+"'=mod(view"+a+"+1,4))"}, RIGHT);
  202. actionStream << printTurnGuard(a, "left", LEFT, "view"+a+">0") << printTurnUpdate(a, {1.0, "(view"+a+"'=view"+a+"-1)"}, LEFT);
  203. actionStream << printTurnGuard(a, "left", LEFT, "view"+a+"=0") << printTurnUpdate(a, {1.0, "(view"+a+"'=3)"}, LEFT);
  204. }
  205. void PrismModulesPrinter::printMovementActionsForRobot(const AgentName &a) {
  206. actionStream << printMovementGuard(a, "North", 3) << printMovementUpdate(a, {1.0, northUpdate(a)});
  207. actionStream << printMovementGuard(a, "East", 0) << printMovementUpdate(a, {1.0, eastUpdate(a)});
  208. actionStream << printMovementGuard(a, "South", 1) << printMovementUpdate(a, {1.0, southUpdate(a)});
  209. actionStream << printMovementGuard(a, "West", 2) << printMovementUpdate(a, {1.0, westUpdate(a)});
  210. if(faultyBehaviour()) {
  211. std::string actionName = "[" + a + "_stuck]";
  212. agentNameActionMap.at(a).insert({FORWARD, actionName});
  213. actionStream << "\t" << actionName << " " << "previousAction" << a << "=" << std::to_string(FORWARD);
  214. actionStream << " & ((view" << a << "=0 & " << a << "CannotMoveEastWall) |";
  215. actionStream << " (view" << a << "=1 & " << a << "CannotMoveSouthWall) |";
  216. actionStream << " (view" << a << "=2 & " << a << "CannotMoveWestWall) |";
  217. actionStream << " (view" << a << "=3 & " << a << "CannotMoveNorthWall) ) -> true;\n";
  218. }
  219. }
  220. std::string PrismModulesPrinter::printMovementGuard(const AgentName &a, const std::string &direction, const size_t &viewDirection) {
  221. std::string actionName = "[" + a + "_move_" + direction + "]";
  222. agentNameActionMap.at(a).insert({FORWARD, actionName});
  223. std::string guard = " " + actionName + " " + viewVariable(a, viewDirection);
  224. if(slipperyBehaviour()) guard += " & !" + a + "IsOnSlippery";
  225. if(anyLava) guard += " & !" + a + "IsOnLava";
  226. if(anyGoals) guard += " & !" + a + "IsOnGoal";
  227. guard += " & !" + a + "CannotMove" + direction + "Wall";
  228. if(anyPortableObject()) guard += " & !" + a + "CannotMoveConditionally";
  229. guard += " -> ";
  230. return guard;
  231. }
  232. std::string PrismModulesPrinter::printMovementUpdate(const AgentName &a, const update &u) const {
  233. return updateToString(u) + ";\n";
  234. }
  235. std::string PrismModulesPrinter::printTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::string &cond) {
  236. std::string actionName = "[" + a + "_turn_" + direction + "]";
  237. agentNameActionMap.at(a).insert({actionId, actionName});
  238. return "\t" + actionName + " " + cond + " -> ";
  239. }
  240. std::string PrismModulesPrinter::printTurnUpdate(const AgentName &a, const update &u, const ActionId &actionId) const {
  241. return updateToString(u) + ";\n";
  242. }
  243. void PrismModulesPrinter::printSlipperyMovementActionsForRobot(const AgentName &a) {
  244. if(!slipperyTiles.at("North").empty()) {
  245. printSlipperyMovementActionsForNorth(a);
  246. printSlipperyTurnActionsForNorth(a);
  247. }
  248. if(!slipperyTiles.at("East").empty()) {
  249. printSlipperyMovementActionsForEast(a) ;
  250. printSlipperyTurnActionsForEast(a);
  251. }
  252. if(!slipperyTiles.at("South").empty()) {
  253. printSlipperyMovementActionsForSouth(a);
  254. printSlipperyTurnActionsForSouth(a);
  255. }
  256. if(!slipperyTiles.at("West").empty()) {
  257. printSlipperyMovementActionsForWest(a) ;
  258. printSlipperyTurnActionsForWest(a);
  259. }
  260. }
  261. void PrismModulesPrinter::printSlipperyMovementActionsForNorth(const AgentName &a) {
  262. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended) * 1/2, northUpdate(a)+"&"+eastUpdate(a)}, {(1 - probIntended) * 1/2, northUpdate(a)+"&"+westUpdate(a)} }) << ";\n";
  263. actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1/2, northUpdate(a)+"&"+eastUpdate(a)}, {1/2, northUpdate(a)+"&"+westUpdate(a)} }) << ";\n";
  264. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+westUpdate(a)} }) << ";\n";
  265. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+eastUpdate(a)} }) << ";\n";
  266. actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+westUpdate(a) } }) << ";\n";
  267. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << ";\n";
  268. actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+eastUpdate(a)} }) << ";\n";
  269. actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n";
  270. actionStream << printSlipperyMovementGuard(a, "North", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  271. actionStream << printSlipperyMovementGuard(a, "North", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  272. actionStream << printSlipperyMovementGuard(a, "North", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a) } }) << ";\n";
  273. actionStream << printSlipperyMovementGuard(a, "North", 2, { a+"CannotSlipWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n";
  274. actionStream << printSlipperyMovementGuard(a, "North", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  275. actionStream << printSlipperyMovementGuard(a, "North", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  276. actionStream << printSlipperyMovementGuard(a, "North", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a) } }) << ";\n";
  277. actionStream << printSlipperyMovementGuard(a, "North", 0, { a+"CannotSlipEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n";
  278. actionStream << printSlipperyMovementGuard(a, "North", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, southUpdate(a) }, {1 - probIntended, northUpdate(a)} }) << ";\n";
  279. actionStream << printSlipperyMovementGuard(a, "North", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << ";\n";
  280. actionStream << printSlipperyMovementGuard(a, "North", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {1, southUpdate(a)} }) << ";\n";
  281. actionStream << printSlipperyMovementGuard(a, "North", 1, { a+"CannotSlipSouth", a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n";
  282. }
  283. void PrismModulesPrinter::printSlipperyMovementActionsForEast(const AgentName &a) {
  284. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended) * 1/2, eastUpdate(a)+"&"+southUpdate(a)}, {(1 - probIntended) * 1/2, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  285. actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1/2, eastUpdate(a)+"&"+southUpdate(a)}, {1/2, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  286. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  287. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  288. actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a) } }) << ";\n";
  289. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << ";\n";
  290. actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  291. actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n";
  292. actionStream << printSlipperyMovementGuard(a, "East", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, northUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  293. actionStream << printSlipperyMovementGuard(a, "East", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  294. actionStream << printSlipperyMovementGuard(a, "East", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, northUpdate(a) } }) << ";\n";
  295. actionStream << printSlipperyMovementGuard(a, "East", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n";
  296. actionStream << printSlipperyMovementGuard(a, "East", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, southUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  297. actionStream << printSlipperyMovementGuard(a, "East", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  298. actionStream << printSlipperyMovementGuard(a, "East", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, southUpdate(a) } }) << ";\n";
  299. actionStream << printSlipperyMovementGuard(a, "East", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n";
  300. actionStream << printSlipperyMovementGuard(a, "East", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a) }, {1 - probIntended, westUpdate(a)} }) << ";\n";
  301. actionStream << printSlipperyMovementGuard(a, "East", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << ";\n";
  302. actionStream << printSlipperyMovementGuard(a, "East", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, westUpdate(a)} }) << ";\n";
  303. actionStream << printSlipperyMovementGuard(a, "East", 2, { a+"CannotSlipWest", a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n";
  304. }
  305. void PrismModulesPrinter::printSlipperyMovementActionsForSouth(const AgentName &a) {
  306. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended) * 1/2, southUpdate(a)+"&"+eastUpdate(a)}, {(1 - probIntended) * 1/2, southUpdate(a)+"&"+westUpdate(a)} }) << ";\n";
  307. actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1/2, southUpdate(a)+"&"+eastUpdate(a)}, {1/2, southUpdate(a)+"&"+westUpdate(a)} }) << ";\n";
  308. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+westUpdate(a)} }) << ";\n";
  309. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+eastUpdate(a)} }) << ";\n";
  310. actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+westUpdate(a) } }) << ";\n";
  311. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << ";\n";
  312. actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+eastUpdate(a)} }) << ";\n";
  313. actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n";
  314. actionStream << printSlipperyMovementGuard(a, "South", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  315. actionStream << printSlipperyMovementGuard(a, "South", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  316. actionStream << printSlipperyMovementGuard(a, "South", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a) } }) << ";\n";
  317. actionStream << printSlipperyMovementGuard(a, "South", 2, { a+"CannotSlipWest", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n";
  318. actionStream << printSlipperyMovementGuard(a, "South", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  319. actionStream << printSlipperyMovementGuard(a, "South", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  320. actionStream << printSlipperyMovementGuard(a, "South", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a) } }) << ";\n";
  321. actionStream << printSlipperyMovementGuard(a, "South", 0, { a+"CannotSlipEast", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n";
  322. actionStream << printSlipperyMovementGuard(a, "South", 3, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a) }, {1 - probIntended, northUpdate(a)} }) << ";\n";
  323. actionStream << printSlipperyMovementGuard(a, "South", 3, { a+"CannotSlipSouth", "!"+a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {1, northUpdate(a)} }) << ";\n";
  324. actionStream << printSlipperyMovementGuard(a, "South", 3, {"!"+a+"CannotSlipSouth", a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << ";\n";
  325. actionStream << printSlipperyMovementGuard(a, "South", 3, { a+"CannotSlipSouth", a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n";
  326. }
  327. void PrismModulesPrinter::printSlipperyMovementActionsForWest(const AgentName &a) {
  328. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended) * 1/2, westUpdate(a)+"&"+southUpdate(a)}, {(1 - probIntended) * 1/2, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  329. actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1/2, westUpdate(a)+"&"+southUpdate(a)}, {1/2, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  330. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  331. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  332. actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a) } }) << ";\n";
  333. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << ";\n";
  334. actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  335. actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n";
  336. actionStream << printSlipperyMovementGuard(a, "West", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, northUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  337. actionStream << printSlipperyMovementGuard(a, "West", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n";
  338. actionStream << printSlipperyMovementGuard(a, "West", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, northUpdate(a) } }) << ";\n";
  339. actionStream << printSlipperyMovementGuard(a, "West", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n";
  340. actionStream << printSlipperyMovementGuard(a, "West", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, southUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  341. actionStream << printSlipperyMovementGuard(a, "West", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n";
  342. actionStream << printSlipperyMovementGuard(a, "West", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, southUpdate(a) } }) << ";\n";
  343. actionStream << printSlipperyMovementGuard(a, "West", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n";
  344. actionStream << printSlipperyMovementGuard(a, "West", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a) }, {1 - probIntended, eastUpdate(a)} }) << ";\n";
  345. actionStream << printSlipperyMovementGuard(a, "West", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << ";\n";
  346. actionStream << printSlipperyMovementGuard(a, "West", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {1, eastUpdate(a)} }) << ";\n";
  347. actionStream << printSlipperyMovementGuard(a, "West", 0, { a+"CannotSlipEast", a+"CannotSlipWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n";
  348. }
  349. void PrismModulesPrinter::printSlipperyTurnActionsForNorth(const AgentName &a) {
  350. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, {"!"+a+"CannotSlipNorth"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, northUpdate(a)} }) << ";\n";
  351. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, { a+"CannotSlipNorth"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n";
  352. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipNorth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, northUpdate(a)} }) << ";\n";
  353. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipNorth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, northUpdate(a)} }) << ";\n";
  354. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipNorth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n";
  355. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipNorth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n";
  356. }
  357. void PrismModulesPrinter::printSlipperyTurnActionsForEast(const AgentName &a) {
  358. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, {"!"+a+"CannotSlipEast"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, eastUpdate(a)} }) << ";\n";
  359. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, { a+"CannotSlipEast"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n";
  360. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipEast"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, eastUpdate(a)} }) << ";\n";
  361. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipEast"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, eastUpdate(a)} }) << ";\n";
  362. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipEast"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n";
  363. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipEast"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n";
  364. }
  365. void PrismModulesPrinter::printSlipperyTurnActionsForSouth(const AgentName &a) {
  366. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, {"!"+a+"CannotSlipSouth"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, southUpdate(a)} }) << ";\n";
  367. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, { a+"CannotSlipSouth"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n";
  368. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipSouth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, southUpdate(a)} }) << ";\n";
  369. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipSouth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, southUpdate(a)} }) << ";\n";
  370. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipSouth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n";
  371. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipSouth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n";
  372. }
  373. void PrismModulesPrinter::printSlipperyTurnActionsForWest(const AgentName &a) {
  374. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, {"!"+a+"CannotSlipWest"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, westUpdate(a)} }) << ";\n";
  375. actionStream << printSlipperyTurnGuard(a, "right", RIGHT, { a+"CannotSlipWest"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n";
  376. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipWest"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, westUpdate(a)} }) << ";\n";
  377. actionStream << printSlipperyTurnGuard(a, "left", LEFT, {"!"+a+"CannotSlipWest"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, westUpdate(a)} }) << ";\n";
  378. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipWest"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n";
  379. actionStream << printSlipperyTurnGuard(a, "left", LEFT, { a+"CannotSlipWest"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n";
  380. }
  381. std::string PrismModulesPrinter::printSlipperyMovementGuard(const AgentName &a, const std::string &direction, const ViewDirection &viewDirection, const std::vector<std::string> &guards) {
  382. std::string actionName = "[" + a + "_move_" + viewDirectionToString.at(viewDirection) + "]";
  383. agentNameActionMap.at(a).insert({FORWARD, actionName});
  384. return "\t" + actionName + " " + viewVariable(a, viewDirection) + a + "IsOnSlippery" + direction + " & " + buildConjunction(a, guards) + " -> ";
  385. }
  386. std::string PrismModulesPrinter::printSlipperyMovementUpdate(const AgentName &a, const std::string &direction, const updates &u) const {
  387. return updatesToString(u);
  388. }
  389. std::string PrismModulesPrinter::printSlipperyTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::vector<std::string> &guards, const std::string &cond) {
  390. std::string actionName = "[" + a + "_turn_" + direction + "]";
  391. agentNameActionMap.at(a).insert({actionId, actionName});
  392. return "\t" + actionName + " " + buildConjunction(a, guards) + " & " + cond + " -> ";
  393. }
  394. std::string PrismModulesPrinter::printSlipperyTurnUpdate(const AgentName &a, const updates &u) {
  395. return updatesToString(u);
  396. }
  397. void PrismModulesPrinter::printFaultyMovementModule(const AgentName &a) {
  398. os << "\nmodule " << a << "FaultyBehaviour" << std::endl;
  399. os << "\tpreviousAction" << a << " : [-1..2] init -1;\n";
  400. for(const auto [actionId, actionName] : agentNameActionMap.at(a)) {
  401. os << "\t" << actionName << faultyBehaviourGuard(a, actionId) << " -> " << faultyBehaviourUpdate(a, actionId) << ";\n";
  402. }
  403. os << "endmodule\n\n";
  404. }
  405. void PrismModulesPrinter::printMoveModule() {
  406. os << "\nmodule " << "Arbiter" << std::endl;
  407. os << "\tclock : [0.." << agentIndexMap.size() - 1 << "] init 0;\n";
  408. for(const auto [agentName, actions] : agentNameActionMap) {
  409. for(const auto [actionId, actionName] : actions) {
  410. os << "\t" << actionName << " " << moveGuard(agentName) << " -> " << moveUpdate(agentName) << ";\n";
  411. }
  412. }
  413. os << "endmodule\n\n";
  414. }
  415. void PrismModulesPrinter::printConfiguredActions(const AgentName &agentName) {
  416. for (auto& config : configuration) {
  417. if (config.type_ == ConfigType::Module && !config.overwrite_ && agentName == config.module_) {
  418. os << config.expression_ ;
  419. }
  420. }
  421. os << "\n";
  422. }
  423. void PrismModulesPrinter::printDoneActions(const AgentName &agentName) {
  424. os << "\t[" << agentName << "_done]" << moveGuard(agentName) << agentName << "IsInGoal | " << agentName << "IsInLava -> (" << agentName << "Done'=true);\n";
  425. }
  426. void PrismModulesPrinter::printPlayerStruct(const AgentName &agentName) {
  427. os << "player " << agentName << "\n\t";
  428. bool first = true;
  429. for(const auto [actionId, actionName] : agentNameActionMap.at(agentName)) {
  430. if(first) first = false;
  431. else os << ", ";
  432. os << actionName;
  433. }
  434. os << "\nendplayer\n";
  435. }
  436. void PrismModulesPrinter::printRewards(const AgentName &agentName, const std::map<coordinates, float> &stateRewards, const cells &lava, const cells &goals, const std::map<Color, cells> &backgroundTiles) {
  437. if(lava.size() != 0) {
  438. os << "rewards \"" << agentName << "SafetyNoBFS\"\n";
  439. os << "\t" <<agentName << "IsInLavaAndNotDone: -100;\n";
  440. os << "endrewards\n";
  441. }
  442. if (!goals.empty() || !lava.empty()) {
  443. os << "rewards \"" << agentName << "SafetyNoBFSAndGoal\"\n";
  444. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  445. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  446. os << "endrewards\n";
  447. }
  448. os << "rewards \"" << agentName << "Time\"\n";
  449. os << "\t!" << agentName << "IsInGoal : -1;\n";
  450. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  451. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  452. os << "endrewards\n";
  453. if(stateRewards.size() > 0) {
  454. os << "rewards \"" << agentName << "SafetyWithBFS\"\n";
  455. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  456. for(auto const [coordinates, reward] : stateRewards) {
  457. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  458. }
  459. os << "endrewards\n";
  460. }
  461. if(stateRewards.size() > 0) {
  462. os << "rewards \"" << agentName << "SafetyWithBFSAndGoal\"\n";
  463. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone: 100;\n";
  464. if(lava.size() != 0) os << "\tAgentIsInLavaAndNotDone: -100;\n";
  465. for(auto const [coordinates, reward] : stateRewards) {
  466. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  467. }
  468. os << "endrewards\n";
  469. }
  470. for(auto const entry : backgroundTiles)
  471. {
  472. std::cout << getColor(entry.first) << " ";
  473. for(auto const cell : entry.second){
  474. std::cout << cell.getCoordinates().first << " " << cell.getCoordinates().second << std::endl;
  475. }
  476. }
  477. if(backgroundTiles.size() > 0) {
  478. os << "rewards \"TaxiReward\"\n";
  479. os << "\t!AgentIsInGoal : -1;\n";
  480. std::string allPassengersPickedUp = "";
  481. bool first = true;
  482. for(auto const [color, cells] : backgroundTiles) {
  483. if(cells.size() == 0) continue;
  484. if(first) first = false; else allPassengersPickedUp += "&";
  485. std::string c = getColor(color);
  486. c.at(0) = std::toupper(c.at(0));
  487. std::string visitedLabel = agentName + "_picked_up_" + c;
  488. allPassengersPickedUp += visitedLabel;
  489. os << "[" << agentName << "_pickup_" << c << "] true : 100;\n";
  490. }
  491. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & " << allPassengersPickedUp << " : 100;\n";
  492. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & !(" << allPassengersPickedUp << ") : -100;\n";
  493. os << "endrewards";
  494. }
  495. }
  496. std::string PrismModulesPrinter::faultyBehaviourGuard(const AgentName &agentName, const ActionId &actionId) const {
  497. if(faultyBehaviour()) {
  498. if(actionId == NOFAULT) {
  499. return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + ") ";
  500. } else {
  501. return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + " | previousAction" + agentName + "=" + std::to_string(actionId) + ") ";
  502. }
  503. } else {
  504. return "";
  505. }
  506. }
  507. std::string PrismModulesPrinter::faultyBehaviourUpdate(const AgentName &agentName, const ActionId &actionId) const {
  508. if(actionId != NOFAULT) {
  509. return updatesToString({ {1 - faultyProbability, "(previousAction" + agentName + "'=" + std::to_string(NOFAULT) + ")"}, {faultyProbability, "(previousAction" + agentName + "'=" + std::to_string(actionId) + ")" } });
  510. } else {
  511. return "true";
  512. }
  513. }
  514. std::string PrismModulesPrinter::moveGuard(const AgentName &agentName) const {
  515. return "clock=" + std::to_string(agentIndexMap.at(agentName));
  516. }
  517. std::string PrismModulesPrinter::moveUpdate(const AgentName &agentName) const {
  518. size_t agentIndex = agentIndexMap.at(agentName);
  519. return (agentIndex == numberOfPlayer - 1) ? "(clock'=0) " : "(clock'=" + std::to_string(agentIndex + 1) + ") ";
  520. }
  521. std::string PrismModulesPrinter::updatesToString(const updates &updates) const {
  522. if(updates.empty()) return "true";
  523. std::string updatesString = "";
  524. bool first = true;
  525. for(auto const update : updates) {
  526. if(first) first = false;
  527. else updatesString += " + ";
  528. updatesString += updateToString(update);
  529. }
  530. return updatesString;
  531. }
  532. std::string PrismModulesPrinter::updateToString(const update &u) const {
  533. return std::to_string(u.first) + ": " + u.second;
  534. }
  535. std::string PrismModulesPrinter::viewVariable(const AgentName &agentName, const size_t &agentDirection) const {
  536. return "view" + agentName + "=" + std::to_string(agentDirection) + " & ";
  537. }
  538. bool PrismModulesPrinter::anyPortableObject() const {
  539. return !keys.empty() || !boxes.empty() || !balls.empty();
  540. }
  541. bool PrismModulesPrinter::faultyBehaviour() const {
  542. return faultyProbability > 0.0f;
  543. }
  544. bool PrismModulesPrinter::slipperyBehaviour() const {
  545. return !slipperyTiles.at("North").empty() || !slipperyTiles.at("East").empty() || !slipperyTiles.at("South").empty() || !slipperyTiles.at("West").empty();
  546. }
  547. bool PrismModulesPrinter::isGame() const {
  548. return modelType == ModelType::SMG;
  549. }
  550. std::string PrismModulesPrinter::buildConjunction(const AgentName &a, std::vector<std::string> formulae) const {
  551. if(formulae.empty()) return "true";
  552. std::string conjunction = "";
  553. bool first = true;
  554. for(auto const formula : formulae) {
  555. if(first) first = false;
  556. else conjunction += " & ";
  557. conjunction += formula;
  558. }
  559. return conjunction;
  560. }
  561. }