Robotics Library  0.6.2
Prm.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef _RL_PLAN_PRM_H_
28 #define _RL_PLAN_PRM_H_
29 
30 #include <queue>
31 #include <boost/graph/adjacency_list.hpp>
32 #include <boost/pending/disjoint_sets.hpp>
33 #include <CGAL/Search_traits.h>
34 
36 #include "Planner.h"
37 #include "VectorPtr.h"
38 
39 namespace rl
40 {
41  namespace plan
42  {
43  class Model;
44  class Sampler;
45  class Verifier;
46 
50  class Prm : public Planner
51  {
52  public:
53  Prm();
54 
55  virtual ~Prm();
56 
57  virtual void construct(const ::std::size_t& steps);
58 
59  virtual ::std::string getName() const;
60 
61  ::std::size_t getNumEdges() const;
62 
63  ::std::size_t getNumVertices() const;
64 
65  void getPath(VectorList& path);
66 
67  void reset();
68 
69  bool solve();
70 
72  ::std::size_t degree;
73 
75  ::std::size_t k;
76 
78  bool kd;
79 
82 
84 
86 
87  protected:
88  struct EdgeBundle
89  {
91  };
92 
93  struct GraphBundle;
94 
95  typedef ::boost::adjacency_list_traits<
96  ::boost::listS,
97  ::boost::listS,
98  ::boost::undirectedS,
99  ::boost::listS
100  >::vertex_descriptor Vertex;
101 
103  {
105 
106  ::std::size_t index;
107 
109 
111 
113 
114  ::std::size_t rank;
115  };
116 
117  typedef ::boost::adjacency_list<
118  ::boost::listS,
119  ::boost::listS,
120  ::boost::undirectedS,
121  VertexBundle,
122  EdgeBundle,
124  > Graph;
125 
126  typedef ::std::pair< const ::rl::math::Vector*, Vertex > QueryItem;
127 
129  {
131 
133 
134  const ::rl::math::Real* operator()(const QueryItem& p, const int&) const;
135  };
136 
137  struct Distance
138  {
140 
141  Distance();
142 
143  Distance(Model* model);
144 
145  template< typename SearchTraits > ::rl::math::Real max_distance_to_rectangle(const Query_item& q, const ::CGAL::Kd_tree_rectangle< SearchTraits >& r) const;
146 
147  template< typename SearchTraits > ::rl::math::Real min_distance_to_rectangle(const Query_item& q, const ::CGAL::Kd_tree_rectangle< SearchTraits >& r) const;
148 
149  ::rl::math::Real min_distance_to_rectangle(const ::rl::math::Real& q, const ::rl::math::Real& min, const ::rl::math::Real& max, const ::std::size_t& cutting_dimension) const;
150 
151  ::rl::math::Real new_distance(const ::rl::math::Real& dist, const ::rl::math::Real& old_off, const ::rl::math::Real& new_off, const int& cutting_dimension) const;
152 
154 
155  ::rl::math::Real transformed_distance(const Query_item& q1, const Query_item& q2) const;
156 
158  };
159 
160  typedef ::CGAL::Search_traits< ::rl::math::Real, QueryItem, const ::rl::math::Real*, CartesianIterator > SearchTraits;
161 
163 
164  typedef NeighborSearch::Tree NeighborSearchTree;
165 
166  typedef ::boost::shared_ptr< NeighborSearchTree > NeighborSearchTreePtr;
167 
168  typedef ::std::vector< NeighborSearchTreePtr > NearestNeighbors;
169 
170  struct GraphBundle
171  {
173  };
174 
175  typedef ::boost::graph_traits< Graph >::edge_descriptor Edge;
176 
177  typedef ::boost::graph_traits< Graph >::edge_iterator EdgeIterator;
178 
179  typedef ::std::pair< EdgeIterator, EdgeIterator > EdgeIteratorPair;
180 
181  typedef ::boost::graph_traits< Graph >::vertex_iterator VertexIterator;
182 
183  typedef ::std::pair< VertexIterator, VertexIterator > VertexIteratorPair;
184 
185  typedef ::boost::property_map< Graph, void* VertexBundle::* >::type VertexParentMap;
186 
187  typedef ::boost::property_map< Graph, ::std::size_t VertexBundle::* >::type VertexRankMap;
188 
189  typedef ::std::pair< Vertex, ::rl::math::Real > Neighbor;
190 
191  struct Compare
192  {
193  bool operator()(const Neighbor& x, const Neighbor& y) const;
194  };
195 
196  typedef ::std::priority_queue< Neighbor, ::std::vector< Neighbor >, Compare > NeighborQueue;
197 
198  Edge addEdge(const Vertex& u, const Vertex& v, const ::rl::math::Real& weight);
199 
200  void addPoint(NearestNeighbors& nn, const QueryItem& p);
201 
202  Vertex addVertex(const VectorPtr& q);
203 
204  void insert(const Vertex& vertex);
205 
207 
208  ::boost::disjoint_sets< VertexRankMap, VertexParentMap > ds;
209 
211 
213 
214  private:
215 
216  };
217  }
218 }
219 
220 #endif // _RL_PLAN_PRM_H_
rl::plan::Prm::CartesianIterator::operator()
const ::rl::math::Real * operator()(const QueryItem &p) const
Definition: Prm.cpp:332
rl::plan::Prm::VertexParentMap
::boost::property_map< Graph, void *VertexBundle::* >::type VertexParentMap
Definition: Prm.h:185
rl::plan::Prm::radius
::rl::math::Real radius
Maximum radius for connecting neighbors.
Definition: Prm.h:81
rl::plan::Prm::EdgeIteratorPair
::std::pair< EdgeIterator, EdgeIterator > EdgeIteratorPair
Definition: Prm.h:179
rl::plan::VectorPtr
::boost::shared_ptr< ::rl::math::Vector > VectorPtr
Definition: VectorPtr.h:37
rl::plan::Orthogonal_k_neighbor_search
Definition: Orthogonal_k_neighbor_search.h:37
rl::plan::Prm::VertexBundle::parent
Vertex parent
Definition: Prm.h:108
rl::plan::Prm::Distance::transformed_distance
::rl::math::Real transformed_distance(const ::rl::math::Real &d) const
Definition: Prm.cpp:412
rl::plan::Prm::NeighborSearchTree
NeighborSearch::Tree NeighborSearchTree
Definition: Prm.h:164
rl::plan::Prm::Distance::max_distance_to_rectangle
::rl::math::Real max_distance_to_rectangle(const Query_item &q, const ::CGAL::Kd_tree_rectangle< SearchTraits > &r) const
rl::plan::Verifier
Definition: Verifier.h:39
rl::plan::Prm::sampler
Sampler * sampler
Definition: Prm.h:83
rl::plan::Prm::Compare::operator()
bool operator()(const Neighbor &x, const Neighbor &y) const
Definition: Prm.cpp:344
rl::plan::Prm::Neighbor
::std::pair< Vertex, ::rl::math::Real > Neighbor
Definition: Prm.h:189
rl::plan::Prm::Distance
Definition: Prm.h:138
rl::plan::Prm::NearestNeighbors
::std::vector< NeighborSearchTreePtr > NearestNeighbors
Definition: Prm.h:168
rl::plan::Prm::getName
virtual ::std::string getName() const
Definition: Prm.cpp:146
rl::plan::Prm::VertexBundle::rank
::std::size_t rank
Definition: Prm.h:114
rl::plan::Prm::VertexIterator
::boost::graph_traits< Graph >::vertex_iterator VertexIterator
Definition: Prm.h:181
rl::plan::Prm::VertexRankMap
::boost::property_map< Graph, ::std::size_t VertexBundle::* >::type VertexRankMap
Definition: Prm.h:187
rl::plan::Prm::NeighborQueue
::std::priority_queue< Neighbor, ::std::vector< Neighbor >, Compare > NeighborQueue
Definition: Prm.h:196
rl::plan::Prm::getPath
void getPath(VectorList &path)
Get solution path.
Definition: Prm.cpp:176
rl::plan::Prm::degree
::std::size_t degree
Maximum degree per vertex.
Definition: Prm.h:72
rl::plan::Prm::NeighborSearchTreePtr
::boost::shared_ptr< NeighborSearchTree > NeighborSearchTreePtr
Definition: Prm.h:166
rl::plan::Prm::EdgeBundle
Definition: Prm.h:89
rl::plan::Prm::ds
::boost::disjoint_sets< VertexRankMap, VertexParentMap > ds
Definition: Prm.h:208
rl::plan::Prm::EdgeIterator
::boost::graph_traits< Graph >::edge_iterator EdgeIterator
Definition: Prm.h:177
rl::plan::Prm::Distance::min_distance_to_rectangle
::rl::math::Real min_distance_to_rectangle(const Query_item &q, const ::CGAL::Kd_tree_rectangle< SearchTraits > &r) const
rl::plan::Prm::Compare
Definition: Prm.h:192
rl::plan::Prm::verifier
Verifier * verifier
Definition: Prm.h:85
Orthogonal_k_neighbor_search.h
rl::plan::Prm::QueryItem
::std::pair< const ::rl::math::Vector *, Vertex > QueryItem
Definition: Prm.h:126
rl::plan::Planner
Definition: Planner.h:44
rl::plan::Prm::k
::std::size_t k
Maximum number of tested neighbors.
Definition: Prm.h:75
rl::plan::Prm::Graph
::boost::adjacency_list< ::boost::listS, ::boost::listS, ::boost::undirectedS, VertexBundle, EdgeBundle, GraphBundle > Graph
Definition: Prm.h:124
rl::plan::Prm::addVertex
Vertex addVertex(const VectorPtr &q)
Definition: Prm.cpp:118
rl::plan::Prm::EdgeBundle::weight
::rl::math::Real weight
Definition: Prm.h:90
rl::plan::Model
Definition: Model.h:42
rl::plan::Prm::GraphBundle
Definition: Prm.h:171
rl::plan::Prm::Distance::model
Model * model
Definition: Prm.h:157
rl::plan::Prm::construct
virtual void construct(const ::std::size_t &steps)
Definition: Prm.cpp:134
rl::plan::Prm::graph
Graph graph
Definition: Prm.h:212
rl::plan::Prm::Prm
Prm()
Definition: Prm.cpp:43
rl::plan::Prm::VertexBundle::q
VectorPtr q
Definition: Prm.h:112
VectorPtr.h
rl::plan::Prm::insert
void insert(const Vertex &vertex)
Definition: Prm.cpp:190
rl::plan::Prm::reset
void reset()
Reset planner.
Definition: Prm.cpp:282
rl::plan::Prm::CartesianIterator
Definition: Prm.h:129
rl::plan::Prm::VertexIteratorPair
::std::pair< VertexIterator, VertexIterator > VertexIteratorPair
Definition: Prm.h:183
rl::plan::Prm::CartesianIterator::result_type
typedefconst ::rl::math::Real * result_type
Definition: Prm.h:130
rl::plan::VectorList
::std::list< ::rl::math::Vector > VectorList
Definition: VectorList.h:37
rl::plan::Prm::GraphBundle::nn
NearestNeighbors nn
Definition: Prm.h:172
rl::plan::Prm::VertexBundle::distance
::rl::math::Real distance
Definition: Prm.h:104
rl::plan::Prm::VertexBundle::predecessor
Vertex predecessor
Definition: Prm.h:110
rl::plan::Prm::kd
bool kd
Use kd-tree for nearest neighbor search instead of brute-force.
Definition: Prm.h:78
Planner.h
rl::plan::Prm::Distance::Query_item
QueryItem Query_item
Definition: Prm.h:139
rl::plan::Prm
Probabilistic Roadmap.
Definition: Prm.h:51
rl::plan::Prm::getNumEdges
::std::size_t getNumEdges() const
Definition: Prm.cpp:164
rl::plan::Prm::Distance::Distance
Distance()
Definition: Prm.cpp:349
rl::plan::Prm::addPoint
void addPoint(NearestNeighbors &nn, const QueryItem &p)
Definition: Prm.cpp:82
rl::plan::Prm::Vertex
::boost::adjacency_list_traits< ::boost::listS, ::boost::listS, ::boost::undirectedS, ::boost::listS >::vertex_descriptor Vertex
Definition: Prm.h:93
rl::plan::Prm::VertexBundle
Definition: Prm.h:103
rl::plan::Sampler
Definition: Sampler.h:39
rl::plan::Prm::VertexBundle::index
::std::size_t index
Definition: Prm.h:106
rl::plan::Prm::end
Vertex end
Definition: Prm.h:210
rl::plan::Prm::solve
bool solve()
Find collision free path.
Definition: Prm.cpp:291
rl::plan::Prm::begin
Vertex begin
Definition: Prm.h:206
rl::plan::Prm::NeighborSearch
Orthogonal_k_neighbor_search< SearchTraits, Distance > NeighborSearch
Definition: Prm.h:162
rl::plan::Prm::addEdge
Edge addEdge(const Vertex &u, const Vertex &v, const ::rl::math::Real &weight)
Definition: Prm.cpp:66
rl::math::Real
double Real
Definition: Real.h:34
rl::plan::Prm::getNumVertices
::std::size_t getNumVertices() const
Definition: Prm.cpp:170
rl::plan::Prm::Edge
::boost::graph_traits< Graph >::edge_descriptor Edge
Definition: Prm.h:175
rl::plan::Prm::SearchTraits
::CGAL::Search_traits< ::rl::math::Real, QueryItem, const ::rl::math::Real *, CartesianIterator > SearchTraits
Definition: Prm.h:160
rl::plan::Prm::Distance::new_distance
::rl::math::Real new_distance(const ::rl::math::Real &dist, const ::rl::math::Real &old_off, const ::rl::math::Real &new_off, const int &cutting_dimension) const
Definition: Prm.cpp:406
rl::plan::Prm::~Prm
virtual ~Prm()
Definition: Prm.cpp:61
rl
Definition: Ati.cpp:35