Loading...
Searching...
No Matches
ATRRT.h
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2025, Joris Chomarat
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 copyright holder 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/* Author: Joris Chomarat */
36
37#ifndef OMPL_GEOMETRIC_PLANNERS_RRT_ATRRT_
38#define OMPL_GEOMETRIC_PLANNERS_RRT_ATRRT_
39
40#include "ompl/geometric/planners/PlannerIncludes.h"
41#include "ompl/datastructures/NearestNeighbors.h"
42#include "ompl/base/OptimizationObjective.h"
43
44/*
45 NOTES:
46 **Variable Names that have been converted to longer versions from standards:
47 nearest_neighbors_ -> nn_
48 planner_termination_condition -> ptc
49
50 **Inherited Member Variables Key:
51 si_ -> SpaceInformation
52 pdef_ -> ProblemDefinition
53 pis_ -> PlannerInputStates - Utility class to extract valid input states
54*/
55
56namespace ompl
57{
58 namespace geometric
59 {
83
85 class ATRRT : public base::Planner
86 {
87 public:
89 ATRRT(const base::SpaceInformationPtr &si);
90
91 ~ATRRT() override;
92
93 void getPlannerData(base::PlannerData &data) const override;
94
95 base::PlannerStatus solve(const base::PlannerTerminationCondition &plannerTerminationCondition) override;
96
97 void clear() override;
98
108 void setGoalBias(double goalBias)
109 {
110 goalBias_ = goalBias;
111 }
112
114 double getGoalBias() const
115 {
116 return goalBias_;
117 }
118
124 void setRange(double distance)
125 {
126 maxDistance_ = distance;
127 }
128
130 double getRange() const
131 {
132 return maxDistance_;
133 }
134
140 void setTempChangeFactor(double factor)
141 {
142 tempChangeFactor_ = exp(factor);
143 }
144
146 double getTempChangeFactor() const
147 {
148 return log(tempChangeFactor_);
149 }
150
154 void setCostThreshold(double maxCost)
155 {
156 costThreshold_ = base::Cost(maxCost);
157 }
158
162 double getCostThreshold() const
163 {
164 return costThreshold_.value();
165 }
166
169 void setInitTemperature(double initTemperature)
170 {
171 initTemperature_ = initTemperature;
173 }
174
176 double getInitTemperature() const
177 {
178 return initTemperature_;
179 }
180
183 void setFrontierThreshold(double frontier_threshold)
184 {
185 frontierThreshold_ = frontier_threshold;
186 }
187
190 double getFrontierThreshold() const
191 {
192 return frontierThreshold_;
193 }
194
197 void setFrontierNodeRatio(double frontierNodeRatio)
198 {
199 frontierNodeRatio_ = frontierNodeRatio;
200 }
201
204 double getFrontierNodeRatio() const
205 {
206 return frontierNodeRatio_;
207 }
208
210 template <template <typename T> class NN>
212 {
213 if (nearestNeighbors_->size() == 0)
214 OMPL_WARN("Calling setNearestNeighbors will clear all states.");
215 clear();
216 nearestNeighbors_ = std::make_shared<NN<Motion *>>();
217 setup();
218 }
219
220 void setup() override;
221
222 protected:
227 class Motion
228 {
229 public:
230 Motion() = default;
231
233 Motion(const base::SpaceInformationPtr &si) : state(si->allocState())
234 {
235 }
236
237 ~Motion() = default;
238
241
243 std::vector<Motion *> neighbors;
244
247 };
248
250 void freeMemory();
251
253 double distanceFunction(const Motion *a, const Motion *b) const
254 {
255 return si_->distance(a->state, b->state);
256 }
257
261 bool transitionTest(const base::Cost &motionCost);
262
264 bool minExpansionControl(double randMotionDistance);
265
267 void addUsefulCycles(Motion *newMotion, Motion *nearMotion);
268
270 void addEdge(Motion *a, Motion *b);
271
273 std::vector<ompl::geometric::ATRRT::Motion *> computeDijkstraLowestCostPath(Motion *a, Motion *b);
274
276 ompl::base::Cost computeCostLowestCostPath(Motion *a, Motion *b);
277
279 base::StateSamplerPtr sampler_;
280
282 std::shared_ptr<NearestNeighbors<Motion *>> nearestNeighbors_;
283
286 double goalBias_{.05};
287
289 double maxDistance_{0.};
290
293
296
299 {
300 bool operator()(const std::pair<Motion *, base::Cost> &a,
301 const std::pair<Motion *, base::Cost> &b) const
302 {
303 return a.second.value() > b.second.value();
304 }
305 };
306
307 // *********************************************************************************************************
308 // ATRRT-Specific Variables
309 // *********************************************************************************************************
310
311 // Transtion Test -----------------------------------------------------------------------
312
316 double temp_;
317
320
323
326
330
333
335 ompl::base::OptimizationObjectivePtr opt_;
336
337 // Useful Cycles -----------------------------------------------------------------------
338
340 double gamma_{1.0};
341
345
346 // Minimum Expansion Control ------------------------------------------------------------
356 };
357
358 } // namespace geometric
359} // namespace ompl
360
361#endif // OMPL_GEOMETRIC_PLANNERS_RRT_ATRRT_
Random number generation. An instance of this class cannot be used by multiple threads at once (membe...
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition Cost.h:48
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique,...
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
Base class for a planner.
Definition Planner.h:216
SpaceInformationPtr si_
The space information for which planning is done.
Definition Planner.h:401
Definition of an abstract state.
Definition State.h:50
Representation of a motion.
Definition ATRRT.h:228
std::vector< Motion * > neighbors
The connected motions in the exploration graph.
Definition ATRRT.h:243
base::State * state
The state contained by the motion.
Definition ATRRT.h:240
base::Cost cost
Cost of the state.
Definition ATRRT.h:246
Motion(const base::SpaceInformationPtr &si)
Constructor that allocates memory for the state.
Definition ATRRT.h:233
double frontierThreshold_
The distance between an old state and a new state that qualifies it as a frontier state.
Definition ATRRT.h:353
double getCostThreshold() const
Get the cost threshold (default is infinity). Any motion cost that is not better than this cost (acco...
Definition ATRRT.h:162
base::Cost worstCost_
The least desirable (e.g., maximum) cost value in the search tree.
Definition ATRRT.h:322
double getFrontierNodeRatio() const
Get the ratio between adding nonfrontier nodes to frontier nodes, for example .1 is 1/10 or one nonfr...
Definition ATRRT.h:204
void setGoalBias(double goalBias)
Set the goal bias.
Definition ATRRT.h:108
double getInitTemperature() const
Get the temperature at the start of planning.
Definition ATRRT.h:176
double distanceFunction(const Motion *a, const Motion *b) const
Compute distance between motions (actually distance between contained states).
Definition ATRRT.h:253
ompl::base::OptimizationObjectivePtr opt_
The optimization objective being optimized by ATRRT.
Definition ATRRT.h:335
Motion * lastGoalMotion_
The most recent goal motion. Used for PlannerData computation.
Definition ATRRT.h:295
ompl::base::Cost computeCostLowestCostPath(Motion *a, Motion *b)
Compute cost of lowest-cost path found by Dijkstra.
Definition ATRRT.cpp:531
double goalBias_
The fraction of time the goal is picked as the state to expand towards (if such a state is available)...
Definition ATRRT.h:286
void setInitTemperature(double initTemperature)
Set the initial temperature at the beginning of the algorithm. Should be high to allow for initial ex...
Definition ATRRT.h:169
double nonfrontierCount_
The number of non-frontier nodes in the search tree.
Definition ATRRT.h:348
ATRRT(const base::SpaceInformationPtr &si)
Constructor.
Definition ATRRT.cpp:44
double getGoalBias() const
Get the goal bias the planner is using.
Definition ATRRT.h:114
void setNearestNeighbors()
Set a different nearest neighbors datastructure.
Definition ATRRT.h:211
bool transitionTest(const base::Cost &motionCost)
Filter irrelevant configuration regarding the search of low-cost paths before inserting into tree.
Definition ATRRT.cpp:401
void freeMemory()
Free the memory allocated by this planner.
Definition ATRRT.cpp:132
bool minExpansionControl(double randMotionDistance)
Use ratio to prefer frontier nodes to nonfrontier ones.
Definition ATRRT.cpp:428
double getFrontierThreshold() const
Get the distance between a new state and the nearest neighbor that qualifies that state as being a fr...
Definition ATRRT.h:190
void setRange(double distance)
Set the range the planner is supposed to use.
Definition ATRRT.h:124
base::StateSamplerPtr sampler_
State sampler.
Definition ATRRT.h:279
double temp_
Temperature parameter used to control the difficulty level of transition tests. Low temperatures limi...
Definition ATRRT.h:316
double neighborhoodRadiusFactor_
Factor of maxDistance_ used to calculate neighborhood radius TODO: temporary solution.
Definition ATRRT.h:344
base::Cost bestCost_
The most desirable (e.g., minimum) cost value in the search tree.
Definition ATRRT.h:319
double maxDistance_
The maximum length of a motion to be added to a tree.
Definition ATRRT.h:289
void getPlannerData(base::PlannerData &data) const override
Get information about the current run of the motion planner. Repeated calls to this function will upd...
Definition ATRRT.cpp:380
void setFrontierThreshold(double frontier_threshold)
Set the distance between a new state and the nearest neighbor that qualifies that state as being a fr...
Definition ATRRT.h:183
void clear() override
Clear all internal datastructures. Planner settings are not affected. Subsequent calls to solve() wil...
Definition ATRRT.cpp:75
base::Cost costThreshold_
All motion costs must be better than this cost (default is infinity).
Definition ATRRT.h:325
double frontierCount_
The number of frontier nodes in the search tree.
Definition ATRRT.h:350
base::PlannerStatus solve(const base::PlannerTerminationCondition &plannerTerminationCondition) override
Function that can solve the motion planning problem. This function can be called multiple times on th...
Definition ATRRT.cpp:148
double getRange() const
Get the range the planner is using.
Definition ATRRT.h:130
double getTempChangeFactor() const
Get the factor by which the temperature rises based on current acceptance/rejection rate.
Definition ATRRT.h:146
RNG rng_
The random number generator.
Definition ATRRT.h:292
double frontierNodeRatio_
Target ratio of non-frontier nodes to frontier nodes. rho.
Definition ATRRT.h:355
double initTemperature_
The initial value of temp_.
Definition ATRRT.h:332
void setFrontierNodeRatio(double frontierNodeRatio)
Set the ratio between adding nonfrontier nodes to frontier nodes, for example .1 is 1/10 or one nonfr...
Definition ATRRT.h:197
double tempChangeFactor_
The value of the expression exp^T_rate. The temperature is increased by this factor whenever the tran...
Definition ATRRT.h:329
void setup() override
Perform extra configuration steps, if needed. This call will also issue a call to ompl::base::SpaceIn...
Definition ATRRT.cpp:92
std::vector< ompl::geometric::ATRRT::Motion * > computeDijkstraLowestCostPath(Motion *a, Motion *b)
Compute lowest-cost path in graph between two motions.
Definition ATRRT.cpp:489
void setCostThreshold(double maxCost)
Set the cost threshold (default is infinity). Any motion cost that is not better than this cost (acco...
Definition ATRRT.h:154
std::shared_ptr< NearestNeighbors< Motion * > > nearestNeighbors_
A nearest-neighbors datastructure containing the tree of motions.
Definition ATRRT.h:282
void addUsefulCycles(Motion *newMotion, Motion *nearMotion)
improve solution found by TRRT
Definition ATRRT.cpp:451
void addEdge(Motion *a, Motion *b)
Add bidirectional edge between two motions.
Definition ATRRT.cpp:483
void setTempChangeFactor(double factor)
Set the factor by which the temperature is increased after a failed transition test....
Definition ATRRT.h:140
double gamma_
Constant derived from the free space volume.
Definition ATRRT.h:340
#define OMPL_WARN(fmt,...)
Log a formatted warning string.
Definition Console.h:66
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.
A class to store the exit status of Planner::solve().
bool stating which motion cost is better
Definition ATRRT.h:299