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 __INTERVAL_PLANNER_H_
00030 #define __INTERVAL_PLANNER_H_
00031
00032 #include <sbpl_dynamic_planner/DiscreteSpaceTimeIntervalInformation.h>
00033
00034
00035
00036
00037 #define IntervalPlanner_DEFAULT_INITIAL_EPS 5.0
00038 #define IntervalPlanner_DECREASE_EPS 1.0
00039
00040
00041
00042
00043
00044 #define IntervalPlanner_INCONS_LIST_ID 0
00045
00046 class CMDP;
00047 class CMDPSTATE;
00048 class CMDPACTION;
00049 class CHeap;
00050 class CList;
00051
00052
00053
00054
00055
00056 typedef class INTERVALPLANNERSEARCHSTATEDATA : public AbstractSearchState
00057 {
00058 public:
00059 CMDPSTATE* MDPstate;
00060
00061 unsigned int v;
00062 unsigned int g;
00063 short unsigned int iterationclosed;
00064 short unsigned int callnumberaccessed;
00065 short unsigned int numofexpands;
00066
00067 CMDPSTATE *bestpredstate;
00068
00069 CMDPSTATE *bestnextstate;
00070 unsigned int costtobestnextstate;
00071 int h;
00072
00073 bool opt;
00074 unsigned int temp_g;
00075 CMDPSTATE* temp_bestpredstate;
00076
00077
00078 public:
00079 INTERVALPLANNERSEARCHSTATEDATA() {};
00080 ~INTERVALPLANNERSEARCHSTATEDATA() {};
00081 } IntervalPlannerState;
00082
00083
00084
00085
00086
00087
00088 typedef struct INTERVALPLANNERSEARCHSTATESPACE
00089 {
00090 double eps;
00091 double eps_satisfied;
00092 CHeap* heap;
00093 CList* inconslist;
00094 short unsigned int searchiteration;
00095 short unsigned int callnumber;
00096 CMDPSTATE* searchgoalstate;
00097 CMDPSTATE* searchstartstate;
00098
00099 CMDP searchMDP;
00100
00101 bool bReevaluatefvals;
00102 bool bReinitializeSearchStateSpace;
00103 bool bNewSearchIteration;
00104
00105 } IntervalPlannerSearchStateSpace_t;
00106
00107
00108
00109
00110 class IntervalPlanner : public SBPLPlanner
00111 {
00112
00113 public:
00118 IntervalPlanner(DiscreteSpaceTimeIntervalInformation* environment);
00119
00123 ~IntervalPlanner();
00124
00130 int set_start(int start_stateID);
00131
00137 int set_goal(int goal_stateID);
00138
00145 int replan(double allocated_time_secs, vector<int>* solution_stateIDs_V);
00146
00154 int replan(double allocated_time_sec, vector<int>* solution_stateIDs_V, int* solcost);
00155
00159 int force_planning_from_scratch();
00160
00165 int set_search_mode(bool bSearchUntilFirstSolution);
00166
00170 virtual double get_solution_eps() const {return pSearchStateSpace_->eps_satisfied;};
00171
00175 virtual int get_n_expands() const { return searchexpands; }
00176
00180 void set_finalsolution_eps(double finalsolution_eps){IntervalPlanner_FINAL_EPS = finalsolution_eps;};
00181
00185 virtual void set_initialsolution_eps(double initialsolution_eps) {finitial_eps = initialsolution_eps;};
00186
00190 virtual void set_decrease_eps_step(double dec_eps) {decrease_eps = dec_eps;};
00191
00200 void getSearchStats(bool* solutionFound, vector<int>* numExpands, vector<int>* solutionCost, vector<double>* searchTime, vector<double>* searchEps);
00201
00202 void print_searchpath(FILE* fOut);
00203 void costs_changed(StateChangeQuery const & stateChange);
00204 void costs_changed();
00205
00206 private:
00207 int numOptStates;
00208 int numSubOptStates;
00209 int totalNumOptStates;
00210 int totalNumSubOptStates;
00211
00212 DiscreteSpaceTimeIntervalInformation *environment_;
00213 double IntervalPlanner_FINAL_EPS;
00214
00215
00216 double finitial_eps;
00217 double decrease_eps;
00218 MDPConfig* MDPCfg_;
00219
00220 bool bforwardsearch;
00221
00222 bool bsearchuntilfirstsolution;
00223
00224 IntervalPlannerSearchStateSpace_t* pSearchStateSpace_;
00225
00226 unsigned int searchexpands;
00227 int MaxMemoryCounter;
00228 clock_t TimeStarted;
00229 FILE *fDeb;
00230 bool solfound;
00231 double searchtime;
00232 int finalsolcost;
00233
00234 vector<double> epsV;
00235 vector<unsigned int> expandsV;
00236 vector<unsigned int> solcostV;
00237 vector<double> searchTimeV;
00238
00239
00240 void Initialize_searchinfo(CMDPSTATE* state, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00241
00242 CMDPSTATE* CreateState(int stateID, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00243
00244 CMDPSTATE* GetState(int stateID, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00245
00246 int ComputeHeuristic(CMDPSTATE* MDPstate, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00247
00248
00249 void InitializeSearchStateInfo(IntervalPlannerState* state, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00250
00251
00252 void ReInitializeSearchStateInfo(IntervalPlannerState* state, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00253
00254 void DeleteSearchStateData(IntervalPlannerState* state);
00255
00256
00257 void UpdatePreds(IntervalPlannerState* state, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00258
00259
00260
00261 void UpdateSuccs(IntervalPlannerState* state, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00262
00263 int GetGVal(int StateID, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00264
00265
00266 int ImprovePath(IntervalPlannerSearchStateSpace_t* pSearchStateSpace, double MaxNumofSecs);
00267
00268 void BuildNewOPENList(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00269
00270 void Reevaluatefvals(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00271
00272
00273
00274 int CreateSearchStateSpace(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00275
00276
00277 void DeleteSearchStateSpace(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00278
00279
00280 void PrintSearchState(IntervalPlannerState* state, FILE* fOut);
00281
00282
00283
00284
00285 int ResetSearchStateSpace(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00286
00287
00288 void ReInitializeSearchStateSpace(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00289
00290
00291 int InitializeSearchStateSpace(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00292
00293 int SetSearchGoalState(int SearchGoalStateID, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00294
00295
00296 int SetSearchStartState(int SearchStartStateID, IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00297
00298
00299 int ReconstructPath(IntervalPlannerSearchStateSpace_t* pSearchStateSpace);
00300
00301
00302 void PrintSearchPath(IntervalPlannerSearchStateSpace_t* pSearchStateSpace, FILE* fOut);
00303
00304 int getHeurValue(IntervalPlannerSearchStateSpace_t* pSearchStateSpace, int StateID);
00305
00306
00307 vector<int> GetSearchPath(IntervalPlannerSearchStateSpace_t* pSearchStateSpace, int& solcost);
00308
00309
00310 bool Search(IntervalPlannerSearchStateSpace_t* pSearchStateSpace, vector<int>& pathIds, int & PathCost, bool bFirstSolution, bool bOptimalSolution, double MaxNumofSecs);
00311
00312
00313 };
00314
00315
00316 #endif
00317
00318
00319