00001 00006 #ifndef _CARTPOLE_H_ 00007 #define _CARTPOLE_H_ 00008 00009 #include <set> 00010 #include <rl_common/Random.h> 00011 #include <rl_common/core.hh> 00012 00014 class CartPole: public Environment { 00015 public: 00016 00021 CartPole(Random &rand); 00022 00027 CartPole(Random &rand, bool stochastic); 00028 00029 virtual ~CartPole(); 00030 00031 virtual const std::vector<float> &sensation() const; 00032 virtual float apply(int action); 00033 00035 float transition(float force); 00036 00037 virtual bool terminal() const; 00038 virtual void reset(); 00039 00040 virtual int getNumActions(); 00041 virtual void getMinMaxFeatures(std::vector<float> *minFeat, std::vector<float> *maxFeat); 00042 virtual void getMinMaxReward(float* minR, float* maxR); 00043 00045 void setSensation(std::vector<float> newS); 00046 00047 virtual std::vector<experience> getSeedings(); 00048 00050 experience getExp(float s0, float s1, float s2, float s3, int a); 00051 00052 protected: 00053 enum car_action_t {LEFT, RIGHT}; 00054 00055 private: 00056 00057 float GRAVITY; 00058 float MASSCART; 00059 float MASSPOLE; 00060 float TOTAL_MASS; 00061 float LENGTH; 00062 00063 float POLEMASS_LENGTH; 00064 float FORCE_MAG; 00065 float TAU; 00066 00067 float FOURTHIRDS; 00068 float DEG_T_RAD; 00069 float RAD_T_DEG; 00070 00071 const bool noisy; 00072 Random &rng; 00073 00074 std::vector<float> s; 00075 00076 float &cartPos; 00077 float &cartVel; 00078 float &poleAngle; 00079 float &poleVel; 00080 00081 float reward(); 00082 00083 }; 00084 00085 #endif