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.

706 lines
47 KiB

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