batching_pomp  1.0
This is an implementation of an algorithmic framework for anytime motion planning on large dense roadmaps.
VertexBatching.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_VERTEX_BATCHING_HPP_
28 #define BATCHING_POMP_VERTEX_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 
44 template<class Graph, class VStateMap, class StateCon, class EDistance>
45 class VertexBatching : public BatchingManager<Graph, VStateMap, StateCon, EDistance>
46 {
47 
48 typedef boost::graph_traits<Graph> GraphTypes;
49 typedef typename GraphTypes::vertex_iterator VertexIter;
50 typedef typename GraphTypes::vertex_descriptor Vertex;
51 
52 
53 public:
54 
58  VertexBatching(const ompl::base::StateSpacePtr _space,
59  VStateMap _stateMap,
60  std::string _roadmapFileName,
61  Graph& _fullRoadmap,
62  Graph& _currentRoadmap,
63  unsigned int _initNumVertices,
64  double _vertInflFactor
65  )
66  : BatchingManager<Graph, VStateMap, StateCon, EDistance>(_space,_stateMap,_roadmapFileName,_fullRoadmap,_currentRoadmap)
67  , mNumVerticesAdded{0u}
68  , mNextVertexTarget{_initNumVertices}
69  , mVertInflFactor{_vertInflFactor}
70  {
72  boost::tie(mCurrVertex,mLastVertex) = vertices(BatchingManager<Graph, VStateMap, StateCon, EDistance>::mFullRoadmap);
73  }
74 
77  void setVertexInflationFactor(double _vertInflFactor)
78  {
79  mVertInflFactor = _vertInflFactor;
80  }
81 
82  double getVertexInflationFactor() const
83  {
84  return mVertInflFactor;
85  }
86 
89  void updateWithNewSolutionCost(double _newSolnCost) override
90  {
91  }
92 
93 
94  void nextBatch(const std::function<bool(const ompl::base::State*)>& _pruneFunction,
95  ompl::NearestNeighbors<Vertex>& _vertexNN) override
96  {
97 
99  OMPL_INFORM("Batching exhausted! No updates with nextBatch!");
100  return;
101  }
102 
103  OMPL_INFORM("New Vertex Batch called!");
105 
106  std::vector<Vertex> vertex_vector(mNextVertexTarget - mNumVerticesAdded);
107  size_t idx{0};
108 
109  while(mNumVerticesAdded < mNextVertexTarget)
110  {
111 
112  // Only add if best cost through vertex better than current solution
113  if(!_pruneFunction(BatchingManager<Graph, VStateMap, StateCon, EDistance>::mFullRoadmap[*mCurrVertex].v_state->state)) {
116  vertex_vector[idx++] = newVertex;
117  }
118 
119  // Increment stuff
120  ++mCurrVertex;
121  ++mNumVerticesAdded;
122 
123  if(mCurrVertex == mLastVertex) {
125  break;
126  }
127  }
128 
129  // Update nearest neighbour structure with vertices
130  // TODO : Is this the most efficient way?
131  if(idx > 0u) {
132  vertex_vector.resize(idx);
133  _vertexNN.add(vertex_vector);
134  }
135 
136  // Update size of next subgraph
137  mNextVertexTarget = static_cast<unsigned int>(mNextVertexTarget * mVertInflFactor);
138  }
139 
140 private:
141 
142  unsigned int mNumVerticesAdded;
143  unsigned int mNextVertexTarget;
144  double mVertInflFactor;
145 
146  VertexIter mCurrVertex;
147  VertexIter mLastVertex;
148 
149 };
150 
151 } //namespace batching
152 } //namespace batching_pomp
153 
154 #endif //BATCHING_POMP_VERTEX_BATCHING_HPP_
Derived class of BatchingManager that implements Vertex Batching.
Definition: VertexBatching.hpp:45
void nextBatch(const std::function< bool(const ompl::base::State *)> &_pruneFunction, ompl::NearestNeighbors< Vertex > &_vertexNN) override
Definition: VertexBatching.hpp:94
Abstract class that represents the batching strategy used for the planning algorithm.
Definition: BatchingManager.hpp:51
VertexBatching(const ompl::base::StateSpacePtr _space, VStateMap _stateMap, std::string _roadmapFileName, Graph &_fullRoadmap, Graph &_currentRoadmap, unsigned int _initNumVertices, double _vertInflFactor)
Definition: VertexBatching.hpp:58
Definition: BatchingManager.hpp:36
Composite struct to associate the state space with each state.
Definition: BatchingPOMP.hpp:55
void setVertexInflationFactor(double _vertInflFactor)
Setters and Getters.
Definition: VertexBatching.hpp:77
void updateWithNewSolutionCost(double _newSolnCost) override
Overriden methods.
Definition: VertexBatching.hpp:89