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_CONTROL_PLANNERS_SST_SST_
38 #define OMPL_CONTROL_PLANNERS_SST_SST_
39 
40 #include "ompl/control/planners/PlannerIncludes.h"
41 #include "ompl/datastructures/NearestNeighbors.h"
42 
43 namespace ompl
44 {
45  namespace control
46  {
59  class SST : public base::Planner
60  {
61  public:
62 
64  SST(const 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 
106  void setSelectionRadius(double selectionRadius)
107  {
108  selectionRadius_ = selectionRadius;
109  }
110 
112  double getSelectionRadius() const
113  {
114  return selectionRadius_;
115  }
116 
117 
128  void setPruningRadius(double pruningRadius)
129  {
130  pruningRadius_ = pruningRadius;
131  }
132 
134  double getPruningRadius() const
135  {
136  return pruningRadius_;
137  }
138 
140  template<template<typename T> class NN>
142  {
143  nn_.reset(new NN<Motion*>());
144  witnesses_.reset(new NN<Motion*>());
145  }
146 
147  protected:
148 
149 
154  class Motion
155  {
156  public:
157 
158  Motion() : accCost_(0), state_(nullptr), control_(nullptr), steps_(0), parent_(nullptr), numChildren_(0), inactive_(false)
159  {
160  }
161 
163  Motion(const SpaceInformation *si) : accCost_(0), state_(si->allocState()), control_(si->allocControl()), steps_(0), parent_(nullptr), numChildren_(0), inactive_(false)
164  {
165  }
166 
167  virtual ~Motion()
168  {
169  }
170 
171  virtual base::State* getState() const
172  {
173  return state_;
174  }
175  virtual Motion* getParent() const
176  {
177  return parent_;
178  }
179 
180  base::Cost accCost_;
181 
184 
187 
189  unsigned int steps_;
190 
193 
195  unsigned numChildren_;
196 
198  bool inactive_;
199 
200 
201  };
202 
203  class Witness : public Motion
204  {
205  public:
206 
207  Witness() : Motion(), rep_(nullptr)
208  {
209  }
210 
211  Witness(const SpaceInformation *si) : Motion(si), rep_(nullptr)
212  {
213  }
214  virtual base::State* getState() const
215  {
216  return rep_->state_;
217  }
218  virtual Motion* getParent() const
219  {
220  return rep_->parent_;
221  }
222 
223  void linkRep(Motion *lRep)
224  {
225  rep_ = lRep;
226  }
227 
230  };
231 
233  Motion* selectNode(Motion *sample);
234 
237 
239  void freeMemory();
240 
242  double distanceFunction(const Motion *a, const Motion *b) const
243  {
244  return si_->distance(a->state_, b->state_);
245  }
246 
249 
252 
255 
257  std::shared_ptr< NearestNeighbors<Motion*> > nn_;
258 
259 
261  std::shared_ptr< NearestNeighbors<Motion*> > witnesses_;
262 
264  double goalBias_;
265 
268 
271 
274 
276  std::vector<base::State*> prevSolution_;
277  std::vector<Control*> prevSolutionControls_;
278  std::vector<unsigned> prevSolutionSteps_;
279 
282 
285 
286  };
287  }
288 }
289 
290 #endif
virtual void setup()
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition: SST.cpp:68
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:163
unsigned numChildren_
Number of children.
Definition: SST.h:195
base::StateSamplerPtr sampler_
State sampler.
Definition: SST.h:248
Definition of an abstract control.
Definition: Control.h:48
Motion * parent_
The parent motion in the exploration tree.
Definition: SST.h:192
base::Cost prevSolutionCost_
The best solution cost we found so far.
Definition: SST.h:281
Witness * findClosestWitness(Motion *node)
Find the closest witness node to a newly generated potential node.
Definition: SST.cpp:181
A shared pointer wrapper for ompl::base::StateSampler.
A shared pointer wrapper for ompl::control::ControlSampler.
bool inactive_
If inactive, this node is not considered for selection.
Definition: SST.h:198
std::shared_ptr< NearestNeighbors< Motion * > > nn_
A nearest-neighbors datastructure containing the tree of motions.
Definition: SST.h:257
Motion(const SpaceInformation *si)
Constructor that allocates memory for the state and the control.
Definition: SST.h:163
std::vector< base::State * > prevSolution_
The best solution we found so far.
Definition: SST.h:276
Control * control_
The control contained by the motion.
Definition: SST.h:186
const SpaceInformation * siC_
The base::SpaceInformation cast as control::SpaceInformation, for convenience.
Definition: SST.h:254
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
double getSelectionRadius() const
Get the selection radius the planner is using.
Definition: SST.h:112
ControlSamplerPtr controlSampler_
Control sampler.
Definition: SST.h:251
double getGoalBias() const
Get the goal bias the planner is using.
Definition: SST.h:93
SST(const SpaceInformationPtr &si)
Constructor.
Definition: SST.cpp:46
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:408
double pruningRadius_
The radius for determining the size of the pruning region.
Definition: SST.h:270
virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc)
Continue solving for some amount of time. Return true if solution was found.
Definition: SST.cpp:205
base::OptimizationObjectivePtr opt_
The optimization objective.
Definition: SST.h:284
Motion * rep_
The node in the tree that is within the pruning radius.
Definition: SST.h:229
Main namespace. Contains everything in this library.
Definition: Cost.h:42
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states)
Definition: SST.h:242
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition: RandomNumbers.h:58
void setPruningRadius(double pruningRadius)
Set the radius for pruning nodes.
Definition: SST.h:128
Base class for a planner.
Definition: Planner.h:230
Motion * selectNode(Motion *sample)
Finds the best node in the tree withing the selection radius around a random sample.
Definition: SST.cpp:152
double selectionRadius_
The radius for determining the node selected for extension.
Definition: SST.h:267
void setNearestNeighbors()
Set a different nearest neighbors datastructure.
Definition: SST.h:141
unsigned int steps_
The number of steps_ the control is applied for.
Definition: SST.h:189
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
Definition of an abstract state.
Definition: State.h:50
A shared pointer wrapper for ompl::control::SpaceInformation.
base::State * state_
The state contained by the motion.
Definition: SST.h:183
A shared pointer wrapper for ompl::base::OptimizationObjective.
RNG rng_
The random number generator.
Definition: SST.h:273
std::shared_ptr< NearestNeighbors< Motion * > > witnesses_
A nearest-neighbors datastructure containing the tree of witness motions.
Definition: SST.h:261
SpaceInformationPtr si_
The space information for which planning is done.
Definition: Planner.h:398
Representation of a motion.
Definition: SST.h:154
virtual void clear()
Clear datastructures. Call this function if the input data to the planner has changed and you do not ...
Definition: SST.cpp:100
Space information containing necessary information for planning with controls. setup() needs to be ca...
void setGoalBias(double goalBias)
Definition: SST.h:87
double getPruningRadius() const
Get the pruning radius the planner is using.
Definition: SST.h:134
void freeMemory()
Free the memory allocated by this planner.
Definition: SST.cpp:113
void setSelectionRadius(double selectionRadius)
Set the radius for selecting nodes relative to random sample.
Definition: SST.h:106
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
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:264