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.

1148 lines
63 KiB

11 months ago
  1. #include "PrismModulesPrinter.h"
  2. #include <map>
  3. #include <string>
  4. namespace prism {
  5. PrismModulesPrinter::PrismModulesPrinter(const ModelType &modelType, const size_t &numberOfPlayer, std::vector<Configuration> config, const bool enforceOneWays)
  6. : modelType(modelType), numberOfPlayer(numberOfPlayer), enforceOneWays(enforceOneWays), configuration(config), viewDirectionMapping({{0, "East"}, {1, "South"}, {2, "West"}, {3, "North"}}) {
  7. }
  8. std::ostream& PrismModulesPrinter::printModel(std::ostream &os, const ModelType &modelType) {
  9. switch(modelType) {
  10. case(ModelType::MDP):
  11. os << "mdp";
  12. break;
  13. case(ModelType::SMG):
  14. os << "smg";
  15. break;
  16. }
  17. os << "\n\n";
  18. return os;
  19. }
  20. std::ostream& PrismModulesPrinter::printBackgroundLabels(std::ostream &os, const AgentName &agentName, const std::pair<Color, cells> &backgroundTiles) {
  21. if(backgroundTiles.second.size() == 0) return os;
  22. bool first = true;
  23. std::string color = getColor(backgroundTiles.first);
  24. color.at(0) = std::toupper(color.at(0));
  25. os << "formula " << agentName << "On" << color << " = ";
  26. for(auto const& cell : backgroundTiles.second) {
  27. if(first) first = false; else os << " | ";
  28. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  29. }
  30. os << ";\n";
  31. os << "label \"" << agentName << "On" << color << "\" = " << agentName << "On" << color << ";\n";
  32. return os;
  33. }
  34. std::ostream& PrismModulesPrinter::printRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &grid_cells, const cells &keys, const cells &doors) {
  35. bool first = true;
  36. os << "formula " << agentName << "CannotMove" << direction << " = " ;
  37. for(auto const& cell : grid_cells) {
  38. if(first) first = false;
  39. else os << " | ";
  40. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  41. }
  42. if (!keys.empty()) {
  43. os << " | " << agentName << "CannotMove" << direction << "BecauseOfKey";
  44. }
  45. if (!doors.empty()) {
  46. os << " | " << agentName << "CannotMove" << direction << "BecauseOfDoor";
  47. }
  48. os << ";\n";
  49. return os;
  50. }
  51. std::ostream& PrismModulesPrinter::printKeyRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &keys) {
  52. bool first = true;
  53. os << "formula " << agentName << "CannotMove" << direction << "BecauseOfKey" << " = ";
  54. for (auto const& key : keys) {
  55. if(first) first = false;
  56. else os << " | ";
  57. std::string keyColor = key.getColor();
  58. std::string xKey = "xKey" + keyColor;
  59. std::string yKey = "yKey" + keyColor;
  60. coordinates coords;
  61. os << "(!" << agentName << "_has_" << keyColor << "_key & ";
  62. if (direction == "North") {
  63. os << " x" << agentName << " = " << xKey << "&y" << agentName << "-1 = " << yKey << ")";
  64. } else if (direction == "South") {
  65. os << " x" << agentName << " = " << xKey << "&y" << agentName << "+1 = " << yKey << ")";
  66. } else if (direction == "East") {
  67. os << " x" << agentName << "+1 = " << xKey << "&y" << agentName << " = " << yKey << ")";
  68. } else if (direction == "West") {
  69. os << " x" << agentName << "-1 = " << xKey << "&y" << agentName << " = " << yKey << ")";
  70. } else {
  71. os << "Invalid Direction! in Key Restriction";
  72. }
  73. }
  74. os << ";\n";
  75. return os;
  76. }
  77. std::ostream& PrismModulesPrinter::printDoorRestrictionFormula(std::ostream& os, const AgentName &agentName, const std::string &direction, const cells &doors) {
  78. bool first = true;
  79. os << "formula " << agentName << "CannotMove" << direction << "BecauseOfDoor" << " = ";
  80. for (auto const& door : doors) {
  81. if (first) first = false;
  82. else os << " | ";
  83. std::string doorColor = door.getColor();
  84. size_t y = door.getCoordinates().first;
  85. size_t x = door.getCoordinates().second;
  86. os << "(!Door" << doorColor << "open & ";
  87. if (direction == "North") {
  88. os << " x" << agentName << " = " << x << "&y" << agentName << "-1 = " << y << ")";
  89. } else if (direction == "South") {
  90. os << " x" << agentName << " = " << x << "&y" << agentName << "+1 = " << y << ")";
  91. } else if (direction == "East") {
  92. os << " x" << agentName << "+1 = " << x << "&y" << agentName << " = " << y << ")";
  93. } else if (direction == "West") {
  94. os << " x" << agentName << "-1 = " << y << "&y" << agentName << " = " << y << ")";
  95. } else {
  96. os << "Invalid Direction! in Key Restriction";
  97. }
  98. }
  99. os << ";\n";
  100. return os;
  101. }
  102. std::ostream& PrismModulesPrinter::printIsOnSlipperyFormula(std::ostream& os, const AgentName &agentName, const std::vector<std::reference_wrapper<cells>> &slipperyCollection, const cells &slipperyNorth, const cells &slipperyEast, const cells &slipperySouth, const cells &slipperyWest) {
  103. if(std::find_if(slipperyCollection.cbegin(), slipperyCollection.cend(), [=](const std::reference_wrapper<cells>& c) { return !c.get().empty(); }) == slipperyCollection.cend()) {
  104. os << "formula " << agentName << "IsOnSlippery = false;\n";
  105. return os;
  106. }
  107. bool first = true;
  108. if (!slipperyNorth.empty()) {
  109. os << "formula " << agentName << "IsOnSlipperyNorth = ";
  110. for (const auto& cell : slipperyNorth) {
  111. if(first) first = false; else os << " | ";
  112. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  113. }
  114. os << ";\n";
  115. }
  116. if (!slipperyEast.empty()) {
  117. first = true;
  118. os << "formula " << agentName << "IsOnSlipperyEast = ";
  119. for (const auto& cell : slipperyEast) {
  120. if(first) first = false; else os << " | ";
  121. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  122. }
  123. os << ";\n";
  124. }
  125. if (!slipperySouth.empty()) {
  126. first = true;
  127. os << "formula " << agentName << "IsOnSlipperySouth = ";
  128. for (const auto& cell : slipperySouth) {
  129. if(first) first = false; else os << " | ";
  130. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  131. }
  132. os << ";\n";
  133. }
  134. if (!slipperyWest.empty()) {
  135. first = true;
  136. os << "formula " << agentName << "IsOnSlipperyWest = ";
  137. for (const auto& cell : slipperyWest) {
  138. if(first) first = false; else os << " | ";
  139. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  140. }
  141. os << ";\n";
  142. }
  143. first = true;
  144. os << "formula " << agentName << "IsOnSlippery = ";
  145. for (const auto& slippery: slipperyCollection) {
  146. for(const auto& cell : slippery.get()) {
  147. if(first) first = false; else os << " | ";
  148. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  149. }
  150. }
  151. os << ";\n";
  152. if(enforceOneWays) {
  153. first = true;
  154. os << "formula " << agentName << "IsOnSlipperyNorth = ";
  155. for (const auto& cell: slipperyNorth) {
  156. if(first) first = false; else os << " | ";
  157. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  158. }
  159. os << ";\n";
  160. first = true;
  161. os << "formula " << agentName << "IsOnSlipperyEast = ";
  162. for (const auto& cell: slipperyEast) {
  163. if(first) first = false; else os << " | ";
  164. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  165. }
  166. os << ";\n";
  167. first = true;
  168. os << "formula " << agentName << "IsOnSlipperySouth = ";
  169. for (const auto& cell: slipperySouth) {
  170. if(first) first = false; else os << " | ";
  171. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  172. }
  173. os << ";\n";
  174. first = true;
  175. os << "formula " << agentName << "IsOnSlipperyWest = ";
  176. for (const auto& cell: slipperyWest) {
  177. if(first) first = false; else os << " | ";
  178. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  179. }
  180. os << ";\n";
  181. }
  182. return os;
  183. }
  184. std::ostream& PrismModulesPrinter::printIsInLavaFormula(std::ostream& os, const AgentName &agentName, const cells &lava) {
  185. if(lava.size() == 0) {
  186. os << "formula " << agentName << "IsInLava = false;\n";
  187. return os;
  188. }
  189. bool first = true;
  190. os << "formula " << agentName << "IsInLava = ";
  191. for(auto const& cell : lava) {
  192. if(first) first = false; else os << " | ";
  193. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  194. }
  195. os << ";\n";
  196. os << "formula " << agentName << "IsInLavaAndNotDone = " << agentName << "IsInLava & !" << agentName << "Done;\n";
  197. os << "label \"" << agentName << "IsInLavaAndNotDone\" = " << agentName << "IsInLava & !" << agentName << "Done;\n";
  198. return os;
  199. }
  200. std::ostream& PrismModulesPrinter::printTurningNotAllowedFormulas(std::ostream& os, const AgentName &agentName, const cells &noTurnFloor) {
  201. if( (!enforceOneWays or noTurnFloor.size() == 0) or (noTurnFloor.size() == 0) ) {
  202. os << "formula " << agentName << "CannotTurn = false;\n";
  203. return os;
  204. }
  205. bool first = true;
  206. os << "formula " << agentName << "CannotTurn = ";
  207. for(auto const& cell : noTurnFloor) {
  208. if(first) first = false; else os << " | ";
  209. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  210. }
  211. os << " | " << agentName << "IsOnSlippery;\n";
  212. return os;
  213. }
  214. std::ostream& PrismModulesPrinter::printIsFixedFormulas(std::ostream& os, const AgentName &agentName) {
  215. os << "formula " << agentName << "IsFixed = false;\n";
  216. os << "formula " << agentName << "SlipperyTurnLeftAllowed = true;\n";
  217. os << "formula " << agentName << "SlipperyTurnRightAllowed = true;\n";
  218. os << "formula " << agentName << "SlipperyMoveForwardAllowed = true;\n";
  219. os << "label \"FixedStates" << agentName << "\" = " << agentName << "IsFixed | !" << agentName << "SlipperyTurnRightAllowed | !" << agentName << "SlipperyTurnLeftAllowed | !" << agentName << "SlipperyMoveForwardAllowed | " << agentName << "IsInGoal | " << agentName << "IsInLava";
  220. if(enforceOneWays) {
  221. os << " | " << agentName << "CannotTurn";
  222. }
  223. os << ";\n";
  224. //os << "label \"FixedStates\" = " << agentName << "IsFixed | " << agentName << "IsOnSlippery | " << agentName << "IsInGoal | " << agentName << "IsInLava;\n";
  225. return os;
  226. }
  227. std::ostream& PrismModulesPrinter::printWallFormula(std::ostream& os, const AgentName &agentName, const cells &walls) {
  228. os << "formula " << agentName << "IsOnWall = ";
  229. bool first = true;
  230. for(auto const& cell : walls) {
  231. if(first) first = false; else os << " | ";
  232. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  233. }
  234. os << ";\n";
  235. return os;
  236. }
  237. std::ostream& PrismModulesPrinter::printFormulas(std::ostream& os,
  238. const AgentName &agentName,
  239. const cells &restrictionNorth,
  240. const cells &restrictionEast,
  241. const cells &restrictionSouth,
  242. const cells &restrictionWest,
  243. const std::vector<std::reference_wrapper<cells>> &slipperyCollection,
  244. const cells &lava,
  245. const cells &walls,
  246. const cells &noTurnFloor,
  247. const cells &slipperyNorth,
  248. const cells &slipperyEast,
  249. const cells &slipperySouth,
  250. const cells &slipperyWest,
  251. const cells &keys,
  252. const cells &doors) {
  253. printRestrictionFormula(os, agentName, "North", restrictionNorth, keys, doors);
  254. printRestrictionFormula(os, agentName, "East", restrictionEast, keys, doors);
  255. printRestrictionFormula(os, agentName, "South", restrictionSouth, keys, doors);
  256. printRestrictionFormula(os, agentName, "West", restrictionWest, keys, doors);
  257. if (!keys.empty()) {
  258. printKeyRestrictionFormula(os, agentName, "North", keys);
  259. printKeyRestrictionFormula(os, agentName, "East", keys);
  260. printKeyRestrictionFormula(os, agentName, "South", keys);
  261. printKeyRestrictionFormula(os, agentName, "West", keys);
  262. }
  263. if (!doors.empty()) {
  264. printDoorRestrictionFormula(os, agentName, "North", doors);
  265. printDoorRestrictionFormula(os, agentName, "East", doors);
  266. printDoorRestrictionFormula(os, agentName, "South", doors);
  267. printDoorRestrictionFormula(os, agentName, "West", doors);
  268. }
  269. printIsOnSlipperyFormula(os, agentName, slipperyCollection, slipperyNorth, slipperyEast, slipperySouth, slipperyWest);
  270. printIsInLavaFormula(os, agentName, lava);
  271. printWallFormula(os, agentName, walls);
  272. printTurningNotAllowedFormulas(os, agentName, noTurnFloor);
  273. printIsFixedFormulas(os, agentName);
  274. os << "\n";
  275. return os;
  276. }
  277. std::ostream& PrismModulesPrinter::printGoalLabel(std::ostream& os, const AgentName &agentName, const cells &goals) {
  278. if(goals.size() == 0) {
  279. os << "formula " << agentName << "IsInGoal = false;\n";
  280. return os;
  281. }
  282. bool first = true;
  283. os << "formula " << agentName << "IsInGoal = ";
  284. for(auto const& cell : goals) {
  285. if(first) first = false; else os << " | ";
  286. os << "(x" << agentName << "=" << cell.column << "&y" << agentName << "=" << cell.row << ")";
  287. }
  288. os << ";\n";
  289. os << "formula " << agentName << "IsInGoalAndNotDone = " << agentName << "IsInGoal & !" << agentName << "Done;\n";
  290. os << "label \"" << agentName << "IsInGoalAndNotDone\" = " << agentName << "IsInGoal & !" << agentName << "Done;\n";
  291. return os;
  292. }
  293. std::ostream& PrismModulesPrinter::printCrashLabel(std::ostream &os, const std::vector<AgentName> agentNames) {
  294. os << "label crash = ";
  295. bool first = true;
  296. for(auto const& agentName : agentNames) {
  297. if(agentName == "Agent") continue;
  298. if(first) first = false; else os << " | ";
  299. os << "(xAgent=x" << agentName << ")&(yAgent=y" << agentName << ")";
  300. }
  301. os << ";\n\n";
  302. return os;
  303. }
  304. std::ostream& PrismModulesPrinter::printConfiguration(std::ostream& os, const std::vector<Configuration>& configurations) {
  305. for (auto& configuration : configurations) {
  306. if (configuration.overwrite_ || configuration.type_ == ConfigType::Module) {
  307. continue;
  308. }
  309. os << configuration.expression_ << std::endl;
  310. }
  311. return os;
  312. }
  313. std::ostream& PrismModulesPrinter::printConstants(std::ostream &os, const std::vector<std::string> &constants) {
  314. for (auto& constant : constants) {
  315. os << constant << std::endl;
  316. }
  317. return os;
  318. }
  319. std::ostream& PrismModulesPrinter::printAvoidanceLabel(std::ostream &os, const std::vector<AgentName> agentNames, const int &distance) {
  320. os << "label avoidance = ";
  321. bool first = true;
  322. for(auto const& agentName : agentNames) {
  323. if(agentName == "Agent") continue;
  324. if(first) first = false; else os << " | ";
  325. os << "max(xAgent-x" << agentName << ",x" << agentName << "-xAgent)+";
  326. os << "max(yAgent-y" << agentName << ",y" << agentName << "-yAgent) ";
  327. }
  328. os << ";\n\n";
  329. return os;
  330. }
  331. // TODO this does not account for multiple agents yet, i.e. key can be picked up multiple times
  332. std::ostream& PrismModulesPrinter::printKeysLabels(std::ostream& os, const AgentName &agentName, const cells &keys) {
  333. if(keys.size() == 0) return os;
  334. for(auto const& key : keys) {
  335. std::string keyColor = key.getColor();
  336. std::string xKey = "xKey" + keyColor;
  337. std::string yKey = "yKey" + keyColor;
  338. os << "label \"" << agentName << "PickedUp" << keyColor << "Key\" = " << agentName << "_has_" << keyColor << "_key = true;\n";
  339. os << "formula " << agentName << "CanPickUp" << keyColor << "Key = ";
  340. os << "((x" << agentName << "-1 = " << xKey << "&y" << agentName << " = " << yKey << "&view" << agentName << " = 2) |";
  341. os << " (x" << agentName << "+1 = " << xKey << "&y" << agentName << " = " << yKey << "&view" << agentName << " = 0) |";
  342. os << " (x" << agentName << " = " << xKey << "&y" << agentName << "-1 = " << yKey << "&view" << agentName << " = 3) |";
  343. os << " (x" << agentName << " = " << xKey << "&y" << agentName << "+1 = " << yKey << "&view" << agentName << " = 1) ) &";
  344. os << "!" << agentName << "_has_" << keyColor << "_key;";
  345. }
  346. os << "\n";
  347. return os;
  348. }
  349. std::ostream& PrismModulesPrinter::printBooleansForKeys(std::ostream &os, const AgentName &agentName, const cells &keys) {
  350. for(auto const& key : keys) {
  351. os << "\t" << agentName << "_has_"<< key.getColor() << "_key : bool;\n";//init false;\n";
  352. }
  353. os << "\n";
  354. return os;
  355. }
  356. std::ostream& PrismModulesPrinter::printBooleansForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles) {
  357. for(auto const& [color, cells] : backgroundTiles) {
  358. if(cells.size() == 0) continue;
  359. std::string c = getColor(color);
  360. c.at(0) = std::toupper(c.at(0));
  361. os << "\t" << agentName << "_picked_up_" << c << " : bool init false;\n";
  362. }
  363. os << "\n";
  364. return os;
  365. }
  366. std::ostream& PrismModulesPrinter::printActionsForKeys(std::ostream &os, const AgentName &agentName, const cells &keys) {
  367. for(auto const& key : keys) { // TODO ADD Drop action and enforce that pickup only possible if pockets empty (nothing picked up already)
  368. os << "\n";
  369. std::string keyColor = key.getColor();
  370. os << "\t[pickup_" << keyColor << "_key]\t" << pickupGuard(agentName, keyColor) << "-> ";
  371. os << "(" << agentName << "_has_" << keyColor << "_key'=true) & (" << agentName << "_is_carrying_object'=true);\n";
  372. os << "\n";
  373. os << "\t[drop_" << keyColor << "_key_north]\t" << dropGuard(agentName, keyColor, 3) << "-> ";
  374. os << "(" << agentName << "_has_" << keyColor << "_key'=false) & (" << agentName << "_is_carrying_object'=false);\n";
  375. os << "\t[drop_" << keyColor << "_key_west]\t" << dropGuard(agentName, keyColor, 2) << "-> ";
  376. os << "(" << agentName << "_has_" << keyColor << "_key'=false) & (" << agentName << "_is_carrying_object'=false);\n";
  377. os << "\t[drop_" << keyColor << "_key_south]\t" << dropGuard(agentName, keyColor, 1) << "-> ";
  378. os << "(" << agentName << "_has_" << keyColor << "_key'=false) & (" << agentName << "_is_carrying_object'=false);\n";
  379. os << "\t[drop_" << keyColor << "_key_east]\t" << dropGuard(agentName, keyColor, 0) << "-> ";
  380. os << "(" << agentName << "_has_" << keyColor << "_key'=false) & (" << agentName << "_is_carrying_object'=false);\n";
  381. }
  382. return os;
  383. }
  384. std::string PrismModulesPrinter::pickupGuard(const AgentName &agentName, const std::string keyColor ) {
  385. return "!" + agentName + "_is_carrying_object &\t" + agentName + "CanPickUp" + keyColor + "Key ";
  386. }
  387. std::string PrismModulesPrinter::dropGuard(const AgentName &agentName, const std::string keyColor, size_t view) {
  388. return viewVariable(agentName, view, true) + "\t!" + agentName + "CannotMove" + viewDirectionMapping.at(view) + "\t&\t" + agentName + "_has_" + keyColor + "_key\t";
  389. }
  390. std::ostream& PrismModulesPrinter::printActionsForBackground(std::ostream &os, const AgentName &agentName, const std::map<Color, cells> &backgroundTiles) {
  391. for(auto const& [color, cells] : backgroundTiles) {
  392. if(cells.size() == 0) continue;
  393. std::string c = getColor(color);
  394. c.at(0) = std::toupper(c.at(0));
  395. os << "\t[" << agentName << "_pickup_" << c << "] " << agentName << "On" << c << " & !" << agentName << "_picked_up_" << c << " -> ";
  396. os << "(" << agentName << "_picked_up_" << c << "'=true);\n";
  397. }
  398. os << "\n";
  399. return os;
  400. }
  401. std::ostream& PrismModulesPrinter::printInitStruct(std::ostream &os, const AgentNameAndPositionMap &agents, const KeyNameAndPositionMap &keys, const cells &lockedDoors, const cells &unlockedDoors, prism::ModelType modelType) {
  402. os << "init\n";
  403. os << "\t";
  404. bool first = true;
  405. for (auto const& agent : agents) {
  406. if (first) first = false;
  407. else os << " & ";
  408. os << "(!" << agent.first << "IsInGoal & !" << agent.first << "IsInLava & !" << agent.first << "Done & !" << agent.first << "IsOnWall & ";
  409. os << "x" << agent.first << "=" << agent.second.second << " & y" << agent.first << "=" << agent.second.first << ")";
  410. os << " & !" << agent.first << "_is_carrying_object";
  411. if(enforceOneWays) {
  412. os << " & ( !AgentCannotTurn ) ";
  413. } else {
  414. // os << " & ( !AgentIsOnSlippery ) ";
  415. }
  416. for (auto const& key : keys) {
  417. os << " & ( !" << agent.first << "_has_" << key.first << "_key )";
  418. }
  419. }
  420. for (auto const& key : keys) {
  421. os << " & ( xKey" << key.first << "="<< key.second.second<< ")";
  422. os << " & ( yKey" << key.first << "=" << key.second.first << ")";
  423. }
  424. for (auto const& locked : lockedDoors) {
  425. os << " & (Door" << locked.getColor() << "locked & !Door" << locked.getColor() << "open)";
  426. }
  427. for (auto const& unlocked : unlockedDoors) {
  428. os << " & (!Door" << unlocked.getColor() << "locked & !Door" << unlocked.getColor() << "open)";
  429. }
  430. if (modelType == ModelType::SMG) {
  431. os << " & move=0";
  432. }
  433. os << "\nendinit\n\n";
  434. return os;
  435. }
  436. std::ostream& PrismModulesPrinter::printModule(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const coordinates &boundaries, const coordinates& initialPosition, const cells &keys, const std::map<Color, cells> &backgroundTiles, const bool agentWithView, const std::vector<float> &probabilities, const double faultyProbability) {
  437. os << "module " << agentName << "\n";
  438. os << "\tx" << agentName << " : [1.." << boundaries.second << "];\n";
  439. os << "\ty" << agentName << " : [1.." << boundaries.first << "];\n";
  440. os << "\t" << agentName << "_is_carrying_object : bool;\n";
  441. printBooleansForKeys(os, agentName, keys);
  442. printBooleansForBackground(os, agentName, backgroundTiles);
  443. os << "\t" << agentName << "Done : bool;\n";
  444. if(agentWithView) {
  445. os << "\tview" << agentName << " : [0..3];\n";
  446. os << "\n";
  447. if (faultyProbability != 0.0) {
  448. os << "\t[" << agentName << "_turn_right] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery -> " << 100 - faultyProbability << "/100:" << "(view" << agentName << "'=mod(view" << agentName << " + 1, 4))" << moveUpdate(agentIndex) << "\n + " << faultyProbability << "/100:" << "(view" << agentName << "'=mod(view" << agentName << " + 2, 4))" << ";\n";
  449. os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery & view" << agentName << ">1 -> " << 100 - faultyProbability << "/100:" << "(view" << agentName << "'=mod(view" << agentName << " - 1, 4))" << moveUpdate(agentIndex) << "\n + " << faultyProbability << "/100:" << "(view" << agentName << "'=mod(view" << agentName << " - 2, 4))" << ";\n";
  450. os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery & view" << agentName << "=0 -> " << 100 - faultyProbability << "/100:" << "(view" << agentName << "'=3)" << moveUpdate(agentIndex) << "\n + " << faultyProbability << "/100:" << "(view" << agentName << "'=2)" << ";\n";
  451. os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery & view" << agentName << "=1 -> " << 100 - faultyProbability << "/100:" << "(view" << agentName << "'=0)" << moveUpdate(agentIndex) << "\n + " << faultyProbability << "/100:" << "(view" << agentName << "'=3)" << ";\n";
  452. } else {
  453. os << "\t[" << agentName << "_turn_right] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery -> (view" << agentName << "'=mod(view" << agentName << " + 1, 4)) " << moveUpdate(agentIndex) << ";\n";
  454. os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery & view" << agentName << ">0 -> (view" << agentName << "'=view" << agentName << " - 1) " << moveUpdate(agentIndex) << ";\n";
  455. os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !" << agentName << "IsOnSlippery & view" << agentName << "=0 -> (view" << agentName << "'=3) " << moveUpdate(agentIndex) << ";\n";
  456. }
  457. if(enforceOneWays) {
  458. os << "\t[" << agentName << "_stuck] !" << agentName << "IsFixed & " << agentName << "CannotTurn & view" << agentName << " = 0 & " << agentName << "CannotMoveEast -> true;\n";
  459. os << "\t[" << agentName << "_stuck] !" << agentName << "IsFixed & " << agentName << "CannotTurn & view" << agentName << " = 1 & " << agentName << "CannotMoveSouth -> true;\n";
  460. os << "\t[" << agentName << "_stuck] !" << agentName << "IsFixed & " << agentName << "CannotTurn & view" << agentName << " = 2 & " << agentName << "CannotMoveWest -> true;\n";
  461. os << "\t[" << agentName << "_stuck] !" << agentName << "IsFixed & " << agentName << "CannotTurn & view" << agentName << " = 3 & " << agentName << "CannotMoveNorth -> true;\n";
  462. }
  463. } else {
  464. os << "\t[" << agentName << "_turns] " << " !" << agentName << "CannotTurn & " << " !" << agentName << "IsFixed & " << moveGuard(agentIndex) << " true -> (x" << agentName << "'=x" << agentName << ")" << moveUpdate(agentIndex) << ";\n";
  465. }
  466. printActionsForKeys(os, agentName, keys);
  467. printActionsForBackground(os, agentName, backgroundTiles);
  468. os << "\n";
  469. printMovementActions(os, agentName, agentIndex, agentWithView, 1.0, faultyProbability);
  470. for(auto const& probability : probabilities) {
  471. printMovementActions(os, agentName, agentIndex, agentWithView, probability);
  472. }
  473. printDoneActions(os, agentName, agentIndex);
  474. printConfiguredActions(os, agentName);
  475. os << "\n";
  476. return os;
  477. }
  478. std::ostream& PrismModulesPrinter::printKeyModule(std::ostream &os, const cell &key, const coordinates &boundaries, AgentName agentName) {
  479. std::string keyIdentifier = "Key" + key.getColor();
  480. os << "module " << keyIdentifier << "\n";
  481. os << "\tx" << keyIdentifier << " : [-1.." << boundaries.second << "];\n";
  482. os << "\ty" << keyIdentifier << " : [-1.." << boundaries.first << "];\n";
  483. os << "\n";
  484. printKeyActions(os, key ,keyIdentifier, agentName);
  485. os << "\n";
  486. return os;
  487. }
  488. std::ostream& PrismModulesPrinter::printKeyActions(std::ostream &os, const cell &key ,const std::string &keyIdentifier, AgentName agentName) {
  489. std::string keyColor = key.getColor();
  490. os << "\t[pickup_" << keyColor << "key]\t" << pickupGuard(agentName, keyColor) << "-> ";
  491. os << "(xKey" << keyColor << "'=-1) & (yKey" << keyColor << "'=-1)" << ";\n";
  492. os << "\t[drop_" << keyColor << "_key_north]\t" << dropGuard(agentName, keyColor, 3) << "-> ";
  493. os << "(xKey" << keyColor << "'=x" << agentName << ") & (yKey" << keyColor << "'=y" <<agentName << "-1) ;\n";
  494. os << "\t[drop_" << keyColor << "_key_west]\t" << dropGuard(agentName, keyColor, 2) << "-> ";
  495. os << "(xKey" << keyColor << "'=x" << agentName << "-1) & (yKey" << keyColor << "'=y" <<agentName << ") ;\n";
  496. os << "\t[drop_" << keyColor << "_key_south]\t" << dropGuard(agentName, keyColor, 1) << "-> ";
  497. os << "(xKey" << keyColor << "'=x" << agentName << ") & (yKey" << keyColor << "'=y" <<agentName << "+1) ;\n";
  498. os << "\t[drop_" << keyColor << "_key_east]\t" << dropGuard(agentName, keyColor, 0) << "-> ";
  499. os << "(xKey" << keyColor << "'=x" << agentName << "+1) & (yKey" << keyColor << "'=y" <<agentName << ") ;\n";
  500. return os;
  501. }
  502. std::ostream& PrismModulesPrinter::printDoorModule(std::ostream &os, const cell &door, const coordinates &boundaries, AgentName agent) {
  503. std::string doorIdentifier = "Door" + door.getColor();
  504. os << "module " << doorIdentifier << "\n";
  505. os << "\t" << doorIdentifier << "locked : bool;\n";
  506. os << "\t" << doorIdentifier << "open : bool;\n";
  507. printDoorActions(os, door, doorIdentifier, agent);
  508. return os;
  509. }
  510. std::ostream& PrismModulesPrinter::printDoorActions(std::ostream &os, const cell &door ,const std::string &doorIdentifier, AgentName agentName) {
  511. os << "\t[" << "unlock_" << doorIdentifier << "]\t" << unlockGuard(agentName, door) << " -> ";
  512. os << "(" << doorIdentifier << "locked'=false) & (" << doorIdentifier << "open'=true) ;\n";
  513. os << "\t[" << "toggle_" << doorIdentifier << "]\t" << toggleGuard(agentName, door) << " -> ";
  514. os << "(" << doorIdentifier << "open'=!" << doorIdentifier << "open) ;\n";
  515. return os;
  516. }
  517. std::string PrismModulesPrinter::unlockGuard(const AgentName &agentName, const cell& door) {
  518. std::string doorColor = door.getColor();
  519. std::string ret;
  520. ret += agentName + "_has_" + doorColor + "_key & ";
  521. ret += "((" + viewVariable(agentName, 0, true) + "x" + agentName + "+ 1 = " + std::to_string(door.column) + " & y" + agentName + "= " + std::to_string(door.row) + ")";
  522. ret += " | (" + viewVariable(agentName, 1, true) + "x" + agentName + " = " + std::to_string(door.column) + " & y" + agentName + " + 1 = " + std::to_string(door.row) + ")";
  523. ret += " | (" + viewVariable(agentName, 2, true) + "x" + agentName + "- 1 = " + std::to_string(door.column) + " & y" + agentName + "= " + std::to_string(door.row) + ")";
  524. ret += " | (" + viewVariable(agentName, 3, true) + "x" + agentName + " = " + std::to_string(door.column) + " & y" + agentName + " - 1 = " + std::to_string(door.row) + "))";
  525. return ret;
  526. }
  527. std::string PrismModulesPrinter::toggleGuard(const AgentName &agentName, const cell& door) {
  528. std::string doorColor = door.getColor();
  529. std::string ret;
  530. ret += "!Door" + doorColor + "locked & (";
  531. ret += "(" + viewVariable(agentName, 0, true) + "x" + agentName + "+ 1 = " + std::to_string(door.column) + " & y" + agentName + "= " + std::to_string(door.row) + ")";
  532. ret += " | (" + viewVariable(agentName, 1, true) + "x" + agentName + " = " + std::to_string(door.column) + " & y" + agentName + " + 1 = " + std::to_string(door.row) + ")";
  533. ret += " | (" + viewVariable(agentName, 2, true) + "x" + agentName + "- 1 = " + std::to_string(door.column) + " & y" + agentName + "= " + std::to_string(door.row) + ")";
  534. ret += " | (" + viewVariable(agentName, 3, true) + "x" + agentName + " = " + std::to_string(door.column) + " & y" + agentName + " - 1 = " + std::to_string(door.row) + "))";
  535. return ret;
  536. }
  537. std::ostream& PrismModulesPrinter::printConfiguredActions(std::ostream &os, const AgentName &agentName) {
  538. for (auto& config : configuration) {
  539. if (config.type_ == ConfigType::Module && !config.overwrite_ && agentName == config.module_) {
  540. os << config.expression_ ;
  541. }
  542. }
  543. os << "\n";
  544. return os;
  545. }
  546. std::ostream& PrismModulesPrinter::printMovementActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex, const bool agentWithView, const float &probability, const double &stickyProbability) {
  547. if(stickyProbability != 0.0) {
  548. os << "\t[" << agentName << "_move_north]" << moveGuard(agentIndex) << viewVariable(agentName, 3, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveNorth -> " << (100 - stickyProbability) << "/100:" << "(y" << agentName << "'=y" << agentName << "-1)" << moveUpdate(agentIndex) << "\n+ " << (stickyProbability) << "/100:" << "(y" << agentName << "'=max(y" << agentName << "-2, 1 ))" << moveUpdate(agentIndex) << ";\n";
  549. os << "\t[" << agentName << "_move_east] " << moveGuard(agentIndex) << viewVariable(agentName, 0, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveEast -> " << (100 - stickyProbability) << "/100:" << "(x" << agentName << "'=x" << agentName << "+1)" << moveUpdate(agentIndex) << "\n+ " << (stickyProbability) << "/100:" << "(x" << agentName << "'=min(x" << agentName << "+2, width))" << moveUpdate(agentIndex) << ";\n";
  550. os << "\t[" << agentName << "_move_south]" << moveGuard(agentIndex) << viewVariable(agentName, 1, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveSouth -> " << (100 - stickyProbability) << "/100:" << "(y" << agentName << "'=y" << agentName << "+1)" << moveUpdate(agentIndex) << "\n+ " << (stickyProbability) << "/100:" << "(y" << agentName << "'=min(y" << agentName << "+2, height))" << moveUpdate(agentIndex) << ";\n";
  551. os << "\t[" << agentName << "_move_west] " << moveGuard(agentIndex) << viewVariable(agentName, 2, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveWest -> " << (100 - stickyProbability) << "/100:" << "(x" << agentName << "'=x" << agentName << "-1)" << moveUpdate(agentIndex) << "\n+ " << (stickyProbability) << "/100:" << "(x" << agentName << "'=max(x" << agentName << "-1, 1))" << moveUpdate(agentIndex) << ";\n";
  552. }
  553. else if(probability >= 1) {
  554. os << "\t[" << agentName << "_move_north]" << moveGuard(agentIndex) << viewVariable(agentName, 3, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveNorth -> (y" << agentName << "'=y" << agentName << "-1)" << moveUpdate(agentIndex) << ";\n";
  555. os << "\t[" << agentName << "_move_east] " << moveGuard(agentIndex) << viewVariable(agentName, 0, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveEast -> (x" << agentName << "'=x" << agentName << "+1)" << moveUpdate(agentIndex) << ";\n";
  556. os << "\t[" << agentName << "_move_south]" << moveGuard(agentIndex) << viewVariable(agentName, 1, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveSouth -> (y" << agentName << "'=y" << agentName << "+1)" << moveUpdate(agentIndex) << ";\n";
  557. os << "\t[" << agentName << "_move_west] " << moveGuard(agentIndex) << viewVariable(agentName, 2, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava &!" << agentName << "IsInGoal & !" << agentName << "CannotMoveWest -> (x" << agentName << "'=x" << agentName << "-1)" << moveUpdate(agentIndex) << ";\n";
  558. } else {
  559. std::string probabilityString = std::to_string(probability);
  560. std::string percentageString = std::to_string((int)(100 * probability));
  561. std::string complementProbabilityString = std::to_string(1 - probability);
  562. os << "\t[" << agentName << "_move_north_" << percentageString << "] ";
  563. os << moveGuard(agentIndex) << viewVariable(agentName, 3, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava & !" << agentName << "CannotMoveNorth -> ";
  564. os << probabilityString << ": (y" << agentName << "'=y" << agentName << "-1)" << moveUpdate(agentIndex) << " + ";
  565. os << complementProbabilityString << ": (y" << agentName << "'=y" << agentName << ") " << moveUpdate(agentIndex) << ";\n";
  566. os << "\t[" << agentName << "_move_east_" << percentageString << "] ";
  567. os << moveGuard(agentIndex) << viewVariable(agentName, 0, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava & !" << agentName << "CannotMoveEast -> ";
  568. os << probabilityString << ": (x" << agentName << "'=x" << agentName << "+1)" << moveUpdate(agentIndex) << " + ";
  569. os << complementProbabilityString << ": (x" << agentName << "'=x" << agentName << ") " << moveUpdate(agentIndex) << ";\n";
  570. os << "\t[" << agentName << "_move_south_" << percentageString << "] ";
  571. os << moveGuard(agentIndex) << viewVariable(agentName, 1, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava & !" << agentName << "CannotMoveSouth -> ";
  572. os << probabilityString << ": (y" << agentName << "'=y" << agentName << "+1)" << moveUpdate(agentIndex) << " + ";
  573. os << complementProbabilityString << ": (y" << agentName << "'=y" << agentName << ") " << moveUpdate(agentIndex) << ";\n";
  574. os << "\t[" << agentName << "_move_west_" << percentageString << "] ";
  575. os << moveGuard(agentIndex) << viewVariable(agentName, 2, agentWithView) << " !" << agentName << "IsFixed & " << " !" << agentName << "IsOnSlippery & !" << agentName << "IsInLava & !" << agentName << "CannotMoveWest -> ";
  576. os << probabilityString << ": (x" << agentName << "'=x" << agentName << "-1)" << moveUpdate(agentIndex) << " + ";
  577. os << complementProbabilityString << ": (x" << agentName << "'=x" << agentName << ") " << moveUpdate(agentIndex) << ";\n";
  578. }
  579. return os;
  580. }
  581. std::ostream& PrismModulesPrinter::printDoneActions(std::ostream &os, const AgentName &agentName, const size_t &agentIndex) {
  582. os << "\t[" << agentName << "_done]" << moveGuard(agentIndex) << agentName << "IsInGoal | " << agentName << "IsInLava -> (" << agentName << "Done'=true);\n";
  583. return os;
  584. }
  585. 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) {
  586. constexpr std::size_t PROB_PIECES = 9, ALL_POSS_DIRECTIONS = 9;
  587. std::array<std::string, ALL_POSS_DIRECTIONS> positionTransition = {
  588. /* north */ "(y" + agentName + "'=y" + agentName + "-1)",
  589. /* north east */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "-1)",
  590. /* east */ "(x" + agentName + "'=x" + agentName + "+1)",
  591. /* east south */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "+1)",
  592. /* south */ "(y" + agentName + "'=y" + agentName + "+1)",
  593. /* south west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "+1)",
  594. /* west */ "(x" + agentName + "'=x" + agentName + "-1)",
  595. /* north west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "-1)",
  596. /* own position */ "(x" + agentName + "'=x" + agentName + ") & (y" + agentName + "'=y" + agentName + ")"
  597. };
  598. // view transition appdx in form (guard, update part)
  599. // IMPORTANT: No mod() usage for turn left due to bug in mod() function for decrement
  600. std::array<std::tuple<std::string, std::string, std::string>, 3> viewTransition = {
  601. std::make_tuple(" & " + agentName + "SlipperyTurnRightAllowed ", " & (view" + agentName + "'=mod(view" + agentName + " + 1, 4))", "_right]"),
  602. std::make_tuple(" & " + agentName + "SlipperyTurnLeftAllowed & view" + agentName + ">0", " & (view" + agentName + "'=view" + agentName + " - 1)", "_left]"),
  603. std::make_tuple(" & " + agentName + "SlipperyTurnLeftAllowed & view" + agentName + "=0", " & (view" + agentName + "'=3)", "_left]")
  604. };
  605. // direction specifics
  606. std::string actionName;
  607. std::string positionGuard;
  608. std::size_t remainPosIndex = 8;
  609. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // { n, ne, e, se, s, sw, w, nw, CURRENT POS }
  610. std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants;
  611. switch (orientation)
  612. {
  613. case SlipperyType::North:
  614. actionName = "\t[" + agentName + "turn_at_slip_north";
  615. positionGuard = "\t" + agentName + "IsOnSlipperyNorth";
  616. prob_piece_dir = { 0, 0, 0, 0, 1, 0, 0, 0, 0 /* <- R */ };
  617. prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_turn_displacement" /* <- R */, "prop_zero", "prop_zero", "prop_zero","prop_zero" };
  618. break;
  619. case SlipperyType::South:
  620. actionName = "\t[" + agentName + "turn_at_slip_south";
  621. positionGuard = "\t" + agentName + "IsOnSlipperySouth";
  622. prob_piece_dir = { 1, 0, 0, 0, 0, 0, 0, 0, 0 /* <- R */ };
  623. prob_piece_dir_constants = { "prop_turn_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" };
  624. break;
  625. case SlipperyType::East:
  626. actionName = "\t[" + agentName + "turn_at_slip_east";
  627. positionGuard = "\t" + agentName + "IsOnSlipperyEast";
  628. prob_piece_dir = { 0, 0, 0, 0, 0, 0, 1, 0, 0 /* <- R */ };
  629. prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_turn_displacement", "prop_zero", "prop_zero" };
  630. break;
  631. case SlipperyType::West:
  632. actionName = "\t[" + agentName + "turn_at_slip_west";
  633. positionGuard = "\t" + agentName + "IsOnSlipperyWest";
  634. prob_piece_dir = { 0, 0, 1, 0, 0, 0, 0, 0, 0 /* <- R */ };
  635. prob_piece_dir_constants = { "prop_zero", "prop_zero", "prop_turn_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" };
  636. break;
  637. }
  638. slipperyActions.insert(actionName + "_left]");
  639. slipperyActions.insert(actionName + "_right]");
  640. // override probability to 0 if corresp. direction is blocked
  641. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS - 1; i++) {
  642. if (!neighborhood.at(i))
  643. prob_piece_dir.at(i) = 0;
  644. }
  645. // determine residual probability (R) by replacing 0 with (1 - overall sum)
  646. prob_piece_dir.at(remainPosIndex) = PROB_PIECES - std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0);
  647. prob_piece_dir_constants.at(remainPosIndex) = "prop_turn_intended";
  648. // <DEBUG_AREA>
  649. {
  650. assert(prob_piece_dir.at(remainPosIndex) <= 9 && prob_piece_dir.at(remainPosIndex) >= 6 && "Value not in Range!");
  651. assert(std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0) == PROB_PIECES && "Does not sum up to 1!");
  652. }
  653. // </DEBUG_AREA>
  654. // generic output (for every view transition)
  655. for (std::size_t v = 0; v < viewTransition.size(); v++) {
  656. os << actionName << std::get<2>(viewTransition.at(v)) << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << std::get<0>(viewTransition.at(v));
  657. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  658. if (i == remainPosIndex) {
  659. 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");
  660. } else {
  661. os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  662. }
  663. }
  664. }
  665. return os;
  666. }
  667. 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) {
  668. constexpr std::size_t PROB_PIECES = 9, ALL_POSS_DIRECTIONS = 8;
  669. std::array<std::string, ALL_POSS_DIRECTIONS> positionTransition = {
  670. /* north */ "(y" + agentName + "'=y" + agentName + "-1)",
  671. /* north east */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "-1)",
  672. /* east */ "(x" + agentName + "'=x" + agentName + "+1)",
  673. /* east south */ "(x" + agentName + "'=x" + agentName + "+1) & (y" + agentName + "'=y" + agentName + "+1)",
  674. /* south */ "(y" + agentName + "'=y" + agentName + "+1)",
  675. /* south west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "+1)",
  676. /* west */ "(x" + agentName + "'=x" + agentName + "-1)",
  677. /* north west */ "(x" + agentName + "'=x" + agentName + "-1) & (y" + agentName + "'=y" + agentName + "-1)"
  678. };
  679. // direction specifics
  680. std::size_t straightPosIndex, straightPosIndex_east, straightPosIndex_south, straightPosIndex_west, straightPosIndex_north;
  681. std::string actionName, specialTransition; // if straight ahead is blocked
  682. std::string positionGuard;
  683. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // { n, ne, e, se, s, sw, w, nw }
  684. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_north; // { n, ne, e, se, s, sw, w, nw }
  685. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_east; // { n, ne, e, se, s, sw, w, nw }
  686. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_south; // { n, ne, e, se, s, sw, w, nw }
  687. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir_agent_west; // { n, ne, e, se, s, sw, w, nw }
  688. std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants;
  689. std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_north;
  690. std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_east;
  691. std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_south;
  692. std::array<std::string, ALL_POSS_DIRECTIONS> prob_piece_dir_constants_agent_west;
  693. switch (orientation)
  694. {
  695. case SlipperyType::North:
  696. actionName = "\t[" + agentName + "move_on_slip_north]";
  697. positionGuard = "\t" + agentName + "IsOnSlipperyNorth";
  698. prob_piece_dir = { 0, 0, 1, 2, 0 /* <- R */, 2, 1, 0 };
  699. prob_piece_dir_agent_south = { 0 , 0, 0, 1, 0 /*s <- R */, 1, 0, 0};
  700. prob_piece_dir_agent_east = { 0, 0, 0 /*e <- R */, 2, 0, 0, 0, 0 };
  701. prob_piece_dir_agent_north = { 0 /*n <- R */, 0, 0, 0, 2 , 0, 0, 0 };
  702. prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 2, 0 /* <- R */, 0 };
  703. 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" };
  704. 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" };
  705. prob_piece_dir_constants_agent_east = { "prop_zero", "prop_zero", "prop_zero", "prop_displacement", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  706. prob_piece_dir_constants_agent_south = { "prop_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  707. prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_displacement", "prop_zero", "prop_zero" } ;
  708. straightPosIndex = 4;
  709. straightPosIndex_east = 2;
  710. straightPosIndex_south = 4;
  711. straightPosIndex_west = 6;
  712. straightPosIndex_north = 0;
  713. specialTransition = "(y" + agentName + "'=y" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "+1)");
  714. break;
  715. case SlipperyType::South:
  716. actionName = "\t[" + agentName + "move_on_slip_south]";
  717. positionGuard = "\t" + agentName + "IsOnSlipperySouth";
  718. prob_piece_dir = { 0 /* <- R */, 2, 1, 0, 0, 0, 1, 2 };
  719. // { n, ne, e, se, s, sw, w, nw }
  720. prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  721. prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  722. prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  723. prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  724. 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" };
  725. 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" };
  726. prob_piece_dir_constants_agent_east = { "prop_zero", "prop_displacement", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" };
  727. prob_piece_dir_constants_agent_south = { "prop_displacement", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  728. prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_displacement" } ;
  729. straightPosIndex = 0; // always north
  730. straightPosIndex_east = 2;
  731. straightPosIndex_south = 4;
  732. straightPosIndex_west = 6;
  733. straightPosIndex_north = 0;
  734. specialTransition = "(y" + agentName + "'=y" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "-1)");
  735. break;
  736. case SlipperyType::East:
  737. actionName = "\t[" + agentName + "move_on_slip_east]";
  738. positionGuard = "\t" + agentName + "IsOnSlipperyEast";
  739. // { n, ne, e, se, s, sw, w, nw }
  740. prob_piece_dir = { 1, 0, 0, 0, 1, 2, 0 /* <- R */, 2 };
  741. // TODO
  742. prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  743. prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  744. prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  745. prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  746. 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" };
  747. 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" };
  748. prob_piece_dir_constants_agent_east = { "prop_zero", "prop_zero", "prop_zero", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_displacement", "prop_zero" };
  749. 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" } ;
  750. 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" } ;
  751. straightPosIndex = 6;
  752. straightPosIndex_east = 2;
  753. straightPosIndex_south = 4;
  754. straightPosIndex_west = 6;
  755. straightPosIndex_north = 0;
  756. specialTransition = "(x" + agentName + "'=x" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "-1)");
  757. break;
  758. case SlipperyType::West:
  759. actionName = "\t[" + agentName + "move_on_slip_west]";
  760. positionGuard = "\t" + agentName + "IsOnSlipperyWest";
  761. prob_piece_dir = { 1, 2, 0 /* <- R */, 2, 1, 0, 0, 0 };
  762. // TODO
  763. // { n, ne, e, se, s, sw, w, nw }
  764. prob_piece_dir_agent_north = { 0 /*n <- R */, 1, 0, 0, 0, 0, 0, 1};
  765. prob_piece_dir_agent_east = { 0, 2, 0 /*e <- R */, 0, 0, 0, 0, 0 };
  766. prob_piece_dir_agent_south = { 2, 0, 0, 0, 0 /*s <- R */, 0, 0, 0 };
  767. prob_piece_dir_agent_west = { 0, 0, 0, 0, 0, 0, 0 /* <- R */, 2 };
  768. 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" };
  769. 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" };
  770. 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" };
  771. 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" } ;
  772. prob_piece_dir_constants_agent_west ={ "prop_zero", "prop_zero", "prop_displacement", "prop_zero", "prop_zero" /* <- R */, "prop_zero", "prop_zero", "prop_zero" } ;
  773. straightPosIndex = 2;
  774. straightPosIndex_east = 2;
  775. straightPosIndex_south = 4;
  776. straightPosIndex_west = 6;
  777. straightPosIndex_north = 0;
  778. specialTransition = "(x" + agentName + "'=x" + agentName + (!neighborhood.at(straightPosIndex) ? ")" : "+1)");
  779. break;
  780. }
  781. slipperyActions.insert(actionName);
  782. // override probability to 0 if corresp. direction is blocked
  783. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  784. if (!neighborhood.at(i))
  785. prob_piece_dir.at(i) = 0;
  786. }
  787. // determine residual probability (R) by replacing 0 with (1 - overall sum)
  788. if(enforceOneWays) {
  789. prob_piece_dir = {0,0,0,0,0,0,0,0};
  790. prob_piece_dir_constants = {"zero","zero","zero","zero","zero","zero","zero","zero"};
  791. }
  792. prob_piece_dir.at(straightPosIndex) = PROB_PIECES - std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0);
  793. prob_piece_dir_constants.at(straightPosIndex) = "prop_intended";
  794. prob_piece_dir_constants_agent_east.at(straightPosIndex_east) = "prop_intended";
  795. prob_piece_dir_constants_agent_south.at(straightPosIndex_south) = "prop_intended";
  796. prob_piece_dir_constants_agent_west.at(straightPosIndex_west) = "prop_intended";
  797. prob_piece_dir_constants_agent_north.at(straightPosIndex_north) = "prop_intended";
  798. // <DEBUG_AREA>
  799. {
  800. assert(prob_piece_dir.at(straightPosIndex) <= 9 && prob_piece_dir.at(straightPosIndex) >= 3 && "Value not in Range!");
  801. assert(std::accumulate(prob_piece_dir.begin(), prob_piece_dir.end(), 0) == PROB_PIECES && "Does not sum up to 1!");
  802. 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!"));
  803. 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!"));
  804. 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!"));
  805. 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!"));
  806. }
  807. // </DEBUG_AREA>
  808. // special case: straight forward is blocked (then remain in same position)
  809. positionTransition.at(straightPosIndex) = specialTransition;
  810. // generic output (for every view and every possible view direction)
  811. size_t current_dir = 0; // East
  812. os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  813. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  814. os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_east.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  815. }
  816. current_dir = 1; // South
  817. os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  818. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  819. os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_south.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  820. }
  821. current_dir = 2; // West
  822. os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  823. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  824. os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_west.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  825. }
  826. current_dir = 3; // North
  827. os << actionName << moveGuard(agentIndex) << " x" << agentName << "=" << c.second << " & y" << agentName << "=" << c.first << " & " << agentName << "SlipperyMoveForwardAllowed " << "& " << "view" << agentName << "=" << current_dir;
  828. for (std::size_t i = 0; i < ALL_POSS_DIRECTIONS; i++) {
  829. os << (i == 0 ? " -> " : " + ") << prob_piece_dir_constants_agent_north.at(i) << " : " << positionTransition.at(i) << moveUpdate(agentIndex) << (i == ALL_POSS_DIRECTIONS - 1 ? ";\n" : "\n");
  830. }
  831. return os;
  832. }
  833. std::ostream& PrismModulesPrinter::printEndmodule(std::ostream &os) {
  834. os << "endmodule\n";
  835. os << "\n";
  836. return os;
  837. }
  838. std::ostream& PrismModulesPrinter::printPlayerStruct(std::ostream &os, const AgentName &agentName, const bool agentWithView, const std::vector<float> &probabilities, const std::set<std::string> &slipperyActions) {
  839. os << "player " << agentName << "\n\t";
  840. bool first = true;
  841. std::list<std::string> allActions = { "_move_north", "_move_east", "_move_south", "_move_west" };
  842. std::list<std::string> movementActions = allActions;
  843. for(auto const& probability : probabilities) {
  844. std::string percentageString = std::to_string((int)(100 * probability));
  845. for(auto const& movement : movementActions) {
  846. allActions.push_back(movement + "_" + percentageString);
  847. }
  848. }
  849. if(agentWithView) {
  850. allActions.push_back("_turn_left");
  851. allActions.push_back("_turn_right");
  852. } else {
  853. allActions.push_back("_turns");
  854. }
  855. for(auto const& action : allActions) {
  856. if(first) first = false; else os << ", ";
  857. os << "[" << agentName << action << "]";
  858. }
  859. for(auto const& action : slipperyActions) {
  860. os << ", " << action;
  861. }
  862. os << ", [" << agentName << "_done]";
  863. os << "\nendplayer\n";
  864. return os;
  865. }
  866. std::ostream& PrismModulesPrinter::printGlobalMoveVariable(std::ostream &os, const size_t &numberOfPlayer) {
  867. os << "\nglobal move : [0.." << std::to_string(numberOfPlayer - 1) << "];\n\n";
  868. return os;
  869. }
  870. 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) {
  871. if(lava.size() != 0) {
  872. os << "rewards \"" << agentName << "SafetyNoBFS\"\n";
  873. os << "\t" <<agentName << "IsInLavaAndNotDone: -100;\n";
  874. os << "endrewards\n";
  875. }
  876. if (!goals.empty() || !lava.empty()) {
  877. os << "rewards \"" << agentName << "SafetyNoBFSAndGoal\"\n";
  878. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  879. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  880. os << "endrewards\n";
  881. }
  882. os << "rewards \"" << agentName << "Time\"\n";
  883. os << "\t!" << agentName << "IsInGoal : -1;\n";
  884. if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n";
  885. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  886. os << "endrewards\n";
  887. if(stateRewards.size() > 0) {
  888. os << "rewards \"" << agentName << "SafetyWithBFS\"\n";
  889. if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n";
  890. for(auto const [coordinates, reward] : stateRewards) {
  891. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  892. }
  893. os << "endrewards\n";
  894. }
  895. if(stateRewards.size() > 0) {
  896. os << "rewards \"" << agentName << "SafetyWithBFSAndGoal\"\n";
  897. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone: 100;\n";
  898. if(lava.size() != 0) os << "\tAgentIsInLavaAndNotDone: -100;\n";
  899. for(auto const [coordinates, reward] : stateRewards) {
  900. os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n";
  901. }
  902. os << "endrewards\n";
  903. }
  904. for(auto const entry : backgroundTiles)
  905. {
  906. std::cout << getColor(entry.first) << " ";
  907. for(auto const cell : entry.second){
  908. std::cout << cell.getCoordinates().first << " " << cell.getCoordinates().second << std::endl;
  909. }
  910. }
  911. if(backgroundTiles.size() > 0) {
  912. os << "rewards \"TaxiReward\"\n";
  913. os << "\t!AgentIsInGoal : -1;\n";
  914. std::string allPassengersPickedUp = "";
  915. bool first = true;
  916. for(auto const [color, cells] : backgroundTiles) {
  917. if(cells.size() == 0) continue;
  918. if(first) first = false; else allPassengersPickedUp += "&";
  919. std::string c = getColor(color);
  920. c.at(0) = std::toupper(c.at(0));
  921. std::string visitedLabel = agentName + "_picked_up_" + c;
  922. allPassengersPickedUp += visitedLabel;
  923. os << "[" << agentName << "_pickup_" << c << "] true : 100;\n";
  924. }
  925. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & " << allPassengersPickedUp << " : 100;\n";
  926. if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & !(" << allPassengersPickedUp << ") : -100;\n";
  927. os << "endrewards";
  928. }
  929. return os;
  930. }
  931. std::string PrismModulesPrinter::moveGuard(const size_t &agentIndex) {
  932. return isGame() ? " move=" + std::to_string(agentIndex) + " & " : " ";
  933. }
  934. std::string PrismModulesPrinter::moveUpdate(const size_t &agentIndex) {
  935. return isGame() ?
  936. (agentIndex == numberOfPlayer - 1) ?
  937. " & (move'=0) " :
  938. " & (move'=" + std::to_string(agentIndex + 1) + ") " :
  939. "";
  940. }
  941. std::string PrismModulesPrinter::viewVariable(const AgentName &agentName, const size_t &agentDirection, const bool agentWithView) {
  942. return agentWithView ? " view" + agentName + "=" + std::to_string(agentDirection) + " & " : " ";
  943. }
  944. bool PrismModulesPrinter::isGame() const {
  945. return modelType == ModelType::SMG;
  946. }
  947. }