Loading...
Searching...
No Matches
RandomGeometricGraph.h
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2019, University of Oxford
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: Marlin Strub
36
37#ifndef OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_RANDOM_GEOMETRIC_GRAPH_
38#define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_RANDOM_GEOMETRIC_GRAPH_
39
40#include <limits>
41#include <memory>
42#include <iostream> // This is needed for ompl's nearest neighbors struct...
43
44#include "ompl/datastructures/NearestNeighborsGNATNoThreadSafety.h"
45#include "ompl/base/samplers/InformedStateSampler.h"
46#include "ompl/base/Planner.h"
47#include "ompl/base/ProblemDefinition.h"
48#include "ompl/base/OptimizationObjective.h"
49
50#include "ompl/geometric/planners/informedtrees/eitstar/State.h"
51#include "ompl/geometric/planners/informedtrees/eitstar/Edge.h"
52
53namespace ompl
54{
55 namespace geometric
56 {
57 namespace eitstar
58 {
60 {
61 public:
64 RandomGeometricGraph(const std::shared_ptr<ompl::base::SpaceInformation> &spaceInfo,
65 const ompl::base::Cost &solutionCost);
66
69
71 void setup(const std::shared_ptr<ompl::base::ProblemDefinition> &problem,
73
76 void clear();
77
79 void clearQuery();
80
85
89
91 void setRadiusFactor(double factor);
92
94 double getRadiusFactor() const;
95
97 void setEffortThreshold(const unsigned int threshold);
98
100 unsigned int getEffortThreshold() const;
101
103 void enablePruning(bool prune);
104
106 bool isPruningEnabled() const;
107
109 void enableMultiquery(bool multiquery);
110
112 bool isMultiqueryEnabled() const;
113
115 void setUseKNearest(bool useKNearest);
116
119 bool getUseKNearest() const;
120
122 void setMaxNumberOfGoals(unsigned int maxNumberOfGoals);
123
125 unsigned int getMaxNumberOfGoals() const;
126
128 bool addStates(std::size_t numStates,
129 const ompl::base::PlannerTerminationCondition &terminationCondition);
130
132 void prune();
133
135 std::vector<std::weak_ptr<State>> getNeighbors(const std::shared_ptr<State> &state) const;
136
138 const std::vector<std::shared_ptr<State>> &getStartStates() const;
139
141 const std::vector<std::shared_ptr<State>> &getGoalStates() const;
142
144 unsigned int getNumberOfSampledStates() const;
145
147 unsigned int getNumberOfValidSamples() const;
148
150 unsigned int getNumberOfNearestNeighborCalls() const;
151
153 std::shared_ptr<State> registerStartState(const ompl::base::State *start);
154
156 std::shared_ptr<State> registerGoalState(const ompl::base::State *goal);
157
159 void registerWhitelistedState(const std::shared_ptr<State> &state) const;
160
162 bool hasStartState() const;
163
165 bool hasGoalState() const;
166
168 bool isStart(const std::shared_ptr<State> &state) const;
169
171 bool isGoal(const std::shared_ptr<State> &state) const;
172
174 std::vector<std::shared_ptr<State>> getStates() const;
175
177 void registerInvalidEdge(const Edge &edge) const;
178
180 std::size_t getTag() const;
181
183 unsigned int inadmissibleEffortToCome(const std::shared_ptr<State> &state) const;
184
185 private:
189 std::shared_ptr<State>
190 getNewSample(const ompl::base::PlannerTerminationCondition &terminationCondition);
191
193 std::size_t countSamplesInInformedSet() const;
194
197 bool canBePruned(const std::shared_ptr<State> &state) const;
198
200 void pruneStartsAndGoals();
201
203 ompl::base::Cost lowerBoundCostToCome(const std::shared_ptr<State> &state) const;
204
206 unsigned int lowerBoundEffortToCome(const std::shared_ptr<State> &state) const;
207
209 ompl::base::Cost lowerBoundCostToGo(const std::shared_ptr<State> &state) const;
210
212 void initializeState(const std::shared_ptr<State> &state);
213
215 std::size_t computeNumberOfNeighbors(std::size_t numInformedSamples) const;
216
218 double computeRadius(std::size_t numInformedSamples) const;
219
221 mutable std::vector<std::shared_ptr<State>> whitelistedStates_{};
222
224 std::size_t tag_{1u};
225
227 std::vector<std::shared_ptr<State>> buffer_;
228
230 std::vector<std::shared_ptr<State>> startGoalBuffer_;
231
233 std::size_t currentNumSamples_{0u};
234
237
239 std::vector<std::shared_ptr<State>> newSamples_;
240
242 std::shared_ptr<ompl::base::InformedSampler> sampler_{nullptr};
243
245 std::shared_ptr<ompl::base::SpaceInformation> spaceInfo_;
246
248 std::shared_ptr<ompl::base::StateSpace> space_;
249
251 std::shared_ptr<ompl::base::ProblemDefinition> problem_;
252
254 std::shared_ptr<ompl::base::OptimizationObjective> objective_;
255
257 std::vector<std::shared_ptr<State>> startStates_;
258
260 std::vector<std::shared_ptr<State>> goalStates_;
261
264 std::vector<std::shared_ptr<State>> prunedStartStates_;
265
268 std::vector<std::shared_ptr<State>> prunedGoalStates_;
269
271 bool isPruningEnabled_{true};
272
274 bool isMultiqueryEnabled_{false};
275
277 bool useKNearest_{true};
278
280 unsigned int maxNumGoals_{1u};
281
284 std::size_t numNeighbors_{std::numeric_limits<std::size_t>::max()};
285
287 std::size_t k_rgg_{std::numeric_limits<std::size_t>::max()};
288
290 double radius_{std::numeric_limits<double>::infinity()};
291
293 double radiusFactor_{1.001};
294
296 unsigned int effortThreshold_{50000};
297
299 const double dimension_;
300
302 const double unitNBallMeasure_;
303
305 const ompl::base::Cost &solutionCost_;
306
308 ompl::base::Cost minPossibleCost_{std::numeric_limits<double>::signaling_NaN()};
309
311 mutable unsigned int numSampledStates_{0u};
312
314 mutable unsigned int numValidSamples_{0u};
315
317 mutable unsigned int numNearestNeighborCalls_{0u};
318 };
319
320 } // namespace eitstar
321
322 } // namespace geometric
323
324} // namespace ompl
325
326#endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_RANDOM_GEOMETRIC_GRAPH_
Geometric Near-neighbor Access Tree (GNAT), a data structure for nearest neighbor search.
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition Cost.h:48
Helper class to extract valid start & goal states. Usually used internally by planners.
Definition Planner.h:78
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Definition of an abstract state.
Definition State.h:50
void setEffortThreshold(const unsigned int threshold)
Sets the effort threshold.
std::vector< std::shared_ptr< State > > getStates() const
Returns all sampled states (that have not been pruned).
std::size_t getTag() const
Returns the tag of the current RGG.
bool getUseKNearest() const
Returns whether the graph uses a k-nearest connection model. If false, it uses an r-disc model.
void registerWhitelistedState(const std::shared_ptr< State > &state) const
Registers a whitelisted state.
unsigned int getEffortThreshold() const
Gets the effort threshold.
RandomGeometricGraph(const std::shared_ptr< ompl::base::SpaceInformation > &spaceInfo, const ompl::base::Cost &solutionCost)
Constructs a random geometric graph with the given space information and reference to the current sol...
const std::vector< std::shared_ptr< State > > & getGoalStates() const
Returns the goal states.
std::vector< std::weak_ptr< State > > getNeighbors(const std::shared_ptr< State > &state) const
Returns the neighbors of a state.
void prune()
Prunes the graph of states that can not improve the current solution.
void setUseKNearest(bool useKNearest)
Set whether to use a k-nearest connection model. If false, it uses an r-disc model.
void clearQuery()
Clears all query-specific structures, such as start and goal states.
bool hasStartState() const
Returns whether a start state is available.
unsigned int getMaxNumberOfGoals() const
Returns the maximum number of goals EIT* will sample from sampleable goal regions.
bool hasGoalState() const
Returns whether a goal state is available.
bool isStart(const std::shared_ptr< State > &state) const
Returns whether the given state is a start state.
double getRadiusFactor() const
Returns the radius factor (eta in the paper).
void enablePruning(bool prune)
Enable pruning of the graph.
unsigned int getNumberOfNearestNeighborCalls() const
Returns the number of nearest neighbor calls.
bool isGoal(const std::shared_ptr< State > &state) const
Returns whether the given state is a goal state.
const std::vector< std::shared_ptr< State > > & getStartStates() const
Returns the start states.
unsigned int getNumberOfSampledStates() const
Returns the number of sampled states.
void setMaxNumberOfGoals(unsigned int maxNumberOfGoals)
Sets the maximum number of goals EIT* will sample from sampleable goal regions.
std::shared_ptr< State > registerStartState(const ompl::base::State *start)
Sets the start state.
bool addStates(std::size_t numStates, const ompl::base::PlannerTerminationCondition &terminationCondition)
Samples random states and adds them to the graph.
unsigned int getNumberOfValidSamples() const
Returns the number of valid samples.
void clear()
Clears all internal planner structures but retains settings. Subsequent calls to solve() will start f...
void registerInvalidEdge(const Edge &edge) const
Registers an invalid edge.
bool isMultiqueryEnabled() const
Returns Whether multiquery usage of the graph is enabled.
void updateStartAndGoalStates(const ompl::base::PlannerTerminationCondition &terminationCondition, ompl::base::PlannerInputStates *inputStates)
Adds new starts and goals to the graph if available and creates a new informed sampler if necessary.
void enableMultiquery(bool multiquery)
Enable multiquery usage of the graph.
ompl::base::Cost minPossibleCost() const
Returns the minimum possible cost for the current problem, using admissible cost estimates to calcula...
bool isPruningEnabled() const
Returns Whether pruning is enabled.
std::shared_ptr< State > registerGoalState(const ompl::base::State *goal)
Sets the goal state.
unsigned int inadmissibleEffortToCome(const std::shared_ptr< State > &state) const
Returns the inadmissible effort to come.
void setup(const std::shared_ptr< ompl::base::ProblemDefinition > &problem, ompl::base::PlannerInputStates *inputStates)
Setup the graph with the given problem definition and planner input states.
~RandomGeometricGraph()=default
Destricts this random geometric graph.
void setRadiusFactor(double factor)
Sets the radius factor (eta in the paper).
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.
A struct for basic edge data.
Definition Edge.h:57