00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __ENVIRONMENT_ROBARM_H_
00030 #define __ENVIRONMENT_ROBARM_H_
00031
00032
00033
00034 #define NUMOFLINKS 6
00035
00036
00037 #define ROBARM_LONGACTIONDIST_CELLS 30 //for R* max. distance in coord to a sample point. It should be exactly this, for one of the coordinates and this or smaller for the rest
00038 #define ROBARM_NUMOFRANDSUCCSATDIST 10 //# of random successors at distance defined above, used by R* search
00039
00040
00041
00042 #define ENDEFF_CHECK_ONLY 0
00043
00044 #define UNIFORM_COST 1 //all the actions have the same costs when set
00045
00046
00047 #define INVALID_NUMBER 999
00048
00049
00050 typedef struct
00051 {
00052 short unsigned int x;
00053 short unsigned int y;
00054 bool bIsObstacle;
00055 }CELLV;
00056
00057
00058
00059 typedef struct STATE2D_t
00060 {
00061 unsigned int g;
00062 short unsigned int iterationclosed;
00063 short unsigned int x;
00064 short unsigned int y;
00065 } State2D;
00066
00067
00068 typedef struct ENV_ROBARM_CONFIG
00069 {
00070 double EnvWidth_m;
00071 double EnvHeight_m;
00072 int EnvWidth_c;
00073 int EnvHeight_c;
00074 int BaseX_c;
00075 short unsigned int EndEffGoalX_c;
00076 short unsigned int EndEffGoalY_c;
00077 double LinkLength_m[NUMOFLINKS];
00078 double LinkStartAngles_d[NUMOFLINKS];
00079 double LinkGoalAngles_d[NUMOFLINKS];
00080 char** Grid2D;
00081 double GridCellWidth;
00082
00083 double angledelta[NUMOFLINKS];
00084 int anglevals[NUMOFLINKS];
00085
00086 } EnvROBARMConfig_t;
00087
00088
00089
00090 typedef struct ENVROBARMHASHENTRY
00091 {
00092 int stateID;
00093
00094 short unsigned int coord[NUMOFLINKS];
00095 short unsigned int endeffx;
00096 short unsigned int endeffy;
00097 } EnvROBARMHashEntry_t;
00098
00099
00100 typedef struct
00101 {
00102 EnvROBARMHashEntry_t* goalHashEntry;
00103 EnvROBARMHashEntry_t* startHashEntry;
00104
00105
00106 int HashTableSize;
00107 vector<EnvROBARMHashEntry_t*>* Coord2StateIDHashTable;
00108
00109
00110 vector<EnvROBARMHashEntry_t*> StateID2CoordTable;
00111
00112
00113 int** Heur;
00114
00115 }EnvironmentROBARM_t;
00116
00119 class EnvironmentROBARM : public DiscreteSpaceInformation
00120 {
00121
00122 public:
00123
00126 bool InitializeEnv(const char* sEnvFile);
00127
00130 bool InitializeMDPCfg(MDPConfig *MDPCfg);
00131
00134 int GetFromToHeuristic(int FromStateID, int ToStateID);
00137 int GetGoalHeuristic(int stateID);
00140 int GetStartHeuristic(int stateID);
00143 void SetAllActionsandAllOutcomes(CMDPSTATE* state);
00146 void SetAllPreds(CMDPSTATE* state);
00149 void GetSuccs(int SourceStateID, vector<int>* SuccIDV, vector<int>* CostV);
00152 void GetPreds(int TargetStateID, vector<int>* PredIDV, vector<int>* CostV);
00153
00156 int SizeofCreatedEnv();
00159 void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL);
00162 void PrintEnv_Config(FILE* fOut);
00163
00164
00165 ~EnvironmentROBARM(){};
00168 void PrintTimeStat(FILE* fOut);
00169
00170 private:
00171
00172
00173 EnvROBARMConfig_t EnvROBARMCfg;
00174 EnvironmentROBARM_t EnvROBARM;
00175
00176
00177
00178 void ComputeContAngles(short unsigned int coord[NUMOFLINKS], double angle[NUMOFLINKS]);
00179 void ComputeCoord(double angle[NUMOFLINKS], short unsigned int coord[NUMOFLINKS]);
00180 int ComputeEndEffectorPos(double angles[NUMOFLINKS], short unsigned int* pX, short unsigned int* pY);
00181 int IsValidCoord(short unsigned int coord[NUMOFLINKS], char** Grid2D=NULL, vector<CELLV>* pTestedCells=NULL);
00182 int distanceincoord(unsigned short* statecoord1, unsigned short* statecoord2);
00183 void ReInitializeState2D(State2D* state);
00184 void InitializeState2D(State2D* state, short unsigned int x, short unsigned int y);
00185 void Search2DwithQueue(State2D** statespace, int* HeurGrid, int searchstartx, int searchstarty);
00186 void Create2DStateSpace(State2D*** statespace2D);
00187 void Delete2DStateSpace(State2D*** statespace2D);
00188 void printangles(FILE* fOut, short unsigned int* coord, bool bGoal, bool bVerbose, bool bLocal);
00189 void DiscretizeAngles();
00190 void Cell2ContXY(int x, int y, double *pX, double *pY);
00191 void ContXY2Cell(double x, double y, short unsigned int* pX, short unsigned int *pY);
00192 int IsValidLineSegment(double x0, double y0, double x1, double y1, char **Grid2D,
00193 vector<CELLV>* pTestedCells);
00194 void GetRandomSuccsatDistance(int SourceStateID, std::vector<int>* SuccIDV, std::vector<int>* CLowV);
00195 unsigned int GetHeurBasedonCoord(short unsigned int coord[NUMOFLINKS]);
00196 void PrintHeader(FILE* fOut);
00197 int cost(short unsigned int state1coord[], short unsigned int state2coord[]);
00198
00199
00200
00201
00202 void ReadConfiguration(FILE* fCfg);
00203
00204 void InitializeEnvConfig();
00205
00206 unsigned int GETHASHBIN(short unsigned int* coord, int numofcoord);
00207
00208 void PrintHashTableHist();
00209
00210
00211 EnvROBARMHashEntry_t* GetHashEntry(short unsigned int* coord, int numofcoord, bool bIsGoal);
00212
00213 EnvROBARMHashEntry_t* CreateNewHashEntry(short unsigned int* coord, int numofcoord, short unsigned int endeffx, short unsigned int endeffy);
00214
00215
00216 void CreateStartandGoalStates();
00217
00218 bool InitializeEnvironment();
00219
00220 void ComputeHeuristicValues();
00221
00222 bool IsValidCell(int X, int Y);
00223
00224 bool IsWithinMapCell(int X, int Y);
00225
00226
00227 int GetEdgeCost(int FromStateID, int ToStateID);
00228 int GetRandomState();
00229 bool AreEquivalent(int State1ID, int State2ID);
00230
00231 void PrintSuccGoal(int SourceStateID, int costtogoal, bool bVerbose, bool bLocal , FILE* fOut );
00232
00233
00234 };
00235
00236
00237
00238
00239
00240
00241
00242 #endif
00243