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 __WEIGHTED_A_STAR_H_
00030 #define __WEIGHTED_A_STAR_H_
00031
00032 #include <sbpl_dynamic_planner/DiscreteSpaceTimeInformation.h>
00033
00034
00035
00036
00037 #define WeightedAStar_DEFAULT_INITIAL_EPS 5.0
00038 #define WeightedAStar_DECREASE_EPS 5.0
00039
00040
00041
00042
00043
00044 #define WeightedAStar_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 WEIGHTEDASTARSEARCHSTATEDATA : 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
00074 public:
00075 WEIGHTEDASTARSEARCHSTATEDATA() {};
00076 ~WEIGHTEDASTARSEARCHSTATEDATA() {};
00077 } WeightedAStarState;
00078
00079
00080
00081 typedef struct{
00082 WeightedAStarState* state;
00083 CKey key;
00084 bool done;
00085 } HoldState_t;
00086
00087 typedef struct{
00088 bool active;
00089 vector<HoldState_t*> hold;
00090 } BubbleData_t;
00091
00092
00093
00094
00095
00096 typedef struct WEIGHTEDASTARSEARCHSTATESPACE
00097 {
00098 double eps;
00099 double eps_satisfied;
00100 CHeap* heap;
00101 CList* inconslist;
00102 short unsigned int searchiteration;
00103 short unsigned int callnumber;
00104 CMDPSTATE* searchgoalstate;
00105 CMDPSTATE* searchstartstate;
00106
00107 CMDP searchMDP;
00108
00109 bool bReevaluatefvals;
00110 bool bReinitializeSearchStateSpace;
00111 bool bNewSearchIteration;
00112
00113 } WeightedAStarSearchStateSpace_t;
00114
00115
00116
00117
00118 class WeightedAStar : public SBPLPlanner
00119 {
00120
00121 public:
00122 int replan(double allocated_time_secs, vector<int>* solution_stateIDs_V);
00123 int replan(double allocated_time_sec, vector<int>* solution_stateIDs_V, int* solcost);
00124
00125 int set_goal(int goal_stateID);
00126 int set_start(int start_stateID);
00127 void costs_changed(StateChangeQuery const & stateChange);
00128 void costs_changed();
00129 int force_planning_from_scratch();
00130
00131 int set_search_mode(bool bSearchUntilFirstSolution);
00132
00133
00134 virtual double get_solution_eps() const {return pSearchStateSpace_->eps_satisfied;};
00135 virtual int get_n_expands() const { return searchexpands; }
00136 void set_finalsolution_eps(double finalsolution_eps){WeightedAStar_FINAL_EPS = finalsolution_eps;};
00137 virtual void set_initialsolution_eps(double initialsolution_eps) {finitial_eps = initialsolution_eps; set_finalsolution_eps(initialsolution_eps);};
00138 void getSearchStats(bool* solutionFound, int* numExpands, int* solutionCost, double* searchTime);
00139
00140 void print_searchpath(FILE* fOut);
00141
00142
00143
00144 WeightedAStar(DiscreteSpaceTimeInformation* environment, bool bforwardsearch);
00145 ~WeightedAStar();
00146
00147
00148
00149 private:
00150
00151 DiscreteSpaceTimeInformation *environment_;
00152 double WeightedAStar_FINAL_EPS;
00153
00154
00155 double finitial_eps;
00156 MDPConfig* MDPCfg_;
00157
00158 bool bforwardsearch;
00159
00160 bool bsearchuntilfirstsolution;
00161
00162 WeightedAStarSearchStateSpace_t* pSearchStateSpace_;
00163
00164 unsigned int searchexpands;
00165 int MaxMemoryCounter;
00166 clock_t TimeStarted;
00167 FILE *fDeb;
00168 bool solfound;
00169 double searchtime;
00170 int finalsolcost;
00171
00172 vector<BubbleData_t> bubbles;
00173
00174
00175 void Initialize_searchinfo(CMDPSTATE* state, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00176
00177 CMDPSTATE* CreateState(int stateID, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00178
00179 CMDPSTATE* GetState(int stateID, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00180
00181 int ComputeHeuristic(CMDPSTATE* MDPstate, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00182
00183
00184 void InitializeSearchStateInfo(WeightedAStarState* state, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00185
00186
00187 void ReInitializeSearchStateInfo(WeightedAStarState* state, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00188
00189 void DeleteSearchStateData(WeightedAStarState* state);
00190
00191
00192 void UpdatePreds(WeightedAStarState* state, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00193
00194
00195
00196 void UpdateSuccs(WeightedAStarState* state, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00197
00198 int GetGVal(int StateID, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00199
00200
00201 int ImprovePath(WeightedAStarSearchStateSpace_t* pSearchStateSpace, double MaxNumofSecs);
00202
00203 void BuildNewOPENList(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00204
00205 void Reevaluatefvals(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00206
00207
00208
00209 int CreateSearchStateSpace(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00210
00211
00212 void DeleteSearchStateSpace(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00213
00214
00215 void PrintSearchState(WeightedAStarState* state, FILE* fOut);
00216
00217
00218
00219
00220 int ResetSearchStateSpace(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00221
00222
00223 void ReInitializeSearchStateSpace(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00224
00225
00226 int InitializeSearchStateSpace(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00227
00228 int SetSearchGoalState(int SearchGoalStateID, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00229
00230
00231 int SetSearchStartState(int SearchStartStateID, WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00232
00233
00234 int ReconstructPath(WeightedAStarSearchStateSpace_t* pSearchStateSpace);
00235
00236
00237 void PrintSearchPath(WeightedAStarSearchStateSpace_t* pSearchStateSpace, FILE* fOut);
00238
00239 int getHeurValue(WeightedAStarSearchStateSpace_t* pSearchStateSpace, int StateID);
00240
00241
00242 vector<int> GetSearchPath(WeightedAStarSearchStateSpace_t* pSearchStateSpace, int& solcost);
00243
00244
00245 bool Search(WeightedAStarSearchStateSpace_t* pSearchStateSpace, vector<int>& pathIds, int & PathCost, bool bFirstSolution, bool bOptimalSolution, double MaxNumofSecs);
00246
00247
00248 };
00249
00250
00251 #endif
00252
00253
00254