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.

742 lines
59 KiB

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