Loading...
Searching...
No Matches
Vertex.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/**********************************************************************
36 * Attribution Notice:
37 *
38 * This file contains code partially derived from the AIT* or BIT* planner
39 * in the Open Motion Planning Library (OMPL). Structural elements such as
40 * vertex representation and basic parent–child relationships were adapted
41 * from that planner.
42 *
43 * Additional modifications and new logic for the BLIT* planner were
44 * independently developed by Yi Wang.
45 *********************************************************************/
46
47// Authors: Yi Wang, Eyal Weiss, Bingxian Mu, Oren Salzman
48
49#ifndef OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BLITSTAR_VERTEX_
50#define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BLITSTAR_VERTEX_
51
52#include <memory>
53#include <vector>
54
55#include "ompl/base/OptimizationObjective.h"
56#include "ompl/base/ProblemDefinition.h"
57#include "ompl/base/ScopedState.h"
58#include "ompl/base/SpaceInformation.h"
59#include "ompl/base/State.h"
60#include "ompl/datastructures/BinaryHeap.h"
61
62#include "ompl/geometric/planners/lazyinformedtrees/blitstar/Queuetypes.h"
63
64namespace ompl
65{
66 namespace geometric
67 {
68 namespace blitstar
69 {
70 class Vertex : public std::enable_shared_from_this<Vertex>
71 {
72 public:
74 Vertex(const ompl::base::SpaceInformationPtr &spaceInformation,
75 const ompl::base::ProblemDefinitionPtr &problemDefinition, const std::size_t &batchId);
76
78 explicit Vertex(const std::shared_ptr<Vertex> &other);
79
81 virtual ~Vertex();
82
84 std::size_t getId() const;
85
88
90 ompl::base::State const *getState() const;
91
94
97
100
103
106
109
112 ompl::base::Cost getValidReverseEdgeCost() const;
113
115 void resetForwardParent();
116 void resetReverseParent();
117 void resetForwardEdgeParent();
118 void resetReverseEdgeParent();
119
121 bool hasForwardParent() const;
122 bool hasReverseParent() const;
123 bool hasReverseEdgeParent() const;
124 bool hasForwardEdgeParent() const;
125
127 std::shared_ptr<Vertex> getForwardParent() const;
128 std::shared_ptr<Vertex> getForwardEdgeParent() const;
129
131 std::shared_ptr<Vertex> getReverseParent() const;
132 std::shared_ptr<Vertex> getReverseEdgeParent() const;
133
135 void setForwardEdgeCost(const ompl::base::Cost &cost);
136
139
141 void setCostToComeFromGoal(const ompl::base::Cost &cost);
142
144 void setCostToGoToGoal(const ompl::base::Cost &cost);
145
147 void setCostToGoToStart(const ompl::base::Cost &cost);
148
150 void addToForwardChildren(const std::shared_ptr<Vertex> &vertex);
151
153 void removeFromForwardChildren(std::size_t vertexId);
154
156 std::vector<std::shared_ptr<Vertex>> getForwardChildren() const;
157
159 void addToReverseChildren(const std::shared_ptr<Vertex> &vertex);
160
162 void removeFromReverseChildren(std::size_t vertexId);
163
165 std::vector<std::shared_ptr<Vertex>> getReverseChildren() const;
166
168 void whitelistAsChild(const std::shared_ptr<Vertex> &vertex) const;
169
171 bool isWhitelistedAsChild(const std::shared_ptr<Vertex> &vertex) const;
172
174 void blacklistAsChild(const std::shared_ptr<Vertex> &vertex) const;
175
176 std::size_t getIncomingCollisionCheckResolution(const std::size_t vertexId) const;
177
178 void setIncomingCollisionCheckResolution(const std::size_t vertexId, std::size_t numChecks) const;
180 bool isBlacklistedAsChild(const std::shared_ptr<Vertex> &vertex) const;
181
183 bool hasCachedNeighbors() const;
185 void cacheNeighbors(const std::vector<std::shared_ptr<Vertex>> &neighbors) const;
186
188 const std::vector<std::shared_ptr<Vertex>> getNeighbors() const;
189
191 bool isGoal();
192 void setMeet();
193 bool isStart();
194 bool meetVertex();
195
197 bool nearObstacle();
198 void setGoalVertex();
199 bool forwardInvalid();
200 bool reverseInvalid();
201
203 void setStartVertex();
204 void setNearObstacle();
205 void setForwardInvalid();
206 void setReverseInvalid();
207
209 void setReverseExpanded();
210 void setForwardExpanded();
211
213 bool isForwardExpanded();
214 bool isReverseExpanded();
215
217 std::size_t getForwardId();
218 std::size_t getReverseId();
219
222 ompl::base::Cost getLowerCostBoundToStart();
223
225 void setForwardId(const std::size_t counter);
226 void setReverseId(const std::size_t counter);
227
229 void setLowerCostBoundToGoal(const ompl::base::Cost &ToGoal);
230 void setLowerCostBoundToStart(const ompl::base::Cost &ToStart);
231
233 void resetMeet();
234 void resetNearObstacle();
235 void resetBackwardParent();
236 void resetForwardId();
237 void resetReverseId();
238 void resetForwardInvalid();
239 void resetReverseInvalid();
240 void resetForwardExpanded();
241 void resetReverseExpanded();
242 void resetCostToComeFromGoal();
243 void resetCostToComeFromStart();
244
247 void resetReverseVertexQueuePointer();
248
250 typename VertexQueue::Element *getForwardVertexQueuePointer() const;
251 typename VertexQueue::Element *getReverseVertexQueuePointer() const;
253 void setForwardVertexQueuePointer(typename VertexQueue::Element *pointer);
254 void setReverseVertexQueuePointer(typename VertexQueue::Element *pointer);
255
257 void setForwardValidParent(const std::shared_ptr<Vertex> &vertex, const ompl::base::Cost &edgeCost);
258 void setReverseValidParent(const std::shared_ptr<Vertex> &vertex, const ompl::base::Cost &edgeCost);
259
261 void setReverseVertexParent(const std::shared_ptr<Vertex> &vertex, const ompl::base::Cost &edgeCost);
262 void setForwardVertexParent(const std::shared_ptr<Vertex> &vertex, const ompl::base::Cost &edgeCost);
263
264 private:
266 const ompl::base::SpaceInformationPtr spaceInformation_;
267
269 const ompl::base::ProblemDefinitionPtr problemDefinition_;
270
272 const ompl::base::OptimizationObjectivePtr objective_;
273
275 std::vector<std::weak_ptr<Vertex>> forwardChildren_{};
276 std::vector<std::weak_ptr<Vertex>> reverseChildren_{};
277
279 mutable std::vector<std::weak_ptr<Vertex>> neighbors_{};
280
282 mutable std::vector<std::weak_ptr<Vertex>> whitelistedChildren_{};
283
285 mutable std::vector<std::weak_ptr<Vertex>> blacklistedChildren_{};
286
288 std::weak_ptr<Vertex> forwardParent_;
289 std::weak_ptr<Vertex> forwardEdgeParent_;
290
292 std::weak_ptr<Vertex> reverseParent_;
293 std::weak_ptr<Vertex> reverseEdgeParent_;
294
296 ompl::base::State *state_;
297
299 mutable ompl::base::Cost costToComeFromStart_{0u};
300 mutable ompl::base::Cost costToComeFromGoal_{0u};
301
303 ompl::base::Cost lowerCostBoundToGoToGoal_{0u};
304 ompl::base::Cost lowerCostBoundToGoToStart_{0u};
305
307 ompl::base::Cost edgeCostFromForwardParent_{0u};
308 ompl::base::Cost edgeCostFromBackwardParent_{0u};
309
311 ompl::base::Cost edgeCostFromValidForwardParent_{0u};
312 ompl::base::Cost edgeCostFromValidReverseParent_{0u};
313
315 mutable ompl::base::Cost expandedCostToComeFromGoal_{0u};
316 mutable ompl::base::Cost expandedCostToComeFromStart_{0u};
317
320 mutable ompl::base::Cost costToGoToGoal_{0u};
321
324 mutable ompl::base::Cost costToGoToStart_{0u};
325
327 mutable ompl::base::Cost totalEstimateCost_{0u};
328
330 bool goalVertex_{false};
331 bool meetVertex_{false};
332 bool startVertex_{false};
333
335 bool nearObstacle_{false};
336
338 const std::size_t vertexId_;
339
341 const std::size_t &batchId_;
342
344 bool IsForwardExpanded_{false};
345 bool IsReverseExpanded_{false};
346
348 std::size_t ForwardVersion_{0};
349 std::size_t ReverseVersion_{0};
350
352 bool forwardInvalidChildState_{false};
353 bool reverseInvalidChildState_{false};
354
356 mutable std::size_t neighborBatchId_{0u};
357
359 mutable std::size_t forwardVertexQueuePointerId_{0u};
360 mutable std::size_t reverseVertexQueuePointerId_{0u};
361
362 mutable std::map<std::size_t, std::size_t> incomingCollisionCheckResolution_{};
364 mutable typename VertexQueue::Element *reverseVertexQueuePointer_{nullptr};
365 mutable typename VertexQueue::Element *forwardVertexQueuePointer_{nullptr};
366 };
367
368 } // namespace blitstar
369
370 } // namespace geometric
371
372} // namespace ompl
373
374#endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BLITSTAR_VERTEX_
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition Cost.h:48
Definition of a scoped state.
Definition ScopedState.h:57
Definition of an abstract state.
Definition State.h:50
void whitelistAsChild(const std::shared_ptr< Vertex > &vertex) const
Whitelists a child.
Definition Vertex.cpp:504
ompl::base::State * getState()
Provides write access to the underlying state.
Definition Vertex.cpp:116
void setCostToComeFromStart(const ompl::base::Cost &cost)
Sets the cost to come to this vertex.
Definition Vertex.cpp:255
bool isForwardExpanded()
Check whether a state is expanded.
Definition Vertex.cpp:342
bool isBlacklistedAsChild(const std::shared_ptr< Vertex > &vertex) const
Returns whether a child is blacklisted.
Definition Vertex.cpp:557
void setCostToGoToGoal(const ompl::base::Cost &cost)
Sets the cost to go To goal heuristic of this vertex.
Definition Vertex.cpp:318
void blacklistAsChild(const std::shared_ptr< Vertex > &vertex) const
Blacklists a child.
Definition Vertex.cpp:552
void setCostToComeFromGoal(const ompl::base::Cost &cost)
Sets the cost to come to this vertex from the goal.
Definition Vertex.cpp:273
std::vector< std::shared_ptr< Vertex > > getForwardChildren() const
Returns this vertex's children in the forward search tree.
Definition Vertex.cpp:609
std::shared_ptr< Vertex > getReverseParent() const
Returns the parent of the vertex (in the reverse-search tree).
Definition Vertex.cpp:240
std::size_t getForwardId()
get the current search counter of a state
Definition Vertex.cpp:158
Vertex(const ompl::base::SpaceInformationPtr &spaceInformation, const ompl::base::ProblemDefinitionPtr &problemDefinition, const std::size_t &batchId)
Constructs a vertex by sampling a state.
Definition Vertex.cpp:63
bool isGoal()
set and evalue whether this vertex is a start, goal or meeting state.
Definition Vertex.cpp:136
void setLowerCostBoundToGoal(const ompl::base::Cost &ToGoal)
Set the lower-cost-bound-to-go of this vertex.
Definition Vertex.cpp:377
ompl::base::Cost getCostToComeFromStart() const
Returns the cost to come to this vertex from the start.
Definition Vertex.cpp:131
void cacheNeighbors(const std::vector< std::shared_ptr< Vertex > > &neighbors) const
Caches the neighbors for the current approximation.
Definition Vertex.cpp:585
void removeFromReverseChildren(std::size_t vertexId)
Removes a vertex from this vertex's forward children.
Definition Vertex.cpp:485
void setStartVertex()
remark the state to be near obstalce.
Definition Vertex.cpp:149
ompl::base::Cost getEdgeCostFromReverseParent() const
Returns the edge cost from the reverse parent.
Definition Vertex.cpp:205
bool isWhitelistedAsChild(const std::shared_ptr< Vertex > &vertex) const
Returns whether a child is whitelisted.
Definition Vertex.cpp:509
ompl::base::Cost getLowerCostBoundToGoal()
Set the the lower bound of the estimated heuristic value.
Definition Vertex.cpp:387
std::vector< std::shared_ptr< Vertex > > getReverseChildren() const
Returns this vertex's children in the reverse search tree.
Definition Vertex.cpp:620
void setForwardEdgeCost(const ompl::base::Cost &cost)
Sets the cost to come to this vertex.
Definition Vertex.cpp:250
VertexQueue::Element * getForwardVertexQueuePointer() const
Returns the reverse queue pointer of this vertex.
Definition Vertex.cpp:659
bool hasForwardParent() const
Returns whether this vertex has a parent in either search.
Definition Vertex.cpp:210
void setForwardValidParent(const std::shared_ptr< Vertex > &vertex, const ompl::base::Cost &edgeCost)
Sets the valid parent vertex (in a valid path).
Definition Vertex.cpp:392
void addToForwardChildren(const std::shared_ptr< Vertex > &vertex)
Adds a vertex to this vertex's forward children.
Definition Vertex.cpp:456
void setForwardVertexQueuePointer(typename VertexQueue::Element *pointer)
Sets the reverse queue pointer of this vertex.
Definition Vertex.cpp:643
virtual ~Vertex()
Destructs the vertex.
Definition Vertex.cpp:105
void setForwardId(const std::size_t counter)
Set the current search counter.
Definition Vertex.cpp:154
ompl::base::Cost getCostToGoToGoal() const
Returns the cost to go heuristic from this vertex.
Definition Vertex.cpp:185
void removeFromForwardChildren(std::size_t vertexId)
Removes a vertex from this vertex's forward children.
Definition Vertex.cpp:461
ompl::base::ScopedState getScopedState() const
Returns a scoped copy of the underlying state.
Definition Vertex.cpp:126
ompl::base::Cost getCostToComeFromGoal() const
Returns the cost to come to this vertex from the goal.
Definition Vertex.cpp:180
bool hasCachedNeighbors() const
Returns whether the vertex knows its nearest neighbors on the current approximation.
Definition Vertex.cpp:580
const std::vector< std::shared_ptr< Vertex > > getNeighbors() const
Returns the nearest neighbors, throws if not up to date.
Definition Vertex.cpp:592
void resetForwardParent()
Resets associated parents of this vertex.
Definition Vertex.cpp:408
void setCostToGoToStart(const ompl::base::Cost &cost)
Sets the cost to go To start heuristic of this vertex.
Definition Vertex.cpp:323
std::size_t getId() const
Get the unique id of this vertex.
Definition Vertex.cpp:111
void setReverseExpanded()
Sets wether this vertex is expanded.
Definition Vertex.cpp:362
bool nearObstacle()
whether a state is near obstalce
Definition Vertex.cpp:333
void resetForwardVertexQueuePointer()
Resets the reverse queue pointer.
Definition Vertex.cpp:682
void addToReverseChildren(const std::shared_ptr< Vertex > &vertex)
Adds a vertex this vertex's children.
Definition Vertex.cpp:480
std::shared_ptr< Vertex > getForwardParent() const
Returns the parent of the vertex (in the forward-search tree).
Definition Vertex.cpp:220
void resetMeet()
Resets the value of aforementioned values.
Definition Vertex.cpp:260
void setReverseVertexParent(const std::shared_ptr< Vertex > &vertex, const ompl::base::Cost &edgeCost)
Sets the parent vertex (in the reverse or forward -search tree).
Definition Vertex.cpp:432
ompl::base::Cost getValidForwardEdgeCost() const
Returns the valid edge cost from the forward and backward tree on a valid path.
Definition Vertex.cpp:195
ompl::base::Cost getEdgeCostFromForwardParent() const
Returns the edge cost from the forward parent.
Definition Vertex.cpp:190
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.