Loading...
Searching...
No Matches
SearchQueue.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, Marlin Strub */
36
37#ifndef OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BITSTAR_SEARCHQUEUE_
38#define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BITSTAR_SEARCHQUEUE_
39
40#include <array>
41#include <functional>
42#include <map>
43#include <unordered_map>
44#include <utility>
45#include <vector>
46
47#include "ompl/base/Cost.h"
48#include "ompl/base/OptimizationObjective.h"
49#include "ompl/datastructures/BinaryHeap.h"
50#include "ompl/datastructures/NearestNeighbors.h"
51#include "ompl/geometric/planners/informedtrees/BITstar.h"
52
53namespace ompl
54{
55 namespace geometric
56 {
62
65 {
66 public:
67 // ---
68 // Aliases.
69 // ---
70
72 using SortKey = std::array<ompl::base::Cost, 3u>;
73
75 using SortKeyAndVertexPtrPair = std::pair<SortKey, VertexPtrPair>;
76
79 std::function<bool(const SortKeyAndVertexPtrPair &, const SortKeyAndVertexPtrPair &)>;
80
83
85 using EdgeQueueElemPtr = EdgeQueue::Element *;
86
88 using EdgeQueueElemPtrVector = std::vector<EdgeQueueElemPtr>;
89
90 // ---
91 // Construction, initialization, and destruction.
92 // ---
93
95 SearchQueue(NameFunc nameFunc);
96
98 virtual ~SearchQueue() = default;
99
101 void setup(CostHelper *costHelpPtr, ImplicitGraph *graphPtr);
102
104 void reset();
105
107 void enableCascadingRewirings(bool enable);
108
109 // ---
110 // Insertion.
111 // ---
112
114 void insertOutgoingEdges(const VertexPtr &vertex);
115
118
121
123 void addToInconsistentSet(const VertexPtr &vertex);
124
125 // ---
126 // Access.
127 // ---
128
131
134
137
138 // ---
139 // Modification.
140 // ---
141
145 void clear();
146
149
151 void rebuildEdgeQueue();
152
154 void update(const EdgeQueueElemPtr elementPtr);
155
157 void setInflationFactor(double factor);
158
160 void registerSolutionCost(const ompl::base::Cost &solutionCost);
161
164
167
170
172 void removeFromInconsistentSet(const VertexPtr &vertex);
173
174 // ---
175 // Information access.
176 // ---
177
179 double getInflationFactor() const;
180
182 std::shared_ptr<const unsigned int> getSearchId() const;
183
186 bool canPossiblyImproveCurrentSolution(const VertexPtr &state) const;
187
190 bool canPossiblyImproveCurrentSolution(const VertexPtrPair &edge) const;
191
193 unsigned int numEdges();
194
198 bool isEmpty();
199
201 void getEdges(VertexConstPtrPairVector *edgeQueue);
202
204 unsigned int numEdgesPopped() const;
205
206 private:
207 // ---
208 // High level primitives.
209 // ---
210
212 void enqueueEdges(const VertexPtr &parent, const VertexPtrVector &possibleChildren);
213
215 void enqueueEdgeConditionally(const VertexPtr &parent, const VertexPtr &child);
216
219 void enqueueEdge(const VertexPtrPair &edge);
220
221 // ---
222 // Sorting.
223 // ---
224
226 SortKey createSortKey(const VertexPtrPair &edge) const;
227
230 bool lexicographicalBetterThan(const std::array<ompl::base::Cost, 3> &lhs,
231 const std::array<ompl::base::Cost, 3> &rhs) const;
232
233 // ---
234 // Debug helpers.
235 // ---
236
238 void assertSetup() const;
239
240 // ---
241 // Member variables (Make all are configured in setup() and reset in reset()).
242 // ---
243
245 NameFunc nameFunc_;
246
248 bool isSetup_{false};
249
251 bool isCascadingOfRewiringsEnabled_{false};
252
255 CostHelper *costHelpPtr_{nullptr};
256
258 ImplicitGraph *graphPtr_{nullptr};
259
261 EdgeQueue edgeQueue_;
262
264 VertexPtrVector inconsistentVertices_;
265
267 double inflationFactor_{1.0};
268
271 ompl::base::Cost solutionCost_{std::numeric_limits<double>::infinity()};
272
274 bool hasExactSolution_{false};
275
278 const std::shared_ptr<unsigned int> searchId_;
279
282 unsigned int numEdgesPopped_{0u};
283
284 }; // class SearchQueue
285 } // namespace geometric
286} // namespace ompl
287#endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_BITSTAR_SEARCHQUEUE_
This class provides an implementation of an updatable min-heap. Using it is a bit cumbersome,...
Definition BinaryHeap.h:53
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition Cost.h:48
A helper class to handle the various heuristic functions in one place.
Definition CostHelper.h:69
A conceptual representation of samples as an edge-implicit random geometric graph.
A queue of edges, sorted according to a sort key.
Definition SearchQueue.h:65
void reset()
Reset the queue to the state of construction.
VertexPtrPair popFrontEdge()
Pop the best edge off the queue, removing it from the front of the edge queue in the process.
void insertOutgoingEdges(const VertexPtr &vertex)
Update the edge queue by adding all the potential edges from the vertex to nearby states.
virtual ~SearchQueue()=default
Destruct the search queue using the default deconstructor.
double getInflationFactor() const
Get the cost-to-go inflation factor.
void enableCascadingRewirings(bool enable)
Set whether cascading of rewirings is enabled.
void rebuildEdgeQueue()
Update all the sort keys of the edges in the queue and resort.
bool isEmpty()
Returns true if the queue is empty. In the case where the edge queue is empty but the vertex queue is...
std::array< ompl::base::Cost, 3u > SortKey
A triplet of costs, i.e., the edge queue sorting key.
Definition SearchQueue.h:72
VertexPtrPair getFrontEdge()
Get the best edge on the queue, leaving it at the front of the edge queue.
void removeInEdgesConnectedToVertexFromQueue(const VertexPtr &vertex)
Erase all edges in the edge queue that lead to the given vertex.
ompl::BinaryHeap< SortKeyAndVertexPtrPair, EdgeComparisonFunction > EdgeQueue
The underlying edge queue. Using static keys for the same reason as the Vertex Queue.
Definition SearchQueue.h:82
bool canPossiblyImproveCurrentSolution(const VertexPtr &state) const
The condition used to insert vertices into the queue. Compares lowerBoundHeuristicVertex to the given...
std::shared_ptr< const unsigned int > getSearchId() const
Allow access to the current search id.
void clear()
Finish the queue if it is sorted, if not resort the queue. Finishing the queue clears all the edge co...
void insertOutgoingEdgesOfStartVertices()
Insert the outgoing edges of all start vertices.
unsigned int numEdges()
Returns the number of edges in the queue. Will resort/expand the queue if necessary.
void insertOutgoingEdgesOfInconsistentVertices()
Insert the outgoing edges of all inconsistent vertices.
void registerSolutionCost(const ompl::base::Cost &solutionCost)
Mark that a solution has been found.
SortKey getFrontEdgeValue()
Get the value of the best edge on the queue, leaving it at the front of the edge queue.
void addToInconsistentSet(const VertexPtr &vertex)
Add a vertex to the set of inconsistent vertices.
void removeFromInconsistentSet(const VertexPtr &vertex)
Remove a vertex from the set of inconsistent vertices.
void removeOutEdgesConnectedToVertexFromQueue(const VertexPtr &vertex)
Erase all edges in the edge queue that leave from the given vertex.
unsigned int numEdgesPopped() const
The number of edges popped off the queue for processing (numEdgesPopped_).
void setInflationFactor(double factor)
Set the cost-to-go inflation factor.
SearchQueue(NameFunc nameFunc)
Construct a search queue. It must be setup before use.
std::vector< EdgeQueueElemPtr > EdgeQueueElemPtrVector
A vector of edge queue pointers.
Definition SearchQueue.h:88
void removeAllEdgesConnectedToVertexFromQueue(const VertexPtr &vertex)
Erase all edges in the edge queue that are connected to the given vertex.
std::function< bool(const SortKeyAndVertexPtrPair &, const SortKeyAndVertexPtrPair &)> EdgeComparisonFunction
The function signature of the sorting function for the Edge Queue.
Definition SearchQueue.h:78
EdgeQueue::Element * EdgeQueueElemPtr
An element pointer into the edge queue binary heap.
Definition SearchQueue.h:85
void getEdges(VertexConstPtrPairVector *edgeQueue)
Get a copy of the edge queue. This is expensive and is only meant for animations/debugging.
void update(const EdgeQueueElemPtr elementPtr)
Update the sort key of a particular edge and its position in the queue.
std::pair< SortKey, VertexPtrPair > SortKeyAndVertexPtrPair
The data stored in the edge-queue binary heap.
Definition SearchQueue.h:75
void clearInconsistentSet()
Clear the set of inconsistent vertices.
std::vector< VertexPtr > VertexPtrVector
A vector of shared pointers to vertices.
Definition BITstar.h:125
std::pair< VertexPtr, VertexPtr > VertexPtrPair
A pair of vertices, i.e., an edge.
Definition BITstar.h:134
std::shared_ptr< Vertex > VertexPtr
A shared pointer to a vertex.
Definition BITstar.h:116
void setup() override
Setup the algorithm.
Definition BITstar.cpp:168
std::vector< VertexConstPtrPair > VertexConstPtrPairVector
A vector of pairs of const vertices, i.e., a vector of edges.
Definition BITstar.h:143
std::function< std::string()> NameFunc
A utility functor for ImplicitGraph and SearchQueue.
Definition BITstar.h:149
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.