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.

970 lines
66 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 &key : keys) {
  35. printPortableObjectModule(key);
  36. }
  37. for(const auto &ball : balls) {
  38. printPortableObjectModule(ball);
  39. }
  40. for(const auto &box : boxes) {
  41. printPortableObjectModule(box);
  42. }
  43. for(const auto &door : unlockedDoors) {
  44. printDoorModule(door, true);
  45. }
  46. for(const auto &door : lockedDoors) {
  47. printDoorModule(door, false);
  48. }
  49. for(const auto [agentName, initialPosition] : agentNameAndPositionMap) {
  50. printRobotModule(agentName, initialPosition);
  51. }
  52. return os;
  53. }
  54. std::ostream& PrismModulesPrinter::printConfiguration(std::ostream& os, const std::vector<Configuration>& configurations) {
  55. for (auto& configuration : configurations) {
  56. if (configuration.overwrite_ || configuration.type_ == ConfigType::Module) {
  57. continue;
  58. }
  59. os << configuration.expression_ << std::endl;
  60. }
  61. return os;
  62. }
  63. std::ostream& PrismModulesPrinter::printConstants(std::ostream &os, const std::vector<std::string> &constants) {
  64. for (auto& constant : constants) {
  65. os << constant << std::endl;
  66. }
  67. return os;
  68. }
  69. std::ostream& PrismModulesPrinter::printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType) {
  70. /*
  71. os << "init\n";
  72. os << "\t";
  73. bool first = true;
  74. for (auto const& agent : agents) {
  75. if (first) first = false;
  76. else os << " & ";
  77. os << "(!" << agent.first << "IsInGoal & !" << agent.first << "IsInLava & !" << agent.first << "Done & !" << agent.first << "IsOnWall & ";
  78. os << "x" << agent.first << "=" << agent.second.second << " & y" << agent.first << "=" << agent.second.first << ")";
  79. os << " & !" << agent.first << "_is_carrying_object";
  80. // os << " & ( !AgentIsOnSlippery ) ";
  81. }
  82. for (auto const& key : keys) {
  83. os << " & ( !" << agent.first << "_has_" << key.first << "_key )";
  84. }
  85. }
  86. for (auto const& key : keys) {
  87. os << " & ( xKey" << key.first << "="<< key.second.second<< ")";
  88. os << " & ( yKey" << key.first << "=" << key.second.first << ")";
  89. }
  90. for (auto const& locked : lockedDoors) {
  91. os << " & (Door" << locked.getColor() << "locked & !Door" << locked.getColor() << "open)";
  92. }
  93. for (auto const& unlocked : unlockedDoors) {
  94. os << " & (!Door" << unlocked.getColor() << "locked & !Door" << unlocked.getColor() << "open)";
  95. }
  96. if (modelType == ModelType::SMG) {
  97. os << " & move=0";
  98. }
  99. os << "\nendinit\n\n";
  100. */
  101. return os;
  102. }
  103. void PrismModulesPrinter::printPortableObjectModule(const cell &object) {
  104. std::string identifier = capitalize(object.getColor()) + object.getType();
  105. os << "\nmodule " << identifier << std::endl;
  106. os << "\tx" << identifier << " : [-1.." << maxBoundaries.second << "] init " << object.column << ";\n";
  107. os << "\ty" << identifier << " : [-1.." << maxBoundaries.first << "] init " << object.row << ";\n";
  108. os << "\t" << identifier << "PickedUp : bool;\n";
  109. os << "\n";
  110. for(const auto [name, position] : agentNameAndPositionMap) {
  111. printPortableObjectActions(name, identifier);
  112. }
  113. os << "endmodule\n\n";
  114. }
  115. void PrismModulesPrinter::printPortableObjectActions(const std::string &agentName, const std::string &identifier) {
  116. os << "\t[" << agentName << "_pickup_" << identifier << "]\ttrue -> (x" << identifier << "'=-1) & (y" << identifier << "'=-1) & (" << identifier << "PickedUp'=true);\n";
  117. os << "\t[" << agentName << "_drop_" << identifier << "_north]\ttrue -> (x" << identifier << "'=x" << agentName << ") & (y" << identifier << "'=y" << agentName << "-1) & (" << identifier << "PickedUp'=false);\n";
  118. os << "\t[" << agentName << "_drop_" << identifier << "_west]\ttrue -> (x" << identifier << "'=x" << agentName << "-1) & (y" << identifier << "'=y" << agentName << ") & (" << identifier << "PickedUp'=false);\n";
  119. os << "\t[" << agentName << "_drop_" << identifier << "_south]\ttrue -> (x" << identifier << "'=x" << agentName << ") & (y" << identifier << "'=y" << agentName << "+1) & (" << identifier << "PickedUp'=false);\n";
  120. os << "\t[" << agentName << "_drop_" << identifier << "_east]\ttrue -> (x" << identifier << "'=x" << agentName << "+1) & (y" << identifier << "'=y" << agentName << ") & (" << identifier << "PickedUp'=false);\n";
  121. }
  122. void PrismModulesPrinter::printDoorModule(const cell &door, const bool &opened) {
  123. std::string identifier = capitalize(door.getColor()) + door.getType();
  124. os << "\nmodule " << identifier << std::endl;
  125. os << "\t" << identifier << "Open : bool init false;\n";
  126. os << "\n";
  127. if(opened) {
  128. for(const auto [name, position] : agentNameAndPositionMap) {
  129. printUnlockedDoorActions(name, identifier);
  130. }
  131. } else {
  132. for(const auto [name, position] : agentNameAndPositionMap) {
  133. printLockedDoorActions(name, identifier);
  134. }
  135. }
  136. os << "endmodule\n\n";
  137. }
  138. void PrismModulesPrinter::printLockedDoorActions(const std::string &agentName, const std::string &identifier) {
  139. os << "\t[" << agentName << "_unlock_" << identifier << "] !" << identifier << "Open -> (" << identifier << "Open'=true);\n";
  140. os << "\t[" << agentName << "_close_" << identifier << "] " << identifier << "Open -> (" << identifier << "Open'=false);\n";
  141. }
  142. void PrismModulesPrinter::printUnlockedDoorActions(const std::string &agentName, const std::string &identifier) {
  143. os << "\t[" << agentName << "_open_" << identifier << "] !" << identifier << "Open -> (" << identifier << "Open'=true);\n";
  144. os << "\t[" << agentName << "_close_" << identifier << "] " << identifier << "Open -> (" << identifier << "Open'=false);\n";
  145. }
  146. void PrismModulesPrinter::printRobotModule(const AgentName &agentName, const coordinates &initialPosition) {
  147. os << "\nmodule " << agentName << std::endl;
  148. os << "\tx" << agentName << " : [0.." << maxBoundaries.second << "] init " << initialPosition.second << ";\n";
  149. os << "\ty" << agentName << " : [0.." << maxBoundaries.first << "] init " << initialPosition.first << ";\n";
  150. os << "\tview" << agentName << " : [0..3] init 1;\n";
  151. if(faultyBehaviour()) os << "\tpreviousAction" << agentName << " : [-1..2] init -1;\n";
  152. printTurnActionsForRobot(agentName);
  153. printMovementActionsForRobot(agentName);
  154. if(slipperyBehaviour()) printSlipperyMovementActionsForRobot(agentName);
  155. for(const auto &door : unlockedDoors) {
  156. std::string identifier = capitalize(door.getColor()) + door.getType();
  157. printUnlockedDoorActionsForRobot(agentName, identifier);
  158. }
  159. for(const auto &door : lockedDoors) {
  160. std::string identifier = capitalize(door.getColor()) + door.getType();
  161. std::string key = capitalize(door.getColor()) + "Key";
  162. printLockedDoorActionsForRobot(agentName, identifier, key);
  163. }
  164. for(const auto &key : keys) {
  165. std::string identifier = capitalize(key.getColor()) + key.getType();
  166. os << "\t" << agentName << "Carrying" << identifier << " : bool init false;\n";
  167. printPortableObjectActionsForRobot(agentName, identifier);
  168. }
  169. for(const auto &ball : balls) {
  170. std::string identifier = capitalize(ball.getColor()) + ball.getType();
  171. os << "\t" << agentName << "Carrying" << identifier << " : bool init false;\n";
  172. printPortableObjectActionsForRobot(agentName, identifier);
  173. }
  174. for(const auto &box : boxes) {
  175. std::string identifier = capitalize(box.getColor()) + box.getType();
  176. os << "\t" << agentName << "Carrying" << identifier << " : bool init false;\n";
  177. printPortableObjectActionsForRobot(agentName, identifier);
  178. }
  179. os << "\n" << actionStream.str();
  180. actionStream.str(std::string());
  181. os << "endmodule\n\n";
  182. }
  183. void PrismModulesPrinter::printPortableObjectActionsForRobot(const std::string &a, const std::string &i) {
  184. actionStream << "\t[" << a << "_pickup_" << i << "] " << faultyBehaviourGuard(a, NOFAULT) << moveGuard(a) << " !" << a << "IsCarrying & " << a << "CannotMove" << i << " -> (" << a << "Carrying" << i << "'=true);\n";
  185. actionStream << "\t[" << a << "_drop_" << i << "_north]\t" << faultyBehaviourGuard(a, NOFAULT) << moveGuard(a) << a << "Carrying" << i << " & view" << a << "=3 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveNorthWall -> (" << a << "Carrying" << i << "'=false);\n";
  186. actionStream << "\t[" << a << "_drop_" << i << "_west] \t" << faultyBehaviourGuard(a, NOFAULT) << moveGuard(a) << a << "Carrying" << i << " & view" << a << "=2 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveWestWall -> (" << a << "Carrying" << i << "'=false);\n";
  187. actionStream << "\t[" << a << "_drop_" << i << "_south]\t" << faultyBehaviourGuard(a, NOFAULT) << moveGuard(a) << a << "Carrying" << i << " & view" << a << "=1 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveSouthWall -> (" << a << "Carrying" << i << "'=false);\n";
  188. actionStream << "\t[" << a << "_drop_" << i << "_east] \t" << faultyBehaviourGuard(a, NOFAULT) << moveGuard(a) << a << "Carrying" << i << " & view" << a << "=0 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveEastWall -> (" << a << "Carrying" << i << "'=false);\n";
  189. actionStream << "\n";
  190. }
  191. void PrismModulesPrinter::printUnlockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier) {
  192. actionStream << "\t[" << agentName << "_open_" << identifier << "] " << faultyBehaviourGuard(agentName, NOFAULT) << moveGuard(agentName) << agentName << "CannotMove" << identifier << " -> true;\n";
  193. actionStream << "\t[" << agentName << "_close_" << identifier << "] " << faultyBehaviourGuard(agentName, NOFAULT) << moveGuard(agentName) << agentName << "IsNextTo" << identifier << " -> true;\n";
  194. actionStream << "\n";
  195. }
  196. void PrismModulesPrinter::printLockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier, const std::string &key) {
  197. actionStream << "\t[" << agentName << "_unlock_" << identifier << "] " << faultyBehaviourGuard(agentName, NOFAULT) << moveGuard(agentName) << agentName << "CannotMove" << identifier << " & " << agentName << "Carrying" << key << " -> true;\n";
  198. actionStream << "\t[" << agentName << "_close_" << identifier << "] " << faultyBehaviourGuard(agentName, NOFAULT) << moveGuard(agentName) << agentName << "IsNextTo" << identifier << " & " << agentName << "Carrying" << key << " -> true;\n";
  199. actionStream << "\n";
  200. }
  201. void PrismModulesPrinter::printTurnActionsForRobot(const AgentName &a) {
  202. actionStream << printTurnGuard(a, "right", RIGHT, "true") << printTurnUpdate(a, {1.0, "(view"+a+"'=mod(view"+a+"+1,4))"}, RIGHT);
  203. actionStream << printTurnGuard(a, "left", LEFT, "view"+a+">0") << printTurnUpdate(a, {1.0, "(view"+a+"'=view"+a+"-1)"}, LEFT);
  204. actionStream << printTurnGuard(a, "left", LEFT, "view"+a+"=0") << printTurnUpdate(a, {1.0, "(view"+a+"'=3)"}, LEFT);
  205. }
  206. void PrismModulesPrinter::printMovementActionsForRobot(const AgentName &a) {
  207. actionStream << printMovementGuard(a, "North", 3) << printMovementUpdate(a, {1.0, "(y"+a+"'=y"+a+"-1)"});
  208. actionStream << printMovementGuard(a, "East", 0) << printMovementUpdate(a, {1.0, "(x"+a+"'=x"+a+"+1)"});
  209. actionStream << printMovementGuard(a, "South", 1) << printMovementUpdate(a, {1.0, "(y"+a+"'=y"+a+"+1)"});
  210. actionStream << printMovementGuard(a, "West", 2) << printMovementUpdate(a, {1.0, "(x"+a+"'=x"+a+"-1)"});
  211. }
  212. std::string PrismModulesPrinter::printMovementGuard(const AgentName &a, const std::string &direction, const size_t &viewDirection) const {
  213. return "\t[" + a + "_move_" + direction + "]" + moveGuard(a) + viewVariable(a, viewDirection) + faultyBehaviourGuard(a, FORWARD) + " !" + a + "IsOnSlippery & !" + a + "IsOnLava & !" + a + "IsOnGoal & !" + a + "CannotMove" + direction + "Wall &!" + a + "CannotMoveConditionally -> ";
  214. }
  215. std::string PrismModulesPrinter::printMovementUpdate(const AgentName &a, const update &u) const {
  216. if(!faultyBehaviour()) {
  217. return updateToString(u) + ";\n";
  218. } else {
  219. update nonFaultyUpdate = {u.first - faultyProbability, u.second + " & " + faultyBehaviourUpdate(a, NOFAULT)};
  220. update faultyUpdate = {faultyProbability, u.second + " & " + faultyBehaviourUpdate(a, FORWARD)};
  221. return updateToString(nonFaultyUpdate) + " + " + updateToString(faultyUpdate) + ";\n";
  222. }
  223. }
  224. std::string PrismModulesPrinter::printTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::string &cond) const {
  225. return "\t[" + a + "_turn_" + direction + "]" + moveGuard(a) + faultyBehaviourGuard(a, actionId) + cond + " -> ";
  226. }
  227. std::string PrismModulesPrinter::printTurnUpdate(const AgentName &a, const update &u, const ActionId &actionId) const {
  228. if(!faultyBehaviour()) {
  229. return updateToString(u) + ";\n";
  230. } else {
  231. update nonFaultyUpdate = {u.first - faultyProbability, u.second + " & " + faultyBehaviourUpdate(a, NOFAULT)};
  232. update faultyUpdate = {faultyProbability, u.second + " & " + faultyBehaviourUpdate(a, actionId)};
  233. return updateToString(nonFaultyUpdate) + " + " + updateToString(faultyUpdate) + ";\n";
  234. }
  235. }
  236. void PrismModulesPrinter::printSlipperyMovementActionsForRobot(const AgentName &a) {
  237. if(!slipperyTiles.at("North").empty()) {
  238. printSlipperyMovementActionsForNorth(a);
  239. printSlipperyTurnActionsForNorth(a);
  240. }
  241. if(!slipperyTiles.at("East").empty()) {
  242. printSlipperyMovementActionsForEast(a) ;
  243. printSlipperyTurnActionsForEast(a);
  244. }
  245. if(!slipperyTiles.at("South").empty()) {
  246. printSlipperyMovementActionsForSouth(a);
  247. printSlipperyTurnActionsForSouth(a);
  248. }
  249. if(!slipperyTiles.at("West").empty()) {
  250. printSlipperyMovementActionsForWest(a) ;
  251. printSlipperyTurnActionsForWest(a);
  252. }
  253. }
  254. void PrismModulesPrinter::printSlipperyMovementActionsForNorth(const AgentName &a) {
  255. 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";
  256. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "CanSlipNorthEast", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1/2, northUpdate(a)+"&"+eastUpdate(a)}, {1/2, northUpdate(a)+"&"+westUpdate(a)} });
  257. actionStream << printSlipperyMovementGuard(a, "North", 3, { "CanSlipNorth", "!CanSlipNorthEast", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+westUpdate(a)} }) << "\n";
  258. actionStream << printSlipperyMovementGuard(a, "North", 3, { "CanSlipNorth", "CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  259. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "!CanSlipNorthEast", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+westUpdate(a) } }) << "\n";
  260. actionStream << printSlipperyMovementGuard(a, "North", 3, { "CanSlipNorth", "!CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << "\n";
  261. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  262. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "!CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  263. actionStream << printSlipperyMovementGuard(a, "North", 2, { "CanSlipWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  264. actionStream << printSlipperyMovementGuard(a, "North", 2, {"!CanSlipWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  265. actionStream << printSlipperyMovementGuard(a, "North", 2, { "CanSlipWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a) } }) << "\n";
  266. actionStream << printSlipperyMovementGuard(a, "North", 2, {"!CanSlipWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  267. actionStream << printSlipperyMovementGuard(a, "North", 0, { "CanSlipEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  268. actionStream << printSlipperyMovementGuard(a, "North", 0, {"!CanSlipEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  269. actionStream << printSlipperyMovementGuard(a, "North", 0, { "CanSlipEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a) } }) << "\n";
  270. actionStream << printSlipperyMovementGuard(a, "North", 0, {"!CanSlipEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  271. actionStream << printSlipperyMovementGuard(a, "North", 1, { "CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, southUpdate(a) }, {1 - probIntended, northUpdate(a)} }) << "\n";
  272. actionStream << printSlipperyMovementGuard(a, "North", 1, {"!CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << "\n";
  273. actionStream << printSlipperyMovementGuard(a, "North", 1, { "CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {1, southUpdate(a)} }) << "\n";
  274. actionStream << printSlipperyMovementGuard(a, "North", 1, {"!CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  275. }
  276. void PrismModulesPrinter::printSlipperyMovementActionsForEast(const AgentName &a) {
  277. 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";
  278. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "CanSlipSouthEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1/2, eastUpdate(a)+"&"+southUpdate(a)}, {1/2, eastUpdate(a)+"&"+northUpdate(a)} });
  279. actionStream << printSlipperyMovementGuard(a, "East", 0, { "CanSlipEast", "!CanSlipSouthEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  280. actionStream << printSlipperyMovementGuard(a, "East", 0, { "CanSlipEast", "CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  281. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "!CanSlipSouthEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a) } }) << "\n";
  282. actionStream << printSlipperyMovementGuard(a, "East", 0, { "CanSlipEast", "!CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << "\n";
  283. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  284. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "!CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  285. actionStream << printSlipperyMovementGuard(a, "East", 3, { "CanSlipNorth", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, northUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  286. actionStream << printSlipperyMovementGuard(a, "East", 3, {"!CanSlipNorth", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  287. actionStream << printSlipperyMovementGuard(a, "East", 3, { "CanSlipNorth", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, northUpdate(a) } }) << "\n";
  288. actionStream << printSlipperyMovementGuard(a, "East", 3, {"!CanSlipNorth", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  289. actionStream << printSlipperyMovementGuard(a, "East", 1, { "CanSlipSouth", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, southUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  290. actionStream << printSlipperyMovementGuard(a, "East", 1, {"!CanSlipSouth", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  291. actionStream << printSlipperyMovementGuard(a, "East", 1, { "CanSlipSouth", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, southUpdate(a) } }) << "\n";
  292. actionStream << printSlipperyMovementGuard(a, "East", 1, {"!CanSlipSouth", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  293. actionStream << printSlipperyMovementGuard(a, "East", 2, { "CanSlipWest", "CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a) }, {1 - probIntended, westUpdate(a)} }) << "\n";
  294. actionStream << printSlipperyMovementGuard(a, "East", 2, {"!CanSlipWest", "CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << "\n";
  295. actionStream << printSlipperyMovementGuard(a, "East", 2, { "CanSlipWest", "!CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, westUpdate(a)} }) << "\n";
  296. actionStream << printSlipperyMovementGuard(a, "East", 2, {"!CanSlipWest", "!CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  297. }
  298. void PrismModulesPrinter::printSlipperyMovementActionsForSouth(const AgentName &a) {
  299. 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";
  300. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "CanSlipSouthEast", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1/2, southUpdate(a)+"&"+eastUpdate(a)}, {1/2, southUpdate(a)+"&"+westUpdate(a)} });
  301. actionStream << printSlipperyMovementGuard(a, "South", 1, { "CanSlipSouth", "!CanSlipSouthEast", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+westUpdate(a)} }) << "\n";
  302. actionStream << printSlipperyMovementGuard(a, "South", 1, { "CanSlipSouth", "CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  303. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "!CanSlipSouthEast", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+westUpdate(a) } }) << "\n";
  304. actionStream << printSlipperyMovementGuard(a, "South", 1, { "CanSlipSouth", "!CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << "\n";
  305. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  306. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "!CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  307. actionStream << printSlipperyMovementGuard(a, "South", 2, { "CanSlipWest", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  308. actionStream << printSlipperyMovementGuard(a, "South", 2, {"!CanSlipWest", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  309. actionStream << printSlipperyMovementGuard(a, "South", 2, { "CanSlipWest", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a) } }) << "\n";
  310. actionStream << printSlipperyMovementGuard(a, "South", 2, {"!CanSlipWest", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  311. actionStream << printSlipperyMovementGuard(a, "South", 0, { "CanSlipEast", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  312. actionStream << printSlipperyMovementGuard(a, "South", 0, {"!CanSlipEast", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  313. actionStream << printSlipperyMovementGuard(a, "South", 0, { "CanSlipEast", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a) } }) << "\n";
  314. actionStream << printSlipperyMovementGuard(a, "South", 0, {"!CanSlipEast", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  315. actionStream << printSlipperyMovementGuard(a, "South", 3, { "CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a) }, {1 - probIntended, northUpdate(a)} }) << "\n";
  316. actionStream << printSlipperyMovementGuard(a, "South", 3, {"!CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {1, northUpdate(a)} }) << "\n";
  317. actionStream << printSlipperyMovementGuard(a, "South", 3, { "CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << "\n";
  318. actionStream << printSlipperyMovementGuard(a, "South", 3, {"!CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  319. }
  320. void PrismModulesPrinter::printSlipperyMovementActionsForWest(const AgentName &a) {
  321. 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";
  322. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "CanSlipSouthWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1/2, westUpdate(a)+"&"+southUpdate(a)}, {1/2, westUpdate(a)+"&"+northUpdate(a)} });
  323. actionStream << printSlipperyMovementGuard(a, "West", 2, { "CanSlipWest", "!CanSlipSouthWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  324. actionStream << printSlipperyMovementGuard(a, "West", 2, { "CanSlipWest", "CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  325. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "!CanSlipSouthWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a) } }) << "\n";
  326. actionStream << printSlipperyMovementGuard(a, "West", 2, { "CanSlipWest", "!CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << "\n";
  327. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  328. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "!CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  329. actionStream << printSlipperyMovementGuard(a, "West", 3, { "CanSlipNorth", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, northUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  330. actionStream << printSlipperyMovementGuard(a, "West", 3, {"!CanSlipNorth", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  331. actionStream << printSlipperyMovementGuard(a, "West", 3, { "CanSlipNorth", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a) } }) << "\n";
  332. actionStream << printSlipperyMovementGuard(a, "West", 3, {"!CanSlipNorth", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  333. actionStream << printSlipperyMovementGuard(a, "West", 1, { "CanSlipSouth", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, southUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  334. actionStream << printSlipperyMovementGuard(a, "West", 1, {"!CanSlipSouth", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  335. actionStream << printSlipperyMovementGuard(a, "West", 1, { "CanSlipSouth", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, southUpdate(a) } }) << "\n";
  336. actionStream << printSlipperyMovementGuard(a, "West", 1, {"!CanSlipSouth", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  337. actionStream << printSlipperyMovementGuard(a, "West", 0, { "CanSlipEast", "CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a) }, {1 - probIntended, eastUpdate(a)} }) << "\n";
  338. actionStream << printSlipperyMovementGuard(a, "West", 0, {"!CanSlipEast", "CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << "\n";
  339. actionStream << printSlipperyMovementGuard(a, "West", 0, { "CanSlipEast", "!CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {1, eastUpdate(a)} }) << "\n";
  340. actionStream << printSlipperyMovementGuard(a, "West", 0, {"!CanSlipEast", "!CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  341. }
  342. void PrismModulesPrinter::printSlipperyTurnActionsForNorth(const AgentName &a) {
  343. actionStream << printSlipperyTurnGuard(a, "right", { "CanSlipNorth"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, northUpdate(a)} }) << "\n";
  344. actionStream << printSlipperyTurnGuard(a, "right", {"!CanSlipNorth"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  345. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipNorth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"-1)"}, {1 - probIntended, northUpdate(a)} }) << "\n";
  346. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipNorth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"=3)"}, {1 - probIntended, northUpdate(a)} }) << "\n";
  347. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipNorth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  348. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipNorth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"=3)"} }) << "\n";
  349. }
  350. void PrismModulesPrinter::printSlipperyTurnActionsForEast(const AgentName &a) {
  351. actionStream << printSlipperyTurnGuard(a, "right", { "CanSlipEast"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, eastUpdate(a)} }) << "\n";
  352. actionStream << printSlipperyTurnGuard(a, "right", {"!CanSlipEast"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  353. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipEast"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"-1)"}, {1 - probIntended, eastUpdate(a)} }) << "\n";
  354. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipEast"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"=3)"}, {1 - probIntended, eastUpdate(a)} }) << "\n";
  355. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipEast"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  356. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipEast"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"=3)"} }) << "\n";
  357. }
  358. void PrismModulesPrinter::printSlipperyTurnActionsForSouth(const AgentName &a) {
  359. actionStream << printSlipperyTurnGuard(a, "right", { "CanSlipSouth"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, southUpdate(a)} }) << "\n";
  360. actionStream << printSlipperyTurnGuard(a, "right", {"!CanSlipSouth"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  361. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipSouth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"-1)"}, {1 - probIntended, southUpdate(a)} }) << "\n";
  362. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipSouth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"=3)"}, {1 - probIntended, southUpdate(a)} }) << "\n";
  363. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipSouth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  364. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipSouth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"=3)"} }) << "\n";
  365. }
  366. void PrismModulesPrinter::printSlipperyTurnActionsForWest(const AgentName &a) {
  367. actionStream << printSlipperyTurnGuard(a, "right", { "CanSlipWest"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, westUpdate(a)} }) << "\n";
  368. actionStream << printSlipperyTurnGuard(a, "right", {"!CanSlipWest"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  369. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipWest"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"-1)"}, {1 - probIntended, westUpdate(a)} }) << "\n";
  370. actionStream << printSlipperyTurnGuard(a, "left", { "CanSlipWest"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"=3)"}, {1 - probIntended, westUpdate(a)} }) << "\n";
  371. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipWest"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << "\n";
  372. actionStream << printSlipperyTurnGuard(a, "left", {"!CanSlipWest"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"=3)"} }) << "\n";
  373. }
  374. std::string PrismModulesPrinter::printSlipperyMovementGuard(const AgentName &a, const std::string &direction, const ViewDirection &viewDirection, const std::vector<std::string> &guards) const {
  375. return "\t[" + a + "_move_" + direction + "] " + moveGuard(a) + viewVariable(a, viewDirection) + faultyBehaviourGuard(a, FORWARD) + a + "IsOnSlippery" + direction + " & " + buildConjunction(a, guards) + " -> ";
  376. }
  377. std::string PrismModulesPrinter::printSlipperyMovementUpdate(const AgentName &a, const std::string &direction, const updates &u) const {
  378. return updatesToString(u, a, FORWARD);
  379. }
  380. std::string PrismModulesPrinter::printSlipperyTurnGuard(const AgentName &a, const std::string &direction, const std::vector<std::string> &guards, const std::string &cond) const {
  381. return "\t[" + a + "_turn_" + direction + "] " + buildConjunction(a, guards) + " & " + cond + " -> ";
  382. }
  383. std::string PrismModulesPrinter::printSlipperyTurnUpdate(const AgentName &a, const updates &u) {
  384. return updatesToString(u, a, NOFAULT);
  385. }
  386. std::ostream& PrismModulesPrinter::printConfiguredActions(std::ostream &os, const AgentName &agentName) {
  387. for (auto& config : configuration) {
  388. if (config.type_ == ConfigType::Module && !config.overwrite_ && agentName == config.module_) {
  389. os << config.expression_ ;
  390. }
  391. }
  392. os << "\n";
  393. return os;
  394. }
  395. std::ostream& PrismModulesPrinter::printDoneActions(std::ostream &os, const AgentName &agentName) {
  396. os << "\t[" << agentName << "_done]" << moveGuard(agentName) << agentName << "IsInGoal | " << agentName << "IsInLava -> (" << agentName << "Done'=true);\n";
  397. return os;
  398. }
  399. std::ostream& PrismModulesPrinter::printSlipperyTurn(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &c, std::set<std::string> &slipperyActions, const std::array<bool, 8>& neighborhood, SlipperyType orientation) {
  400. // constexpr std::size_t PROB_PIECES = 9, ALL_POSS_DIRECTIONS = 9;
  401. // std::array<std::string, ALL_POSS_DIRECTIONS> positionTransition = {
  402. // /* north */ "(y" + agentName + "'=y" + agentName + "-1)",
  403. // /* north east */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "-1)",
  404. // /* east */ "(x" + agentName + "'=x" + agentName + "+1)",
  405. // /* east south */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "+1)",
  406. // /* south */ "(y" + agentName + "'=y" + agentName + "+1)",
  407. // /* south west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "+1)",
  408. // /* west */ "(x" + agentName + "'=x" + agentName + "-1)",
  409. // /* north west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "-1)",
  410. // /* own position */ "(x" + agentName + "'=x" + agentName + ") & (y" + agentName + "'=y" + agentName + ")"
  411. // };
  412. // // view transition appdx in form (guard, update part)
  413. // // IMPORTANT: No mod() usage for turn left due to bug in mod() function for decrement
  414. // std::array<std::tuple<std::string, std::string, std::string>, 3> viewTransition = {
  415. // std::make_tuple(" & " + agentName + "SlipperyTurnRightAllowed ", " & (view" + agentName + "'=mod(view" + agentName + " + 1, 4))", "_right]"),
  416. // std::make_tuple(" & " + agentName + "SlipperyTurnLeftAllowed & view" + agentName + ">0", " & (view" + agentName + "'=view" + agentName + " - 1)", "_left]"),
  417. // std::make_tuple(" & " + agentName + "SlipperyTurnLeftAllowed & view" + agentName + "=0", " & (view" + agentName + "'=3)", "_left]")
  418. // };
  419. // // direction specifics
  420. // std::string actionName;
  421. // std::string positionGuard;
  422. // std::size_t remainPosIndex = 8;
  423. // std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // { n, ne, e, se, s, sw, w, nw, CURRENT POS }
  424. // std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants;
  425. // switch (orientation)
  426. // {
  427. // case SlipperyType::North:
  428. // actionName = "\t[" + agentName + "turn_at_slip_north";
  429. // positionGuard = "\t" + agentName + "IsOnSlipperyNorth";
  430. // prob_piece_dir = { 0, 0, 0, 0, 1, 0, 0, 0, 0 /* <- R */ };
  431. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_turn_displacement" /* <- R */, "prop_zero", "prop_zero", "prop_zero","prop_zero" };
  432. // break;
  433. // case SlipperyType::South:
  434. // actionName = "\t[" + agentName + "turn_at_slip_south";
  435. // positionGuard = "\t" + agentName + "IsOnSlipperySouth";
  436. // prob_piece_dir = { 1, 0, 0, 0, 0, 0, 0, 0, 0 /* <- R */ };
  437. // prob_piece_dir_constants = { "prop_turn_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" };
  438. // break;
  439. // case SlipperyType::East:
  440. // actionName = "\t[" + agentName + "turn_at_slip_east";
  441. // positionGuard = "\t" + agentName + "IsOnSlipperyEast";
  442. // prob_piece_dir = { 0, 0, 0, 0, 0, 0, 1, 0, 0 /* <- R */ };
  443. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_turn_displacement", "prop_zero", "prop_zero" };
  444. // break;
  445. // case SlipperyType::West:
  446. // actionName = "\t[" + agentName + "turn_at_slip_west";
  447. // positionGuard = "\t" + agentName + "IsOnSlipperyWest";
  448. // prob_piece_dir = { 0, 0, 1, 0, 0, 0, 0, 0, 0 /* <- R */ };
  449. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_turn_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" };
  450. // break;
  451. // }
  452. // slipperyActions.insert(actionName + "_left]");
  453. // slipperyActions.insert(actionName + "_right]");
  454. // // override probability to 0 if corresp. direction is blocked
  455. // for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS - 1; i++) {
  456. // if (!neighborhood.at(i))
  457. // prob_piece_dir.at(i) = 0;
  458. // }
  459. // // determine residual probability (R) by replacing 0 with (1 - overall sum)
  460. // prob_piece_dir.at(remainPosIndex) = PROB_PIECES - std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0);
  461. // prob_piece_dir_constants.at(remainPosIndex) = "prop_turn_intended";
  462. // // <DEBUG_AREA>
  463. // {
  464. // assert(prob_piece_dir.at(remainPosIndex) <= 9 && prob_piece_dir.at(remainPosIndex) >= 6 && "Value not in Range!");
  465. // assert(std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0) == PROB_PIECES && "Does not sum up to 1!");
  466. // }
  467. // // </DEBUG_AREA>
  468. // // generic output (for every view transition)
  469. // for (std::size_t v = 0; v < viewTransition.size(); v++) {
  470. // os << actionName << std::get<2>(viewTransition.at(v)) << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << std::get<0>(viewTransition.at(v));
  471. // for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  472. // if (i == remainPosIndex) {
  473. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants.at(i) << " : " << positionTransition.at(i) << std::get<1>(viewTransition.at(v)) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  474. // } else {
  475. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  476. // }
  477. // }
  478. // }
  479. return os;
  480. }
  481. std::ostream& PrismModulesPrinter::printSlipperyMove(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &c, std::set<std::string> &slipperyActions, const std::array<bool, 8>& neighborhood, SlipperyType orientation) {
  482. //constexpr std::size_t PROB_PIECES = 9, ALL_POSS_DIRECTIONS = 8;
  483. //std::array<std::string, ALL_POSS_DIRECTIONS> positionTransition = {
  484. // /* north */ "(y" + agentName + "'=y" + agentName + "-1)",
  485. // /* north east */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "-1)",
  486. // /* east */ "(x" + agentName + "'=x" + agentName + "+1)",
  487. // /* east south */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "+1)",
  488. // /* south */ "(y" + agentName + "'=y" + agentName + "+1)",
  489. // /* south west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "+1)",
  490. // /* west */ "(x" + agentName + "'=x" + agentName + "-1)",
  491. // /* north west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "-1)"
  492. //};
  493. //// direction specifics
  494. //std::size_t straightPosIndex, straightPosIndex_east, straightPosIndex_south, straightPosIndex_west, straightPosIndex_north;
  495. //std::string actionName, specialTransition; // if straight ahead is blocked
  496. //std::string positionGuard;
  497. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // { n, ne, e, se, s, sw, w, nw }
  498. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_north; // { n, ne, e, se, s, sw, w, nw }
  499. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_east; // { n, ne, e, se, s, sw, w, nw }
  500. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_south; // { n, ne, e, se, s, sw, w, nw }
  501. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_west; // { n, ne, e, se, s, sw, w, nw }
  502. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants;
  503. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_north;
  504. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_east;
  505. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_south;
  506. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_west;
  507. //switch (orientation)
  508. //{
  509. // case SlipperyType::North:
  510. // actionName = "\t[" + agentName + "move_on_slip_north]";
  511. // positionGuard = "\t" + agentName + "IsOnSlipperyNorth";
  512. // prob_piece_dir = { 0, 0, 1, 2, 0 /* <- R */, 2, 1, 0 };
  513. // prob_piece_dir_agent_south = { 0 , 0, 0, 1, 0 /*s <- R */, 1, 0, 0};
  514. // prob_piece_dir_agent_east = { 0, 0, 0 /*e <- R */, 2, 0, 0, 0, 0 };
  515. // prob_piece_dir_agent_north = { 0 /*n <- R */, 0, 0, 0, 2 , 0, 0, 0 };
  516. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 2, 0 /* <- R */, 0 };
  517. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_displacement * 1/2", "prop_displacement", "prop_zero" /* <- R */, "prop_displacement", "prop_displacement * 1/2", "prop_zero" };
  518. // prob_piece_dir_constants_agent_north = { "prop_zero", "prop_zero", "prop_zero", "prop_displacement * 1/2", "prop_zero" /* <- R */, "prop_displacement * 1/2", "prop_zero", "prop_zero" };
  519. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_zero", "prop_zero", "prop_displacement", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  520. // prob_piece_dir_constants_agent_south = { "prop_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  521. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_displacement", "prop_zero", "prop_zero" } ;
  522. // straightPosIndex = 4;
  523. // straightPosIndex_east = 2;
  524. // straightPosIndex_south = 4;
  525. // straightPosIndex_west = 6;
  526. // straightPosIndex_north = 0;
  527. // specialTransition = "(y" + agentName + "'=y" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "+1)");
  528. // break;
  529. // case SlipperyType::South:
  530. // actionName = "\t[" + agentName + "move_on_slip_south]";
  531. // positionGuard = "\t" + agentName + "IsOnSlipperySouth";
  532. // prob_piece_dir = { 0 /* <- R */, 2, 1, 0, 0, 0, 1, 2 };
  533. // // { n, ne, e, se, s, sw, w, nw }
  534. // prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  535. // prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  536. // prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  537. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  538. // prob_piece_dir_constants = { "prop_zero" /* <- R */, "prop_displacement", "prop_displacement * 1/2", "prop_zero", "prop_zero", "prop_zero", "prop_displacement * 1/2", "prop_displacement" };
  539. // prob_piece_dir_constants_agent_north = { "prop_zero", "prop_displacement * 1/2", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_displacement * 1/2" };
  540. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_displacement", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  541. // prob_piece_dir_constants_agent_south = { "prop_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  542. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_displacement" } ;
  543. // straightPosIndex = 0; // always north
  544. // straightPosIndex_east = 2;
  545. // straightPosIndex_south = 4;
  546. // straightPosIndex_west = 6;
  547. // straightPosIndex_north = 0;
  548. // specialTransition = "(y" + agentName + "'=y" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "-1)");
  549. // break;
  550. // case SlipperyType::East:
  551. // actionName = "\t[" + agentName + "move_on_slip_east]";
  552. // positionGuard = "\t" + agentName + "IsOnSlipperyEast";
  553. // // { n, ne, e, se, s, sw, w, nw }
  554. // prob_piece_dir = { 1, 0, 0, 0, 1, 2, 0 /* <- R */, 2 };
  555. // // TODO
  556. // prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  557. // prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  558. // prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  559. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  560. // prob_piece_dir_constants = { "prop_displacement * 1/2", "prop_zero", "prop_zero", "prop_zero", "prop_displacement * 1/2", "prop_displacement", "prop_zero" /* <- R */, "prop_displacement" };
  561. // prob_piece_dir_constants_agent_north = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_displacement * 1/2", "prop_displacement * 1/2" };
  562. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_displacement", "prop_zero" };
  563. // prob_piece_dir_constants_agent_south = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_displacement * 1/2", "prop_displacement * 1/2", "prop_zero" } ;
  564. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_displacement * 1/2", "prop_zero", "prop_displacement * 1/2" } ;
  565. // straightPosIndex = 6;
  566. // straightPosIndex_east = 2;
  567. // straightPosIndex_south = 4;
  568. // straightPosIndex_west = 6;
  569. // straightPosIndex_north = 0;
  570. // specialTransition = "(x" + agentName + "'=x" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "-1)");
  571. // break;
  572. // case SlipperyType::West:
  573. // actionName = "\t[" + agentName + "move_on_slip_west]";
  574. // positionGuard = "\t" + agentName + "IsOnSlipperyWest";
  575. // prob_piece_dir = { 1, 2, 0 /* <- R */, 2, 1, 0, 0, 0 };
  576. // // TODO
  577. // // { n, ne, e, se, s, sw, w, nw }
  578. // prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  579. // prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  580. // prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  581. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  582. // prob_piece_dir_constants = {"prop_displacement * 1/2", "prop_displacement", "prop_zero" /* <- R */, "prop_displacement", "prop_displacement * 1/2", "prop_zero","prop_zero", "prop_zero" };
  583. // prob_piece_dir_constants_agent_north = { "prop_zero", "prop_displacement * 1/2", "prop_displacement * 1/2", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  584. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_displacement * 1/2", "prop_zero", "prop_displacement * 1/2", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  585. // prob_piece_dir_constants_agent_south = { "prop_zero", "prop_zero", "prop_displacement * 1/2", "prop_displacement * 1/2", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  586. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_displacement", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  587. // straightPosIndex = 2;
  588. // straightPosIndex_east = 2;
  589. // straightPosIndex_south = 4;
  590. // straightPosIndex_west = 6;
  591. // straightPosIndex_north = 0;
  592. // specialTransition = "(x" + agentName + "'=x" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "+1)");
  593. // break;
  594. //}
  595. //slipperyActions.insert(actionName);
  596. //// override probability to 0 if corresp. direction is blocked
  597. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  598. // if (!neighborhood.at(i))
  599. // prob_piece_dir.at(i) = 0;
  600. //}
  601. //// determine residual probability (R) by replacing 0 with (1 - overall sum)
  602. //prob_piece_dir.at(straightPosIndex) = PROB_PIECES - std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0);
  603. //prob_piece_dir_constants.at(straightPosIndex) = "prop_intended";
  604. //prob_piece_dir_constants_agent_east.at(straightPosIndex_east) = "prop_intended";
  605. //prob_piece_dir_constants_agent_south.at(straightPosIndex_south) = "prop_intended";
  606. //prob_piece_dir_constants_agent_west.at(straightPosIndex_west) = "prop_intended";
  607. //prob_piece_dir_constants_agent_north.at(straightPosIndex_north) = "prop_intended";
  608. //// <DEBUG_AREA>
  609. //{
  610. // assert(prob_piece_dir.at(straightPosIndex) <= 9 && prob_piece_dir.at(straightPosIndex) >= 3 && "Value not in Range!");
  611. // assert(std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0) == PROB_PIECES && "Does not sum up to 1!");
  612. // assert(orientation != SlipperyType::North || (prob_piece_dir.at(7) == 0 && prob_piece_dir.at(0) == 0 && prob_piece_dir.at(1) == 0 && "Slippery up should be impossible!"));
  613. // assert(orientation != SlipperyType::South || (prob_piece_dir.at(3) == 0 && prob_piece_dir.at(4) == 0 && prob_piece_dir.at(5) == 0 && "Slippery down should be impossible!"));
  614. // assert(orientation != SlipperyType::East || (prob_piece_dir.at(1) == 0 && prob_piece_dir.at(2) == 0 && prob_piece_dir.at(3) == 0 && "Slippery right should be impossible!"));
  615. // assert(orientation != SlipperyType::West || (prob_piece_dir.at(5) == 0 && prob_piece_dir.at(6) == 0 && prob_piece_dir.at(7) == 0 && "Slippery left should be impossible!"));
  616. //}
  617. //// </DEBUG_AREA>
  618. //// special case: straight forward is blocked (then remain in same position)
  619. //positionTransition.at(straightPosIndex) = specialTransition;
  620. //// generic output (for every view and every possible view direction)
  621. //size_t current_dir = 0; // East
  622. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  623. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  624. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_east.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  625. //}
  626. //current_dir = 1; // South
  627. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  628. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  629. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_south.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  630. //}
  631. //current_dir = 2; // West
  632. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  633. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  634. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_west.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  635. //}
  636. //current_dir = 3; // North
  637. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  638. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  639. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_north.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  640. //}
  641. return os;
  642. }
  643. std::ostream& PrismModulesPrinter::printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities, const std::set<std::string> &slipperyActions) {
  644. os << "player " << agentName << "\n\t";
  645. bool first = true;
  646. std::list<std::string> allActions = { "_move_north", "_move_east", "_move_south", "_move_west" };
  647. std::list<std::string> movementActions = allActions;
  648. for(auto const& probability : probabilities) {
  649. std::string percentageString = std::to_string((int)(100 * probability));
  650. for(auto const& movement : movementActions) {
  651. allActions.push_back(movement + "_" + percentageString);
  652. }
  653. }
  654. if(agentWithView) {
  655. allActions.push_back("_turn_left");
  656. allActions.push_back("_turn_right");
  657. } else {
  658. allActions.push_back("_turns");
  659. }
  660. for(auto const& action : allActions) {
  661. if(first) first = false; else os << ", ";
  662. os << "[" << agentName << action << "]";
  663. }
  664. for(auto const& action : slipperyActions) {
  665. os << ", " << action;
  666. }
  667. os << ", [" << agentName << "_done]";
  668. os << "\nendplayer\n";
  669. return os;
  670. }
  671. std::ostream& PrismModulesPrinter::printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer) {
  672. os << "\nglobal move : [0.." << std::to_string(numberOfPlayer - 1) << "];\n\n";
  673. return os;
  674. }
  675. 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) {
  676. if(lava.size() != 0) {
  677. os << "rewards \"" << agentName << "SafetyNoBFS\"\n";
  678. os << "\t" <<agentName << "IsInLavaAndNotDone: -100;\n";
  679. os << "endrewards\n";
  680. }
  681. if (!goals.empty() || !lava.empty()) {
  682. os << "rewards \"" << agentName << "SafetyNoBFSAndGoal\"\n";
  683. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  684. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  685. os << "endrewards\n";
  686. }
  687. os << "rewards \"" << agentName << "Time\"\n";
  688. os << "\t!" << agentName << "IsInGoal : -1;\n";
  689. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  690. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  691. os << "endrewards\n";
  692. if(stateRewards.size() > 0) {
  693. os << "rewards \"" << agentName << "SafetyWithBFS\"\n";
  694. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  695. for(auto const [coordinates, reward] : stateRewards) {
  696. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  697. }
  698. os << "endrewards\n";
  699. }
  700. if(stateRewards.size() > 0) {
  701. os << "rewards \"" << agentName << "SafetyWithBFSAndGoal\"\n";
  702. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone: 100;\n";
  703. if(lava.size() != 0) os << "\tAgentIsInLavaAndNotDone: -100;\n";
  704. for(auto const [coordinates, reward] : stateRewards) {
  705. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  706. }
  707. os << "endrewards\n";
  708. }
  709. for(auto const entry : backgroundTiles)
  710. {
  711. std::cout << getColor(entry.first) << " ";
  712. for(auto const cell : entry.second){
  713. std::cout << cell.getCoordinates().first << " " << cell.getCoordinates().second << std::endl;
  714. }
  715. }
  716. if(backgroundTiles.size() > 0) {
  717. os << "rewards \"TaxiReward\"\n";
  718. os << "\t!AgentIsInGoal : -1;\n";
  719. std::string allPassengersPickedUp = "";
  720. bool first = true;
  721. for(auto const [color, cells] : backgroundTiles) {
  722. if(cells.size() == 0) continue;
  723. if(first) first = false; else allPassengersPickedUp += "&";
  724. std::string c = getColor(color);
  725. c.at(0) = std::toupper(c.at(0));
  726. std::string visitedLabel = agentName + "_picked_up_" + c;
  727. allPassengersPickedUp += visitedLabel;
  728. os << "[" << agentName << "_pickup_" << c << "] true : 100;\n";
  729. }
  730. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & " << allPassengersPickedUp << " : 100;\n";
  731. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & !(" << allPassengersPickedUp << ") : -100;\n";
  732. os << "endrewards";
  733. }
  734. return os;
  735. }
  736. std::string PrismModulesPrinter::moveGuard(const AgentName &agentName) const {
  737. return isGame() ? " move=" + std::to_string(agentIndexMap.at(agentName)) + " & " : " ";
  738. }
  739. std::string PrismModulesPrinter::faultyBehaviourGuard(const AgentName &agentName, const ActionId &actionId) const {
  740. if(faultyBehaviour()) {
  741. if(actionId == NOFAULT) {
  742. return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + ") & ";
  743. } else {
  744. return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + " | previousAction" + agentName + "=" + std::to_string(actionId) + ") & ";
  745. }
  746. } else {
  747. return "";
  748. }
  749. }
  750. std::string PrismModulesPrinter::faultyBehaviourUpdate(const AgentName &agentName, const ActionId &actionId) const {
  751. return "(previousAction" + agentName + "'=" + std::to_string(actionId) + ")";
  752. }
  753. std::string PrismModulesPrinter::moveUpdate(const AgentName &agentName) const {
  754. size_t agentIndex = agentIndexMap.at(agentName);
  755. return isGame() ?
  756. (agentIndex == numberOfPlayer - 1) ?
  757. " & (move'=0) " :
  758. " & (move'=" + std::to_string(agentIndex + 1) + ") " :
  759. "";
  760. }
  761. std::string PrismModulesPrinter::updatesToString(const updates &updates, const AgentName &a, const ActionId &actionId) const {
  762. if(updates.empty()) return "true";
  763. std::string updatesString = "";
  764. bool first = true;
  765. for(auto const update : updates) {
  766. if(first) first = false;
  767. else updatesString += " + ";
  768. updatesString += updateToString(update);
  769. if(faultyBehaviour()) updatesString += "&" + faultyBehaviourUpdate(a, actionId);
  770. }
  771. return updatesString;
  772. }
  773. std::string PrismModulesPrinter::updateToString(const update &u) const {
  774. return std::to_string(u.first) + ": " + u.second;
  775. }
  776. std::string PrismModulesPrinter::viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView) const {
  777. return agentWithView ? " view" + agentName + "=" + std::to_string(agentDirection) + " & " : " ";
  778. }
  779. bool PrismModulesPrinter::anyPortableObject() const {
  780. return !keys.empty() || !boxes.empty() || !balls.empty();
  781. }
  782. bool PrismModulesPrinter::faultyBehaviour() const {
  783. return faultyProbability > 0.0f;
  784. }
  785. bool PrismModulesPrinter::slipperyBehaviour() const {
  786. return !slipperyTiles.at("North").empty() || !slipperyTiles.at("East").empty() || !slipperyTiles.at("South").empty() || !slipperyTiles.at("West").empty();
  787. }
  788. bool PrismModulesPrinter::isGame() const {
  789. return modelType == ModelType::SMG;
  790. }
  791. std::string PrismModulesPrinter::buildConjunction(const AgentName &a, std::vector<std::string> formulae) const {
  792. if(formulae.empty()) return "true";
  793. std::string conjunction = "";
  794. bool first = true;
  795. for(auto const formula : formulae) {
  796. if(first) first = false;
  797. else conjunction += " & ";
  798. conjunction += formula;
  799. }
  800. return conjunction;
  801. }
  802. }