BiTRRT.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, 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: Ryan Luna */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_RRT_BITRRT_
38 #define OMPL_GEOMETRIC_PLANNERS_RRT_BITRRT_
39 
40 #include <cmath>
41 #include "ompl/geometric/planners/PlannerIncludes.h"
42 #include "ompl/datastructures/NearestNeighbors.h"
43 #include "ompl/base/OptimizationObjective.h"
44 
45 namespace ompl
46 {
47  namespace geometric
48  {
49 
64 
66  class BiTRRT : public base::Planner
67  {
68  public:
71  virtual ~BiTRRT();
72  virtual void clear();
73  virtual void setup();
74  virtual void getPlannerData(base::PlannerData &data) const;
76 
80  void setRange(double distance)
81  {
82  maxDistance_ = distance;
83  }
84 
86  double getRange() const
87  {
88  return maxDistance_;
89  }
90 
96  void setTempChangeFactor(double factor)
97  {
98  tempChangeFactor_ = exp(factor);
99  }
100 
103  double getTempChangeFactor() const
104  {
105  return log(tempChangeFactor_);
106  }
107 
111  void setCostThreshold(double maxCost)
112  {
113  costThreshold_ = base::Cost(maxCost);
114  }
115 
119  double getCostThreshold() const
120  {
121  return costThreshold_.value();
122  }
123 
126  void setInitTemperature(double initTemperature)
127  {
128  initTemperature_ = initTemperature;
129  }
130 
132  double getInitTemperature() const
133  {
134  return initTemperature_;
135  }
136 
139  void setFrontierThreshold(double frontierThreshold)
140  {
141  frontierThreshold_ = frontierThreshold;
142  }
143 
146  double getFrontierThreshold() const
147  {
148  return frontierThreshold_;
149  }
150 
154  void setFrontierNodeRatio(double frontierNodeRatio)
155  {
156  frontierNodeRatio_ = frontierNodeRatio;
157  }
158 
161  double getFrontierNodeRatio() const
162  {
163  return frontierNodeRatio_;
164  }
165 
167  template<template<typename T> class NN>
169  {
170  tStart_.reset(new NN<Motion*>());
171  tGoal_.reset(new NN<Motion*>());
172  }
173 
174  protected:
175 
177  class Motion
178  {
179  public:
180 
182  Motion() : state(nullptr), parent(nullptr), root(nullptr) {}
183 
185  Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(nullptr), root(nullptr) {}
186 
187  ~Motion() {}
188 
189 
192 
195 
198 
202 
203  };
204 
206  void freeMemory();
207 
210  typedef std::shared_ptr< NearestNeighbors<Motion*> > TreeData;
211 
214  Motion* addMotion(const base::State* state, TreeData& tree, Motion* parent = nullptr);
215 
220  bool transitionTest(const base::Cost& motionCost);
221 
224  bool minExpansionControl(double dist);
225 
228  {
235  };
236 
239  GrowResult extendTree(Motion* rmotion, TreeData& tree, Motion*& xmotion);
240 
243  GrowResult extendTree(Motion* nearest, TreeData& tree, Motion* toMotion, Motion*& result);
244 
247  bool connectTrees(Motion* nmotion, TreeData& tree, Motion* xmotion);
248 
250  double distanceFunction(const Motion *a, const Motion *b) const
251  {
252  return si_->distance(a->state, b->state);
253  }
254 
256  double maxDistance_;
257 
261 
264 
267 
270 
273 
277 
280 
282  double temp_;
283 
286 
289 
293 
296  std::pair<Motion*, Motion*> connectionPoint_;
297 
300 
303 
306  };
307  }
308 }
309 
310 #endif
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
Motion * addMotion(const base::State *state, TreeData &tree, Motion *parent=nullptr)
Add a state to the given tree. The motion created is returned.
Definition: BiTRRT.cpp:163
double frontierThreshold_
The distance between an existing state and a new state that qualifies it as a frontier state...
Definition: BiTRRT.h:276
void log(const char *file, int line, LogLevel level, const char *m,...)
Root level logging function. This should not be invoked directly, but rather used via a logging macro...
Definition: Console.cpp:120
base::State * state
The state contained by the motion.
Definition: BiTRRT.h:191
std::pair< Motion *, Motion * > connectionPoint_
The most recent connection point for the two trees. Used for PlannerData computation.
Definition: BiTRRT.h:296
virtual void getPlannerData(base::PlannerData &data) const
Get information about the current run of the motion planner. Repeated calls to this function will upd...
Definition: BiTRRT.cpp:457
bool minExpansionControl(double dist)
Use frontier node ratio to filter nodes that do not add new information to the search tree...
Definition: BiTRRT.cpp:208
double getFrontierNodeRatio() const
Get the ratio between adding non-frontier nodes to frontier nodes.
Definition: BiTRRT.h:161
bool transitionTest(const base::Cost &motionCost)
Transition test that filters transitions based on the motion cost. If the motion cost is near or belo...
Definition: BiTRRT.cpp:181
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: BiTRRT.cpp:119
base::Cost bestCost_
The most desirable (e.g., minimum) cost value in the search tree.
Definition: BiTRRT.h:263
GrowResult extendTree(Motion *rmotion, TreeData &tree, Motion *&xmotion)
Extend tree toward the state in rmotion. Store the result of the extension, if any, in result.
Definition: BiTRRT.cpp:259
virtual void clear()
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: BiTRRT.cpp:101
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
double getRange() const
Get the range the planner is using.
Definition: BiTRRT.h:86
double getTempChangeFactor() const
Get the factor by which the temperature is increased after a failed transition.
Definition: BiTRRT.h:103
Motion * parent
The parent motion in the exploration tree.
Definition: BiTRRT.h:194
double nonfrontierCount_
A count of the number of non-frontier nodes in the trees.
Definition: BiTRRT.h:285
TreeData tStart_
The start tree.
Definition: BiTRRT.h:299
BiTRRT(const base::SpaceInformationPtr &si)
Constructor.
Definition: BiTRRT.cpp:45
double getFrontierThreshold() const
Get the distance between a new state and the nearest neighbor that qualifies a state as being a front...
Definition: BiTRRT.h:146
double initTemperature_
The temperature that planning begins at.
Definition: BiTRRT.h:272
double connectionRange_
The range at which the algorithm will attempt to connect the two trees.
Definition: BiTRRT.h:292
void setFrontierNodeRatio(double frontierNodeRatio)
Set the ratio between adding non-frontier nodes to frontier nodes. For example: .1 is one non-frontie...
Definition: BiTRRT.h:154
base::Cost worstCost_
The least desirable (e.g., maximum) cost value in the search tree.
Definition: BiTRRT.h:266
virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc)
Function that can solve the motion planning problem. This function can be called multiple times on th...
Definition: BiTRRT.cpp:326
double tempChangeFactor_
The factor by which the temperature is increased after a failed transition test.
Definition: BiTRRT.h:260
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition: BiTRRT.h:256
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates memory for the state.
Definition: BiTRRT.h:185
void setNearestNeighbors()
Set a different nearest neighbors datastructure.
Definition: BiTRRT.h:168
void freeMemory()
Free all memory allocated during planning.
Definition: BiTRRT.cpp:74
Base class for a planner.
Definition: Planner.h:230
GrowResult
The result of a call to extendTree.
Definition: BiTRRT.h:227
Motion()
Default constructor.
Definition: BiTRRT.h:182
double value() const
The value of the cost.
Definition: Cost.h:54
const base::State * root
Pointer to the root of the tree this motion is contained in.
Definition: BiTRRT.h:201
void setTempChangeFactor(double factor)
Set the factor by which the temperature is increased after a failed transition test. This value should be in the range (0, 1], typically close to zero (default is 0.1). This value is an exponential (e^factor) that is multiplied with the current temperature.
Definition: BiTRRT.h:96
*double getCostThreshold() const
Get the cost threshold (default is infinity). Any motion cost that is not better than this cost (acco...
Definition: BiTRRT.h:119
TreeData tGoal_
The goal tree.
Definition: BiTRRT.h:302
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
void setInitTemperature(double initTemperature)
Set the initial temperature at the start of planning. Should be high to allow for initial exploration...
Definition: BiTRRT.h:126
Progress was made toward extension.
Definition: BiTRRT.h:232
A shared pointer wrapper for ompl::base::SpaceInformation.
double frontierCount_
A count of the number of frontier nodes in the trees.
Definition: BiTRRT.h:288
Definition of an abstract state.
Definition: State.h:50
ompl::base::OptimizationObjectivePtr opt_
The objective (cost function) being optimized.
Definition: BiTRRT.h:305
void setFrontierThreshold(double frontierThreshold)
Set the distance between a new state and the nearest neighbor that qualifies a state as being a front...
Definition: BiTRRT.h:139
No extension was possible.
Definition: BiTRRT.h:230
Representation of a motion in the search tree.
Definition: BiTRRT.h:177
A shared pointer wrapper for ompl::base::OptimizationObjective.
double frontierNodeRatio_
The target ratio of non-frontier nodes to frontier nodes.
Definition: BiTRRT.h:279
void setRange(double distance)
Set the maximum possible length of any one motion in the search tree. Very short/long motions may inh...
Definition: BiTRRT.h:80
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
Definition: BiTRRT.h:250
base::Cost costThreshold_
All motion costs must be better than this cost (default is infinity)
Definition: BiTRRT.h:269
double getInitTemperature() const
Get the initial temperature at the start of planning.
Definition: BiTRRT.h:132
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:398
void setCostThreshold(double maxCost)
Set the cost threshold (default is infinity). Any motion cost that is not better than this cost (acco...
Definition: BiTRRT.h:111
base::Cost cost
Cost of the state.
Definition: BiTRRT.h:197
bool connectTrees(Motion *nmotion, TreeData &tree, Motion *xmotion)
Attempt to connect tree to nmotion, which is in the other tree. xmotion is scratch space and will be ...
Definition: BiTRRT.cpp:266
Bi-directional Transition-based Rapidly-exploring Random Trees.
Definition: BiTRRT.h:66
The desired state was reached during extension.
Definition: BiTRRT.h:234
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
std::shared_ptr< NearestNeighbors< Motion * > > TreeData
The nearest-neighbors data structure that contains the entire the tree of motions generated during pl...
Definition: BiTRRT.h:210
double temp_
The current temperature.
Definition: BiTRRT.h:282