InformedStateSampler.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2014, University of Toronto
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 University of Toronto 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: Jonathan Gammell */
36 
37 #ifndef OMPL_BASE_SAMPLERS_INFORMED_SAMPLER_
38 #define OMPL_BASE_SAMPLERS_INFORMED_SAMPLER_
39 
40 // We inherit from StateSampler
41 #include "ompl/base/StateSampler.h"
42 // Deriving functions must be able to sample within a given cost
43 #include "ompl/base/Cost.h"
44 // We use a pointer to the problem definition to access problem and solution data.
45 #include "ompl/base/ProblemDefinition.h"
46 
47 //For std::function
48 #include <functional>
49 
50 namespace ompl
51 {
52  namespace base
53  {
54  OMPL_CLASS_FORWARD(InformedSampler);
55  OMPL_CLASS_FORWARD(InformedStateSampler);
56 
57 
62  {
63  public:
64  // non-copyable
65  InformedSampler(const InformedSampler&) = delete;
66  InformedSampler& operator=(const InformedSampler&) = delete;
67 
70  InformedSampler(const ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls);
71 
72  virtual ~InformedSampler(void)
73  {
74  }
75 
77  virtual bool sampleUniform(State *statePtr, const Cost &maxCost) = 0;
78 
80  virtual bool sampleUniform(State *statePtr, const Cost &minCost, const Cost &maxCost) = 0;
81 
83  virtual bool hasInformedMeasure() const = 0;
84 
86  virtual double getInformedMeasure(const Cost &currentCost) const = 0;
87 
89  virtual double getInformedMeasure(const Cost &minCost, const Cost &maxCost) const;
90 
93  virtual Cost heuristicSolnCost(const State *statePtr) const;
94 
95  protected:
103  unsigned int numIters_;
104  };
105 
106 
107 
108 
111  {
112  public:
113 
115  typedef std::function<Cost ()> GetCurrentCostFunc;
116 
118  InformedStateSampler(const ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls, const GetCurrentCostFunc &costFunc);
119 
121  InformedStateSampler(const ProblemDefinitionPtr &probDefn, const GetCurrentCostFunc &costFunc, const InformedSamplerPtr &infSampler);
122 
123  virtual ~InformedStateSampler(void)
124  {
125  }
126 
128  virtual void sampleUniform(State *statePtr);
129 
131  virtual void sampleUniformNear(State *statePtr, const State *near, const double distance);
132 
134  virtual void sampleGaussian(State *statePtr, const State *mean, const double stdDev);
135 
136  private:
138  void commonConstructor(const GetCurrentCostFunc &costFunc, const InformedSamplerPtr &infSampler);
139 
141  GetCurrentCostFunc bestCostFunc_;
143  StateSamplerPtr baseSampler_;
145  InformedSamplerPtr infSampler_;
146  };
147  }
148 }
149 
150 
151 #endif // OMPL_BASE_SAMPLERS_INFORMED_SAMPLER_
A shared pointer wrapper for ompl::base::ProblemDefinition.
virtual Cost heuristicSolnCost(const State *statePtr) const
A helper function to calculate the heuristic estimate of the solution cost for a given state using th...
A shared pointer wrapper for ompl::base::StateSpace.
A shared pointer wrapper for ompl::base::StateSampler.
OptimizationObjectivePtr opt_
A copy of the optimization objective.
An abstract class for the concept of using information about the state space and the current solution...
StateSpacePtr space_
A copy of the state space.
virtual bool sampleUniform(State *statePtr, const Cost &maxCost)=0
Sample uniformly in the subset of the state space whose heuristic solution estimates are less than th...
virtual void sampleUniformNear(State *statePtr, const State *near, const double distance)
By default sampleUniformNear throws. This can be overloaded by a specific informed sampler if desired...
virtual void sampleUniform(State *statePtr)
Sample uniformly in the subset of the state space whose heuristic solution estimates are less than th...
virtual double getInformedMeasure(const Cost &currentCost) const =0
The measure of the subset of the state space defined by the current solution cost that is being searc...
InformedStateSampler(const ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls, const GetCurrentCostFunc &costFunc)
Construct a sampler that only generates states with a heuristic solution estimate that is less than t...
Definition of an abstract state.
Definition: State.h:50
A shared pointer wrapper for ompl::base::OptimizationObjective.
ProblemDefinitionPtr probDefn_
A copy of the problem definition.
Abstract definition of a state space sampler.
Definition: StateSampler.h:65
std::function< Cost()> GetCurrentCostFunc
The definition of a function pointer for querying the current solution cost.
unsigned int numIters_
The number of iterations I'm allowed to attempt.
A wrapper class that allows an InformedSampler to be used as a StateSampler.
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
virtual bool hasInformedMeasure() const =0
Whether the sampler can provide a measure of the informed subset.
virtual void sampleGaussian(State *statePtr, const State *mean, const double stdDev)
By default sampleGaussian throws. This can be overloaded by a specific informed sampler if desired...