environment.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 __ENVIRONMENT_H_
00030 #define __ENVIRONMENT_H_
00031 
00038 class DiscreteSpaceInformation
00039 {
00040 
00041 public:
00042 
00048         std::vector<int*> StateID2IndexMapping;
00049         
00052         FILE* fDeb;
00053 
00056         virtual bool InitializeEnv(const char* sEnvFile) = 0;
00057 
00060         virtual bool InitializeMDPCfg(MDPConfig *MDPCfg) = 0;
00061 
00064         virtual int  GetFromToHeuristic(int FromStateID, int ToStateID) = 0;
00067         virtual int  GetGoalHeuristic(int stateID) = 0;
00070         virtual int  GetStartHeuristic(int stateID) = 0;
00071 
00077         virtual void GetSuccs(int SourceStateID, std::vector<int>* SuccIDV, std::vector<int>* CostV) = 0;
00080         virtual void GetPreds(int TargetStateID, std::vector<int>* PredIDV, std::vector<int>* CostV) = 0;
00083         virtual void SetAllActionsandAllOutcomes(CMDPSTATE* state) = 0;
00086         virtual void SetAllPreds(CMDPSTATE* state) = 0;
00087 
00090         virtual int      SizeofCreatedEnv() = 0;
00093         virtual void PrintState(int stateID, bool bVerbose, FILE* fOut=NULL) = 0;
00096         virtual void PrintEnv_Config(FILE* fOut) = 0;
00097 
00100         virtual bool SetEnvParameter(const char* parameter, int value)
00101         {
00102                 SBPL_ERROR("ERROR: Environment has no parameters that can be set via SetEnvParameter function\n");
00103                 return false;
00104         }
00105 
00107         virtual std::vector<int> GetExpandedStates()
00108         {
00109                 SBPL_ERROR("Error: Not yet defined for any environment other than door environment.\n");
00110                 std::vector<int> list;
00111                 return list;
00112         }
00113 
00119         virtual bool AreEquivalent(int StateID1, int StateID2){
00120                 SBPL_ERROR("ERROR: environment does not support calls to AreEquivalent function\n");
00121                 throw new SBPL_Exception();
00122         }
00123 
00129         virtual void GetRandomSuccsatDistance(int SourceStateID, std::vector<int>* SuccIDV, std::vector<int>* CLowV)
00130         {
00131                 SBPL_ERROR("ERROR: environment does not support calls to GetRandomSuccsatDistance function\n");
00132                 throw new SBPL_Exception();
00133         }
00136         virtual void GetRandomPredsatDistance(int TargetStateID, std::vector<int>* PredIDV, std::vector<int>* CLowV)
00137         {
00138                 SBPL_ERROR("ERROR: environment does not support calls to GetRandomPredsatDistance function\n");
00139                 throw new SBPL_Exception();
00140         };
00141 
00142     
00145         virtual void EnsureHeuristicsUpdated(bool bGoalHeuristics)
00146         {
00147                 //by default the heuristics are up-to-date, but in some cases, the heuristics are computed only when really needed. For example,
00148                 //xytheta environment uses 2D gridsearch as heuristics, and then re-computes them only when this function is called. This 
00149                 //minimizes the number of times heuristics are re-computed which is an expensive operation
00150                 //if bGoalHeuristics == true, then it updates goal heuristics (for forward search), otherwise it updates start heuristics (for backward search)
00151 
00152         };
00153 
00156         virtual ~DiscreteSpaceInformation(){
00157     SBPL_PRINTF("destroying discretespaceinformation\n");
00158     for(unsigned int i = 0; i < StateID2IndexMapping.size(); ++i){
00159       if(StateID2IndexMapping[i] != NULL)
00160         delete[] StateID2IndexMapping[i];
00161     }
00162     SBPL_FCLOSE(fDeb);
00163   }
00164 
00165 
00168         DiscreteSpaceInformation()
00169         {
00170 
00171 #ifndef ROS
00172     const char* envdebug = "envdebug.txt";
00173 #endif
00174           if((fDeb = SBPL_FOPEN(envdebug, "w")) == NULL)
00175             {
00176               SBPL_ERROR("ERROR: failed to open debug file for environment\n");
00177               throw new SBPL_Exception();
00178             }
00179 
00180         }
00181 };
00182 
00183 
00184 
00185 #endif
00186 
 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