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
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef OMPL_BASE_PLANNER_
00038 #define OMPL_BASE_PLANNER_
00039
00040 #include "ompl/base/SpaceInformation.h"
00041 #include "ompl/base/ProblemDefinition.h"
00042 #include "ompl/base/PlannerData.h"
00043 #include "ompl/base/PlannerTerminationCondition.h"
00044 #include "ompl/util/Console.h"
00045 #include "ompl/util/Time.h"
00046 #include "ompl/util/ClassForward.h"
00047 #include <boost/function.hpp>
00048 #include <boost/concept_check.hpp>
00049 #include <boost/noncopyable.hpp>
00050 #include <string>
00051
00052 namespace ompl
00053 {
00054
00055 namespace base
00056 {
00057
00059 ClassForward(Planner);
00060
00076 class PlannerInputStates
00077 {
00078 public:
00079
00081 PlannerInputStates(const PlannerPtr &planner) : planner_(planner.get())
00082 {
00083 tempState_ = NULL;
00084 update();
00085 }
00086
00088 PlannerInputStates(const Planner *planner) : planner_(planner)
00089 {
00090 tempState_ = NULL;
00091 update();
00092 }
00093
00097 PlannerInputStates(void) : planner_(NULL)
00098 {
00099 tempState_ = NULL;
00100 clear();
00101 }
00102
00104 ~PlannerInputStates(void)
00105 {
00106 clear();
00107 }
00108
00110 void clear(void);
00111
00115 void restart(void);
00116
00122 bool update(void);
00123
00132 bool use(const SpaceInformationPtr &si, const ProblemDefinitionPtr &pdef);
00133
00142 bool use(const SpaceInformation *si, const ProblemDefinition *pdef);
00143
00146 void checkValidity(void) const;
00147
00150 const State* nextStart(void);
00151
00160 const State* nextGoal(const PlannerTerminationCondition &ptc);
00161
00163 const State* nextGoal(void);
00164
00166 bool haveMoreStartStates(void) const;
00167
00169 bool haveMoreGoalStates(void) const;
00170
00174 unsigned int getSeenStartStatesCount(void) const
00175 {
00176 return addedStartStates_;
00177 }
00178
00180 unsigned int getSampledGoalsCount(void) const
00181 {
00182 return sampledGoalsCount_;
00183 }
00184
00185 private:
00186
00187 const Planner *planner_;
00188
00189 unsigned int addedStartStates_;
00190 unsigned int sampledGoalsCount_;
00191 State *tempState_;
00192
00193 const ProblemDefinition *pdef_;
00194 const SpaceInformation *si_;
00195 };
00196
00198 struct PlannerSpecs
00199 {
00200 PlannerSpecs(void) : recognizedGoal(GOAL_ANY), multithreaded(false), approximateSolutions(false),
00201 optimizingPaths(false), estimatingProbabilities(false)
00202 {
00203 }
00204
00206 GoalType recognizedGoal;
00207
00209 bool multithreaded;
00210
00212 bool approximateSolutions;
00213
00216 bool optimizingPaths;
00217
00219 bool estimatingProbabilities;
00220 };
00221
00223 class Planner : private boost::noncopyable
00224 {
00225
00226 public:
00227
00229 Planner(const SpaceInformationPtr &si, const std::string &name);
00230
00232 virtual ~Planner(void)
00233 {
00234 }
00235
00237 template<class T>
00238 T* as(void)
00239 {
00241 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
00242
00243 return static_cast<T*>(this);
00244 }
00245
00247 template<class T>
00248 const T* as(void) const
00249 {
00251 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
00252
00253 return static_cast<const T*>(this);
00254 }
00255
00257 const SpaceInformationPtr& getSpaceInformation(void) const;
00258
00260 const ProblemDefinitionPtr& getProblemDefinition(void) const;
00261
00263 const PlannerInputStates& getPlannerInputStates(void) const;
00264
00269 virtual void setProblemDefinition(const ProblemDefinitionPtr &pdef);
00270
00283 virtual bool solve(const PlannerTerminationCondition &ptc) = 0;
00284
00287 bool solve(const PlannerTerminationConditionFn &ptc, double checkInterval);
00288
00292 bool solve(double solveTime);
00293
00297 virtual void clear(void);
00298
00305 virtual void getPlannerData(PlannerData &data) const;
00306
00308 const std::string& getName(void) const;
00309
00311 void setName(const std::string &name);
00312
00314 const PlannerSpecs& getSpecs(void) const;
00315
00320 virtual void setup(void);
00321
00326 virtual void checkValidity(void);
00327
00329 bool isSetup(void) const;
00330
00331 protected:
00332
00334 SpaceInformationPtr si_;
00335
00337 ProblemDefinitionPtr pdef_;
00338
00340 PlannerInputStates pis_;
00341
00343 std::string name_;
00344
00346 PlannerSpecs specs_;
00347
00349 bool setup_;
00350
00352 msg::Interface msg_;
00353 };
00354
00356 typedef boost::function1<PlannerPtr, const SpaceInformationPtr&> PlannerAllocator;
00357 }
00358 }
00359
00360 #endif