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.

125 lines
7.9 KiB

1 year ago
  1. From cbcb339cad57db456fb11dc844c99119cb8485e8 Mon Sep 17 00:00:00 2001
  2. From: sp <stefan.pranger@iaik.tugraz.at>
  3. Date: Wed, 5 Jul 2023 15:44:04 +0200
  4. Subject: [PATCH] WIP: differentiate between slippery tilt direction
  5. ---
  6. Minigrid2PRISM/util/Grid.cpp | 24 +++++++++++++++------
  7. Minigrid2PRISM/util/Grid.h | 5 ++++-
  8. Minigrid2PRISM/util/MinigridGrammar.h | 5 ++++-
  9. Minigrid2PRISM/util/PrismModulesPrinter.cpp | 10 ++++-----
  10. 4 files changed, 31 insertions(+), 13 deletions(-)
  11. diff --git a/Minigrid2PRISM/util/Grid.cpp b/Minigrid2PRISM/util/Grid.cpp
  12. index 9da5786..c6cf225 100644
  13. --- a/Minigrid2PRISM/util/Grid.cpp
  14. +++ b/Minigrid2PRISM/util/Grid.cpp
  15. @@ -16,8 +16,17 @@ Grid::Grid(cells gridCells, cells background, const GridOptions &gridOptions, co
  16. std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(floor), [](cell c) {
  17. return c.type == Type::Floor;
  18. });
  19. - std::copy_if(background.begin(), background.end(), std::back_inserter(slippery), [](cell c) {
  20. - return c.type == Type::Slippery;
  21. + std::copy_if(background.begin(), background.end(), std::back_inserter(northSlippery), [](cell c) {
  22. + return c.type == Type::NorthSlippery;
  23. + });
  24. + std::copy_if(background.begin(), background.end(), std::back_inserter(southSlippery), [](cell c) {
  25. + return c.type == Type::SouthSlippery;
  26. + });
  27. + std::copy_if(background.begin(), background.end(), std::back_inserter(eastSlippery), [](cell c) {
  28. + return c.type == Type::EastSlippery;
  29. + });
  30. + std::copy_if(background.begin(), background.end(), std::back_inserter(westSlippery), [](cell c) {
  31. + return c.type == Type::WestSlippery;
  32. });
  33. std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(lockedDoors), [](cell c) {
  34. return c.type == Type::LockedDoor;
  35. @@ -158,11 +167,14 @@ void Grid::printToPrism(std::ostream& os, const prism::ModelType& modelType) {
  36. std::set<std::string> slipperyActions;
  37. if(agentWithProbabilisticBehaviour) printer.printModule(os, agentName, agentIndex, maxBoundaries, agentNameAndPosition->second, keys, agentWithView, gridOptions.probabilitiesForActions);
  38. else printer.printModule(os, agentName, agentIndex, maxBoundaries, agentNameAndPosition->second, keys, agentWithView);
  39. - for(auto const& c : slippery) {
  40. + for(auto const& c : northSlippery) {
  41. + printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 3);
  42. + for(auto const& c : southSlippery) {
  43. + printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 3);
  44. + for(auto const& c : eastSlippery) {
  45. + printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 3);
  46. + for(auto const& c : westSlippery) {
  47. printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 3);
  48. - printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 0);
  49. - printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 1);
  50. - printer.printSlippery(os, agentName, agentIndex, c.getCoordinates(), slipperyActions, getWalkableDirOf8Neighborhood(c), 2);
  51. // printer.printSlipperyMoveNorth(os, agentName, agentIndex, c.getCoordinates(), isBlocked(c.getNorth()), isBlocked(c.getNorth(allGridCells).getEast()), isBlocked(c.getNorth(allGridCells).getWest()), slipperyActions, getWalkableDirOf8Neighborhood(c));
  52. // printer.printSlipperyMoveEast( os, agentName, agentIndex, c.getCoordinates(), isBlocked(c.getEast()), isBlocked(c.getNorth(allGridCells).getEast()), isBlocked(c.getSouth(allGridCells).getEast()), slipperyActions);
  53. // printer.printSlipperyMoveSouth(os, agentName, agentIndex, c.getCoordinates(), isBlocked(c.getSouth()), isBlocked(c.getSouth(allGridCells).getEast()), isBlocked(c.getSouth(allGridCells).getWest()), slipperyActions);
  54. diff --git a/Minigrid2PRISM/util/Grid.h b/Minigrid2PRISM/util/Grid.h
  55. index f42b6e7..f908138 100644
  56. --- a/Minigrid2PRISM/util/Grid.h
  57. +++ b/Minigrid2PRISM/util/Grid.h
  58. @@ -45,7 +45,10 @@ class Grid {
  59. cells walls;
  60. cells floor;
  61. - cells slippery;
  62. + cells northSlippery;
  63. + cells southSlippery;
  64. + cells eastSlippery;
  65. + cells westSlippery;
  66. cells lockedDoors;
  67. cells boxes;
  68. cells lava;
  69. diff --git a/Minigrid2PRISM/util/MinigridGrammar.h b/Minigrid2PRISM/util/MinigridGrammar.h
  70. index 5d73d87..e32db99 100644
  71. --- a/Minigrid2PRISM/util/MinigridGrammar.h
  72. +++ b/Minigrid2PRISM/util/MinigridGrammar.h
  73. @@ -62,7 +62,10 @@ template <typename It>
  74. ("B", Type::Box)
  75. ("G", Type::Goal)
  76. ("V", Type::Lava)
  77. - ("S", Type::Slippery)
  78. + ("n", Type::NorthSlippery)
  79. + ("s", Type::SouthSlippery)
  80. + ("e", Type::EastSlippery)
  81. + ("w", Type::WestSlippery)
  82. ("X", Type::Agent)
  83. ("Z", Type::Adversary);
  84. color_.add
  85. diff --git a/Minigrid2PRISM/util/PrismModulesPrinter.cpp b/Minigrid2PRISM/util/PrismModulesPrinter.cpp
  86. index b6661ef..3a32932 100644
  87. --- a/Minigrid2PRISM/util/PrismModulesPrinter.cpp
  88. +++ b/Minigrid2PRISM/util/PrismModulesPrinter.cpp
  89. @@ -184,9 +184,9 @@ namespace prism {
  90. if(agentWithView) {
  91. os << "\tview" << agentName << " : [0..3] init 0;\n";
  92. os << "\n";
  93. - os << "\t[" << agentName << "_turn_right] " << moveGuard(agentIndex) << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava -> (view" << agentName << "'=mod(view" << agentName << " + 1, 4)) " << moveUpdate(agentIndex) << ";\n";
  94. - os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & view" << agentName << ">0 -> (view" << agentName << "'=view" << agentName << " - 1) " << moveUpdate(agentIndex) << ";\n";
  95. - os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & view" << agentName << "=0 -> (view" << agentName << "'=3) " << moveUpdate(agentIndex) << ";\n";
  96. + os << "\t[" << agentName << "_turn_right] " << moveGuard(agentIndex) << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !AgentIsOnSlippery-> (view" << agentName << "'=mod(view" << agentName << " + 1, 4)) " << moveUpdate(agentIndex) << ";\n";
  97. + os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !AgentIsOnSlippery& view" << agentName << ">0 -> (view" << agentName << "'=view" << agentName << " - 1) " << moveUpdate(agentIndex) << ";\n";
  98. + os << "\t[" << agentName << "_turn_left] " << moveGuard(agentIndex) << " !" << agentName << "IsInGoal & !" << agentName << "IsInLava & !AgentIsOnSlippery& view" << agentName << "=0 -> (view" << agentName << "'=3) " << moveUpdate(agentIndex) << ";\n";
  99. } else {
  100. os << "\t[" << agentName << "_turns] " << moveGuard(agentIndex) << " true -> (x" << agentName << "'=x" << agentName << ")" << moveUpdate(agentIndex) << ";\n";
  101. }
  102. @@ -256,7 +256,7 @@ namespace prism {
  103. // direction specifics
  104. std::size_t straightPosIndex;
  105. - std::string actionName, specialTransition; // if straight ahead is blocked
  106. + std::string actionName, specialTransition; // if straight ahead is blocked
  107. std::array<std::size_t, ALL_POSS_DIRECTIONS> prob_piece_dir; // from north clockwise
  108. switch (direction)
  109. @@ -367,7 +367,7 @@ namespace prism {
  110. std::ostream& PrismModulesPrinter::printRewards(std::ostream &os, const std::map<coordinates, float> &stateRewards, const cells &lava, const cells &goals) {
  111. os << "rewards \"NoBFS\"\n";
  112. - os << "\tAgentIsInGoalAndNotDone: 100;\n";
  113. + //os << "\tAgentIsInGoalAndNotDone: 100;\n";
  114. os << "\tAgentIsInLavaAndNotDone: -100;\n";
  115. os << "endrewards\n";
  116. os << "rewards \"WithBFS\"\n";
  117. --
  118. 2.25.1