batching_pomp  1.0
This is an implementation of an algorithmic framework for anytime motion planning on large dense roadmaps.
EdgeBatching.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_EDGE_BATCHING_HPP_
28 #define BATCHING_POMP_EDGE_BATCHING_HPP_
29 
30 #include <exception>
31 #include <ompl/base/StateSpace.h>
32 #include <ompl/util/Console.h>
33 #include <boost/graph/adjacency_list.hpp>
34 #include <boost/graph/properties.hpp>
35 #include "batching_pomp/batching/BatchingManager.hpp"
36 
37 namespace batching_pomp {
38 namespace batching {
39 
41 
45 template<class Graph, class VStateMap, class StateCon, class EDistance>
46 class EdgeBatching : public BatchingManager<Graph, VStateMap, StateCon, EDistance>
47 {
48 
49 typedef boost::graph_traits<Graph> GraphTypes;
50 typedef typename GraphTypes::vertex_iterator VertexIter;
51 typedef typename GraphTypes::vertex_descriptor Vertex;
52 
53 
54 public:
55 
61  EdgeBatching(const ompl::base::StateSpacePtr _space,
62  VStateMap _stateMap,
63  std::string _roadmapFileName,
64  Graph& _fullRoadmap,
65  Graph& _currentRoadmap,
66  double _radiusInflFactor,
67  std::function<double(unsigned int)> _initRadiusFn,
68  double _maxRadius
69  )
70  : BatchingManager<Graph, VStateMap, StateCon, EDistance>(_space,_stateMap,_roadmapFileName,_fullRoadmap,_currentRoadmap)
71  , mRadiusInflFactor{_radiusInflFactor}
73  , mMaxRadius{_maxRadius}
74  {
75  }
76 
79  void setRadiusInflationFactor(unsigned int _radiusInflFactor)
80  {
81  mRadiusInflFactor = _radiusInflFactor;
82  }
83 
84  double getRadiusInflationFactor() const
85  {
86  return mRadiusInflFactor;
87  }
88 
89  void setInitRadius(double _initRadius)
90  {
91  mInitRadius = _initRadius;
92  }
93 
94  double getInitRadius() const
95  {
96  return mInitRadius;
97  }
98 
99  void setMaxRadius(double _maxRadius)
100  {
101  mMaxRadius = _maxRadius;
102  }
103 
104  double getMaxRadius() const
105  {
106  return mMaxRadius;
107  }
108 
111  void updateWithNewSolutionCost(double _newSolnCost) override
112  {
113  mMaxRadius = std::min(mMaxRadius,_newSolnCost);
114  }
115 
116  void nextBatch(const std::function<bool(const ompl::base::State*)>& _pruneFunction,
117  ompl::NearestNeighbors<Vertex>& _vertexNN) override
118  {
119 
121  OMPL_INFORM("Batching exhausted! No updates with nextBatch!");
122  return;
123  }
124 
125  OMPL_INFORM("New Edge Batch called!");
127 
129  {
130  VertexIter vi, vi_end;
132  size_t idx{0};
133 
134  for(boost::tie(vi,vi_end)=vertices(BatchingManager<Graph, VStateMap, StateCon, EDistance>::mFullRoadmap); vi!=vi_end; ++vi)
135  {
136  if(!_pruneFunction(BatchingManager<Graph, VStateMap, StateCon, EDistance>::mFullRoadmap[*vi].v_state->state)) {
140  vertex_vector[idx++] = newVertex;
141  }
142  }
143 
144  // Truncate to actual number of samples to add
145  vertex_vector.resize(idx);
146  _vertexNN.add(vertex_vector);
147 
149  }
150  else {
152  }
153 
155  {
158  }
159  }
160 
161 
162 private:
163 
164  double mRadiusInflFactor;
165  double mInitRadius;
166  double mMaxRadius;
167 
168 
169 };
170 } //namespace batching
171 } //namespace batching_pomp
172 
173 #endif //BATCHING_POMP_EDGE_BATCHING_HPP_
void updateWithNewSolutionCost(double _newSolnCost) override
Overriden methods.
Definition: EdgeBatching.hpp:111
Abstract class that represents the batching strategy used for the planning algorithm.
Definition: BatchingManager.hpp:51
EdgeBatching(const ompl::base::StateSpacePtr _space, VStateMap _stateMap, std::string _roadmapFileName, Graph &_fullRoadmap, Graph &_currentRoadmap, double _radiusInflFactor, std::function< double(unsigned int)> _initRadiusFn, double _maxRadius)
Definition: EdgeBatching.hpp:61
Definition: BatchingManager.hpp:36
Derived class of BatchingManager that implements Edge Batching.
Definition: EdgeBatching.hpp:46
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: EdgeBatching.hpp:116
void setRadiusInflationFactor(unsigned int _radiusInflFactor)
Setters and Getters.
Definition: EdgeBatching.hpp:79