rstarplanner.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Maxim Likhachev
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  * 
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the University of Pennsylvania nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 #ifndef __RSTARPLANNER_H_
00030 #define __RSTARPLANNER_H_
00031 
00032 
00033 //---configuration----
00034 
00035 //control of EPS
00036 #define RSTAR_DEFAULT_INITIAL_EPS           5.0
00037 #define RSTAR_DECREASE_EPS                              0.2
00038 #define RSTAR_FINAL_EPS                                 1.0
00039 
00040 //the number of states to expand for local search in RSTAR before it declares a hard case and postpones its processing
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         //member variables
00299         double finitial_eps;
00300 
00301         bool bforwardsearch; //if true, then search proceeds forward, otherwise backward
00302 
00303         bool bsearchuntilfirstsolution; //if true, then search until first solution only (see planner.h for search modes)
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         //member functions
00316         void Initialize_searchinfo(CMDPSTATE* state);
00317         CMDPSTATE* CreateState(int stateID);
00318         CMDPSTATE* GetState(int stateID);
00319 
00320         int ComputeHeuristic(CMDPSTATE* MDPstate);
00321 
00322         //initialization of a state
00323         void InitializeSearchStateInfo(RSTARState* state);
00324 
00325         //re-initialization of a state
00326         void ReInitializeSearchStateInfo(RSTARState* state);
00327 
00328         void DeleteSearchStateData(RSTARState* state);
00329         void DeleteSearchActionData(RSTARACTIONDATA* actiondata);
00330 
00331         int GetGVal(int StateID);
00332 
00333         //returns 1 if the solution is found, 0 if the solution does not exist and 2 if it ran out of time
00334         int ImprovePath(double MaxNumofSecs);
00335 
00336         //note this does NOT re-compute heuristics, only re-orders OPEN list based on current eps and h-vals
00337         void Reevaluatefvals();
00338 
00339         //creates (allocates memory) search state space
00340         //does not initialize search statespace
00341         int CreateSearchStateSpace();
00342 
00343         //deallocates memory used by SearchStateSpace
00344         void DeleteSearchStateSpace();
00345 
00346         //debugging 
00347         void PrintSearchState(RSTARState* state, FILE* fOut);
00348 
00349 
00350         //reset properly search state space
00351         //needs to be done before deleting states
00352         int ResetSearchStateSpace();
00353 
00354         //initialization before each search
00355         void ReInitializeSearchStateSpace();
00356 
00357         //very first initialization
00358         int InitializeSearchStateSpace();
00359 
00360         //setting start/goal
00361         int SetSearchGoalState(int SearchGoalStateID);
00362         int SetSearchStartState(int SearchStartStateID);
00363 
00364 
00365         int getHeurValue(int StateID);
00366 
00367         //get path 
00368         vector<int> GetSearchPath(int& solcost);
00369         void PrintSearchPath(FILE* fOut);
00370         
00371         //the actual search
00372         bool Search(vector<int>& pathIds, int & PathCost, bool bFirstSolution, bool bOptimalSolution, double MaxNumofSecs);
00373         //local search
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         //global search functions
00378         void  SetBestPredecessor(RSTARState* rstarState, RSTARState* rstarPredState, CMDPACTION* action);
00379         CKey ComputeKey(RSTARState* rstarState);
00380 
00381         //local search functions
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 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


sbpl
Author(s): Maxim Likhachev/maximl@seas.upenn.edu
autogenerated on Fri Jan 18 2013 13:41:53