batching_pomp  1.0
This is an implementation of an algorithmic framework for anytime motion planning on large dense roadmaps.
HybridBatching.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 #ifndef BATCHING_POMP_HYBRID_BATCHING_HPP_
27 #define BATCHING_POMP_HYBRID_BATCHING_HPP_
28 
29 #include <exception>
30 #include <ompl/base/StateSpace.h>
31 #include <ompl/util/Console.h>
32 #include <boost/graph/adjacency_list.hpp>
33 #include <boost/graph/properties.hpp>
34 #include "batching_pomp/batching/BatchingManager.hpp"
35 
36 namespace batching_pomp {
37 namespace batching {
38 
40 
47 template<class Graph, class VStateMap, class StateCon, class EDistance>
48 class HybridBatching : public BatchingManager<Graph, VStateMap, StateCon, EDistance>
49 {
50 
51 typedef boost::graph_traits<Graph> GraphTypes;
52 typedef typename GraphTypes::vertex_iterator VertexIter;
53 typedef typename GraphTypes::vertex_descriptor Vertex;
54 
55 
56 public:
57 
67  HybridBatching(const ompl::base::StateSpacePtr _space,
68  VStateMap _stateMap,
69  std::string _roadmapFileName,
70  Graph& _fullRoadmap,
71  Graph& _currentRoadmap,
72  unsigned int _initNumVertices,
73  double _vertInflFactor,
74  double _radiusInflFactor,
75  const std::function<double(unsigned int)>& _initRadiusFn,
76  double _maxRadius
77  )
78  : BatchingManager<Graph, VStateMap, StateCon, EDistance>(_space,_stateMap,_roadmapFileName,_fullRoadmap,_currentRoadmap)
79  , mNumVerticesAdded{0u}
80  , mNextVertexTarget{_initNumVertices}
81  , mVertInflFactor{_vertInflFactor}
82  , mRadiusInflFactor{_radiusInflFactor}
83  , mInitRadius{_initRadiusFn(_initNumVertices)}
84  , mMaxRadius{_maxRadius}
85  , mEdgeBatchingMode{false}
86  , mRadiusFn{_initRadiusFn}
87  {
89  boost::tie(mCurrVertex,mLastVertex) = vertices(BatchingManager<Graph, VStateMap, StateCon, EDistance>::mFullRoadmap);
90  }
91 
94  void setVertexInflationFactor(double _vertInflFactor)
95  {
96  mVertInflFactor = _vertInflFactor;
97  }
98 
99  double getVertexInflationFactor() const
100  {
101  return mVertInflFactor;
102  }
103 
104  void setRadiusInflationFactor(unsigned int _radiusInflFactor)
105  {
106  mRadiusInflFactor = _radiusInflFactor;
107  }
108 
109  double getRadiusInflationFactor() const
110  {
111  return mRadiusInflFactor;
112  }
113 
114  void setInitRadius(double _initRadius)
115  {
116  mInitRadius = _initRadius;
117  }
118 
119  double getInitRadius() const
120  {
121  return mInitRadius;
122  }
123 
124  void setMaxRadius(double _maxRadius)
125  {
126  mMaxRadius = _maxRadius;
127  }
128 
129  double getMaxRadius() const
130  {
131  return mMaxRadius;
132  }
133 
134  bool isInEdgeBatchingMode() const
135  {
136  return mEdgeBatchingMode;
137  }
138 
141  void updateWithNewSolutionCost(double _newSolnCost) override
142  {
143  mMaxRadius = std::min(mMaxRadius,_newSolnCost);
144  }
145 
146  void nextBatch(const std::function<bool(const ompl::base::State*)>& _pruneFunction,
147  ompl::NearestNeighbors<Vertex>& _vertexNN) override
148  {
149 
151  OMPL_INFORM("Batching exhausted! No updates with nextBatch!");
152  return;
153  }
154 
155  OMPL_INFORM("New Hybrid Batch called!");
157 
158  if(!mEdgeBatchingMode)
159  {
160  std::vector<Vertex> vertex_vector(mNextVertexTarget - mNumVerticesAdded);
161  size_t idx{0};
162 
163  while(mNumVerticesAdded < mNextVertexTarget)
164  {
165 
166  if(!_pruneFunction(BatchingManager<Graph, VStateMap, StateCon, EDistance>::mFullRoadmap[*mCurrVertex].v_state->state)) {
169  vertex_vector[idx++] = newVertex;
170  }
171 
172  ++mCurrVertex;
173  ++mNumVerticesAdded;
174 
175  // If all samples added, next round will be edge batching mode
176  if(mCurrVertex == mLastVertex) {
177  mEdgeBatchingMode = true;
178  break;
179  }
180  }
181 
182  if(idx > 0u) {
183  vertex_vector.resize(idx);
184  _vertexNN.add(vertex_vector);
185  }
186 
188 
189  mNextVertexTarget = static_cast<unsigned int>(mNextVertexTarget * mVertInflFactor);
190  }
191  else
192  {
194 
196  {
199  }
200  }
201 
202  }
203 
204 
205 private:
206 
207  unsigned int mNumVerticesAdded;
208  unsigned int mNextVertexTarget;
209  double mVertInflFactor;
210 
211  double mRadiusInflFactor;
212  double mInitRadius;
213  double mMaxRadius;
214 
215  VertexIter mCurrVertex;
216  VertexIter mLastVertex;
217 
218  bool mEdgeBatchingMode;
219  std::function<double(unsigned int)> mRadiusFn;
220 
221 };
222 
223 } // namespace batching_pomp
224 } // namespace batching
225 #endif //BATCHING_POMP_HYBRID_BATCHING_HPP_
void setVertexInflationFactor(double _vertInflFactor)
Setters and Getters.
Definition: HybridBatching.hpp:94
Derived class of BatchingManager that implements Hybrid Batching.
Definition: HybridBatching.hpp:48
HybridBatching(const ompl::base::StateSpacePtr _space, VStateMap _stateMap, std::string _roadmapFileName, Graph &_fullRoadmap, Graph &_currentRoadmap, unsigned int _initNumVertices, double _vertInflFactor, double _radiusInflFactor, const std::function< double(unsigned int)> &_initRadiusFn, double _maxRadius)
Definition: HybridBatching.hpp:67
Abstract class that represents the batching strategy used for the planning algorithm.
Definition: BatchingManager.hpp:51
Definition: BatchingManager.hpp:36
void updateWithNewSolutionCost(double _newSolnCost) override
Overriden methods.
Definition: HybridBatching.hpp:141
Composite struct to associate the state space with each state.
Definition: BatchingPOMP.hpp:55
void nextBatch(const std::function< bool(const ompl::base::State *)> &_pruneFunction, ompl::NearestNeighbors< Vertex > &_vertexNN) override
Definition: HybridBatching.hpp:146