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 <boost/function.hpp>
50 #include <boost/concept_check.hpp>
51 #include <boost/noncopyable.hpp>
52 #include <boost/lexical_cast.hpp>
53 #include <string>
54 #include <map>
55 
56 namespace ompl
57 {
58 
59  namespace base
60  {
61 
63 
64  ClassForward(Planner);
66 
83  {
84  public:
85 
87  PlannerInputStates(const PlannerPtr &planner) : planner_(planner.get())
88  {
89  tempState_ = NULL;
90  update();
91  }
92 
94  PlannerInputStates(const Planner *planner) : planner_(planner)
95  {
96  tempState_ = NULL;
97  update();
98  }
99 
103  PlannerInputStates(void) : planner_(NULL)
104  {
105  tempState_ = NULL;
106  clear();
107  }
108 
111  {
112  clear();
113  }
114 
116  void clear(void);
117 
121  void restart(void);
122 
128  bool update(void);
129 
138  bool use(const SpaceInformationPtr &si, const ProblemDefinitionPtr &pdef);
139 
148  bool use(const SpaceInformation *si, const ProblemDefinition *pdef);
149 
152  void checkValidity(void) const;
153 
156  const State* nextStart(void);
157 
166  const State* nextGoal(const PlannerTerminationCondition &ptc);
167 
169  const State* nextGoal(void);
170 
172  bool haveMoreStartStates(void) const;
173 
175  bool haveMoreGoalStates(void) const;
176 
180  unsigned int getSeenStartStatesCount(void) const
181  {
182  return addedStartStates_;
183  }
184 
186  unsigned int getSampledGoalsCount(void) const
187  {
188  return sampledGoalsCount_;
189  }
190 
191  private:
192 
193  const Planner *planner_;
194 
195  unsigned int addedStartStates_;
196  unsigned int sampledGoalsCount_;
197  State *tempState_;
198 
199  const ProblemDefinition *pdef_;
200  const SpaceInformation *si_;
201  };
202 
205  {
207  {
208  }
209 
212 
215 
218 
222 
225  bool directed;
226 
229  };
230 
232  class Planner : private boost::noncopyable
233  {
234 
235  public:
236 
238  Planner(const SpaceInformationPtr &si, const std::string &name);
239 
241  virtual ~Planner(void)
242  {
243  }
244 
246  template<class T>
247  T* as(void)
248  {
250  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
251 
252  return static_cast<T*>(this);
253  }
254 
256  template<class T>
257  const T* as(void) const
258  {
260  BOOST_CONCEPT_ASSERT((boost::Convertible<T*, Planner*>));
261 
262  return static_cast<const T*>(this);
263  }
264 
266  const SpaceInformationPtr& getSpaceInformation(void) const;
267 
269  const ProblemDefinitionPtr& getProblemDefinition(void) const;
270 
272  const PlannerInputStates& getPlannerInputStates(void) const;
273 
278  virtual void setProblemDefinition(const ProblemDefinitionPtr &pdef);
279 
292  virtual PlannerStatus solve(const PlannerTerminationCondition &ptc) = 0;
293 
296  PlannerStatus solve(const PlannerTerminationConditionFn &ptc, double checkInterval);
297 
301  PlannerStatus solve(double solveTime);
302 
306  virtual void clear(void);
307 
314  virtual void getPlannerData(PlannerData &data) const;
315 
317  const std::string& getName(void) const;
318 
320  void setName(const std::string &name);
321 
323  const PlannerSpecs& getSpecs(void) const;
324 
329  virtual void setup(void);
330 
335  virtual void checkValidity(void);
336 
338  bool isSetup(void) const;
339 
342  {
343  return params_;
344  }
345 
347  const ParamSet& params(void) const
348  {
349  return params_;
350  }
351 
353  virtual void printProperties(std::ostream &out) const;
354 
356  virtual void printSettings(std::ostream &out) const;
357 
358  protected:
359 
361  template<typename T, typename PlannerType, typename SetterType, typename GetterType>
362  void declareParam(const std::string &name, const PlannerType &planner, const SetterType& setter, const GetterType& getter)
363  {
364  params_.declareParam<T>(name, boost::bind(setter, planner, _1), boost::bind(getter, planner));
365  }
366 
368  template<typename T, typename PlannerType, typename SetterType>
369  void declareParam(const std::string &name, const PlannerType &planner, const SetterType& setter)
370  {
371  params_.declareParam<T>(name, boost::bind(setter, planner, _1));
372  }
373 
376 
379 
382 
384  std::string name_;
385 
388 
391 
393  bool setup_;
394  };
395 
397  typedef boost::function<PlannerPtr(const SpaceInformationPtr&)> PlannerAllocator;
398  }
399 }
400 
401 #endif