State.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_STATE_
38 #define OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_STATE_
39 
40 #include <memory>
41 #include <set>
42 #include <utility>
43 
44 #include "ompl/base/Cost.h"
45 #include "ompl/base/SpaceInformation.h"
46 #include "ompl/base/State.h"
47 
48 #include "ompl/geometric/planners/informedtrees/eitstar/Vertex.h"
49 
50 namespace ompl
51 {
52  namespace geometric
53  {
54  namespace eitstar
55  {
57  class State : public std::enable_shared_from_this<State> // Inheritance must be public here.
58  {
59  public:
62  State(const std::shared_ptr<ompl::base::SpaceInformation> &spaceInfo,
63  const std::shared_ptr<ompl::base::OptimizationObjective> &objective);
64 
66  ~State();
67 
69  std::size_t getId() const;
70 
72  ompl::base::State *raw() const;
73 
75  bool hasForwardVertex() const;
76 
78  bool hasReverseVertex() const;
79 
81  std::shared_ptr<Vertex> asForwardVertex();
82 
84  std::shared_ptr<Vertex> asReverseVertex();
85 
87  void blacklist(const std::shared_ptr<State> &state);
88 
90  void whitelist(const std::shared_ptr<State> &state);
91 
93  bool isBlacklisted(const std::shared_ptr<State> &state) const;
94 
96  bool isWhitelisted(const std::shared_ptr<State> &state) const;
97 
100  void setEstimatedEffortToGo(std::size_t effort);
101 
105 
109 
113 
117 
120 
122  void setLowerBoundEffortToCome(unsigned int effort);
123 
125  void setInadmissibleEffortToCome(unsigned int effort);
126 
129  unsigned int getEstimatedEffortToGo() const;
130 
134 
138 
142 
146 
149 
152  unsigned int getLowerBoundEffortToCome() const;
153 
156  unsigned int getInadmissibleEffortToCome() const;
157 
159  const std::vector<std::weak_ptr<State>> getSourcesOfIncomingEdgesInForwardQueue() const;
160 
162  void addToSourcesOfIncomingEdgesInForwardQueue(const std::shared_ptr<State> &state) const;
163 
165  void removeFromSourcesOfIncomingEdgesInForwardQueue(const std::shared_ptr<State> &state) const;
166 
169 
171  void setIncomingCollisionCheckResolution(const std::shared_ptr<State> &source,
172  std::size_t numChecks) const;
173 
175  std::size_t getIncomingCollisionCheckResolution(const std::shared_ptr<State> &source) const;
176 
177  private:
179  friend class RandomGeometricGraph;
180 
182  const std::size_t id_;
183 
186  unsigned int estimatedEffortToGo_{std::numeric_limits<unsigned int>::max()};
187 
190  ompl::base::Cost estimatedCostToGo_;
191 
193  unsigned int lowerBoundEffortToCome_{std::numeric_limits<unsigned int>::max()};
194 
196  unsigned int inadmissibleEffortToCome_{std::numeric_limits<unsigned int>::max()};
197 
200  ompl::base::Cost admissibleCostToGo_;
201 
204  ompl::base::Cost lowerBoundCostToGo_;
205 
208  ompl::base::Cost lowerBoundCostToCome_;
209 
211  ompl::base::Cost currentCostToCome_;
212 
214  ompl::base::State *state_;
215 
217  std::weak_ptr<Vertex> forwardVertex_{};
218 
220  std::weak_ptr<Vertex> reverseVertex_{};
221 
223  mutable std::pair<std::size_t, std::vector<std::weak_ptr<State>>> neighbors_{};
224 
226  std::set<std::size_t> blacklist_{}; // Maybe this would be faster as vector?
227 
229  std::set<std::size_t> whitelist_{}; // Maybe this would be faster as vector?
230 
232  mutable std::vector<std::weak_ptr<State>> sourcesOfIncomingEdgesInForwardQueue_{};
233 
237  mutable std::map<std::size_t, std::size_t> incomingCollisionCheckResolution_{};
238 
240  std::shared_ptr<ompl::base::SpaceInformation> spaceInfo_;
241 
243  std::shared_ptr<ompl::base::OptimizationObjective> objective_;
244  };
245 
246  } // namespace eitstar
247 
248  } // namespace geometric
249 
250 } // namespace ompl
251 
252 #endif // OMPL_GEOMETRIC_PLANNERS_INFORMEDTREES_EITSTAR_STATE_
void whitelist(const std::shared_ptr< State > &state)
Whitelists the given state as neighbor.
Definition: State.cpp:248
~State()
Destructs this state, freeing the associated memory.
Definition: State.cpp:168
void setLowerBoundEffortToCome(unsigned int effort)
Sets the lower bound effort to come to this state through the continuous state space.
Definition: State.cpp:293
void blacklist(const std::shared_ptr< State > &state)
Blacklists the given state as neighbor.
Definition: State.cpp:243
ompl::base::Cost getEstimatedCostToGo() const
Returns the best estimate of the cost to go from this state to the goal through the current RGG.
Definition: State.cpp:308
Definition of an abstract state.
Definition: State.h:113
State(const std::shared_ptr< ompl::base::SpaceInformation > &spaceInfo, const std::shared_ptr< ompl::base::OptimizationObjective > &objective)
Constructs the state, allocating the associated memory using information about the underlying space.
Definition: State.cpp:150
void setAdmissibleCostToGo(ompl::base::Cost cost)
Set the admissible estimate of the cost to go from this state to the goal through the current RGG.
Definition: State.cpp:273
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:111
void setInadmissibleEffortToCome(unsigned int effort)
Sets the inadmissible effort to come to this state through the continuous state space.
Definition: State.cpp:298
ompl::base::Cost getLowerBoundCostToGo() const
Returns the lower bound cost to go from this state to the goal through the continuous state space.
Definition: State.cpp:318
void setIncomingCollisionCheckResolution(const std::shared_ptr< State > &source, std::size_t numChecks) const
Sets the number of collision checks already performed on the edge incoming from source.
Definition: State.cpp:374
unsigned int getInadmissibleEffortToCome() const
Returns the inadmissible effort to come from the start to this state through the continuous state spa...
Definition: State.cpp:338
void setEstimatedCostToGo(ompl::base::Cost cost)
Set the best estimate of the cost to go from this state to the goal through the current RGG.
Definition: State.cpp:268
bool hasForwardVertex() const
Returns whether the state has an associated forward vertex.
Definition: State.cpp:183
unsigned int getEstimatedEffortToGo() const
Get the estimated effort (number of collision detections) to go from this state to the goal through t...
Definition: State.cpp:303
std::size_t getIncomingCollisionCheckResolution(const std::shared_ptr< State > &source) const
Returns the number of collision checks already performed on the edge incoming from source.
Definition: State.cpp:380
void setEstimatedEffortToGo(std::size_t effort)
Set the estimated effort (number of collision detections) to go from this state to the goal through t...
Definition: State.cpp:263
ompl::base::State * raw() const
Returns the raw OMPL version of this state.
Definition: State.cpp:178
std::shared_ptr< Vertex > asForwardVertex()
Returns the state as a reverse vertex.
Definition: State.cpp:193
void resetSourcesOfIncomingEdgesInForwardQueue()
Resets the sources of incoming edges in the forward queue.
Definition: State.cpp:369
void setCurrentCostToCome(ompl::base::Cost cost)
Set the current cost to come from the start to this state.
Definition: State.cpp:288
void setLowerBoundCostToCome(ompl::base::Cost cost)
Set the lower bound cost to come from the start to this state through the continuous state space.
Definition: State.cpp:283
bool isWhitelisted(const std::shared_ptr< State > &state) const
Returns whether the given has been whitelisted.
Definition: State.cpp:258
const std::vector< std::weak_ptr< State > > getSourcesOfIncomingEdgesInForwardQueue() const
Returns the sources of incoming edges in forward queue.
Definition: State.cpp:343
unsigned int getLowerBoundEffortToCome() const
Returns the lower bound effort to come from the start to this state through the continuous state spac...
Definition: State.cpp:333
ompl::base::Cost getLowerBoundCostToCome() const
Returns the lower bound cost to come from the start to this state through the continuous state space.
Definition: State.cpp:323
bool isBlacklisted(const std::shared_ptr< State > &state) const
Returns whether the given state has been blacklisted.
Definition: State.cpp:253
std::shared_ptr< Vertex > asReverseVertex()
Returns the state as a reverse vertex.
Definition: State.cpp:218
void addToSourcesOfIncomingEdgesInForwardQueue(const std::shared_ptr< State > &state) const
Adds a source to sources of incoming edges in forward queue.
Definition: State.cpp:348
bool hasReverseVertex() const
Returns whether the state has an associated reverse vertex.
Definition: State.cpp:188
void setLowerBoundCostToGo(ompl::base::Cost cost)
Set the lower bound cost to go from this state to the goal through the continuous state space.
Definition: State.cpp:278
std::size_t getId() const
Returns the state's unique id.
Definition: State.cpp:173
void removeFromSourcesOfIncomingEdgesInForwardQueue(const std::shared_ptr< State > &state) const
Removes a source from sources of incoming edges in forward queue.
Definition: State.cpp:353
ompl::base::Cost getAdmissibleCostToGo() const
Returns the admissible estimate of the cost to go from this state to the goal through the current RGG...
Definition: State.cpp:313
ompl::base::Cost getCurrentCostToCome() const
Returns the current cost to come from the start to this state.
Definition: State.cpp:328
Main namespace. Contains everything in this library.
Definition: AppBase.h:21