AIToolbox
A library that offers tools for AI problem solving.
CornerProblem.hpp
Go to the documentation of this file.
1 #ifndef AI_TOOLBOX_MDP_CORNER_PROBLEM_HEADER_FILE
2 #define AI_TOOLBOX_MDP_CORNER_PROBLEM_HEADER_FILE
3 
6 
7 namespace AIToolbox::MDP {
52  inline AIToolbox::MDP::Model makeCornerProblem(const GridWorld & grid, double stepUncertainty = 0.8) {
53  using namespace GridWorldUtils;
54 
55  size_t S = grid.getWidth() * grid.getHeight();
56  size_t A = 4;
57 
58  AIToolbox::DumbMatrix3D transitions(boost::extents[S][A][S]);
59  AIToolbox::DumbMatrix3D rewards(boost::extents[S][A][S]);
60 
61  for ( size_t x = 0; x < grid.getWidth(); ++x ) {
62  for ( size_t y = 0; y < grid.getHeight(); ++y ) {
63  auto s = grid(x,y);
64  if ( s == 0 || s == S-1 ) {
65  // Self absorbing states
66  for ( size_t a = 0; a < A; ++a )
67  transitions[s][a][s] = 1.0;
68  }
69  else {
70  for ( size_t a = 0; a < A; ++a ) {
71  auto s1 = grid.getAdjacent((Direction)a, s);
72  // If the move takes you outside the map, it doesn't do
73  // anything
74  if ( s == s1 ) transitions[s][a][s1] = 1.0;
75  else {
76  transitions[s][a][s1] = stepUncertainty;
77  transitions[s][a][s] = 1.0 - stepUncertainty;
78  }
79  rewards[s][a][s1] = -1.0;
80  }
81  }
82  }
83  }
84  return Model(S, A, transitions, rewards, 0.95);
85  }
86 }
87 
88 #endif
AIToolbox::MDP::GridWorld
This class represents a simple rectangular gridworld.
Definition: GridWorld.hpp:23
AIToolbox::MDP::makeCornerProblem
AIToolbox::MDP::Model makeCornerProblem(const GridWorld &grid, double stepUncertainty=0.8)
This function sets up the corner problem in a Model.
Definition: CornerProblem.hpp:52
AIToolbox::DumbMatrix3D
boost::multi_array< double, 3 > DumbMatrix3D
Definition: Types.hpp:37
Model.hpp
AIToolbox::MDP::GridWorld::getAdjacent
State getAdjacent(Direction d, State s) const
This function returns the state next to the input in the chosen Direction.
AIToolbox::MDP
Definition: DoubleQLearning.hpp:10
GridWorld.hpp
AIToolbox::MDP::GridWorld::getWidth
unsigned getWidth() const
This function returns the width of the GridWorld.
AIToolbox::MDP::Model
This class represents a Markov Decision Process.
Definition: Model.hpp:70
AIToolbox::MDP::GridWorld::getHeight
unsigned getHeight() const
This function returns the height of the GridWorld.
AIToolbox::MDP::GridWorldUtils::Direction
Direction
The possible actions in a GridWorld-like environment.
Definition: GridWorld.hpp:15