batching_pomp  1.0
This is an implementation of an algorithmic framework for anytime motion planning on large dense roadmaps.
BatchingPOMP.hpp
1 /***********************************************************************
2 Copyright (c) 2017, Carnegie Mellon University
3 All rights reserved.
4 Authors: Shushman Choudhury <shushmanchoudhury@gmail.com>
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *************************************************************************/
26 
27 #ifndef BATCHING_POMP_BATCHINGPOMP_HPP_
28 #define BATCHING_POMP_BATCHINGPOMP_HPP_
29 
30 #include <exception>
31 #include <memory>
32 
33 #include <boost/graph/adjacency_list.hpp>
34 #include <boost/graph/properties.hpp>
35 #include <boost/graph/dijkstra_shortest_paths.hpp>
36 #include <boost/graph/astar_search.hpp>
37 #include <boost/graph/properties.hpp>
38 #include <boost/property_map/dynamic_property_map.hpp>
39 
40 #include <ompl/base/Planner.h>
41 #include <ompl/base/StateSpace.h>
42 #include <ompl/base/ScopedState.h>
43 #include <ompl/base/spaces/RealVectorStateSpace.h>
44 #include <ompl/datastructures/NearestNeighbors.h>
45 #include <ompl/datastructures/NearestNeighborsGNAT.h>
46 
47 #include "batching.hpp"
48 #include "cspacebelief.hpp"
49 #include "util.hpp"
50 
51 
52 namespace batching_pomp {
53 
55 struct StateCon
56 {
57  const ompl::base::StateSpacePtr space;
58  ompl::base::State * state;
59  StateCon(const ompl::base::StateSpacePtr _space)
60  : space{_space}
61  , state{space->allocState()} {}
62  ~StateCon() {space->freeState(this->state); }
63 };
64 
65 typedef std::shared_ptr<StateCon> StateConPtr;
66 
68 class BatchingPOMP : public ompl::base::Planner
69 {
70 
71 public:
72 
74  static const int FREE{1};
75 
77  static const int BLOCKED{-1};
78 
80  static const int UNKNOWN{0};
81 
83  struct VProps
84  {
86  StateConPtr v_state;
87  };
88 
90  struct EProps
91  {
93  double distance;
94 
96  double probFree;
97 
100 
102  std::vector< StateConPtr > edgeStates;
103  };
104 
105  // Graph definitions
106  typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, VProps, EProps> Graph;
107  typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
108  typedef boost::graph_traits<Graph>::vertex_iterator VertexIter;
109  typedef boost::graph_traits<Graph>::edge_descriptor Edge;
110  typedef boost::graph_traits<Graph>::edge_iterator EdgeIter;
111  typedef boost::graph_traits<Graph>::out_edge_iterator OutEdgeIter;
112 
113  // Boost property maps needed by planner
114  typedef boost::property_map<Graph, StateConPtr VProps::*>::type VPStateMap;
115  typedef boost::property_map<Graph, double EProps::*>::type EPDistanceMap;
116  typedef boost::property_map<Graph, boost::vertex_index_t>::type VertexIndexMap;
117 
119  const ompl::base::StateSpacePtr mSpace;
120 
122  std::shared_ptr< batching::BatchingManager<Graph,VPStateMap,StateCon,EPDistanceMap> > mBatchingPtr;
123 
125  std::shared_ptr< cspacebelief::Model<cspacebelief::BeliefPoint> > mBeliefModel;
126 
128  Graph g;
129 
131  Graph full_g;
132 
133  BatchingPOMP(const ompl::base::SpaceInformationPtr & si);
134 
147  BatchingPOMP(const ompl::base::SpaceInformationPtr & si,
149  std::shared_ptr< cspacebelief::Model<cspacebelief::BeliefPoint> > _beliefModel,
150  std::unique_ptr< util::Selector<Graph> > _selector,
151  const std::string& _roadmapFileName,
152  double _startGoalRadius,
153  double _increment = 0.2,
154  double _pruneThreshold = 0.05);
155 
156  ~BatchingPOMP(void);
157 
158  // Setters and Getters
160  double getCurrentAlpha() const;
162  double getCurrentBestCost() const;
164  Vertex getStartVertex() const;
166  Vertex getGoalVertex() const;
168  bool isInitSearchBatch() const;
170  double getIncrement() const;
171  void setIncrement(double _decrement);
172  double getStartGoalRadius() const;
173  void setStartGoalRadius(double _startGoalRadius);
174  double getPruneThreshold() const;
175  void setPruneThreshold(double _pruneThreshold);
177  std::string getGraphType() const;
178  void setGraphType(const std::string& _graphType);
179  std::string getBatchingType() const;
180  void setBatchingType(const std::string& _selectorType);
181  std::string getSelectorType() const;
182  void setSelectorType(const std::string& _selectorType);
183  std::string getRoadmapFileName() const;
184  void setRoadmapFileName(const std::string& _roadmapFileName);
185 
186  // Internal evaluation methods
188  inline unsigned int getNumEdgeChecks(){ return mNumEdgeChecks;}
190  inline unsigned int getNumCollChecks(){ return mNumCollChecks;}
192  inline unsigned int getNumSearches(){ return mNumSearches;}
194  inline unsigned int getNumLookups(){ return mNumLookups;}
196  inline double getLookupTime(){ return mLookupTime;}
198  inline double getSearchTime(){ return mSearchTime;}
200  inline double getCollCheckTime(){return mCollCheckTime;}
201 
202  // OMPL required methods
203  void setProblemDefinition(const ompl::base::ProblemDefinitionPtr & pdef);
204  ompl::base::PlannerStatus solve(const ompl::base::PlannerTerminationCondition & ptc);
205  void setup();
206 
212  double vertexDistFun(const Vertex& u, const Vertex& v) const;
213 
219  void initializeEdgePoints(const Edge& e);
220 
226  double computeAndSetEdgeFreeProbability(const Edge& e);
227 
232  bool checkAndSetEdgeBlocked(const Edge& e);
233 
234 private:
235 
236  // Planning helpers
237  std::unique_ptr<util::Selector<Graph>> mSelector;
238  std::unique_ptr<ompl::NearestNeighborsGNAT<Vertex>> mVertexNN;
239  std::function<double(unsigned int)> mRadiusFun;
240  util::BisectPerm mBisectPermObj;
241  Vertex mStartVertex;
242  Vertex mGoalVertex;
243  std::vector<Edge> mCurrBestPath;
244  std::set<Edge> mEdgesToUpdate;
245 
246  // Planner parameters
247  double mCurrentAlpha;
248  double mIncrement;
249  double mStartGoalRadius;
250  double mPruneThreshold;
251  bool mIsInitSearchBatch;
252  bool mIsPathFound;
253  double mCheckRadius;
254  double mBestPathCost;
255  bool mUsingSelector;
256  std::string mGraphType; // Optional - to be used for non-CPP level calls
257  std::string mBatchingType; // Optional - to be used for non-CPP level calls
258  std::string mSelectorType; // Optional - to be used for non-CPP level calls
259  std::string mRoadmapName;
260 
261  // For planner evaluation
262  unsigned int mNumEdgeChecks;
263  unsigned int mNumCollChecks;
264  unsigned int mNumSearches;
265  unsigned int mNumLookups;
266  double mLookupTime;
267  double mCollCheckTime;
268  double mSearchTime;
269 
270 
271  // Private helper methods
272  double haltonRadiusFun(unsigned int n) const;
273  double rggRadiusFun(unsigned int n) const;
274  bool checkAndUpdatePathBlocked(const std::vector<Edge>& _ePath);
275  void addAffectedEdges(const Edge& e);
276  void updateAffectedEdgeWeights();
277  bool isVertexInadmissible(const ompl::base::State* vState) const ;
278  bool vertexPruneFunction(const ompl::base::State* vState) const;
279  double getPathDistance(const std::vector<Edge>& _ePath) const;
280 };
281 
282 } // namespace batching_pomp
283 #endif //BATCHING_POMP_BATCHINGPOMP_HPP_
int blockedStatus
The collision status of the edge (free, blocked or unknown)
Definition: BatchingPOMP.hpp:99
Generates a Van Der Corput sequence ordering for states to check along an edge.
Definition: BisectPerm.hpp:35
std::shared_ptr< batching::BatchingManager< Graph, VPStateMap, StateCon, EPDistanceMap > > mBatchingPtr
The pointer to the batching manager instance to be used by the planner.
Definition: BatchingPOMP.hpp:122
double getLookupTime()
Total time spent doing model lookups.
Definition: BatchingPOMP.hpp:196
unsigned int getNumCollChecks()
Number of calls to collision checker made thus far.
Definition: BatchingPOMP.hpp:190
double distance
The length of the edge using the space distance metric.
Definition: BatchingPOMP.hpp:93
Graph g
The roadmap that will be continuously searched and updated.
Definition: BatchingPOMP.hpp:128
Abstract class that represents the batching strategy used for the planning algorithm.
Definition: BatchingManager.hpp:51
StateConPtr v_state
The underlying state of the vertex.
Definition: BatchingPOMP.hpp:86
std::shared_ptr< cspacebelief::Model< cspacebelief::BeliefPoint > > mBeliefModel
The pointer to the C-space belief model instance to be used by the planner.
Definition: BatchingPOMP.hpp:125
std::vector< StateConPtr > edgeStates
The set of states embedded in the edge.
Definition: BatchingPOMP.hpp:102
Abstract class that represents the configuration space belief manager.
Definition: Model.hpp:40
Properties associated with each roadmap edge.
Definition: BatchingPOMP.hpp:90
double probFree
The probability of collision of the edge.
Definition: BatchingPOMP.hpp:96
The OMPL Planner class that implements the algorithm.
Definition: BatchingPOMP.hpp:68
unsigned int getNumEdgeChecks()
Number of edges evaluated thus far.
Definition: BatchingPOMP.hpp:188
Definition: BatchingManager.hpp:36
double getSearchTime()
Total time spent doing searches.
Definition: BatchingPOMP.hpp:198
const ompl::base::StateSpacePtr mSpace
The pointer to the OMPL state space.
Definition: BatchingPOMP.hpp:119
A selector assigns an ordering for evaluating edges on a candidate path.
Definition: Selector.hpp:47
double getCollCheckTime()
Total time spent doing collision checks.
Definition: BatchingPOMP.hpp:200
Composite struct to associate the state space with each state.
Definition: BatchingPOMP.hpp:55
Graph full_g
The large, dense roadmap that remains unchanged after being loaded once.
Definition: BatchingPOMP.hpp:131
Properties associated with each roadmap vertex.
Definition: BatchingPOMP.hpp:83
unsigned int getNumLookups()
Number of model lookups made thus far.
Definition: BatchingPOMP.hpp:194
unsigned int getNumSearches()
Number of roadmap searches done thus far.
Definition: BatchingPOMP.hpp:192