All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Planner.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Rice University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #ifndef OMPL_BASE_PLANNER_
38 #define OMPL_BASE_PLANNER_
39 
40 #include "ompl/base/SpaceInformation.h"
41 #include "ompl/base/ProblemDefinition.h"
42 #include "ompl/base/PlannerData.h"
43 #include "ompl/base/PlannerStatus.h"
44 #include "ompl/base/PlannerTerminationCondition.h"
45 #include "ompl/base/GenericParam.h"
46 #include "ompl/util/Console.h"
47 #include "ompl/util/Time.h"
48 #include "ompl/util/ClassForward.h"
49 #include "ompl/util/Deprecation.h"
50 #include <boost/function.hpp>
51 #include <boost/concept_check.hpp>
52 #include <boost/noncopyable.hpp>
53 #include <boost/lexical_cast.hpp>
54 #include <string>
55 #include <map>
56 
57 namespace ompl
58 {
59 
60  namespace base
61  {
62 
64 
65  OMPL_CLASS_FORWARD(Planner);
67 
84  {
85  public:
86 
88  PlannerInputStates(const PlannerPtr &planner) : planner_(planner.get())
89  {
90  tempState_ = NULL;
91  update();
92  }
93 
95  PlannerInputStates(const Planner *planner) : planner_(planner)
96  {
97  tempState_ = NULL;
98  update();
99  }
100 
104  PlannerInputStates(void) : planner_(NULL)
105  {
106  tempState_ = NULL;
107  clear();
108  }
109 
112  {
113  clear();
114  }
115 
117  void clear(void);
118 
122  void restart(void);
123 
129  bool update(void);
130 
139  OMPL_DEPRECATED bool use(const SpaceInformationPtr &si, const ProblemDefinitionPtr &pdef);
140 
149  OMPL_DEPRECATED bool use(const SpaceInformation *si, const ProblemDefinition *pdef);
150 
156  bool use(const ProblemDefinitionPtr &pdef);
157 
163  bool use(const ProblemDefinition *pdef);
164 
167  void checkValidity(void) const;
168 
171  const State* nextStart(void);
172 
181  const State* nextGoal(const PlannerTerminationCondition &ptc);
182 
184  const State* nextGoal(void);
185 
187  bool haveMoreStartStates(void) const;
188 
190  bool haveMoreGoalStates(void) const;
191 
195  unsigned int getSeenStartStatesCount(void) const
196  {
197  return addedStartStates_;
198  }
199 
201  unsigned int getSampledGoalsCount(void) const
202  {
203  return sampledGoalsCount_;
204  }
205 
206  private:
207 
208  const Planner *planner_;
209 
210  unsigned int addedStartStates_;
211  unsigned int sampledGoalsCount_;
212  State *tempState_;
213 
214  const ProblemDefinition *pdef_;
215  const SpaceInformation *si_;
216  };
217 
220  {
222  {
223  }
224 
227 
230 
233 
237 
240  bool directed;
241 
244  };
245 
247  class Planner : private boost::noncopyable
248  {
249 
250  public:
251 
253  Planner(const SpaceInformationPtr &si, const std::string &name);
254 
256  virtual ~Planner(void)
257  {
258  }
259 
261  template<class T>
262  T* as(void)
263  {
265  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
266 
267  return static_cast<T*>(this);
268  }
269 
271  template<class T>
272  const T* as(void) const
273  {
275  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
276 
277  return static_cast<const T*>(this);
278  }
279 
281  const SpaceInformationPtr& getSpaceInformation(void) const;
282 
284  const ProblemDefinitionPtr& getProblemDefinition(void) const;
285 
287  const PlannerInputStates& getPlannerInputStates(void) const;
288 
293  virtual void setProblemDefinition(const ProblemDefinitionPtr &pdef);
294 
307  virtual PlannerStatus solve(const PlannerTerminationCondition &ptc) = 0;
308 
311  PlannerStatus solve(const PlannerTerminationConditionFn &ptc, double checkInterval);
312 
316  PlannerStatus solve(double solveTime);
317 
321  virtual void clear(void);
322 
329  virtual void getPlannerData(PlannerData &data) const;
330 
332  const std::string& getName(void) const;
333 
335  void setName(const std::string &name);
336 
338  const PlannerSpecs& getSpecs(void) const;
339 
344  virtual void setup(void);
345 
350  virtual void checkValidity(void);
351 
353  bool isSetup(void) const;
354 
357  {
358  return params_;
359  }
360 
362  const ParamSet& params(void) const
363  {
364  return params_;
365  }
366 
368  virtual void printProperties(std::ostream &out) const;
369 
371  virtual void printSettings(std::ostream &out) const;
372 
373  protected:
374 
376  template<typename T, typename PlannerType, typename SetterType, typename GetterType>
377  void declareParam(const std::string &name, const PlannerType &planner, const SetterType& setter, const GetterType& getter, const std::string &rangeSuggestion = "")
378  {
379  params_.declareParam<T>(name, boost::bind(setter, planner, _1), boost::bind(getter, planner));
380  if (!rangeSuggestion.empty())
381  params_[name].setRangeSuggestion(rangeSuggestion);
382  }
383 
385  template<typename T, typename PlannerType, typename SetterType>
386  void declareParam(const std::string &name, const PlannerType &planner, const SetterType& setter, const std::string &rangeSuggestion = "")
387  {
388  params_.declareParam<T>(name, boost::bind(setter, planner, _1));
389  if (!rangeSuggestion.empty())
390  params_[name].setRangeSuggestion(rangeSuggestion);
391  }
392 
395 
398 
401 
403  std::string name_;
404 
407 
410 
412  bool setup_;
413  };
414 
416  typedef boost::function<PlannerPtr(const SpaceInformationPtr&)> PlannerAllocator;
417  }
418 }
419 
420 #endif