Parasol Planning Library (PPL)
AdaptiveRRT.h
Go to the documentation of this file.
1 #ifndef ADAPTIVE_RRT_H_
2 #define ADAPTIVE_RRT_H_
3 
4 #include "BasicRRTStrategy.h"
5 
6 // assembly code to measure cpu cycles
7 #include <cstdint>
8 #if defined(__x86_64__) || defined(_M_X64) // For x86_64 architecture
9 static inline uint64_t GetCycles() {
10  uint64_t n;
11  __asm__ __volatile__("rdtsc" : "=A"(n));
12  return n;
13 }
14 #elif defined(__aarch64__) // For ARM64 architecture, like Apple Silicon
15 #include <time.h>
16 static inline uint64_t GetCycles() {
17  struct timespec ts;
18  clock_gettime(CLOCK_MONOTONIC, &ts);
19  return static_cast<uint64_t>(ts.tv_sec) * 1000000000ULL + ts.tv_nsec;
20 }
21 #else
22 #error "Unsupported architecture"
23 #endif
24 
25 
43 class AdaptiveRRT : public BasicRRTStrategy {
44  public:
47 
48  // GrowthSet: map<Growth Method, pair<Weight Tuple, Cost>>
49  typedef std::map<std::string, std::pair<std::pair<double, long>, double>> GrowthSet;
50  // GrowthSets: map<Visibility Threshold, GrowthSet>
51  typedef std::map<double, GrowthSet> GrowthSets;
52 
55  typedef typename RoadmapType::VID VID;
56 
60 
61  //cost calculation method for AdaptiveRRT
63 
67 
68  AdaptiveRRT(double _wallPenalty = 0.5, double _gamma = 0.5,
69  const GrowthSets& _growthSets = GrowthSets(), CostMethod _c = FIXED);
70 
71  AdaptiveRRT(XMLNode& _node);
72 
73  //AdaptiveRRT();
74 
75  virtual ~AdaptiveRRT() = default;
76 
80 
81  virtual void Print(std::ostream& _os) const;
82 
84 
85 
86  protected:
89 
90  virtual void Initialize() override;
91 
95 
99  virtual VID ExpandTree(Cfg& _dir);
100 
104  std::string SelectGrowthMethod(GrowthSet& _gs);
105 
110  void UpdateCost(double _cost, std::string _s, GrowthSet& _gs);
111 
116  void RewardGrowthMethod(double _r, std::string _s, GrowthSet& _gs);
117 
118 
125  VID UpdateTree(VID _nearest, Cfg& _new, Cfg& _dir, double _delta);
126 
133  VID AddNode(Cfg& _newCfg, VID _nearVID, bool _againstWall,
134  double _ratio);
135 
137 
138 
139  private:
140 
147  void AvgVisibility(Cfg& _cfg, double _val);
148 
153  double CostInsensitiveProb(std::string _s, GrowthSet& _gs);
154 
158 
162  double GetVisibility(Cfg& _cfg);
163 
168  double GetCost(std::string _s, GrowthSet& _gs);
169 
173 
174  double m_wallPenalty;
175 
176  double m_gamma;
177 
178  GrowthSets m_growthSets;
179 
180  CostMethod m_costMethod;
181 
183 };
184 
185 #endif
Definition: AdaptiveRRT.h:43
VID AddNode(Cfg &_newCfg, VID _nearVID, bool _againstWall, double _ratio)
Definition: AdaptiveRRT.cpp:341
std::map< double, GrowthSet > GrowthSets
Definition: AdaptiveRRT.h:51
virtual void Print(std::ostream &_os) const
Definition: AdaptiveRRT.cpp:69
virtual ~AdaptiveRRT()=default
AdaptiveRRT(double _wallPenalty=0.5, double _gamma=0.5, const GrowthSets &_growthSets=GrowthSets(), CostMethod _c=FIXED)
Definition: AdaptiveRRT.cpp:10
RoadmapType::VID VID
Definition: AdaptiveRRT.h:55
MPBaseObject::WeightType WeightType
Definition: AdaptiveRRT.h:53
MPBaseObject::RoadmapType RoadmapType
Definition: AdaptiveRRT.h:54
void RewardGrowthMethod(double _r, std::string _s, GrowthSet &_gs)
Definition: AdaptiveRRT.cpp:297
std::string SelectGrowthMethod(GrowthSet &_gs)
Definition: AdaptiveRRT.cpp:231
virtual VID ExpandTree(Cfg &_dir)
Definition: AdaptiveRRT.cpp:109
VID UpdateTree(VID _nearest, Cfg &_new, Cfg &_dir, double _delta)
Definition: AdaptiveRRT.cpp:312
virtual void Initialize() override
Definition: AdaptiveRRT.cpp:93
std::map< std::string, std::pair< std::pair< double, long >, double > > GrowthSet
Definition: AdaptiveRRT.h:49
CostMethod
Definition: AdaptiveRRT.h:62
@ FIXED
Definition: AdaptiveRRT.h:62
@ CYCLES
Definition: AdaptiveRRT.h:62
@ REWARD
Definition: AdaptiveRRT.h:62
void UpdateCost(double _cost, std::string _s, GrowthSet &_gs)
Definition: AdaptiveRRT.cpp:282
Definition: BasicRRTStrategy.h:48
Definition: Cfg.h:38
Definition: Weight.h:36
Definition: GenericStateGraph.h:67
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
Definition: XMLNode.h:27