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.

648 lines
47 KiB

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