Parasol Planning Library (PPL)
DynamicRegionsPRM.h
Go to the documentation of this file.
1 #ifndef PMPL_DYNAMIC_REGIONS_PRM_H_
2 #define PMPL_DYNAMIC_REGIONS_PRM_H_
3 
4 #include "MPStrategyMethod.h"
5 
9 #include "Utilities/XMLNode.h"
11 
12 
30 
31  public:
32 
35 
38  typedef typename RoadmapType::VID VID;
40 
44 
49 
53 
57  struct SamplerSetting {
58  std::string label;
59  size_t count;
60  size_t attempts;
61  };
62 
66  struct EdgeOutput {
69  std::pair<WeightType, WeightType> weights;
70  };
71 
78  bool bridge;
79 
80  std::ostream& Print(std::ostream& _os) const {
81  return _os << "(" << edgeDescriptor.id()
82  << "|"
83  << edgeDescriptor.source() << "," << edgeDescriptor.target()
84  << "|"
86  << "|" << (bridge ? "+" : "-") << ")";
87  }
88 
89  friend std::ostream& operator<<(std::ostream& _os,
90  const LocalComponentDescriptor& _d) {
91  return _d.Print(_os);
92  }
93  };
94 
98  struct ExpansionRegion {
99 
102 
105  size_t edgeIndex{0};
106  double attempts{1};
107  double successes{0};
108 
110 
111  ExpansionRegion(const SkeletonEdgeIterator& _eit, const VID _representative)
112  : edgeIterator(_eit), representative(_representative) {}
113 
115  void TrackSuccess(const size_t _success, const size_t _attempts) {
116  successes *= .9;
117  attempts *= .9;
118  successes += _success;
119  attempts += _attempts;
120  }
121 
123  double GetWeight() const noexcept {
124  return successes / attempts;
125  }
126 
128  const Vector3d& GetCenter() const noexcept {
129  return (*edgeIterator).property()[edgeIndex];
130  }
131 
133  bool LastPoint() const noexcept {
134  return edgeIndex == (*edgeIterator).property().size() - 1;
135  }
136 
138  void Advance() noexcept {
139  ++edgeIndex;
140  }
141 
144  return {(*edgeIterator).descriptor(), representative, false};
145  }
146 
147  };
148 
153  struct EdgeCompare {
154  bool
156  const SkeletonEdgeDescriptor& _d2) const noexcept {
157  // Test ID first since we should only ever have two edges on the same ID (one
158  // for each direction). If ID are equal, sort by source, then target.
159  return _d1.id() < _d2.id()
160  or (!(_d1.id() > _d2.id())
161  and (_d1.source() < _d2.source()
162  or (!(_d1.source() > _d2.source())
163  and _d1.target() < _d2.target()
164  )
165  )
166  );
167  }
168  };
169 
172  struct EdgeIDCompare {
173  bool
175  const SkeletonEdgeDescriptor& _d2) const noexcept {
176  return _d1.id() < _d2.id();
177  }
178  };
179 
182  typedef std::map<Robot*, std::map<SkeletonEdgeDescriptor, std::map<VID, VertexSet>, EdgeCompare>>
184 
186  typedef std::map<Robot*, std::map<SkeletonEdgeDescriptor, std::map<VID, VertexSet>, EdgeIDCompare>>
188 
190  typedef std::map<Robot*, std::map<SkeletonEdgeDescriptor, std::map<VID, ExpansionRegion>, EdgeCompare>>
192 
194  typedef std::map<Robot*, std::set<size_t>> LowClearanceMap;
195 
197  typedef std::map<Robot*, std::set<SkeletonEdgeDescriptor, EdgeCompare>> UnconnectedEdgeMap;
198 
202 
204 
205  DynamicRegionsPRM(XMLNode& _node);
206 
207  virtual ~DynamicRegionsPRM() = default;
208 
212 
213  virtual void Print(std::ostream& _os) const override;
214 
218 
219  virtual void Initialize() override;
220 
221  virtual void Iterate() override;
222 
224 
225  protected:
226 
229 
231  void AddQuery();
232 
234  bool CheckReachedRegion(const VID _query, const VertexSet& _component);
235 
239  void GrowRRT(const VID _q);
240 
242 
246 
250 
251  // Initialize the unconnected edge map
253 
256 
261  const VertexSet& _vids);
262 
267 
272  noexcept;
273 
277  VertexSet& GetBridge(const LocalComponentDescriptor& _d) noexcept;
278 
281  LocalComponentDescriptor FindLocalComponent(const VID _vid) const noexcept;
282 
286 
295  const LocalComponentDescriptor& _d1,
296  const LocalComponentDescriptor& _d2);
297 
300 
302  bool IsEdgeConnected(const SkeletonEdgeDescriptor& _ed);
303 
307 
311 
314  std::pair<std::vector<double>, std::vector<ExpansionRegion*>>
316 
322  bool AdvanceRegion(ExpansionRegion* const _r,
323  const VertexSet& _newVIDs);
324 
329  bool AreSamplesCovered(const ExpansionRegion* const _region,
330  const VertexSet& _samples);
331 
335 
338  std::vector<Cfg> Sample(const Boundary* _b = nullptr);
339 
341  std::vector<Neighbor> FindNearestNeighbors(const Cfg& _cfg,
342  const VertexSet* const _candidates);
343 
346  bool AttemptConnection(const Cfg& _c1, const Cfg& _c2,
347  LPOutput& _lpOuptut);
348 
353  std::vector<EdgeOutput> ConnectToComponent(const Cfg& _cfg,
354  const LocalComponentDescriptor& _d);
355 
357  VID Extend(const VID _nearVID, const Cfg& _target,
358  LPOutput& _lp);
359 
363 
366  CSpaceBoundingSphere MakeBoundary(const Vector3d& _v);
367 
370  double GetRegionRadius(const Vector3d& _v);
371 
374  double GetClearance(const Vector3d& _v);
375 
377  void BuildSkeleton();
378 
379  // Initialize the low clearance map
381 
385 
386  std::vector<SamplerSetting> m_samplers;
387  std::string m_nfLabel;
388  std::string m_lpLabel;
389  std::string m_exLabel;
390  std::string m_decompositionLabel;
391 
392  std::string m_skeletonType{"reeb"};
393  std::string m_skeletonFilename;
394  std::string m_skeletonIO;
395 
399  double m_explore{.5};
400 
403  double m_minRegionRadius{-1};
404 
408 
412 
413  static bool m_initialized;
414 
416 
419 
421 
423 
425 
427 
428 };
429 
430 #endif
#define INVALID_VID
Definition: GenericStateGraph.h:23
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: DynamicRegionsPRM.h:29
LocalComponentDescriptor PromoteLocalComponent(LocalComponentDescriptor _d)
Definition: DynamicRegionsPRM.cpp:932
static LowClearanceMap m_lowClearanceMap
Track low-clearance edges.
Definition: DynamicRegionsPRM.h:422
void ConnectEdgeSegment(const SkeletonEdgeDescriptor _ed)
Definition: DynamicRegionsPRM.cpp:616
std::string m_nfLabel
The neighborhood finder label.
Definition: DynamicRegionsPRM.h:387
virtual ~DynamicRegionsPRM()=default
std::string m_exLabel
The extender label.
Definition: DynamicRegionsPRM.h:389
ExpansionRegion * GetExpansionRegion(const LocalComponentDescriptor &_d) noexcept
Definition: DynamicRegionsPRM.cpp:865
static bool m_initialized
Is the shared state initialized?
Definition: DynamicRegionsPRM.h:413
std::string m_skeletonType
Type of skeleton to build.
Definition: DynamicRegionsPRM.h:392
virtual void Print(std::ostream &_os) const override
Definition: DynamicRegionsPRM.cpp:103
void InitializeLowClearanceMap()
Definition: DynamicRegionsPRM.cpp:1684
RoadmapType::VertexSet VertexSet
Definition: DynamicRegionsPRM.h:39
static BridgeMap m_bridges
Completed local components.
Definition: DynamicRegionsPRM.h:418
std::vector< Cfg > Sample(const Boundary *_b=nullptr)
Definition: DynamicRegionsPRM.cpp:1369
ExpansionRegion * SelectExpansionRegion()
Definition: DynamicRegionsPRM.cpp:1119
void BuildSkeleton()
Build topological skeleton.
Definition: DynamicRegionsPRM.cpp:1588
void UpdateEdgeConnectivity(const SkeletonEdgeDescriptor &_ed)
Update the local connectivity for an edge.
Definition: DynamicRegionsPRM.cpp:1073
std::vector< EdgeOutput > ConnectToComponent(const Cfg &_cfg, const LocalComponentDescriptor &_d)
Definition: DynamicRegionsPRM.cpp:1443
std::vector< SamplerSetting > m_samplers
Samplers to generate nodes.
Definition: DynamicRegionsPRM.h:386
WorkspaceSkeleton::vertex_descriptor SkeletonVertexDescriptor
Definition: DynamicRegionsPRM.h:47
VertexSet & GetLocalComponent(const LocalComponentDescriptor &_d) noexcept
Definition: DynamicRegionsPRM.cpp:852
LocalComponentDescriptor FindLocalComponent(const VID _vid) const noexcept
Definition: DynamicRegionsPRM.cpp:897
std::map< Robot *, std::set< size_t > > LowClearanceMap
Map for low clearance.
Definition: DynamicRegionsPRM.h:194
MPBaseObject::RoadmapType RoadmapType
Definition: DynamicRegionsPRM.h:37
VID Extend(const VID _nearVID, const Cfg &_target, LPOutput &_lp)
Extend a tree node towards a direction.
Definition: DynamicRegionsPRM.cpp:1487
std::string m_skeletonIO
Option to read or write the skeleton.
Definition: DynamicRegionsPRM.h:394
virtual void Initialize() override
Definition: DynamicRegionsPRM.cpp:122
std::map< Robot *, std::map< SkeletonEdgeDescriptor, std::map< VID, VertexSet >, EdgeCompare > > LocalConnectivityMap
Definition: DynamicRegionsPRM.h:183
std::string m_decompositionLabel
The workspace decomposition label.
Definition: DynamicRegionsPRM.h:390
bool AreSamplesCovered(const ExpansionRegion *const _region, const VertexSet &_samples)
Definition: DynamicRegionsPRM.cpp:1342
virtual void Iterate() override
Execute one iteration of the strategy.
Definition: DynamicRegionsPRM.cpp:258
void MakeLocalComponent(const LocalComponentDescriptor &_d, const VertexSet &_vids)
Definition: DynamicRegionsPRM.cpp:805
DynamicRegionsPRM()
Definition: DynamicRegionsPRM.cpp:43
WorkspaceSkeleton::ED SkeletonEdgeDescriptor
Definition: DynamicRegionsPRM.h:45
std::map< Robot *, std::set< SkeletonEdgeDescriptor, EdgeCompare > > UnconnectedEdgeMap
Map for regions with unconnected local components.
Definition: DynamicRegionsPRM.h:197
static RegionMap m_regions
Expansion regions for local components.
Definition: DynamicRegionsPRM.h:420
void InitializeLUnconnectedEdgeMap()
Definition: DynamicRegionsPRM.cpp:1692
bool AdvanceRegion(ExpansionRegion *const _r, const VertexSet &_newVIDs)
Definition: DynamicRegionsPRM.cpp:1196
CSpaceBoundingSphere MakeBoundary(const Vector3d &_v)
Definition: DynamicRegionsPRM.cpp:1528
static LocalConnectivityMap m_localComponents
Local components in progress.
Definition: DynamicRegionsPRM.h:417
MPBaseObject::WeightType WeightType
Definition: DynamicRegionsPRM.h:36
VertexSet & GetBridge(const LocalComponentDescriptor &_d) noexcept
Definition: DynamicRegionsPRM.cpp:885
std::map< Robot *, std::map< SkeletonEdgeDescriptor, std::map< VID, VertexSet >, EdgeIDCompare > > BridgeMap
Bridges are non-directional and tied to edge IDs.
Definition: DynamicRegionsPRM.h:187
bool CheckReachedRegion(const VID _query, const VertexSet &_component)
Hax.
Definition: DynamicRegionsPRM.cpp:369
void AddQuery()
Add start and goals to the roadmap.
Definition: DynamicRegionsPRM.cpp:297
std::vector< Neighbor > FindNearestNeighbors(const Cfg &_cfg, const VertexSet *const _candidates)
Return K nearest neighors from a set of candidates.
Definition: DynamicRegionsPRM.cpp:1394
static UnconnectedEdgeMap m_unconnectedEdges
Track unconnected edges.
Definition: DynamicRegionsPRM.h:424
static WorkspaceSkeleton m_skeleton
The workspace skeleton.
Definition: DynamicRegionsPRM.h:415
bool IsEdgeConnected(const SkeletonEdgeDescriptor &_ed)
Check if an edge is considered locally connected.
Definition: DynamicRegionsPRM.cpp:1106
bool m_aggressiveBridging
Definition: DynamicRegionsPRM.h:407
std::pair< std::vector< double >, std::vector< ExpansionRegion * > > ComputeProbabilities()
Definition: DynamicRegionsPRM.cpp:1155
std::string m_skeletonFilename
The output file for the skeleton graph.
Definition: DynamicRegionsPRM.h:393
WorkspaceSkeleton::adj_edge_iterator SkeletonEdgeIterator
Definition: DynamicRegionsPRM.h:46
double GetRegionRadius(const Vector3d &_v)
Definition: DynamicRegionsPRM.cpp:1548
double m_explore
Definition: DynamicRegionsPRM.h:399
double GetClearance(const Vector3d &_v)
Definition: DynamicRegionsPRM.cpp:1561
bool AttemptConnection(const Cfg &_c1, const Cfg &_c2, LPOutput &_lpOuptut)
Definition: DynamicRegionsPRM.cpp:1430
VertexSet ExpandComponent(ExpansionRegion *const _r)
Definition: DynamicRegionsPRM.cpp:495
LocalComponentDescriptor MergeLocalComponents(const LocalComponentDescriptor &_d1, const LocalComponentDescriptor &_d2)
Definition: DynamicRegionsPRM.cpp:962
RoadmapType::VID VID
Definition: DynamicRegionsPRM.h:38
double m_minRegionRadius
Definition: DynamicRegionsPRM.h:403
WorkspaceSkeleton::vertex_iterator SkeletonVertexIterator
Definition: DynamicRegionsPRM.h:48
void GrowRRT(const VID _q)
Definition: DynamicRegionsPRM.cpp:396
std::string m_lpLabel
The neighborhood finder label.
Definition: DynamicRegionsPRM.h:388
std::map< Robot *, std::map< SkeletonEdgeDescriptor, std::map< VID, ExpansionRegion >, EdgeCompare > > RegionMap
Map for regions.
Definition: DynamicRegionsPRM.h:191
Definition: GenericStateGraph.h:67
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
std::unordered_set< VID > VertexSet
Definition: GenericStateGraph.h:86
Definition: MPStrategyMethod.h:33
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
Definition: DynamicRegionsPRM.h:153
bool operator()(const SkeletonEdgeDescriptor &_d1, const SkeletonEdgeDescriptor &_d2) const noexcept
Definition: DynamicRegionsPRM.h:155
Definition: DynamicRegionsPRM.h:172
bool operator()(const SkeletonEdgeDescriptor &_d1, const SkeletonEdgeDescriptor &_d2) const noexcept
Definition: DynamicRegionsPRM.h:174
Output for connection attempt.
Definition: DynamicRegionsPRM.h:66
VID target
Definition: DynamicRegionsPRM.h:68
VID source
Definition: DynamicRegionsPRM.h:67
std::pair< WeightType, WeightType > weights
Definition: DynamicRegionsPRM.h:69
Representation of an expansion region.
Definition: DynamicRegionsPRM.h:98
double attempts
Number of attempts to extend into this region.
Definition: DynamicRegionsPRM.h:106
const Vector3d & GetCenter() const noexcept
Get the center of this region.
Definition: DynamicRegionsPRM.h:128
const SkeletonEdgeIterator edgeIterator
Iterator to region's edge.
Definition: DynamicRegionsPRM.h:103
double GetWeight() const noexcept
Compute the weight for this region (i.e. success rate).
Definition: DynamicRegionsPRM.h:123
double successes
Number of successful attempts.
Definition: DynamicRegionsPRM.h:107
LocalComponentDescriptor GetLocalComponentDescriptor() const noexcept
Get the descriptor for the local component this region is expanding.
Definition: DynamicRegionsPRM.h:143
VID representative
Representative roadmap vertex.
Definition: DynamicRegionsPRM.h:104
void TrackSuccess(const size_t _success, const size_t _attempts)
Track the success rate of extending into this region.
Definition: DynamicRegionsPRM.h:115
ExpansionRegion(const SkeletonEdgeIterator &_eit, const VID _representative)
Definition: DynamicRegionsPRM.h:111
void Advance() noexcept
Advance this region to the next skeleton edge point.
Definition: DynamicRegionsPRM.h:138
bool LastPoint() const noexcept
Check if this region is at the last point on its skeleton edge.
Definition: DynamicRegionsPRM.h:133
size_t edgeIndex
Which edge point are we at?
Definition: DynamicRegionsPRM.h:105
A descriptor for a local connected component.
Definition: DynamicRegionsPRM.h:75
std::ostream & Print(std::ostream &_os) const
Definition: DynamicRegionsPRM.h:80
bool bridge
Does this span the edge?
Definition: DynamicRegionsPRM.h:78
friend std::ostream & operator<<(std::ostream &_os, const LocalComponentDescriptor &_d)
Definition: DynamicRegionsPRM.h:89
VID representative
Representative roadmap vertex.
Definition: DynamicRegionsPRM.h:77
SkeletonEdgeDescriptor edgeDescriptor
The edge this component is on.
Definition: DynamicRegionsPRM.h:76
Settings for a specific sampler.
Definition: DynamicRegionsPRM.h:57
std::string label
The sampler label.
Definition: DynamicRegionsPRM.h:58
size_t attempts
The number of attempts to generate each sample.
Definition: DynamicRegionsPRM.h:60
size_t count
The number of samples to generate.
Definition: DynamicRegionsPRM.h:59
Definition: LPOutput.h:24