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
00117 bool update(void);
00118
00127 bool use(const SpaceInformationPtr &si, const ProblemDefinitionPtr &pdef);
00128
00137 bool use(const SpaceInformation *si, const ProblemDefinition *pdef);
00138
00141 void checkValidity(void) const;
00142
00145 const State* nextStart(void);
00146
00155 const State* nextGoal(const PlannerTerminationCondition &ptc);
00156
00158 const State* nextGoal(void);
00159
00161 bool haveMoreStartStates(void) const;
00162
00164 bool haveMoreGoalStates(void) const;
00165
00169 unsigned int getSeenStartStatesCount(void) const
00170 {
00171 return addedStartStates_;
00172 }
00173
00175 unsigned int getSampledGoalsCount(void) const
00176 {
00177 return sampledGoalsCount_;
00178 }
00179
00180 private:
00181
00182 const Planner *planner_;
00183
00184 unsigned int addedStartStates_;
00185 unsigned int sampledGoalsCount_;
00186 State *tempState_;
00187
00188 const ProblemDefinition *pdef_;
00189 const SpaceInformation *si_;
00190 };
00191
00193 struct PlannerSpecs
00194 {
00195 PlannerSpecs(void) : recognizedGoal(GOAL_ANY), multithreaded(false), approximateSolutions(false),
00196 optimizingPaths(false), estimatingProbabilities(false)
00197 {
00198 }
00199
00201 GoalType recognizedGoal;
00202
00204 bool multithreaded;
00205
00207 bool approximateSolutions;
00208
00211 bool optimizingPaths;
00212
00214 bool estimatingProbabilities;
00215 };
00216
00218 class Planner : private boost::noncopyable
00219 {
00220
00221 public:
00222
00224 Planner(const SpaceInformationPtr &si, const std::string &name);
00225
00227 virtual ~Planner(void)
00228 {
00229 }
00230
00232 template<class T>
00233 T* as(void)
00234 {
00236 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
00237
00238 return static_cast<T*>(this);
00239 }
00240
00242 template<class T>
00243 const T* as(void) const
00244 {
00246 BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
00247
00248 return static_cast<const T*>(this);
00249 }
00250
00252 const SpaceInformationPtr& getSpaceInformation(void) const;
00253
00255 const ProblemDefinitionPtr& getProblemDefinition(void) const;
00256
00258 const PlannerInputStates& getPlannerInputStates(void) const;
00259
00264 virtual void setProblemDefinition(const ProblemDefinitionPtr &pdef);
00265
00278 virtual bool solve(const PlannerTerminationCondition &ptc) = 0;
00279
00282 bool solve(const PlannerTerminationConditionFn &ptc, double checkInterval);
00283
00287 bool solve(double solveTime);
00288
00292 virtual void clear(void);
00293
00300 virtual void getPlannerData(PlannerData &data) const;
00301
00303 const std::string& getName(void) const;
00304
00306 void setName(const std::string &name);
00307
00309 const PlannerSpecs& getSpecs(void) const;
00310
00315 virtual void setup(void);
00316
00321 virtual void checkValidity(void);
00322
00324 bool isSetup(void) const;
00325
00326 protected:
00327
00329 SpaceInformationPtr si_;
00330
00332 ProblemDefinitionPtr pdef_;
00333
00335 PlannerInputStates pis_;
00336
00338 std::string name_;
00339
00341 PlannerSpecs specs_;
00342
00344 bool setup_;
00345
00347 msg::Interface msg_;
00348 };
00349
00351 typedef boost::function1<PlannerPtr, const SpaceInformationPtr&> PlannerAllocator;
00352 }
00353 }
00354
00355 #endif