SST.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, Rutgers the State University of New Jersey, New Brunswick
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 Rutgers 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 /* Authors: Zakary Littlefield */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_SST_SST_
38 #define OMPL_GEOMETRIC_PLANNERS_SST_SST_
39 
40 #include "ompl/geometric/planners/PlannerIncludes.h"
41 #include "ompl/datastructures/NearestNeighbors.h"
42 
43 namespace ompl
44 {
45  namespace geometric
46  {
59  class SST : public base::Planner
60  {
61  public:
62 
64  SST(const base::SpaceInformationPtr &si);
65 
66  virtual ~SST();
67 
68  virtual void setup();
69 
72 
73  virtual void getPlannerData(base::PlannerData &data) const;
74 
78  virtual void clear();
79 
87  void setGoalBias(double goalBias)
88  {
89  goalBias_ = goalBias;
90  }
91 
93  double getGoalBias() const
94  {
95  return goalBias_;
96  }
97 
98 
104  void setRange(double distance)
105  {
106  maxDistance_ = distance;
107  }
108 
110  double getRange() const
111  {
112  return maxDistance_;
113  }
114 
123  void setSelectionRadius(double selectionRadius)
124  {
125  selectionRadius_ = selectionRadius;
126  }
127 
129  double getSelectionRadius() const
130  {
131  return selectionRadius_;
132  }
133 
134 
145  void setPruningRadius(double pruningRadius)
146  {
147  pruningRadius_ = pruningRadius;
148  }
149 
151  double getPruningRadius() const
152  {
153  return pruningRadius_;
154  }
155 
157  template<template<typename T> class NN>
159  {
160  nn_.reset(new NN<Motion*>());
161  witnesses_.reset(new NN<Motion*>());
162  }
163 
164 
165  protected:
166 
167 
172  class Motion
173  {
174  public:
175 
176  Motion() : accCost_(0), state_(nullptr), parent_(nullptr), numChildren_(0), inactive_(false)
177  {
178  }
179 
181  Motion(const base::SpaceInformationPtr& si) : accCost_(0), state_(si->allocState()), parent_(nullptr), numChildren_(0), inactive_(false)
182  {
183  }
184 
185  virtual ~Motion()
186  {
187  }
188 
189  virtual base::State* getState() const
190  {
191  return state_;
192  }
193  virtual Motion* getParent() const
194  {
195  return parent_;
196  }
197  base::Cost accCost_;
198 
201 
204 
206  unsigned numChildren_;
207 
209  bool inactive_;
210 
211 
212  };
213 
214  class Witness : public Motion
215  {
216  public:
217 
218  Witness() : Motion(), rep_(nullptr)
219  {
220  }
221 
222  Witness(const base::SpaceInformationPtr& si) : Motion(si), rep_(nullptr)
223  {
224  }
225  virtual base::State* getState() const
226  {
227  return rep_->state_;
228  }
229  virtual Motion* getParent() const
230  {
231  return rep_->parent_;
232  }
233 
234  void linkRep(Motion *lRep)
235  {
236  rep_ = lRep;
237  }
238 
241  };
242 
243 
245  Motion* selectNode(Motion *sample);
246 
249 
252 
254  void freeMemory();
255 
257  double distanceFunction(const Motion *a, const Motion *b) const
258  {
259  return si_->distance(a->state_, b->state_);
260  }
261 
264 
266  std::shared_ptr< NearestNeighbors<Motion*> > nn_;
267 
269  std::shared_ptr< NearestNeighbors<Motion*> > witnesses_;
270 
272  double goalBias_;
273 
275  double maxDistance_;
276 
279 
282 
285 
287  std::vector<base::State*> prevSolution_;
288 
291 
294 
295  };
296  }
297 }
298 
299 #endif
Motion * rep_
The node in the tree that is within the pruning radius.
Definition: SST.h:240
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
void freeMemory()
Free the memory allocated by this planner.
Definition: SST.cpp:109
Motion * parent_
The parent motion in the exploration tree.
Definition: SST.h:203
SST(const base::SpaceInformationPtr &si)
Constructor.
Definition: SST.cpp:45
double getGoalBias() const
Get the goal bias the planner is using.
Definition: SST.h:93
void setSelectionRadius(double selectionRadius)
Set the radius for selecting nodes relative to random sample.
Definition: SST.h:123
base::Cost prevSolutionCost_
The best solution cost we found so far.
Definition: SST.h:290
bool inactive_
If inactive, this node is not considered for selection.
Definition: SST.h:209
Motion * selectNode(Motion *sample)
Finds the best node in the tree withing the selection radius around a random sample.
Definition: SST.cpp:142
std::shared_ptr< NearestNeighbors< Motion * > > witnesses_
A nearest-neighbors datastructure containing the tree of witness motions.
Definition: SST.h:269
A shared pointer wrapper for ompl::base::StateSampler.
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
unsigned numChildren_
Number of children.
Definition: SST.h:206
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates memory for the state and the control.
Definition: SST.h:181
double goalBias_
The fraction of time the goal is picked as the state to expand towards (if such a state is available)...
Definition: SST.h:272
void setGoalBias(double goalBias)
Definition: SST.h:87
base::StateSamplerPtr sampler_
State sampler.
Definition: SST.h:263
double getPruningRadius() const
Get the pruning radius the planner is using.
Definition: SST.h:151
void setPruningRadius(double pruningRadius)
Set the radius for pruning nodes.
Definition: SST.h:145
double getSelectionRadius() const
Get the selection radius the planner is using.
Definition: SST.h:129
void setNearestNeighbors()
Set a different nearest neighbors datastructure.
Definition: SST.h:158
std::vector< base::State * > prevSolution_
The best solution we found so far.
Definition: SST.h:287
double getRange() const
Get the range the planner is using.
Definition: SST.h:110
Representation of a motion.
Definition: SST.h:172
base::State * monteCarloProp(Motion *m)
Randomly propagate a new edge.
Definition: SST.cpp:196
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
virtual void clear()
Clear datastructures. Call this function if the input data to the planner has changed and you do not ...
Definition: SST.cpp:97
Base class for a planner.
Definition: Planner.h:230
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: SST.cpp:396
double pruningRadius_
The radius for determining the size of the pruning region.
Definition: SST.h:281
virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc)
Continue solving for some amount of time. Return true if solution was found.
Definition: SST.cpp:212
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
base::OptimizationObjectivePtr opt_
The optimization objective.
Definition: SST.h:293
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: SST.cpp:67
void setRange(double distance)
Set the range the planner is supposed to use.
Definition: SST.h:104
RNG rng_
The random number generator.
Definition: SST.h:284
A shared pointer wrapper for ompl::base::OptimizationObjective.
double selectionRadius_
The radius for determining the node selected for extension.
Definition: SST.h:278
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:398
base::State * state_
The state contained by the motion.
Definition: SST.h:200
Witness * findClosestWitness(Motion *node)
Find the closest witness node to a newly generated potential node.
Definition: SST.cpp:171
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition: SST.h:275
std::shared_ptr< NearestNeighbors< Motion * > > nn_
A nearest-neighbors datastructure containing the tree of motions.
Definition: SST.h:266
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
Definition: SST.h:257