Loading...
Searching...
No Matches
Vertex.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_VERTEX_
38#define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_VERTEX_
39
40#include <memory>
41#include <vector>
42
43#include "ompl/base/Cost.h"
44#include "ompl/base/OptimizationObjective.h"
45#include "ompl/datastructures/BinaryHeap.h"
46
47#include "ompl/geometric/planners/informedtrees/eitstar/Direction.h"
48#include "ompl/geometric/planners/informedtrees/eitstar/Edge.h"
49
50namespace ompl
51{
52 namespace geometric
53 {
54 namespace eitstar
55 {
56 // Forward declare the EIT* state class.
57 class State;
58
60 class Vertex : public std::enable_shared_from_this<Vertex> // Inheritance must be public here.
61 {
62 public:
64 Vertex(const std::shared_ptr<State> &state,
65 const std::shared_ptr<ompl::base::OptimizationObjective> &objective, const Direction &direction);
66
68 ~Vertex();
69
71 std::size_t getId() const;
72
74 std::shared_ptr<State> getState() const;
75
77 const std::vector<std::shared_ptr<Vertex>> &getChildren() const;
78
80 bool hasChildren() const;
81
83 std::vector<std::shared_ptr<Vertex>>
84 updateCurrentCostOfChildren(const std::shared_ptr<ompl::base::OptimizationObjective> &objective);
85
87 void addChild(const std::shared_ptr<Vertex> &vertex);
88
90 void removeChild(const std::shared_ptr<Vertex> &vertex);
91
93 std::weak_ptr<Vertex> getParent() const;
94
96 bool isParent(const std::shared_ptr<Vertex> &vertex) const;
97
100 std::weak_ptr<Vertex> getTwin() const;
101
103 void updateParent(const std::shared_ptr<Vertex> &vertex);
104
106 void setEdgeCost(const ompl::base::Cost &edgeCost);
107
110
112 void resetParent();
113
116 void setTwin(const std::shared_ptr<Vertex> &vertex);
117
119 void clearChildren();
120
122 std::size_t getExpandTag() const;
123
125 void registerExpansionInReverseSearch(std::size_t tag);
126
128 void callOnBranch(const std::function<void(const std::shared_ptr<eitstar::State> &)> &function);
129
130 private:
132 const std::size_t id_;
133
135 const std::shared_ptr<const ompl::base::OptimizationObjective> objective_;
136
138 ompl::base::Cost edgeCost_{std::numeric_limits<double>::signaling_NaN()};
139
141 std::weak_ptr<Vertex> parent_{};
142
145 std::weak_ptr<Vertex> twin_{};
146
148 std::vector<std::shared_ptr<Vertex>> children_{};
149
151 std::size_t expandTag_{0u};
152
154 const std::shared_ptr<State> state_;
155
157 const Direction direction_;
158
161 friend class ReverseQueue;
162
165 mutable std::vector<ompl::BinaryHeap<
166 std::tuple<ompl::base::Cost, ompl::base::Cost, unsigned int, unsigned int, Edge>,
167 std::function<bool(
168 const std::tuple<ompl::base::Cost, ompl::base::Cost, unsigned int, unsigned int, Edge> &,
169 const std::tuple<ompl::base::Cost, ompl::base::Cost, unsigned int, unsigned int, Edge> &)>>::
170 Element *>
171 outgoingReverseQueueLookup_;
172 };
173
174 } // namespace eitstar
175
176 } // namespace geometric
177
178} // namespace ompl
179
180#endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_QUEUE_
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 wrapper class for OMPL's state.
Definition State.h:58
void callOnBranch(const std::function< void(const std::shared_ptr< eitstar::State > &)> &function)
Recursively calls the given function on this vertex and all its children in the tree.
Definition Vertex.cpp:216
const std::vector< std::shared_ptr< Vertex > > & getChildren() const
Returns the children of this vertex.
Definition Vertex.cpp:95
ompl::base::Cost getEdgeCost() const
Returns the cost of the edge in the forward tree that leads to this vertex.
Definition Vertex.cpp:171
friend class ReverseQueue
The edge queue is a friend class to allow efficient updates of outgoing edges of this vertex in the q...
Definition Vertex.h:161
std::weak_ptr< Vertex > getTwin() const
Returns the twin of this vertex, i.e., the vertex in the other search tree with the same underlying s...
Definition Vertex.cpp:161
void resetParent()
Returns the parent of this vertex.
Definition Vertex.cpp:191
void setEdgeCost(const ompl::base::Cost &edgeCost)
Sets the cost of the edge in the forward tree that leads to this vertex.
Definition Vertex.cpp:166
void addChild(const std::shared_ptr< Vertex > &vertex)
Adds the given vertex to this vertex's children.
Definition Vertex.cpp:121
void removeChild(const std::shared_ptr< Vertex > &vertex)
Removes the given vertex from this vertex's children.
Definition Vertex.cpp:129
void updateParent(const std::shared_ptr< Vertex > &vertex)
Resets the parent of this vertex.
Definition Vertex.cpp:176
std::size_t getExpandTag() const
Returns the tag when this vertex was last expanded.
Definition Vertex.cpp:206
std::vector< std::shared_ptr< Vertex > > updateCurrentCostOfChildren(const std::shared_ptr< ompl::base::OptimizationObjective > &objective)
Update the cost-to-come of this vertex's children.
Definition Vertex.cpp:106
std::shared_ptr< State > getState() const
Returns the state associated with this vertex.
Definition Vertex.cpp:90
void setTwin(const std::shared_ptr< Vertex > &vertex)
Sets the twin of this vertex, i.e., the vertex in the other search tree with the same underlying stat...
Definition Vertex.cpp:196
std::weak_ptr< Vertex > getParent() const
Returns the parent of this vertex.
Definition Vertex.cpp:146
bool hasChildren() const
Returns whether this vertex has children.
Definition Vertex.cpp:100
bool isParent(const std::shared_ptr< Vertex > &vertex) const
Returns whether the given vertex is this vertex's parent.
Definition Vertex.cpp:151
~Vertex()
Destructs this vertex.
Definition Vertex.cpp:70
Vertex(const std::shared_ptr< State > &state, const std::shared_ptr< ompl::base::OptimizationObjective > &objective, const Direction &direction)
Constructs the vertex, which must be associated with a state.
Definition Vertex.cpp:59
std::size_t getId() const
Gets the unique vertex-id of this vertex.
Definition Vertex.cpp:85
void registerExpansionInReverseSearch(std::size_t tag)
Sets the expand tag when this vertex was last expanded.
Definition Vertex.cpp:211
void clearChildren()
Resets the children of this vertex.
Definition Vertex.cpp:201
This namespace contains code that is specific to planning under geometric constraints.
Main namespace. Contains everything in this library.