Loading...
Searching...
No Matches
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
50namespace ompl
51{
52 namespace base
53 {
54 OMPL_CLASS_FORWARD(InformedSampler);
55 OMPL_CLASS_FORWARD(InformedStateSampler);
56
60 class InformedSampler
61 {
62 public:
63 // non-copyable
64 InformedSampler(const InformedSampler &) = delete;
65 InformedSampler &operator=(const InformedSampler &) = delete;
66
71 InformedSampler(const ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls);
72
73 virtual ~InformedSampler() = default;
74
78 virtual bool sampleUniform(State *statePtr, const Cost &maxCost) = 0;
79
83 virtual bool sampleUniform(State *statePtr, const Cost &minCost, const Cost &maxCost) = 0;
84
86 virtual bool hasInformedMeasure() const = 0;
87
91 virtual double getInformedMeasure(const Cost &currentCost) const = 0;
92
98 virtual double getInformedMeasure(const Cost &minCost, const Cost &maxCost) const;
99
103 virtual Cost heuristicSolnCost(const State *statePtr) const;
104
107
109 unsigned int getMaxNumberOfIters() const;
110
111 protected:
119 unsigned int numIters_;
120 };
121
123 class InformedStateSampler : public StateSampler
124 {
125 public:
127 using GetCurrentCostFunc = std::function<Cost()>;
128
132 InformedStateSampler(const ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls,
133 const GetCurrentCostFunc &costFunc);
134
138 InformedStateSampler(const ProblemDefinitionPtr &probDefn, const GetCurrentCostFunc &costFunc,
139 const InformedSamplerPtr &infSampler);
140
141 ~InformedStateSampler() override = default;
142
146 void sampleUniform(State *statePtr) override;
147
150 void sampleUniformNear(State *statePtr, const State *near, double distance) override;
151
154 void sampleGaussian(State *statePtr, const State *mean, double stdDev) override;
155
156 private:
158 void commonConstructor(const GetCurrentCostFunc &costFunc, const InformedSamplerPtr &infSampler);
159
162 GetCurrentCostFunc bestCostFunc_;
164 StateSamplerPtr baseSampler_;
166 InformedSamplerPtr infSampler_;
167 };
168 }
169}
170
171#endif // OMPL_BASE_SAMPLERS_INFORMED_SAMPLER_
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition Cost.h:48
An abstract class for the concept of using information about the state space and the current solution...
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...
OptimizationObjectivePtr opt_
A copy of the optimization objective.
unsigned int getMaxNumberOfIters() const
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 Cost heuristicSolnCost(const State *statePtr) const
A helper function to calculate the heuristic estimate of the solution cost for a given state using th...
virtual bool sampleUniform(State *statePtr, const Cost &minCost, const Cost &maxCost)=0
Sample uniformly in the subset of the state space whose heuristic solution estimates are between the ...
ProblemDefinitionPtr probDefn_
A copy of the problem definition.
unsigned int numIters_
The number of iterations I'm allowed to attempt.
virtual bool hasInformedMeasure() const =0
Whether the sampler can provide a measure of the informed subset.
ProblemDefinitionPtr getProblemDefn() const
StateSpacePtr space_
A copy of the state space.
A wrapper class that allows an InformedSampler to be used as a StateSampler.
void sampleUniform(State *statePtr) override
Sample uniformly in the subset of the state space whose heuristic solution estimates are less than th...
std::function< Cost()> GetCurrentCostFunc
The definition of a function pointer for querying the current solution cost.
void sampleUniformNear(State *statePtr, const State *near, double distance) override
By default sampleUniformNear throws. This can be overloaded by a specific informed sampler if desired...
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...
void sampleGaussian(State *statePtr, const State *mean, double stdDev) override
By default sampleGaussian throws. This can be overloaded by a specific informed sampler if desired.
A shared pointer wrapper for ompl::base::OptimizationObjective.
A shared pointer wrapper for ompl::base::ProblemDefinition.
A shared pointer wrapper for ompl::base::StateSampler.
A shared pointer wrapper for ompl::base::StateSpace.
Definition of an abstract state.
Definition State.h:50
This namespace contains sampling based planning routines shared by both planning under geometric cons...
Main namespace. Contains everything in this library.