Vertex.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 */
36 
37 #ifndef OMPL_GEOMETRIC_PLANNERS_BITSTAR_DATASTRUCTURES_VERTEX_
38 #define OMPL_GEOMETRIC_PLANNERS_BITSTAR_DATASTRUCTURES_VERTEX_
39 
40 //vector
41 #include <vector>
42 
43 //shared and weak pointers
44 #include <memory>
45 //For unordered sets of failed children:
46 #include <unordered_set>
47 
48 //OMPL:
49 //The space information
50 #include "ompl/base/SpaceInformation.h"
51 //The optimization objective
52 #include "ompl/base/OptimizationObjective.h"
53 
54 //I am member class of the BITstar class, so I need to include it's definition to be aware of the class BITstar. It has a forward declaration to me.
55 #include "ompl/geometric/planners/bitstar/BITstar.h"
56 
57 namespace ompl
58 {
59  namespace geometric
60  {
61 
81  {
82  public:
84  Vertex(const ompl::base::SpaceInformationPtr& si, const ompl::base::OptimizationObjectivePtr& opt, bool root = false);
85 
87  ~Vertex();
88 
90  BITstar::VertexId getId() const;
91 
94 
96  ompl::base::State const* stateConst() const;
97 
100 
102  bool isRoot() const;
103 
105  bool hasParent() const;
106 
108  bool isInTree() const;
109 
111  unsigned int getDepth() const;
112 
115 
118 
120  void addParent(const VertexPtr& newParent, const ompl::base::Cost& edgeInCost, bool updateChildCosts = true);
121 
123  void removeParent(bool updateChildCosts = true);
124 
126  bool hasChildren() const;
127 
129  void getChildrenConst(std::vector<VertexConstPtr>* children) const;
130 
132  void getChildren(std::vector<VertexPtr>* children);
133 
135  void addChild(const VertexPtr& newChild, bool updateChildCosts = true);
136 
138  void removeChild(VertexPtr oldChild, bool updateChildCosts = true);
139 
141  ompl::base::Cost getCost() const;
142 
145 
147  bool isNew() const;
148 
150  void markNew();
151 
153  void markOld();
154 
156  bool hasBeenExpandedToSamples() const;
157 
159  void markExpandedToSamples();
160 
163 
165  bool hasBeenExpandedToVertices() const;
166 
168  void markExpandedToVertices();
169 
172 
174  bool isPruned() const;
175 
177  void markPruned();
178 
180  void markUnpruned();
181 
183  void markAsFailedChild(const VertexConstPtr& failedChild);
184 
186  bool hasAlreadyFailed(const VertexConstPtr& potentialChild) const;
187 
188  protected:
190  void updateCostAndDepth(bool cascadeUpdates = true);
191 
192  private:
194  BITstar::VertexId vId_;
195 
198 
201 
203  ompl::base::State* state_;
204 
206  bool isRoot_;
207 
209  bool isNew_;
210 
212  bool hasBeenExpandedToSamples_;
213 
215  bool hasBeenExpandedToVertices_;
216 
218  bool isPruned_;
219 
221  unsigned int depth_;
222 
224  VertexPtr parentSPtr_;
225 
227  ompl::base::Cost edgeCost_;
228 
230  ompl::base::Cost cost_;
231 
233  std::vector<VertexWeakPtr> childWPtrs_;
234 
235 
237  void assertNotPruned() const;
238  }; //class: Vertex
239  } //geometric
240 } //ompl
241 #endif //OMPL_GEOMETRIC_PLANNERS_BITSTAR_DATASTRUCTURES_VERTEX_
242 
bool isNew() const
Returns true if the vertex is marked as new. Vertices are new until marked old.
Definition: Vertex.cpp:387
bool hasBeenExpandedToVertices() const
Returns true if the vertex has been expanded towards vertices.
Definition: Vertex.cpp:441
void markAsFailedChild(const VertexConstPtr &failedChild)
Mark the given vertex as a failed connection from this vertex.
VertexConstPtr getParentConst() const
Get the parent of a vertex as a constant pointer.
Definition: Vertex.cpp:157
void markNew()
Mark the vertex as new.
Definition: Vertex.cpp:396
void markExpandedToSamples()
Mark the vertex as expanded towards samples.
Definition: Vertex.cpp:423
VertexPtr getParent()
Get the parent of a vertex as a mutable pointer.
Definition: Vertex.cpp:178
void updateCostAndDepth(bool cascadeUpdates=true)
Calculates the updated cost and depth of the current state, as well as calling all children's updateC...
Definition: Vertex.cpp:494
bool isRoot() const
Whether the vertex is root.
Definition: Vertex.cpp:116
bool hasParent() const
Get whether this vertex has a parent.
Definition: Vertex.cpp:125
bool isPruned() const
Whether the vertex has been pruned.
Definition: Vertex.cpp:468
ompl::base::State * state()
The state of a vertex as a mutable pointer.
Definition: Vertex.cpp:107
std::shared_ptr< const Vertex > VertexConstPtr
A constant vertex shared pointer.
Definition: BITstar.h:125
void addParent(const VertexPtr &newParent, const ompl::base::Cost &edgeInCost, bool updateChildCosts=true)
Set the parent of a vertex, cannot be used to replace a previous parent. Will update this vertex's co...
Definition: Vertex.cpp:199
bool hasChildren() const
Get whether this vertex has any children.
Definition: Vertex.cpp:247
void removeParent(bool updateChildCosts=true)
Remove the parent edge. Will update this vertex's cost, and can update the descendent costs...
Definition: Vertex.cpp:225
void markUnexpandedToVertices()
Mark the vertex as not expanded towards vertices.
Definition: Vertex.cpp:459
A shared pointer wrapper for ompl::base::SpaceInformation.
void markOld()
Mark the vertex as old.
Definition: Vertex.cpp:405
Definition of an abstract state.
Definition: State.h:50
ompl::base::OptimizationObjectivePtr getOpt() const
The optimization objective used by the vertex.
Definition: Vertex.cpp:89
void addChild(const VertexPtr &newChild, bool updateChildCosts=true)
Add a child vertex. Does not change this vertex's cost, and can update the child and its descendent c...
Definition: Vertex.cpp:300
void removeChild(VertexPtr oldChild, bool updateChildCosts=true)
Remove a child vertex. Does not change this vertex's cost, and can update the child and its descenden...
Definition: Vertex.cpp:316
unsigned int getDepth() const
Get the "depth" of the vertex from the root. A root vertex is at depth 0, a direct descendent of the ...
Definition: Vertex.cpp:143
The vertex of the underlying graphs in BIT*.
Definition: Vertex.h:80
void getChildrenConst(std::vector< VertexConstPtr > *children) const
Get the children of a vertex as constant pointers.
Definition: Vertex.cpp:256
A shared pointer wrapper for ompl::base::OptimizationObjective.
void markUnexpandedToSamples()
Mark the vertex as not expanded towards samples.
Definition: Vertex.cpp:432
bool hasBeenExpandedToSamples() const
Returns true if the vertex has been expanded towards samples.
Definition: Vertex.cpp:414
ompl::base::Cost getEdgeInCost() const
Get the incremental cost-to-come of a vertex.
Definition: Vertex.cpp:373
ompl::base::State const * stateConst() const
The state of a vertex as a constant pointer.
Definition: Vertex.cpp:98
bool isInTree() const
Get whether a vertex is "in the graph" or not. This returns true if the vertex is the graph root or i...
Definition: Vertex.cpp:134
void markUnpruned()
Mark the vertex as unpruned.
Definition: Vertex.cpp:484
BITstar::VertexId getId() const
The (unique) vertex ID.
Definition: Vertex.cpp:81
std::shared_ptr< Vertex > VertexPtr
A vertex shared pointer.
Definition: BITstar.h:120
Vertex(const ompl::base::SpaceInformationPtr &si, const ompl::base::OptimizationObjectivePtr &opt, bool root=false)
Constructor.
Definition: Vertex.cpp:48
bool hasAlreadyFailed(const VertexConstPtr &potentialChild) const
Check if the given vertex has previously been marked as a failed child of this vertex.
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
ompl::base::Cost getCost() const
Get the cost-to-come of a vertex. Return infinity if the edge is disconnected.
Definition: Vertex.cpp:364
void markExpandedToVertices()
Mark the vertex as expanded towards vertices.
Definition: Vertex.cpp:450
void markPruned()
Mark the vertex as pruned.
Definition: Vertex.cpp:475
unsigned int VertexId
The vertex id type.
Definition: BITstar.h:131
void getChildren(std::vector< VertexPtr > *children)
Get the children of a vertex as mutable pointers.
Definition: Vertex.cpp:278