STRIDE.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, 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 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: Bryant Gipson, Mark Moll */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_STRIDE_STRIDE_
38 #define OMPL_GEOMETRIC_PLANNERS_STRIDE_STRIDE_
39 
40 #include "ompl/datastructures/Grid.h"
41 #include "ompl/geometric/planners/PlannerIncludes.h"
42 #include "ompl/base/ProjectionEvaluator.h"
43 #include "ompl/datastructures/PDF.h"
44 #include <unordered_map>
45 #include <boost/scoped_ptr.hpp>
46 #include <vector>
47 
48 namespace ompl
49 {
50  template <typename _T>
51  class NearestNeighborsGNAT;
52 
53  namespace geometric
54  {
78  class STRIDE : public base::Planner
79  {
80  public:
82  STRIDE(const base::SpaceInformationPtr &si, bool useProjectedDistance = false, unsigned int degree = 16,
83  unsigned int minDegree = 12, unsigned int maxDegree = 18, unsigned int maxNumPtsPerLeaf = 6,
84  double estimatedDimension = 0.0);
85  ~STRIDE() override;
86 
87  void setup() override;
88 
90 
91  void clear() override;
92 
100  void setGoalBias(double goalBias)
101  {
102  goalBias_ = goalBias;
103  }
104 
106  double getGoalBias() const
107  {
108  return goalBias_;
109  }
110 
114  void setUseProjectedDistance(bool useProjectedDistance)
115  {
116  useProjectedDistance_ = useProjectedDistance;
117  }
122  {
123  return useProjectedDistance_;
124  }
125 
127  void setDegree(unsigned int degree)
128  {
129  degree_ = degree;
130  }
132  unsigned int getDegree() const
133  {
134  return degree_;
135  }
137  void setMinDegree(unsigned int minDegree)
138  {
139  minDegree_ = minDegree;
140  }
142  unsigned int getMinDegree() const
143  {
144  return minDegree_;
145  }
147  void setMaxDegree(unsigned int maxDegree)
148  {
149  maxDegree_ = maxDegree;
150  }
152  unsigned int getMaxDegree() const
153  {
154  return maxDegree_;
155  }
158  void setMaxNumPtsPerLeaf(unsigned int maxNumPtsPerLeaf)
159  {
160  maxNumPtsPerLeaf_ = maxNumPtsPerLeaf;
161  }
164  unsigned int getMaxNumPtsPerLeaf() const
165  {
166  return maxNumPtsPerLeaf_;
167  }
171  void setEstimatedDimension(double estimatedDimension)
172  {
173  estimatedDimension_ = estimatedDimension;
174  }
178  double getEstimatedDimension() const
179  {
180  return estimatedDimension_;
181  }
182 
188  void setRange(double distance)
189  {
190  maxDistance_ = distance;
191  }
192 
194  double getRange() const
195  {
196  return maxDistance_;
197  }
204  void setMinValidPathFraction(double fraction)
205  {
206  minValidPathFraction_ = fraction;
207  }
208 
210  double getMinValidPathFraction() const
211  {
212  return minValidPathFraction_;
213  }
216  void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
217  {
218  projectionEvaluator_ = projectionEvaluator;
219  }
220 
223  void setProjectionEvaluator(const std::string &name)
224  {
225  projectionEvaluator_ = si_->getStateSpace()->getProjection(name);
226  }
227 
230  {
231  return projectionEvaluator_;
232  }
233 
234  void getPlannerData(base::PlannerData &data) const override;
235 
236  protected:
238  class Motion
239  {
240  public:
241  Motion() = default;
242 
244  Motion(const base::SpaceInformationPtr &si) : state(si->allocState())
245  {
246  }
247 
248  ~Motion() = default;
249 
251  base::State *state{nullptr};
252 
254  Motion *parent{nullptr};
255  };
256 
258  void freeMemory();
259 
261  void setupTree();
262 
264  double distanceFunction(const Motion *a, const Motion *b) const
265  {
266  return si_->distance(a->state, b->state);
267  }
268 
270  double projectedDistanceFunction(const Motion *a, const Motion *b) const
271  {
272  unsigned int num_dims = projectionEvaluator_->getDimension();
273  ompl::base::EuclideanProjection aproj(num_dims), bproj(num_dims);
274  projectionEvaluator_->project(a->state, aproj);
275  projectionEvaluator_->project(b->state, bproj);
276  return boost::numeric::ublas::norm_2(aproj - bproj);
277  }
278 
280  void addMotion(Motion *motion);
281 
283  Motion *selectMotion();
284 
287 
290 
292  boost::scoped_ptr<NearestNeighborsGNAT<Motion *>> tree_;
293 
296  double goalBias_{.05};
297 
299  double maxDistance_{0.};
300 
305  unsigned int degree_;
307  unsigned int minDegree_;
309  unsigned int maxDegree_;
311  unsigned int maxNumPtsPerLeaf_;
320 
323  };
324  }
325 }
326 
327 #endif
void setupTree()
Initialize GNAT data structure.
Definition: STRIDE.cpp:91
Search Tree with Resolution Independent Density Estimation.
Definition: STRIDE.h:78
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:174
double getEstimatedDimension() const
Get estimated dimension of the free space, which is needed to compute the sampling weight for a node ...
Definition: STRIDE.h:178
void setProjectionEvaluator(const std::string &name)
Set the projection evaluator (select one from the ones registered with the state space).
Definition: STRIDE.h:223
base::ProjectionEvaluatorPtr projectionEvaluator_
This algorithm can optionally use a projection to guide the exploration.
Definition: STRIDE.h:289
void freeMemory()
Free the memory allocated by this planner.
Definition: STRIDE.cpp:115
A shared pointer wrapper for ompl::base::ValidStateSampler.
Motion * parent
The parent motion in the exploration tree.
Definition: STRIDE.h:254
The definition of a motion.
Definition: STRIDE.h:238
double estimatedDimension_
Estimate of the local dimensionality of the free space around a state.
Definition: STRIDE.h:313
base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc) override
Function that can solve the motion planning problem. This function can be called multiple times on th...
Definition: STRIDE.cpp:131
void setMinDegree(unsigned int minDegree)
Set minimum degree of a node in the GNAT.
Definition: STRIDE.h:137
void setEstimatedDimension(double estimatedDimension)
Set estimated dimension of the free space, which is needed to compute the sampling weight for a node ...
Definition: STRIDE.h:171
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
unsigned int minDegree_
Minimum degree of an internal node in the GNAT.
Definition: STRIDE.h:307
void setup() override
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: STRIDE.cpp:82
bool useProjectedDistance_
Whether to use distance in the projection (instead of distance in the state space) for the GNAT...
Definition: STRIDE.h:303
unsigned int maxDegree_
Maximum degree of an internal node in the GNAT.
Definition: STRIDE.h:309
double projectedDistanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between projections of contained states) ...
Definition: STRIDE.h:270
base::ValidStateSamplerPtr sampler_
Valid state sampler.
Definition: STRIDE.h:286
double getMinValidPathFraction() const
Get the value of the fraction set by setMinValidPathFraction()
Definition: STRIDE.h:210
double getRange() const
Get the range the planner is using.
Definition: STRIDE.h:194
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
double minValidPathFraction_
When extending a motion, the planner can decide to keep the first valid part of it, even if invalid states are found, as long as the valid part represents a sufficiently large fraction from the original motion. This is used only when extendWhileValid_ is true.
Definition: STRIDE.h:319
unsigned int getMaxDegree() const
Set maximum degree of a node in the GNAT.
Definition: STRIDE.h:152
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates memory for the state.
Definition: STRIDE.h:244
void setDegree(unsigned int degree)
Set desired degree of a node in the GNAT.
Definition: STRIDE.h:127
void setMaxNumPtsPerLeaf(unsigned int maxNumPtsPerLeaf)
Set maximum number of elements stored in a leaf node of the GNAT.
Definition: STRIDE.h:158
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
Definition: STRIDE.h:264
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition: STRIDE.h:299
Base class for a planner.
Definition: Planner.h:223
bool getUseProjectedDistance() const
Return whether nearest neighbors are computed based on distances in a projection of the state rather ...
Definition: STRIDE.h:121
const base::ProjectionEvaluatorPtr & getProjectionEvaluator() const
Get the projection evaluator.
Definition: STRIDE.h:229
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
void clear() override
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition: STRIDE.cpp:107
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
A shared pointer wrapper for ompl::base::SpaceInformation.
boost::numeric::ublas::vector< double > EuclideanProjection
The datatype for state projections. This class contains a real vector.
Definition of an abstract state.
Definition: State.h:49
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: STRIDE.h:188
unsigned int degree_
Desired degree of an internal node in the GNAT.
Definition: STRIDE.h:305
STRIDE(const base::SpaceInformationPtr &si, bool useProjectedDistance=false, unsigned int degree=16, unsigned int minDegree=12, unsigned int maxDegree=18, unsigned int maxNumPtsPerLeaf=6, double estimatedDimension=0.0)
Constructor.
Definition: STRIDE.cpp:46
Motion * selectMotion()
Select a motion to continue the expansion of the tree from.
Definition: STRIDE.cpp:237
unsigned int getDegree() const
Get desired degree of a node in the GNAT.
Definition: STRIDE.h:132
double getGoalBias() const
Get the goal bias the planner is using.
Definition: STRIDE.h:106
double goalBias_
The fraction of time the goal is picked as the state to expand towards (if such a state is available)...
Definition: STRIDE.h:296
void getPlannerData(base::PlannerData &data) const override
Get information about the current run of the motion planner. Repeated calls to this function will upd...
Definition: STRIDE.cpp:242
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:406
void setMinValidPathFraction(double fraction)
When extending a motion, the planner can decide to keep the first valid part of it, even if invalid states are found, as long as the valid part represents a sufficiently large fraction from the original motion. This function sets the minimum acceptable fraction (between 0 and 1).
Definition: STRIDE.h:204
base::State * state
The state contained by the motion.
Definition: STRIDE.h:251
unsigned int getMinDegree() const
Get minimum degree of a node in the GNAT.
Definition: STRIDE.h:142
unsigned int maxNumPtsPerLeaf_
Maximum number of points stored in a leaf node in the GNAT.
Definition: STRIDE.h:311
unsigned int getMaxNumPtsPerLeaf() const
Get maximum number of elements stored in a leaf node of the GNAT.
Definition: STRIDE.h:164
void setUseProjectedDistance(bool useProjectedDistance)
Set whether nearest neighbors are computed based on distances in a projection of the state rather dis...
Definition: STRIDE.h:114
void setMaxDegree(unsigned int maxDegree)
Set maximum degree of a node in the GNAT.
Definition: STRIDE.h:147
void setGoalBias(double goalBias)
In the process of randomly selecting states in the state space to attempt to go towards, the algorithm may in fact choose the actual goal state, if it knows it, with some probability. This probability is a real number between 0.0 and 1.0; its value should usually be around 0.05 and should not be too large. It is probably a good idea to use the default value.
Definition: STRIDE.h:100
void addMotion(Motion *motion)
Add a motion to the exploration tree.
Definition: STRIDE.cpp:232
void setProjectionEvaluator(const base::ProjectionEvaluatorPtr &projectionEvaluator)
Set the projection evaluator. This class is able to compute the projection of a given state...
Definition: STRIDE.h:216
boost::scoped_ptr< NearestNeighborsGNAT< Motion * > > tree_
The exploration tree constructed by this algorithm.
Definition: STRIDE.h:292
RNG rng_
The random number generator.
Definition: STRIDE.h:322