Loading...
Searching...
No Matches
ImplicitGraph.h
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2025, University of New Hampshire
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 names of the copyright holders 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 * Attribution Notice:
36 *
37 * This file contains code largely derived from the AIT* or BIT* planner
38 * in the Open Motion Planning Library (OMPL). Specific structural components,
39 * including sampling mechanisms, nearest neighbor routines, and priority
40 * queue management, are adapted from that planner.
41 *
42 * The `addSample()` function and the core efficiency logic of BLIT* were
43 * independently developed and modified by Yi Wang.
44 *********************************************************************/
45
46// Authors: Yi Wang, Eyal Weiss, Bingxian Mu, Oren Salzman
47#ifndef OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BLITSTAR_IMPLICITGRAPH_
48#define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BLITSTAR_IMPLICITGRAPH_
49
50#include <memory>
51
52#include "ompl/base/samplers/InformedStateSampler.h"
53#include "ompl/base/SpaceInformation.h"
54#include "ompl/base/ProblemDefinition.h"
55#include "ompl/base/PlannerTerminationCondition.h"
56#include "ompl/base/Planner.h"
57#include "ompl/datastructures/NearestNeighborsGNATNoThreadSafety.h"
58#include "ompl/geometric/planners/lazyinformedtrees/blitstar/Vertex.h"
59
60namespace ompl
61{
62 namespace geometric
63 {
64 namespace blitstar
65 {
67 {
68 public:
70 ImplicitGraph(const ompl::base::Cost &solutionCost);
71
73 virtual ~ImplicitGraph() = default;
74
76 void setup(const ompl::base::SpaceInformationPtr &spaceInformation,
77 const ompl::base::ProblemDefinitionPtr &problemDefinition,
79
81 void clear();
82
84 void setRewireFactor(double rewireFactor);
85
87 double getRewireFactor() const;
88
90 void setMaxNumberOfGoals(unsigned int maxNumberOfGoals);
91
93 unsigned int getMaxNumberOfGoals() const;
94
96 void setUseKNearest(bool useKNearest);
97
99 bool getUseKNearest() const;
100
103
105 bool addSamples(std::size_t numNewSamples,
106 const ompl::base::PlannerTerminationCondition &terminationCondition, bool need_prune);
107
109 std::size_t getNumVertices() const;
110 std::size_t getNumNeighbors() const;
112 double getConnectionRadius() const;
114 ompl::base::Cost EculideanDistanceToStart(const std::shared_ptr<Vertex> &vertex) const;
116 ompl::base::Cost EculideanDistanceToGoal(const std::shared_ptr<Vertex> &vertex) const;
117
119 void registerStartState(const ompl::base::State *const startState);
120
122 void registerGoalState(const ompl::base::State *const goalState);
123
125 bool hasAStartState() const;
126
128 bool hasAGoalState() const;
129
133 ompl::base::PlannerInputStates *inputStates);
134
136 std::vector<std::shared_ptr<Vertex>> getNeighbors(const std::shared_ptr<Vertex> &vertex) const;
137
139 bool isStart(const std::shared_ptr<Vertex> &vertex) const;
140
142 bool isGoal(const std::shared_ptr<Vertex> &vertex) const;
143
145 const std::vector<std::shared_ptr<Vertex>> &getStartVertices() const;
146
148 const std::vector<std::shared_ptr<Vertex>> &getGoalVertices() const;
149
151 std::vector<std::shared_ptr<Vertex>> getVertices() const;
152
154 void prune();
155
157 std::size_t getNumberOfSampledStates() const;
158
160 std::size_t getNumberOfValidSamples() const;
161
163 std::size_t getNumberOfStateCollisionChecks() const;
164
166 std::size_t getNumberOfNearestNeighborCalls() const;
167
168 private:
170 std::size_t computeNumberOfSamplesInInformedSet() const;
171
173 double computeConnectionRadius(std::size_t numSamples) const;
174
176 std::size_t computeNumberOfNeighbors(std::size_t numSamples) const;
177
179 bool canPossiblyImproveSolution(const std::shared_ptr<Vertex> &vertex) const;
180
182 ompl::base::SpaceInformationPtr spaceInformation_;
183
185 ompl::base::ProblemDefinitionPtr problemDefinition_;
186
188 ompl::base::OptimizationObjectivePtr objective_;
189
191 std::size_t batchId_;
192
194 double rewireFactor_{1.001};
195
197 bool trackApproximateSolution_{false};
198
200 std::shared_ptr<Vertex> bestApproximateGoal_;
201
203 bool useKNearest_{true};
204
206 unsigned int maxNumGoals_{10u};
207
209 double radius_{std::numeric_limits<double>::infinity()};
210
213 std::size_t numNeighbors_{std::numeric_limits<std::size_t>::max()};
214
216 std::size_t k_rgg_{std::numeric_limits<std::size_t>::max()};
217
219 const ompl::base::Cost &solutionCost_;
220
222 ompl::base::InformedSamplerPtr sampler_;
223
225 ompl::NearestNeighborsGNATNoThreadSafety<std::shared_ptr<Vertex>> vertices_;
226
228 std::vector<std::shared_ptr<Vertex>> startVertices_;
229
231 std::vector<std::shared_ptr<Vertex>> goalVertices_;
232
236 std::vector<std::shared_ptr<Vertex>> prunedStartVertices_;
237
241 std::vector<std::shared_ptr<Vertex>> prunedGoalVertices_;
242
244 std::vector<std::shared_ptr<Vertex>> newSamples_;
245
247 mutable std::size_t numValidSamples_{0u};
248
250 mutable std::size_t numSampledStates_{0u};
251
253 mutable std::size_t numNearestNeighborsCalls_{0u};
254 };
255
256 } // namespace blitstar
257
258 } // namespace geometric
259
260} // namespace ompl
261
262#endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BLITSTAR_IMPLICITGRAPH_
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 setRewireFactor(double rewireFactor)
Set the rewire factor of the RGG.
unsigned int getMaxNumberOfGoals() const
Get the maximum number of goals BLIT* will sample from sampleable goal regions.
bool isGoal(const std::shared_ptr< Vertex > &vertex) const
Checks whether the vertex is a goal vertex.
ompl::base::Cost EculideanDistanceToStart(const std::shared_ptr< Vertex > &vertex) const
Gets the Eculidean distance to Start.
std::size_t getNumberOfValidSamples() const
Returns the total number of valid samples found.
std::size_t getNumberOfStateCollisionChecks() const
Get the number of state collision checks.
void setTrackApproximateSolution(bool track)
Sets whether to track approximate solutions or not.
std::size_t getNumVertices() const
Gets the number of samples in the graph.
void setup(const ompl::base::SpaceInformationPtr &spaceInformation, const ompl::base::ProblemDefinitionPtr &problemDefinition, ompl::base::PlannerInputStates *inputStates)
The setup method for the graph. Needed to have it on the stack.
double getRewireFactor() const
Get the reqire factor of the RGG.
void setMaxNumberOfGoals(unsigned int maxNumberOfGoals)
Set the maximum number of goals BLIT* will sample from sampleable goal regions.
const std::vector< std::shared_ptr< Vertex > > & getStartVertices() const
Get the start vertices.
void registerStartState(const ompl::base::State *const startState)
Registers a state as a start state.
bool hasAStartState() const
Returns whether the graph has a goal state.
std::size_t getNumberOfSampledStates() const
Returns the total number of sampled states.
void updateStartAndGoalStates(const ompl::base::PlannerTerminationCondition &terminationCondition, ompl::base::PlannerInputStates *inputStates)
Adds new start and goals to the graph if avavilable and creates a new informed sampler if necessary.
double getConnectionRadius() const
Gets the RGG connection radius.
ImplicitGraph(const ompl::base::Cost &solutionCost)
Constructs an implicit graph.
std::size_t getNumberOfNearestNeighborCalls() const
Get the number of nearest neighbor calls.
virtual ~ImplicitGraph()=default
Destructs an implicit graph.
const std::vector< std::shared_ptr< Vertex > > & getGoalVertices() const
Get the goal vertices.
bool hasAGoalState() const
Returns whether the graph has a goal state.
void registerGoalState(const ompl::base::State *const goalState)
Registers a state as a goal state.
void clear()
Resets the graph to its construction state, without resetting options.
bool getUseKNearest() const
Whether the graph uses a k-nearest connection model. If false, it uses an r-disc model.
void setUseKNearest(bool useKNearest)
Whether to use a k-nearest connection model. If false, it uses an r-disc model.
void prune()
Prune all samples that can not contribute to a solution better than the current one.
std::vector< std::shared_ptr< Vertex > > getNeighbors(const std::shared_ptr< Vertex > &vertex) const
Get neighbors of a vertex.
bool addSamples(std::size_t numNewSamples, const ompl::base::PlannerTerminationCondition &terminationCondition, bool need_prune)
Adds a batch of samples and returns the samples it has added.
ompl::base::Cost EculideanDistanceToGoal(const std::shared_ptr< Vertex > &vertex) const
Gets the Eculidean distance to Goal.
std::vector< std::shared_ptr< Vertex > > getVertices() const
Get all vertices.
bool isStart(const std::shared_ptr< Vertex > &vertex) const
Checks whether the vertex is a start vertex.
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.