#include <StateSpace.h>
Public Member Functions | |
unsigned char | getBestAction (ENV_POS *pos) |
char | getFeedback (ENV_POS *pos, unsigned char _action) |
unsigned int | getMemorySize () |
void | getState (ENV_POS *pos, STATE *_state) |
double | getValue (ENV_POS *pos) |
void | ramtestReadBytes (unsigned int _addr, unsigned char *data, unsigned char _length) |
void | ramtestSaveBytes (unsigned int _addr, unsigned char *data, unsigned char _length) |
void | setBestAction (ENV_POS *pos, unsigned char _action) |
void | setFeedback (ENV_POS *pos, unsigned char _action, char _fb) |
void | setState (ENV_POS *pos, STATE *_state) |
void | setValue (ENV_POS *pos, float _value) |
StateSpace (Environment *newEnv) | |
~StateSpace () | |
Data Fields | |
bool | useInternalRAM |
Private Attributes | |
Environment * | env |
unsigned char * | internStateSpace |
Ram * | ram1 |
STATE | tmpState |
Definition at line 7 of file StateSpace.h.
StateSpace::StateSpace | ( | Environment * | env | ) |
constructor function.
Definition at line 5 of file StateSpace.c.
References State::feedback_down, State::feedback_left, State::feedback_right, State::feedback_up, Environment::getDiscretization(), internStateSpace, ram1, setState(), tmpState, useInternalRAM, State::value, envPosition::x, and envPosition::y.
00005 { 00006 00007 // use internal memory instead of FM24C256 00008 this->useInternalRAM = true; 00009 00010 // init ram 00011 ram1 = new Ram(); 00012 00013 // 00014 ENV_POS d, pos; 00015 env->getDiscretization(&d); 00016 internStateSpace = new unsigned char[d.x * d.y]; 00017 00018 // set's the environment 00019 this->env = env; 00020 00021 // initialize values with zeros 00022 STATE tmpState; 00023 00024 for (int _row=0; _row < d.y; _row++) { 00025 for (int _column=0; _column<d.x; _column++) { 00026 00027 pos.x = _column; 00028 pos.y = _row; 00029 00030 tmpState.value = 0.0; 00031 00032 tmpState.feedback_up = 0; 00033 tmpState.feedback_down = 0; 00034 tmpState.feedback_left = 0; 00035 tmpState.feedback_right = 0; 00036 00037 setState (&pos, &tmpState); 00038 } 00039 } 00040 }
StateSpace::~StateSpace | ( | ) |
destructor
Definition at line 43 of file StateSpace.c.
References internStateSpace, and ram1.
00043 { 00044 delete ram1; 00045 delete[] internStateSpace; 00046 }
unsigned char StateSpace::getBestAction | ( | ENV_POS * | pos | ) |
char StateSpace::getFeedback | ( | ENV_POS * | pos, | |
unsigned char | _action | |||
) |
returns r(s,a) from state (_row, _column)
Definition at line 135 of file StateSpace.c.
References DOWN, State::feedback_down, State::feedback_left, State::feedback_right, State::feedback_up, getState(), LEFT, RIGHT, and UP.
Referenced by ValueIteration::evaluateAction().
00135 { 00136 00137 STATE _s; 00138 this->getState (pos, &_s); 00139 00140 if (_action == UP) { 00141 return _s.feedback_up; 00142 } else if (_action == DOWN) { 00143 return _s.feedback_down; 00144 } else if (_action == LEFT) { 00145 return _s.feedback_left; 00146 } else if (_action == RIGHT) { 00147 return _s.feedback_right; 00148 } 00149 }
unsigned int StateSpace::getMemorySize | ( | ) |
returns the memory-size of the state-space
Definition at line 185 of file StateSpace.c.
References internStateSpace, and useInternalRAM.
00185 { 00186 00187 // Interner RAM 00188 if (this->useInternalRAM) { 00189 return sizeof(internStateSpace); 00190 00191 // SPI RAM 00192 } else { 00193 return 65535; 00194 } 00195 }
returns a state into _state
Definition at line 50 of file StateSpace.c.
References env, Environment::getDiscretization(), internStateSpace, ram1, Ram::readBytes(), STATESIZE, useInternalRAM, envPosition::x, and envPosition::y.
Referenced by getFeedback(), getValue(), V24Control::processGetState(), setFeedback(), and setValue().
00050 { 00051 00052 unsigned int _addr; 00053 unsigned char i; 00054 unsigned char* _bytes = (unsigned char*)_state; 00055 00056 ENV_POS d; 00057 env->getDiscretization(&d); 00058 00059 // compute memory address 00060 _addr = ((pos->y * d.x) + pos->x)*STATESIZE; 00061 00062 // internal RAM 00063 if (this->useInternalRAM) { 00064 for (i=0; i<STATESIZE; i++) { 00065 _bytes[i] = internStateSpace[(_addr + i)]; 00066 } 00067 00068 // SPI memory 00069 } else { 00070 ram1->readBytes(_addr, (unsigned char*)&_state[0], STATESIZE); 00071 } 00072 }
double StateSpace::getValue | ( | ENV_POS * | pos | ) |
returns the Value from state (_row, _column)
Definition at line 128 of file StateSpace.c.
References getState(), and State::value.
Referenced by ValueIteration::doNextAction(), and ValueIteration::evaluateAction().
void StateSpace::ramtestReadBytes | ( | unsigned int | _addr, | |
unsigned char * | data, | |||
unsigned char | _length | |||
) |
RAM-Test function (e.g. reads random numbers into *data from memory)
Definition at line 169 of file StateSpace.c.
References internStateSpace, ram1, Ram::readBytes(), and useInternalRAM.
Referenced by V24Control::processCommand().
00169 { 00170 00171 unsigned char* statesPtr = (unsigned char*)&internStateSpace[0]; 00172 unsigned char i; 00173 00174 if (this->useInternalRAM) { 00175 for (i=0; i<_length; i++) { 00176 data[i] = statesPtr[_addr + i]; 00177 } 00178 00179 } else { 00180 ram1->readBytes(_addr, data, _length); 00181 } 00182 }
void StateSpace::ramtestSaveBytes | ( | unsigned int | _addr, | |
unsigned char * | data, | |||
unsigned char | _length | |||
) |
RAM-Test function (e.g. writes random numbers from *data to memory)
Definition at line 153 of file StateSpace.c.
References internStateSpace, ram1, useInternalRAM, and Ram::writeBytes().
Referenced by V24Control::processCommand().
00153 { 00154 00155 unsigned char* statesPtr = (unsigned char*)&internStateSpace[0]; 00156 unsigned char i; 00157 00158 if (this->useInternalRAM) { 00159 for (i=0; i<_length; i++) { 00160 statesPtr[_addr + i] = data[i]; 00161 } 00162 00163 } else { 00164 ram1->writeBytes(_addr, data, _length); 00165 } 00166 }
void StateSpace::setBestAction | ( | ENV_POS * | pos, | |
unsigned char | _action | |||
) |
void StateSpace::setFeedback | ( | ENV_POS * | pos, | |
unsigned char | _action, | |||
char | _fb | |||
) |
set reward r(s,_action)=_fb in state (_row, _column)
Definition at line 109 of file StateSpace.c.
References DOWN, State::feedback_down, State::feedback_left, State::feedback_right, State::feedback_up, getState(), LEFT, RIGHT, setState(), and UP.
Referenced by ValueIteration::moveAndSaveFeedback().
00109 { 00110 00111 STATE _s; 00112 this->getState (pos, &_s); 00113 00114 if (_action == UP) { 00115 _s.feedback_up = _fb; 00116 } else if (_action == DOWN) { 00117 _s.feedback_down = _fb; 00118 } else if (_action == LEFT) { 00119 _s.feedback_left = _fb; 00120 } else if (_action == RIGHT) { 00121 _s.feedback_right = _fb; 00122 } 00123 00124 this->setState (pos, &_s); 00125 }
update state (_row, _column) with _state
Definition at line 75 of file StateSpace.c.
References env, Environment::getDiscretization(), internStateSpace, ram1, STATESIZE, useInternalRAM, Ram::writeBytes(), envPosition::x, and envPosition::y.
Referenced by V24Control::processSetState(), setFeedback(), setValue(), and StateSpace().
00075 { 00076 00077 unsigned int _addr; 00078 unsigned char i; 00079 unsigned char* _bytes = (unsigned char*)_state; 00080 00081 ENV_POS d; 00082 env->getDiscretization(&d); 00083 00084 // compute memory address 00085 _addr = ((pos->y * d.x) + pos->x)*STATESIZE; 00086 00087 // internal RAM 00088 if (this->useInternalRAM) { 00089 for (i=0; i<STATESIZE; i++) { 00090 internStateSpace[_addr + i] = _bytes[i]; 00091 } 00092 00093 // SPI Memory 00094 } else { 00095 ram1->writeBytes(_addr, (unsigned char*)&_state[0], STATESIZE); 00096 } 00097 }
void StateSpace::setValue | ( | ENV_POS * | pos, | |
float | _value | |||
) |
set Value in state (_row, _column)
Definition at line 100 of file StateSpace.c.
References getState(), setState(), and State::value.
Referenced by ValueIteration::valueIterateAllStates().
00100 { 00101 00102 STATE _s; 00103 this->getState ( pos, &_s ); 00104 _s.value = _value; 00105 this->setState ( pos, &_s ); 00106 }
Environment* StateSpace::env [private] |
Definition at line 34 of file StateSpace.h.
Referenced by getState(), and setState().
unsigned char* StateSpace::internStateSpace [private] |
Definition at line 37 of file StateSpace.h.
Referenced by getMemorySize(), getState(), ramtestReadBytes(), ramtestSaveBytes(), setState(), StateSpace(), and ~StateSpace().
Ram* StateSpace::ram1 [private] |
Definition at line 40 of file StateSpace.h.
Referenced by getState(), ramtestReadBytes(), ramtestSaveBytes(), setState(), StateSpace(), and ~StateSpace().
STATE StateSpace::tmpState [private] |
Definition at line 32 of file StateSpace.h.
Referenced by StateSpace().
Definition at line 29 of file StateSpace.h.
Referenced by getMemorySize(), getState(), ramtestReadBytes(), ramtestSaveBytes(), setState(), and StateSpace().