batching_pomp  1.0
This is an implementation of an algorithmic framework for anytime motion planning on large dense roadmaps.
BatchingManager.hpp
1 /***********************************************************************
2 Copyright (c) 2017, Shushman Choudhury
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_BATCHING_MANAGER_HPP_
28 #define BATCHING_POMP_BATCHING_MANAGER_HPP_
29 
30 #include <functional>
31 #include <ompl/base/StateSpace.h>
32 #include <ompl/datastructures/NearestNeighbors.h>
33 #include <boost/graph/adjacency_list.hpp>
34 #include "batching_pomp/util/RoadmapFromFile.hpp"
35 
36 namespace batching_pomp {
37 namespace batching {
38 
39 
41 
50 template<class Graph, class VStateMap, class StateCon, class EDistance>
52 {
53 
54 typedef boost::graph_traits<Graph> GraphTypes;
55 typedef typename GraphTypes::vertex_iterator VertexIter;
56 typedef typename GraphTypes::vertex_descriptor Vertex;
57 
58 public:
59 
65  BatchingManager(const ompl::base::StateSpacePtr _space,
66  VStateMap _stateMap,
67  std::string _roadmapFileName,
68  Graph& _fullRoadmap,
69  Graph& _currentRoadmap)
70  : mFullRoadmap(_fullRoadmap)
71  , mCurrentRoadmap(_currentRoadmap)
72  , mNumBatches{0u}
73  , mExhausted{false}
74  , mCurrRadius{0.0}
75  {
76  auto file_roadmap_ptr = std::make_shared<
78  (_space,_roadmapFileName);
79  file_roadmap_ptr->generateVertices(mFullRoadmap,_stateMap);
80  mNumVertices = num_vertices(mFullRoadmap);
81  }
82 
90  BatchingManager(const ompl::base::StateSpacePtr _space,
91  VStateMap _stateMap,
92  EDistance _distanceMap,
93  std::string _roadmapFileName,
94  Graph& _fullRoadmap,
95  Graph& _currentRoadmap)
96  : mFullRoadmap(_fullRoadmap)
97  , mCurrentRoadmap(_currentRoadmap)
98  , mNumBatches{0u}
99  , mExhausted{false}
100  , mCurrRadius{0.0}
101  {
102  auto file_roadmap_ptr = std::make_shared<
104  (_space,_roadmapFileName);
105  file_roadmap_ptr->generateVertices(mFullRoadmap,_stateMap);
106  file_roadmap_ptr->generateEdges(mFullRoadmap,_stateMap,_distanceMap);
107  mNumVertices = num_vertices(mFullRoadmap);
108  }
109 
110  virtual ~BatchingManager() = default;
111 
113  // Getters
114  unsigned int getNumBatches() const
115  {
116  return mNumBatches;
117  }
118 
119  unsigned int getNumVertices() const
120  {
121  return mNumVertices;
122  }
123 
124  bool isExhausted() const
125  {
126  return mExhausted;
127  }
128 
129  double getCurrentRadius() const
130  {
131  return mCurrRadius;
132  }
133 
134  const ompl::base::State* getVertexState(const Vertex& v) const
135  {
136  return mFullRoadmap[v].v_state->state;
137  }
138 
144  void pruneVertices(const std::function<bool(const ompl::base::State*)>& _pruneFunction,
145  ompl::NearestNeighbors<Vertex>& _vertexNN)
146  {
147  VertexIter vi,vi_end;
148  std::vector<Vertex> verticesToRemove;
149  verticesToRemove.reserve(num_vertices(mCurrentRoadmap));
150  size_t vRemoved{0};
151 
152  for(boost::tie(vi,vi_end) = vertices(mCurrentRoadmap); vi!=vi_end; ++vi)
153  {
154  if(_pruneFunction(mCurrentRoadmap[*vi].v_state->state)) {
155  verticesToRemove[vRemoved++] = *vi;
156  }
157  }
158 
159  // Now remove vertices lined up
160  for(size_t i=0; i<vRemoved; i++)
161  {
162  _vertexNN.remove(verticesToRemove[i]);
163  clear_vertex(verticesToRemove[i],mCurrentRoadmap);
164  }
165  }
166 
170  virtual void updateWithNewSolutionCost(double _newSolnCost) = 0;
171 
176  virtual void nextBatch(const std::function<bool(const ompl::base::State*)>& _pruneFunction,
177  ompl::NearestNeighbors<Vertex>& _vertexNN) = 0;
178 
179 
180 protected:
181 
183  Graph & mFullRoadmap;
184 
187 
189  unsigned int mNumBatches;
190 
192  unsigned int mNumVertices;
193 
196 
198  double mCurrRadius;
199 
200 };
201 
202 } // namespace batching
203 } // namespace batching_pomp
204 
205 # endif //BATCHING_POMP_BATCHING_MANAGER_HPP_
Abstract class that represents the batching strategy used for the planning algorithm.
Definition: BatchingManager.hpp:51
virtual void updateWithNewSolutionCost(double _newSolnCost)=0
bool mExhausted
The flag that maintains whether the complete roadmap has been fully searched or not.
Definition: BatchingManager.hpp:195
Reads a roadmap encoded as a .graphml file and creates the corresponding Boost Graph.
Definition: RoadmapFromFile.hpp:107
Graph & mCurrentRoadmap
The roadmap currently being searched by the planner.
Definition: BatchingManager.hpp:186
Definition: BatchingManager.hpp:36
void pruneVertices(const std::function< bool(const ompl::base::State *)> &_pruneFunction, ompl::NearestNeighbors< Vertex > &_vertexNN)
Definition: BatchingManager.hpp:144
unsigned int mNumVertices
The number of vertices in the entire roadmap.
Definition: BatchingManager.hpp:192
BatchingManager(const ompl::base::StateSpacePtr _space, VStateMap _stateMap, EDistance _distanceMap, std::string _roadmapFileName, Graph &_fullRoadmap, Graph &_currentRoadmap)
Definition: BatchingManager.hpp:90
unsigned int mNumBatches
The number of batches added till now.
Definition: BatchingManager.hpp:189
virtual void nextBatch(const std::function< bool(const ompl::base::State *)> &_pruneFunction, ompl::NearestNeighbors< Vertex > &_vertexNN)=0
Graph & mFullRoadmap
The entire roadmap that will be used for planning.
Definition: BatchingManager.hpp:183
BatchingManager(const ompl::base::StateSpacePtr _space, VStateMap _stateMap, std::string _roadmapFileName, Graph &_fullRoadmap, Graph &_currentRoadmap)
Definition: BatchingManager.hpp:65
double mCurrRadius
The radius of connectivity for the current batch.
Definition: BatchingManager.hpp:198