ReverseQueue.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_REVERSE_QUEUE_
38 #define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_REVERSE_QUEUE_
39 
40 #include <array>
41 #include <map>
42 #include <tuple>
43 
44 #include "ompl/base/Cost.h"
45 #include "ompl/base/samplers/InformedStateSampler.h"
46 #include "ompl/datastructures/BinaryHeap.h"
47 #include "ompl/datastructures/NearestNeighbors.h"
48 
49 #include "ompl/geometric/planners/informedtrees/eitstar/Direction.h"
50 #include "ompl/geometric/planners/informedtrees/eitstar/Edge.h"
51 #include "ompl/geometric/planners/informedtrees/eitstar/Vertex.h"
52 
53 namespace ompl
54 {
55  namespace geometric
56  {
57  namespace eitstar
58  {
59  class ReverseQueue
60  {
61  public:
63  ReverseQueue(const std::shared_ptr<const ompl::base::OptimizationObjective> &objective,
64  const std::shared_ptr<const ompl::base::StateSpace> &space, const bool isQueueCostOrdered);
65 
67  ~ReverseQueue() = default;
68 
70  bool empty() const;
71 
73  std::size_t size() const;
74 
76  void insertOrUpdate(const Edge &edge);
77 
79  void insertOrUpdate(const std::vector<Edge> &edges);
80 
82  const Edge &peek() const;
83 
85  unsigned int peekEffort() const;
86 
88  Edge pop();
89 
91  void setCostQueueOrder(const bool isQueueCostOrdered);
92 
95 
97  void clear();
98 
100  std::vector<Edge> getEdges() const;
101 
103  void rebuild();
104 
106  void removeOutgoingEdges(const std::shared_ptr<Vertex> &vertex);
107 
109  unsigned int computeAdmissibleSolutionEffort(const Edge &edge) const;
110 
112  ompl::base::Cost computeAdmissibleSolutionCost(const Edge &edge) const;
113 
114  private:
115  using HeapElement = std::tuple<ompl::base::Cost, ompl::base::Cost, unsigned int, unsigned int, Edge>;
116  using CostEffortHeap =
117  ompl::BinaryHeap<HeapElement, std::function<bool(const HeapElement &, const HeapElement &)>>;
118 
120  bool updateIfExists(const Edge &edge);
121 
123  ompl::base::Cost computeAdmissibleCostToComeToTarget(const Edge &edge) const;
124 
126  unsigned int computeInadmissibleSolutionEffort(const Edge &edge) const;
127 
129  std::function<bool(const HeapElement &, const HeapElement &)> getCostComparisonOperator() const;
130 
132  std::function<bool(const HeapElement &, const HeapElement &)> getEffortComparisonOperator() const;
133 
135  bool isQueueCostOrdered_;
136 
138  std::shared_ptr<const ompl::base::OptimizationObjective> objective_;
139 
141  std::shared_ptr<const ompl::base::StateSpace> space_;
142 
144  CostEffortHeap queue_;
145  };
146  } // namespace eitstar
147 
148  } // namespace geometric
149 
150 } // namespace ompl
151 
152 #endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_REVERSE_QUEUE_
ompl::base::Cost getLowerBoundOnOptimalSolutionCost() const
Returns a lower bound on the resolution-optimal solution cost.
std::vector< Edge > getEdges() const
Copies all edges into a vector and returns the vector.
void clear()
Clears the queue, i.e., deletes all elements from it.
void setCostQueueOrder(const bool isQueueCostOrdered)
Updates the queue ordering depending on the given suboptimality factor.
Edge pop()
Returns and deletes the top element of the queue.
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:111
unsigned int peekEffort() const
Get the effort corresponding to the top edge of the queue.
This class provides an implementation of an updatable min-heap. Using it is a bit cumbersome,...
Definition: BinaryHeap.h:84
void removeOutgoingEdges(const std::shared_ptr< Vertex > &vertex)
Removes the outgoing edges of a vertex from the queue.
ompl::base::Cost computeAdmissibleSolutionCost(const Edge &edge) const
Returns the admissible total potential solution cost of an edge.
~ReverseQueue()=default
Destructs this queue.
void insertOrUpdate(const Edge &edge)
Inserts or updates an element in the queue.
const Edge & peek() const
Get a reference to the top edge in the queue.
unsigned int computeAdmissibleSolutionEffort(const Edge &edge) const
Returns the admissible total potential effort of an edge.
std::size_t size() const
Returns the number of elements in the queue.
void rebuild()
Rebuilds the queue.
bool empty() const
Returns whether the queue is empty.
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
ReverseQueue(const std::shared_ptr< const ompl::base::OptimizationObjective > &objective, const std::shared_ptr< const ompl::base::StateSpace > &space, const bool isQueueCostOrdered)
Constructs the queue with the given optimization objective and state space.