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.

920 lines
60 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. }
  240. if(!slipperyTiles.at("East").empty()) {
  241. printSlipperyMovementActionsForEast(a) ;
  242. }
  243. if(!slipperyTiles.at("South").empty()) {
  244. printSlipperyMovementActionsForSouth(a);
  245. }
  246. if(!slipperyTiles.at("West").empty()) {
  247. printSlipperyMovementActionsForWest(a) ;
  248. }
  249. }
  250. void PrismModulesPrinter::printSlipperyMovementActionsForNorth(const AgentName &a) {
  251. 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";
  252. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "CanSlipNorthEast", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1/2, northUpdate(a)+"&"+eastUpdate(a)}, {1/2, northUpdate(a)+"&"+westUpdate(a)} });
  253. actionStream << printSlipperyMovementGuard(a, "North", 3, { "CanSlipNorth", "!CanSlipNorthEast", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+westUpdate(a)} }) << "\n";
  254. actionStream << printSlipperyMovementGuard(a, "North", 3, { "CanSlipNorth", "CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  255. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "!CanSlipNorthEast", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+westUpdate(a) } }) << "\n";
  256. actionStream << printSlipperyMovementGuard(a, "North", 3, { "CanSlipNorth", "!CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << "\n";
  257. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  258. actionStream << printSlipperyMovementGuard(a, "North", 3, {"!CanSlipNorth", "!CanSlipNorthEast", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  259. actionStream << printSlipperyMovementGuard(a, "North", 2, { "CanSlipWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  260. actionStream << printSlipperyMovementGuard(a, "North", 2, {"!CanSlipWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  261. actionStream << printSlipperyMovementGuard(a, "North", 2, { "CanSlipWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a) } }) << "\n";
  262. actionStream << printSlipperyMovementGuard(a, "North", 2, {"!CanSlipWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  263. actionStream << printSlipperyMovementGuard(a, "North", 0, { "CanSlipEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  264. actionStream << printSlipperyMovementGuard(a, "North", 0, {"!CanSlipEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  265. actionStream << printSlipperyMovementGuard(a, "North", 0, { "CanSlipEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a) } }) << "\n";
  266. actionStream << printSlipperyMovementGuard(a, "North", 0, {"!CanSlipEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  267. actionStream << printSlipperyMovementGuard(a, "North", 1, { "CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, southUpdate(a) }, {1 - probIntended, northUpdate(a)} }) << "\n";
  268. actionStream << printSlipperyMovementGuard(a, "North", 1, {"!CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << "\n";
  269. actionStream << printSlipperyMovementGuard(a, "North", 1, { "CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", { {1, southUpdate(a)} }) << "\n";
  270. actionStream << printSlipperyMovementGuard(a, "North", 1, {"!CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "North", {}) << "\n";
  271. }
  272. void PrismModulesPrinter::printSlipperyMovementActionsForEast(const AgentName &a) {
  273. 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";
  274. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "CanSlipSouthEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1/2, eastUpdate(a)+"&"+southUpdate(a)}, {1/2, eastUpdate(a)+"&"+northUpdate(a)} });
  275. actionStream << printSlipperyMovementGuard(a, "East", 0, { "CanSlipEast", "!CanSlipSouthEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  276. actionStream << printSlipperyMovementGuard(a, "East", 0, { "CanSlipEast", "CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  277. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "!CanSlipSouthEast", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a) } }) << "\n";
  278. actionStream << printSlipperyMovementGuard(a, "East", 0, { "CanSlipEast", "!CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << "\n";
  279. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  280. actionStream << printSlipperyMovementGuard(a, "East", 0, {"!CanSlipEast", "!CanSlipSouthEast", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  281. actionStream << printSlipperyMovementGuard(a, "East", 3, { "CanSlipNorth", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, northUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  282. actionStream << printSlipperyMovementGuard(a, "East", 3, {"!CanSlipNorth", "CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  283. actionStream << printSlipperyMovementGuard(a, "East", 3, { "CanSlipNorth", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, northUpdate(a) } }) << "\n";
  284. actionStream << printSlipperyMovementGuard(a, "East", 3, {"!CanSlipNorth", "!CanSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  285. actionStream << printSlipperyMovementGuard(a, "East", 1, { "CanSlipSouth", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, southUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  286. actionStream << printSlipperyMovementGuard(a, "East", 1, {"!CanSlipSouth", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  287. actionStream << printSlipperyMovementGuard(a, "East", 1, { "CanSlipSouth", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, southUpdate(a) } }) << "\n";
  288. actionStream << printSlipperyMovementGuard(a, "East", 1, {"!CanSlipSouth", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  289. actionStream << printSlipperyMovementGuard(a, "East", 2, { "CanSlipWest", "CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a) }, {1 - probIntended, westUpdate(a)} }) << "\n";
  290. actionStream << printSlipperyMovementGuard(a, "East", 2, {"!CanSlipWest", "CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << "\n";
  291. actionStream << printSlipperyMovementGuard(a, "East", 2, { "CanSlipWest", "!CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, westUpdate(a)} }) << "\n";
  292. actionStream << printSlipperyMovementGuard(a, "East", 2, {"!CanSlipWest", "!CanSlipEast"}) << printSlipperyMovementUpdate(a, "East", {}) << "\n";
  293. }
  294. void PrismModulesPrinter::printSlipperyMovementActionsForSouth(const AgentName &a) {
  295. 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";
  296. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "CanSlipSouthEast", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1/2, southUpdate(a)+"&"+eastUpdate(a)}, {1/2, southUpdate(a)+"&"+westUpdate(a)} });
  297. actionStream << printSlipperyMovementGuard(a, "South", 1, { "CanSlipSouth", "!CanSlipSouthEast", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+westUpdate(a)} }) << "\n";
  298. actionStream << printSlipperyMovementGuard(a, "South", 1, { "CanSlipSouth", "CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  299. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "!CanSlipSouthEast", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+westUpdate(a) } }) << "\n";
  300. actionStream << printSlipperyMovementGuard(a, "South", 1, { "CanSlipSouth", "!CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << "\n";
  301. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+eastUpdate(a)} }) << "\n";
  302. actionStream << printSlipperyMovementGuard(a, "South", 1, {"!CanSlipSouth", "!CanSlipSouthEast", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  303. actionStream << printSlipperyMovementGuard(a, "South", 2, { "CanSlipWest", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  304. actionStream << printSlipperyMovementGuard(a, "South", 2, {"!CanSlipWest", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  305. actionStream << printSlipperyMovementGuard(a, "South", 2, { "CanSlipWest", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a) } }) << "\n";
  306. actionStream << printSlipperyMovementGuard(a, "South", 2, {"!CanSlipWest", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  307. actionStream << printSlipperyMovementGuard(a, "South", 0, { "CanSlipEast", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  308. actionStream << printSlipperyMovementGuard(a, "South", 0, {"!CanSlipEast", "CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  309. actionStream << printSlipperyMovementGuard(a, "South", 0, { "CanSlipEast", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a) } }) << "\n";
  310. actionStream << printSlipperyMovementGuard(a, "South", 0, {"!CanSlipEast", "!CanSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  311. actionStream << printSlipperyMovementGuard(a, "South", 3, { "CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a) }, {1 - probIntended, northUpdate(a)} }) << "\n";
  312. actionStream << printSlipperyMovementGuard(a, "South", 3, {"!CanSlipSouth", "CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {1, northUpdate(a)} }) << "\n";
  313. actionStream << printSlipperyMovementGuard(a, "South", 3, { "CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << "\n";
  314. actionStream << printSlipperyMovementGuard(a, "South", 3, {"!CanSlipSouth", "!CanSlipNorth"}) << printSlipperyMovementUpdate(a, "South", {}) << "\n";
  315. }
  316. void PrismModulesPrinter::printSlipperyMovementActionsForWest(const AgentName &a) {
  317. 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";
  318. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "CanSlipSouthWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1/2, westUpdate(a)+"&"+southUpdate(a)}, {1/2, westUpdate(a)+"&"+northUpdate(a)} });
  319. actionStream << printSlipperyMovementGuard(a, "West", 2, { "CanSlipWest", "!CanSlipSouthWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  320. actionStream << printSlipperyMovementGuard(a, "West", 2, { "CanSlipWest", "CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  321. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "!CanSlipSouthWest", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a) } }) << "\n";
  322. actionStream << printSlipperyMovementGuard(a, "West", 2, { "CanSlipWest", "!CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << "\n";
  323. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  324. actionStream << printSlipperyMovementGuard(a, "West", 2, {"!CanSlipWest", "!CanSlipSouthWest", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  325. actionStream << printSlipperyMovementGuard(a, "West", 3, { "CanSlipNorth", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, northUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  326. actionStream << printSlipperyMovementGuard(a, "West", 3, {"!CanSlipNorth", "CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << "\n";
  327. actionStream << printSlipperyMovementGuard(a, "West", 3, { "CanSlipNorth", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a) } }) << "\n";
  328. actionStream << printSlipperyMovementGuard(a, "West", 3, {"!CanSlipNorth", "!CanSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  329. actionStream << printSlipperyMovementGuard(a, "West", 1, { "CanSlipSouth", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, southUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  330. actionStream << printSlipperyMovementGuard(a, "West", 1, {"!CanSlipSouth", "CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << "\n";
  331. actionStream << printSlipperyMovementGuard(a, "West", 1, { "CanSlipSouth", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, southUpdate(a) } }) << "\n";
  332. actionStream << printSlipperyMovementGuard(a, "West", 1, {"!CanSlipSouth", "!CanSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  333. actionStream << printSlipperyMovementGuard(a, "West", 0, { "CanSlipEast", "CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a) }, {1 - probIntended, eastUpdate(a)} }) << "\n";
  334. actionStream << printSlipperyMovementGuard(a, "West", 0, {"!CanSlipEast", "CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << "\n";
  335. actionStream << printSlipperyMovementGuard(a, "West", 0, { "CanSlipEast", "!CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {1, eastUpdate(a)} }) << "\n";
  336. actionStream << printSlipperyMovementGuard(a, "West", 0, {"!CanSlipEast", "!CanSlipWest"}) << printSlipperyMovementUpdate(a, "West", {}) << "\n";
  337. }
  338. std::string PrismModulesPrinter::printSlipperyMovementGuard(const AgentName &a, const std::string &direction, const ViewDirection &viewDirection, const std::vector<std::string> &guards) const {
  339. return "\t[" + a + "_move_" + direction + "]" + moveGuard(a) + viewVariable(a, viewDirection) + faultyBehaviourGuard(a, FORWARD) + a + "IsOnSlippery" + direction + " & " + buildConjunction(a, guards) + " -> ";
  340. }
  341. std::string PrismModulesPrinter::printSlipperyMovementUpdate(const AgentName &a, const std::string &direction, const updates &u) const {
  342. return updatesToString(u, a, FORWARD);
  343. }
  344. std::ostream& PrismModulesPrinter::printConfiguredActions(std::ostream &os, const AgentName &agentName) {
  345. for (auto& config : configuration) {
  346. if (config.type_ == ConfigType::Module && !config.overwrite_ && agentName == config.module_) {
  347. os << config.expression_ ;
  348. }
  349. }
  350. os << "\n";
  351. return os;
  352. }
  353. std::ostream& PrismModulesPrinter::printDoneActions(std::ostream &os, const AgentName &agentName) {
  354. os << "\t[" << agentName << "_done]" << moveGuard(agentName) << agentName << "IsInGoal | " << agentName << "IsInLava -> (" << agentName << "Done'=true);\n";
  355. return os;
  356. }
  357. 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) {
  358. // constexpr std::size_t PROB_PIECES = 9, ALL_POSS_DIRECTIONS = 9;
  359. // std::array<std::string, ALL_POSS_DIRECTIONS> positionTransition = {
  360. // /* north */ "(y" + agentName + "'=y" + agentName + "-1)",
  361. // /* north east */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "-1)",
  362. // /* east */ "(x" + agentName + "'=x" + agentName + "+1)",
  363. // /* east south */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "+1)",
  364. // /* south */ "(y" + agentName + "'=y" + agentName + "+1)",
  365. // /* south west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "+1)",
  366. // /* west */ "(x" + agentName + "'=x" + agentName + "-1)",
  367. // /* north west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "-1)",
  368. // /* own position */ "(x" + agentName + "'=x" + agentName + ") & (y" + agentName + "'=y" + agentName + ")"
  369. // };
  370. // // view transition appdx in form (guard, update part)
  371. // // IMPORTANT: No mod() usage for turn left due to bug in mod() function for decrement
  372. // std::array<std::tuple<std::string, std::string, std::string>, 3> viewTransition = {
  373. // std::make_tuple(" & " + agentName + "SlipperyTurnRightAllowed ", " & (view" + agentName + "'=mod(view" + agentName + " + 1, 4))", "_right]"),
  374. // std::make_tuple(" & " + agentName + "SlipperyTurnLeftAllowed & view" + agentName + ">0", " & (view" + agentName + "'=view" + agentName + " - 1)", "_left]"),
  375. // std::make_tuple(" & " + agentName + "SlipperyTurnLeftAllowed & view" + agentName + "=0", " & (view" + agentName + "'=3)", "_left]")
  376. // };
  377. // // direction specifics
  378. // std::string actionName;
  379. // std::string positionGuard;
  380. // std::size_t remainPosIndex = 8;
  381. // std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // { n, ne, e, se, s, sw, w, nw, CURRENT POS }
  382. // std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants;
  383. // switch (orientation)
  384. // {
  385. // case SlipperyType::North:
  386. // actionName = "\t[" + agentName + "turn_at_slip_north";
  387. // positionGuard = "\t" + agentName + "IsOnSlipperyNorth";
  388. // prob_piece_dir = { 0, 0, 0, 0, 1, 0, 0, 0, 0 /* <- R */ };
  389. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_turn_displacement" /* <- R */, "prop_zero", "prop_zero", "prop_zero","prop_zero" };
  390. // break;
  391. // case SlipperyType::South:
  392. // actionName = "\t[" + agentName + "turn_at_slip_south";
  393. // positionGuard = "\t" + agentName + "IsOnSlipperySouth";
  394. // prob_piece_dir = { 1, 0, 0, 0, 0, 0, 0, 0, 0 /* <- R */ };
  395. // prob_piece_dir_constants = { "prop_turn_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" };
  396. // break;
  397. // case SlipperyType::East:
  398. // actionName = "\t[" + agentName + "turn_at_slip_east";
  399. // positionGuard = "\t" + agentName + "IsOnSlipperyEast";
  400. // prob_piece_dir = { 0, 0, 0, 0, 0, 0, 1, 0, 0 /* <- R */ };
  401. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_turn_displacement", "prop_zero", "prop_zero" };
  402. // break;
  403. // case SlipperyType::West:
  404. // actionName = "\t[" + agentName + "turn_at_slip_west";
  405. // positionGuard = "\t" + agentName + "IsOnSlipperyWest";
  406. // prob_piece_dir = { 0, 0, 1, 0, 0, 0, 0, 0, 0 /* <- R */ };
  407. // prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_turn_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" };
  408. // break;
  409. // }
  410. // slipperyActions.insert(actionName + "_left]");
  411. // slipperyActions.insert(actionName + "_right]");
  412. // // override probability to 0 if corresp. direction is blocked
  413. // for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS - 1; i++) {
  414. // if (!neighborhood.at(i))
  415. // prob_piece_dir.at(i) = 0;
  416. // }
  417. // // determine residual probability (R) by replacing 0 with (1 - overall sum)
  418. // prob_piece_dir.at(remainPosIndex) = PROB_PIECES - std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0);
  419. // prob_piece_dir_constants.at(remainPosIndex) = "prop_turn_intended";
  420. // // <DEBUG_AREA>
  421. // {
  422. // assert(prob_piece_dir.at(remainPosIndex) <= 9 && prob_piece_dir.at(remainPosIndex) >= 6 && "Value not in Range!");
  423. // assert(std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0) == PROB_PIECES && "Does not sum up to 1!");
  424. // }
  425. // // </DEBUG_AREA>
  426. // // generic output (for every view transition)
  427. // for (std::size_t v = 0; v < viewTransition.size(); v++) {
  428. // os << actionName << std::get<2>(viewTransition.at(v)) << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << std::get<0>(viewTransition.at(v));
  429. // for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  430. // if (i == remainPosIndex) {
  431. // 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");
  432. // } else {
  433. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  434. // }
  435. // }
  436. // }
  437. return os;
  438. }
  439. 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) {
  440. //constexpr std::size_t PROB_PIECES = 9, ALL_POSS_DIRECTIONS = 8;
  441. //std::array<std::string, ALL_POSS_DIRECTIONS> positionTransition = {
  442. // /* north */ "(y" + agentName + "'=y" + agentName + "-1)",
  443. // /* north east */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "-1)",
  444. // /* east */ "(x" + agentName + "'=x" + agentName + "+1)",
  445. // /* east south */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "+1)",
  446. // /* south */ "(y" + agentName + "'=y" + agentName + "+1)",
  447. // /* south west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "+1)",
  448. // /* west */ "(x" + agentName + "'=x" + agentName + "-1)",
  449. // /* north west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "-1)"
  450. //};
  451. //// direction specifics
  452. //std::size_t straightPosIndex, straightPosIndex_east, straightPosIndex_south, straightPosIndex_west, straightPosIndex_north;
  453. //std::string actionName, specialTransition; // if straight ahead is blocked
  454. //std::string positionGuard;
  455. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // { n, ne, e, se, s, sw, w, nw }
  456. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_north; // { n, ne, e, se, s, sw, w, nw }
  457. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_east; // { n, ne, e, se, s, sw, w, nw }
  458. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_south; // { n, ne, e, se, s, sw, w, nw }
  459. //std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_west; // { n, ne, e, se, s, sw, w, nw }
  460. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants;
  461. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_north;
  462. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_east;
  463. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_south;
  464. //std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_west;
  465. //switch (orientation)
  466. //{
  467. // case SlipperyType::North:
  468. // actionName = "\t[" + agentName + "move_on_slip_north]";
  469. // positionGuard = "\t" + agentName + "IsOnSlipperyNorth";
  470. // prob_piece_dir = { 0, 0, 1, 2, 0 /* <- R */, 2, 1, 0 };
  471. // prob_piece_dir_agent_south = { 0 , 0, 0, 1, 0 /*s <- R */, 1, 0, 0};
  472. // prob_piece_dir_agent_east = { 0, 0, 0 /*e <- R */, 2, 0, 0, 0, 0 };
  473. // prob_piece_dir_agent_north = { 0 /*n <- R */, 0, 0, 0, 2 , 0, 0, 0 };
  474. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 2, 0 /* <- R */, 0 };
  475. // 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" };
  476. // 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" };
  477. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_zero", "prop_zero", "prop_displacement", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  478. // prob_piece_dir_constants_agent_south = { "prop_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  479. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_displacement", "prop_zero", "prop_zero" } ;
  480. // straightPosIndex = 4;
  481. // straightPosIndex_east = 2;
  482. // straightPosIndex_south = 4;
  483. // straightPosIndex_west = 6;
  484. // straightPosIndex_north = 0;
  485. // specialTransition = "(y" + agentName + "'=y" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "+1)");
  486. // break;
  487. // case SlipperyType::South:
  488. // actionName = "\t[" + agentName + "move_on_slip_south]";
  489. // positionGuard = "\t" + agentName + "IsOnSlipperySouth";
  490. // prob_piece_dir = { 0 /* <- R */, 2, 1, 0, 0, 0, 1, 2 };
  491. // // { n, ne, e, se, s, sw, w, nw }
  492. // prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  493. // prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  494. // prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  495. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  496. // 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" };
  497. // 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" };
  498. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_displacement", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  499. // prob_piece_dir_constants_agent_south = { "prop_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  500. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_displacement" } ;
  501. // straightPosIndex = 0; // always north
  502. // straightPosIndex_east = 2;
  503. // straightPosIndex_south = 4;
  504. // straightPosIndex_west = 6;
  505. // straightPosIndex_north = 0;
  506. // specialTransition = "(y" + agentName + "'=y" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "-1)");
  507. // break;
  508. // case SlipperyType::East:
  509. // actionName = "\t[" + agentName + "move_on_slip_east]";
  510. // positionGuard = "\t" + agentName + "IsOnSlipperyEast";
  511. // // { n, ne, e, se, s, sw, w, nw }
  512. // prob_piece_dir = { 1, 0, 0, 0, 1, 2, 0 /* <- R */, 2 };
  513. // // TODO
  514. // prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  515. // prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  516. // prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  517. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  518. // 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" };
  519. // 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" };
  520. // prob_piece_dir_constants_agent_east = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_displacement", "prop_zero" };
  521. // 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" } ;
  522. // 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" } ;
  523. // straightPosIndex = 6;
  524. // straightPosIndex_east = 2;
  525. // straightPosIndex_south = 4;
  526. // straightPosIndex_west = 6;
  527. // straightPosIndex_north = 0;
  528. // specialTransition = "(x" + agentName + "'=x" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "-1)");
  529. // break;
  530. // case SlipperyType::West:
  531. // actionName = "\t[" + agentName + "move_on_slip_west]";
  532. // positionGuard = "\t" + agentName + "IsOnSlipperyWest";
  533. // prob_piece_dir = { 1, 2, 0 /* <- R */, 2, 1, 0, 0, 0 };
  534. // // TODO
  535. // // { n, ne, e, se, s, sw, w, nw }
  536. // prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  537. // prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  538. // prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  539. // prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  540. // 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" };
  541. // 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" };
  542. // 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" };
  543. // 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" } ;
  544. // prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_displacement", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  545. // straightPosIndex = 2;
  546. // straightPosIndex_east = 2;
  547. // straightPosIndex_south = 4;
  548. // straightPosIndex_west = 6;
  549. // straightPosIndex_north = 0;
  550. // specialTransition = "(x" + agentName + "'=x" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "+1)");
  551. // break;
  552. //}
  553. //slipperyActions.insert(actionName);
  554. //// override probability to 0 if corresp. direction is blocked
  555. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  556. // if (!neighborhood.at(i))
  557. // prob_piece_dir.at(i) = 0;
  558. //}
  559. //// determine residual probability (R) by replacing 0 with (1 - overall sum)
  560. //prob_piece_dir.at(straightPosIndex) = PROB_PIECES - std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0);
  561. //prob_piece_dir_constants.at(straightPosIndex) = "prop_intended";
  562. //prob_piece_dir_constants_agent_east.at(straightPosIndex_east) = "prop_intended";
  563. //prob_piece_dir_constants_agent_south.at(straightPosIndex_south) = "prop_intended";
  564. //prob_piece_dir_constants_agent_west.at(straightPosIndex_west) = "prop_intended";
  565. //prob_piece_dir_constants_agent_north.at(straightPosIndex_north) = "prop_intended";
  566. //// <DEBUG_AREA>
  567. //{
  568. // assert(prob_piece_dir.at(straightPosIndex) <= 9 && prob_piece_dir.at(straightPosIndex) >= 3 && "Value not in Range!");
  569. // assert(std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0) == PROB_PIECES && "Does not sum up to 1!");
  570. // 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!"));
  571. // 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!"));
  572. // 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!"));
  573. // 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!"));
  574. //}
  575. //// </DEBUG_AREA>
  576. //// special case: straight forward is blocked (then remain in same position)
  577. //positionTransition.at(straightPosIndex) = specialTransition;
  578. //// generic output (for every view and every possible view direction)
  579. //size_t current_dir = 0; // East
  580. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  581. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  582. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_east.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  583. //}
  584. //current_dir = 1; // South
  585. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  586. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  587. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_south.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  588. //}
  589. //current_dir = 2; // West
  590. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  591. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  592. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_west.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  593. //}
  594. //current_dir = 3; // North
  595. //os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  596. //for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  597. // os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_north.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  598. //}
  599. return os;
  600. }
  601. std::ostream& PrismModulesPrinter::printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities, const std::set<std::string> &slipperyActions) {
  602. os << "player " << agentName << "\n\t";
  603. bool first = true;
  604. std::list<std::string> allActions = { "_move_north", "_move_east", "_move_south", "_move_west" };
  605. std::list<std::string> movementActions = allActions;
  606. for(auto const& probability : probabilities) {
  607. std::string percentageString = std::to_string((int)(100 * probability));
  608. for(auto const& movement : movementActions) {
  609. allActions.push_back(movement + "_" + percentageString);
  610. }
  611. }
  612. if(agentWithView) {
  613. allActions.push_back("_turn_left");
  614. allActions.push_back("_turn_right");
  615. } else {
  616. allActions.push_back("_turns");
  617. }
  618. for(auto const& action : allActions) {
  619. if(first) first = false; else os << ", ";
  620. os << "[" << agentName << action << "]";
  621. }
  622. for(auto const& action : slipperyActions) {
  623. os << ", " << action;
  624. }
  625. os << ", [" << agentName << "_done]";
  626. os << "\nendplayer\n";
  627. return os;
  628. }
  629. std::ostream& PrismModulesPrinter::printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer) {
  630. os << "\nglobal move : [0.." << std::to_string(numberOfPlayer - 1) << "];\n\n";
  631. return os;
  632. }
  633. 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) {
  634. if(lava.size() != 0) {
  635. os << "rewards \"" << agentName << "SafetyNoBFS\"\n";
  636. os << "\t" <<agentName << "IsInLavaAndNotDone: -100;\n";
  637. os << "endrewards\n";
  638. }
  639. if (!goals.empty() || !lava.empty()) {
  640. os << "rewards \"" << agentName << "SafetyNoBFSAndGoal\"\n";
  641. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  642. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  643. os << "endrewards\n";
  644. }
  645. os << "rewards \"" << agentName << "Time\"\n";
  646. os << "\t!" << agentName << "IsInGoal : -1;\n";
  647. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  648. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  649. os << "endrewards\n";
  650. if(stateRewards.size() > 0) {
  651. os << "rewards \"" << agentName << "SafetyWithBFS\"\n";
  652. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  653. for(auto const [coordinates, reward] : stateRewards) {
  654. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  655. }
  656. os << "endrewards\n";
  657. }
  658. if(stateRewards.size() > 0) {
  659. os << "rewards \"" << agentName << "SafetyWithBFSAndGoal\"\n";
  660. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone: 100;\n";
  661. if(lava.size() != 0) os << "\tAgentIsInLavaAndNotDone: -100;\n";
  662. for(auto const [coordinates, reward] : stateRewards) {
  663. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  664. }
  665. os << "endrewards\n";
  666. }
  667. for(auto const entry : backgroundTiles)
  668. {
  669. std::cout << getColor(entry.first) << " ";
  670. for(auto const cell : entry.second){
  671. std::cout << cell.getCoordinates().first << " " << cell.getCoordinates().second << std::endl;
  672. }
  673. }
  674. if(backgroundTiles.size() > 0) {
  675. os << "rewards \"TaxiReward\"\n";
  676. os << "\t!AgentIsInGoal : -1;\n";
  677. std::string allPassengersPickedUp = "";
  678. bool first = true;
  679. for(auto const [color, cells] : backgroundTiles) {
  680. if(cells.size() == 0) continue;
  681. if(first) first = false; else allPassengersPickedUp += "&";
  682. std::string c = getColor(color);
  683. c.at(0) = std::toupper(c.at(0));
  684. std::string visitedLabel = agentName + "_picked_up_" + c;
  685. allPassengersPickedUp += visitedLabel;
  686. os << "[" << agentName << "_pickup_" << c << "] true : 100;\n";
  687. }
  688. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & " << allPassengersPickedUp << " : 100;\n";
  689. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & !(" << allPassengersPickedUp << ") : -100;\n";
  690. os << "endrewards";
  691. }
  692. return os;
  693. }
  694. std::string PrismModulesPrinter::moveGuard(const AgentName &agentName) const {
  695. return isGame() ? " move=" + std::to_string(agentIndexMap.at(agentName)) + " & " : " ";
  696. }
  697. std::string PrismModulesPrinter::faultyBehaviourGuard(const AgentName &agentName, const ActionId &actionId) const {
  698. if(faultyBehaviour()) {
  699. if(actionId == NOFAULT) {
  700. return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + ") & ";
  701. } else {
  702. return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + " | previousAction" + agentName + "=" + std::to_string(actionId) + ") & ";
  703. }
  704. } else {
  705. return "";
  706. }
  707. }
  708. std::string PrismModulesPrinter::faultyBehaviourUpdate(const AgentName &agentName, const ActionId &actionId) const {
  709. return "(previousAction" + agentName + "'=" + std::to_string(actionId) + ")";
  710. }
  711. std::string PrismModulesPrinter::moveUpdate(const AgentName &agentName) const {
  712. size_t agentIndex = agentIndexMap.at(agentName);
  713. return isGame() ?
  714. (agentIndex == numberOfPlayer - 1) ?
  715. " & (move'=0) " :
  716. " & (move'=" + std::to_string(agentIndex + 1) + ") " :
  717. "";
  718. }
  719. std::string PrismModulesPrinter::updatesToString(const updates &updates, const AgentName &a, const ActionId &actionId) const {
  720. if(updates.empty()) return "true";
  721. std::string updatesString = "";
  722. bool first = true;
  723. for(auto const update : updates) {
  724. if(first) first = false;
  725. else updatesString += " + ";
  726. updatesString += updateToString(update);
  727. if(faultyBehaviour()) updatesString += "&" + faultyBehaviourUpdate(a, actionId);
  728. }
  729. return updatesString;
  730. }
  731. std::string PrismModulesPrinter::updateToString(const update &u) const {
  732. return std::to_string(u.first) + ": " + u.second;
  733. }
  734. std::string PrismModulesPrinter::viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView) const {
  735. return agentWithView ? " view" + agentName + "=" + std::to_string(agentDirection) + " & " : " ";
  736. }
  737. bool PrismModulesPrinter::anyPortableObject() const {
  738. return !keys.empty() || !boxes.empty() || !balls.empty();
  739. }
  740. bool PrismModulesPrinter::faultyBehaviour() const {
  741. return faultyProbability > 0.0f;
  742. }
  743. bool PrismModulesPrinter::slipperyBehaviour() const {
  744. return !slipperyTiles.at("North").empty() || !slipperyTiles.at("East").empty() || !slipperyTiles.at("South").empty() || !slipperyTiles.at("West").empty();
  745. }
  746. bool PrismModulesPrinter::isGame() const {
  747. return modelType == ModelType::SMG;
  748. }
  749. std::string PrismModulesPrinter::buildConjunction(const AgentName &a, std::vector<std::string> formulae) const {
  750. if(formulae.empty()) return "true";
  751. std::string conjunction = "";
  752. bool first = true;
  753. for(auto const formula : formulae) {
  754. if(first) first = false;
  755. else conjunction += " & ";
  756. conjunction += formula;
  757. }
  758. return conjunction;
  759. }
  760. }