Parasol Planning Library (PPL)
DynamicRegionRRT.h
Go to the documentation of this file.
1 #ifndef PPL_DYNAMIC_REGION_RRT_H_
2 #define PPL_DYNAMIC_REGION_RRT_H_
3 
4 #include "BasicRRTStrategy.h"
5 
7 #include "Utilities/XMLNode.h"
9 
21 class DynamicRegionRRT : virtual public BasicRRTStrategy {
22  public:
25 
28  typedef typename RoadmapType::VID VID;
29 
33 
38 
42 
46  struct SamplingRegion {
47 
50 
52  size_t edgeIndex{0};
53  double attempts{1};
54  double successes{1};
55 
57 
59  : edgeIterator(_eit) {}
60 
62  void TrackSuccess(const size_t _success, const size_t _attempts) {
63  successes *= .9;
64  attempts *= .9;
65  successes += _success;
66  attempts += _attempts;
67  }
68 
70  double GetWeight() const noexcept {
71  return successes / attempts;
72  }
73 
75  const Vector3d& GetCenter() const noexcept {
76  return (*edgeIterator).property()[edgeIndex];
77  }
78 
80  bool LastPoint() const noexcept {
81  return edgeIndex == (*edgeIterator).property().size() - 1;
82  }
83 
85  void Advance() noexcept {
86  ++edgeIndex;
87  }
88 
91  if(this != &_region) {
92  edgeIterator = _region.edgeIterator;
93  edgeIndex = _region.edgeIndex;
94  attempts = _region.attempts;
95  successes = _region.successes;
96  }
97  return *this;
98  }
99 
101  bool operator==(const SamplingRegion& _region) const {
102  bool eit = edgeIterator == _region.edgeIterator;
103  bool idx = edgeIndex == _region.edgeIndex;
104  bool att = attempts == _region.attempts;
105  bool succ = successes == _region.successes;
106  return eit and idx and att and succ;
107  }
108 
109  };
110 
114 
116 
117  DynamicRegionRRT(XMLNode& _node);
118 
119  virtual ~DynamicRegionRRT() = default;
120 
124 
125  virtual void Print(std::ostream& _os) const override;
126 
128 
129  protected:
132 
133  virtual void Initialize() override;
134 
138 
140  virtual Cfg SelectTarget() override;
141 
146  virtual std::pair<VID, bool> AddNode(const Cfg& _newCfg) override;
147 
151 
156  Cfg Sample(SamplingRegion* _region);
157 
162  Cfg Sample(const Boundary* const _boundary, const std::string* _samplerLabel);
163 
167  const Vector3d GetVelocityBias(SamplingRegion* _region);
168 
172  bool IsTouching(const Cfg& _cfg, SamplingRegion& _region);
173 
177  CSpaceBoundingSphere MakeBoundary(const Vector3d& _v);
178 
182 
184  void BuildSkeleton();
185 
187  void DirectSkeleton();
188 
191  const size_t SelectSamplingRegion();
192 
195  std::vector<double> ComputeProbabilities();
196 
201  void BiasVelocity(Cfg& _cfg, SamplingRegion* _region);
202 
207  void CheckRegionProximity(const Point3d& _p);
208 
212  std::vector<SamplingRegion*>
214 
218  void AdvanceRegions(const Cfg& _cfg);
219 
224  bool AdvanceRegionToCompletion(const Cfg& _cfg, SamplingRegion& _region);
225 
229 
232 
233  std::string m_skeletonType{"reeb"};
234  std::string m_decompositionLabel;
235  std::string m_scuLabel;
236 
237  bool m_velocityBiasing{false};
238  double m_velocityAlignment{.1};
239 
240  bool m_initialized{false};
241 
243  std::pair<Point3d, Point3d> m_queryPair;
244 
246  std::vector<SamplingRegion> m_regions;
247 
249  std::unordered_map<WorkspaceSkeleton::VD, bool> m_visited;
250 
253  double m_regionFactor{2};
254 
255  double m_regionRadius{0};
256 
260  double m_explore{.5};
261 
265 
267 };
268 
269 #endif
Definition: BasicRRTStrategy.h:48
Definition: Boundary.h:30
An n-dimensional bounding sphere in c-space.
Definition: CSpaceBoundingSphere.h:10
Definition: Cfg.h:38
Definition: Weight.h:36
Definition: DynamicRegionRRT.h:21
const size_t SelectSamplingRegion()
Definition: DynamicRegionRRT.cpp:528
virtual void Initialize() override
Definition: DynamicRegionRRT.cpp:77
std::pair< Point3d, Point3d > m_queryPair
Pair of points we use to direct the skeleton.
Definition: DynamicRegionRRT.h:243
std::string m_scuLabel
The skeleton clearance utility label.
Definition: DynamicRegionRRT.h:235
std::string m_decompositionLabel
The workspace decomposition label.
Definition: DynamicRegionRRT.h:234
const Vector3d GetVelocityBias(SamplingRegion *_region)
Definition: DynamicRegionRRT.cpp:255
WorkspaceSkeleton::ED SkeletonEdgeDescriptor
Definition: DynamicRegionRRT.h:34
virtual ~DynamicRegionRRT()=default
double m_explore
Definition: DynamicRegionRRT.h:260
MPBaseObject::WeightType WeightType
Definition: DynamicRegionRRT.h:26
void CheckRegionProximity(const Point3d &_p)
Definition: DynamicRegionRRT.cpp:621
WorkspaceSkeleton::adj_edge_iterator SkeletonEdgeIterator
Definition: DynamicRegionRRT.h:35
virtual Cfg SelectTarget() override
Get a random configuration to grow towards.
Definition: DynamicRegionRRT.cpp:119
std::vector< SamplingRegion * > CreateRegions(const WorkspaceSkeleton::vertex_iterator _iter)
Definition: DynamicRegionRRT.cpp:637
WorkspaceSkeleton::vertex_descriptor SkeletonVertexDescriptor
Definition: DynamicRegionRRT.h:36
Cfg Sample(SamplingRegion *_region)
Definition: DynamicRegionRRT.cpp:200
CSpaceBoundingSphere MakeBoundary(const Vector3d &_v)
Definition: DynamicRegionRRT.cpp:351
DynamicRegionRRT()
Definition: DynamicRegionRRT.cpp:11
std::string m_skeletonType
Type of skeleton to build.
Definition: DynamicRegionRRT.h:233
bool AdvanceRegionToCompletion(const Cfg &_cfg, SamplingRegion &_region)
Definition: DynamicRegionRRT.cpp:725
MPBaseObject::RoadmapType RoadmapType
Definition: DynamicRegionRRT.h:27
bool IsTouching(const Cfg &_cfg, SamplingRegion &_region)
Definition: DynamicRegionRRT.cpp:317
void AdvanceRegions(const Cfg &_cfg)
Definition: DynamicRegionRRT.cpp:667
std::unordered_map< WorkspaceSkeleton::VD, bool > m_visited
Keep track of which skeleton vertices we've visited.
Definition: DynamicRegionRRT.h:249
double m_regionFactor
Definition: DynamicRegionRRT.h:253
RoadmapType::VID VID
Definition: DynamicRegionRRT.h:28
double m_velocityAlignment
Strength of velocity biasing.
Definition: DynamicRegionRRT.h:238
void BuildSkeleton()
Build topological skeleton.
Definition: DynamicRegionRRT.cpp:372
WorkspaceSkeleton::vertex_iterator SkeletonVertexIterator
Definition: DynamicRegionRRT.h:37
void BiasVelocity(Cfg &_cfg, SamplingRegion *_region)
Definition: DynamicRegionRRT.cpp:595
WorkspaceSkeleton m_skeleton
The directed/pruned workspace skeleton.
Definition: DynamicRegionRRT.h:231
virtual std::pair< VID, bool > AddNode(const Cfg &_newCfg) override
Definition: DynamicRegionRRT.cpp:171
std::vector< double > ComputeProbabilities()
Definition: DynamicRegionRRT.cpp:566
std::vector< SamplingRegion > m_regions
The set of active dynamic sampling regions and associated metadata.
Definition: DynamicRegionRRT.h:246
WorkspaceSkeleton m_originalSkeleton
The original workspace skeleton.
Definition: DynamicRegionRRT.h:230
double m_penetrationFactor
Definition: DynamicRegionRRT.h:264
void DirectSkeleton()
Construct the pruned and directed query skeleton.
Definition: DynamicRegionRRT.cpp:438
bool m_initialized
Have auxiliary structures been initialized?
Definition: DynamicRegionRRT.h:240
virtual void Print(std::ostream &_os) const override
Definition: DynamicRegionRRT.cpp:54
double m_regionRadius
The region radius.
Definition: DynamicRegionRRT.h:255
bool m_velocityBiasing
Use velocity biasing?
Definition: DynamicRegionRRT.h:237
Definition: GenericStateGraph.h:67
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
Geometric skeleton of the workspace.
Definition: WorkspaceSkeleton.h:22
BaseType::EID ED
Definition: WorkspaceSkeleton.h:32
BaseType::VID vertex_descriptor
Definition: WorkspaceSkeleton.h:34
BaseType::VI vertex_iterator
Definition: WorkspaceSkeleton.h:33
BaseType::EI adj_edge_iterator
Definition: WorkspaceSkeleton.h:35
Definition: XMLNode.h:27
Representation of a sampling region.
Definition: DynamicRegionRRT.h:46
bool LastPoint() const noexcept
Check if this region is at the last point on its skeleton edge.
Definition: DynamicRegionRRT.h:80
double GetWeight() const noexcept
Compute the weight for this region (i.e. success rate).
Definition: DynamicRegionRRT.h:70
const Vector3d & GetCenter() const noexcept
Get the center of this region.
Definition: DynamicRegionRRT.h:75
double successes
Number of successful attempts.
Definition: DynamicRegionRRT.h:54
SamplingRegion & operator=(const SamplingRegion &_region)
Assignment operator.
Definition: DynamicRegionRRT.h:90
double attempts
Number of attempts to extend into this region.
Definition: DynamicRegionRRT.h:53
size_t edgeIndex
Which edge point are we at?
Definition: DynamicRegionRRT.h:52
void TrackSuccess(const size_t _success, const size_t _attempts)
Track the success rate of extending into this region.
Definition: DynamicRegionRRT.h:62
SamplingRegion(const SkeletonEdgeIterator &_eit)
Definition: DynamicRegionRRT.h:58
bool operator==(const SamplingRegion &_region) const
Equality operator.
Definition: DynamicRegionRRT.h:101
void Advance() noexcept
Advance this region to the next skeleton edge point.
Definition: DynamicRegionRRT.h:85
SkeletonEdgeIterator edgeIterator
Iterator to region's edge.
Definition: DynamicRegionRRT.h:51