Go to the documentation of this file.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 __RSTARPLANNER_H_
00030 #define __RSTARPLANNER_H_
00031
00032
00033
00034
00035
00036 #define RSTAR_DEFAULT_INITIAL_EPS 5.0
00037 #define RSTAR_DECREASE_EPS 0.2
00038 #define RSTAR_FINAL_EPS 1.0
00039
00040
00041 #define RSTAR_EXPTHRESH 150 //100 //200 TODO - make it a parameter
00042
00043
00044
00045
00046 #define RSTAR_INCONS_LIST_ID 0
00047
00048 class CMDP;
00049 class CMDPSTATE;
00050 class CMDPACTION;
00051 class CHeap;
00052 class CList;
00053
00054
00055
00056
00060 typedef class RSTARSEARCHSTATEDATA : public AbstractSearchState
00061 {
00062 public:
00065 CMDPSTATE* MDPstate;
00068 unsigned int g;
00071 short unsigned int iterationclosed;
00074 short unsigned int callnumberaccessed;
00075
00082 CMDPACTION *bestpredaction;
00083
00086 vector<CMDPACTION*> predactionV;
00087
00090 int h;
00091
00092
00093 public:
00094 RSTARSEARCHSTATEDATA() {};
00095 ~RSTARSEARCHSTATEDATA() {};
00096 } RSTARState;
00097
00100 typedef struct RSTARACTIONDATA_T
00101 {
00104 int clow;
00107 int exp;
00112 vector<int> pathIDs;
00113 }RSTARACTIONDATA;
00114
00115
00118 typedef class RSTARLSEARCHSTATEDATA : public AbstractSearchState
00119 {
00120 public:
00123 CMDPSTATE* MDPstate;
00126 int g;
00127
00130 unsigned int iteration;
00133 unsigned int iterationclosed;
00134
00137 CMDPSTATE* bestpredstate;
00140 int bestpredstateactioncost;
00141
00142
00143 public:
00144 RSTARLSEARCHSTATEDATA() {};
00145 ~RSTARLSEARCHSTATEDATA() {};
00146 } RSTARLSearchState;
00147
00148
00151 class RSTARLSEARCHSTATESPACE
00152 {
00153 public:
00156 CMDP MDP;
00159 CMDPSTATE* StartState;
00162 CMDPSTATE* GoalState;
00165 int iteration;
00166
00169 CHeap* OPEN;
00172 CList* INCONS;
00173
00174 public:
00175 RSTARLSEARCHSTATESPACE(){
00176 OPEN = NULL;
00177 INCONS = NULL;
00178 StartState = NULL;
00179 GoalState = NULL;
00180 };
00181 ~RSTARLSEARCHSTATESPACE(){
00182 if(OPEN != NULL)
00183 delete OPEN;
00184 };
00185 };
00186 typedef class RSTARLSEARCHSTATESPACE RSTARLSearchStateSpace_t;
00187
00188
00191 typedef struct RSTARSEARCHSTATESPACE
00192 {
00195 double eps;
00198 double eps_satisfied;
00201 CHeap* OPEN;
00202
00205 short unsigned int searchiteration;
00208 short unsigned int callnumber;
00211 CMDPSTATE* searchgoalstate;
00214 CMDPSTATE* searchstartstate;
00215
00218 CMDP searchMDP;
00219
00222 bool bReevaluatefvals;
00225 bool bReinitializeSearchStateSpace;
00228 bool bNewSearchIteration;
00229
00230 } RSTARSearchStateSpace_t;
00231
00232
00233
00236 class RSTARPlanner : public SBPLPlanner
00237 {
00238
00239 public:
00242 int replan(double allocated_time_secs, vector<int>* solution_stateIDs_V);
00245 int replan(double allocated_time_sec, vector<int>* solution_stateIDs_V, int* solcost);
00246
00249 int set_goal(int goal_stateID);
00252 int set_start(int start_stateID);
00255 void costs_changed(StateChangeQuery const & stateChange);
00259 void costs_changed();
00262 int force_planning_from_scratch();
00263
00266 int set_search_mode(bool bSearchUntilFirstSolution);
00267
00268
00271 virtual double get_solution_probabilisticeps() const {return pSearchStateSpace->eps_satisfied;};
00274 virtual int get_highlevel_expands() const { return highlevel_searchexpands; }
00277 virtual int get_lowlevel_expands() const { return lowlevel_searchexpands; }
00280 virtual void set_initialsolution_eps(double initialsolution_eps) {finitial_eps = initialsolution_eps;};
00281
00284 void print_searchpath(FILE* fOut);
00285
00286
00289 RSTARPlanner(DiscreteSpaceInformation* environment, bool bforwardsearch);
00292 ~RSTARPlanner();
00293
00294
00295
00296 private:
00297
00298
00299 double finitial_eps;
00300
00301 bool bforwardsearch;
00302
00303 bool bsearchuntilfirstsolution;
00304
00305 RSTARSearchStateSpace_t* pSearchStateSpace;
00306 RSTARLSearchStateSpace_t* pLSearchStateSpace;
00307
00308 unsigned int highlevel_searchexpands;
00309 unsigned int lowlevel_searchexpands;
00310 int MaxMemoryCounter;
00311 clock_t TimeStarted;
00312 FILE *fDeb;
00313
00314
00315
00316 void Initialize_searchinfo(CMDPSTATE* state);
00317 CMDPSTATE* CreateState(int stateID);
00318 CMDPSTATE* GetState(int stateID);
00319
00320 int ComputeHeuristic(CMDPSTATE* MDPstate);
00321
00322
00323 void InitializeSearchStateInfo(RSTARState* state);
00324
00325
00326 void ReInitializeSearchStateInfo(RSTARState* state);
00327
00328 void DeleteSearchStateData(RSTARState* state);
00329 void DeleteSearchActionData(RSTARACTIONDATA* actiondata);
00330
00331 int GetGVal(int StateID);
00332
00333
00334 int ImprovePath(double MaxNumofSecs);
00335
00336
00337 void Reevaluatefvals();
00338
00339
00340
00341 int CreateSearchStateSpace();
00342
00343
00344 void DeleteSearchStateSpace();
00345
00346
00347 void PrintSearchState(RSTARState* state, FILE* fOut);
00348
00349
00350
00351
00352 int ResetSearchStateSpace();
00353
00354
00355 void ReInitializeSearchStateSpace();
00356
00357
00358 int InitializeSearchStateSpace();
00359
00360
00361 int SetSearchGoalState(int SearchGoalStateID);
00362 int SetSearchStartState(int SearchStartStateID);
00363
00364
00365 int getHeurValue(int StateID);
00366
00367
00368 vector<int> GetSearchPath(int& solcost);
00369 void PrintSearchPath(FILE* fOut);
00370
00371
00372 bool Search(vector<int>& pathIds, int & PathCost, bool bFirstSolution, bool bOptimalSolution, double MaxNumofSecs);
00373
00374 bool ComputeLocalPath(int StartStateID, int GoalStateID, int maxc, int maxe,
00375 int *pCost, int *pCostLow, int *pExp, vector<int>* pPathIDs, int* pNewGoalStateID, double maxnumofsecs);
00376
00377
00378 void SetBestPredecessor(RSTARState* rstarState, RSTARState* rstarPredState, CMDPACTION* action);
00379 CKey ComputeKey(RSTARState* rstarState);
00380
00381
00382 void Initialize_rstarlsearchdata(CMDPSTATE* state);
00383 CMDPSTATE* CreateLSearchState(int stateID);
00384 CMDPSTATE* GetLSearchState(int stateID);
00385 bool DestroyLocalSearchMemory();
00386 CKey LocalSearchComputeKey(RSTARLSearchState* rstarlsearchState);
00387
00388
00389
00390
00391 };
00392
00393
00394 #endif
00395
00396
00397