MachineIntelligenceCore:ReinforcementLearning
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Environment.cpp
Go to the documentation of this file.
1 
23 #include <types/Environment.hpp>
24 
25 namespace mic {
26 namespace environments {
27 
28 Environment::Environment(std::string node_name_) : PropertyTree(node_name_),
29  width("width", 4),
30  height("height", 4),
31  roi_size("roi_size", 0),
32  environment_grid(new mic::types::TensorXf()),
33  observation_grid(new mic::types::TensorXf())
34 {
35  // Register properties - so their values can be overridden (read from the configuration file).
36  registerProperty(width);
37  registerProperty(height);
38  registerProperty(roi_size);
39 
40  pomdp_flag = 0;
41 }
42 
44  // TODO Auto-generated destructor stub
45 }
46 
47 
48 bool Environment::moveAgent (mic::types::Action2DInterface ac_) {
49  mic::types::Position2D cur_pos = getAgentPosition();
50  LOG(LDEBUG) << "Current agent position = " << cur_pos;
51  LOG(LDEBUG) << "Move to be performed = " << ac_;
52  // Compute destination.
53  mic::types::Position2D new_pos = cur_pos + ac_;
54  return moveAgentToPosition(new_pos);
55 }
56 
59 }
60 
61 
62 bool Environment::isStateAllowed(long x_, long y_) {
63  return isStateAllowed(mic::types::Position2D(x_, y_));
64 }
65 
66 bool Environment::isStateTerminal(long x_, long y_) {
67  return isStateTerminal(mic::types::Position2D(x_, y_));
68 }
69 
70 bool Environment::isActionAllowed(long x_, long y_, size_t action_) {
71  mic::types::Position2D pos(x_,y_);
72  mic::types::NESWAction ac(action_);
73  // Compute the "destination" coordinates.
74  mic::types::Position2D new_pos = pos + ac;
75  return isStateAllowed(new_pos);
76 }
77 
78 
79 bool Environment::isActionAllowed(mic::types::Position2D pos_, mic::types::Action2DInterface ac_) {
80  // Compute the "destination" coordinates.
81  mic::types::Position2D new_pos = pos_ + ac_;
82  return isStateAllowed(new_pos);
83 }
84 
85 bool Environment::isActionAllowed(mic::types::Action2DInterface ac_) {
86  // Get current player position.
87  mic::types::Position2D pos = getAgentPosition();
88  // Compute the "destination" coordinates.
89  mic::types::Position2D new_pos = pos + ac_;
90  return isStateAllowed(new_pos);
91 }
92 
93 
94 } /* namespace environments */
95 } /* namespace mic */
virtual bool isStateTerminal(long x_, long y_)
Definition: Environment.cpp:66
Environment(std::string node_name_)
Definition: Environment.cpp:28
virtual void moveAgentToInitialPosition()
Definition: Environment.cpp:57
mic::configuration::Property< size_t > width
Property: width of the environment.
virtual bool isActionAllowed(long x_, long y_, size_t action_)
Definition: Environment.cpp:70
bool pomdp_flag
Flag related to.
virtual mic::types::Position2D getAgentPosition()=0
virtual bool moveAgentToPosition(mic::types::Position2D pos_)=0
bool moveAgent(mic::types::Action2DInterface ac_)
Definition: Environment.cpp:48
mic::configuration::Property< size_t > roi_size
Property: size of the ROI (region of interest).
mic::types::Position2D initial_position
Property: initial position of the agent.
mic::configuration::Property< size_t > height
Property: height of the environment.
virtual bool isStateAllowed(long x_, long y_)
Definition: Environment.cpp:62