Parasol Planning Library (PPL)
GroupPath.h
Go to the documentation of this file.
1 #ifndef PMPL_GROUP_PATH_H_
2 #define PMPL_GROUP_PATH_H_
3 
10 // #include "MPLibrary/MPLibrary.h"
12 
13 #include <algorithm>
14 #include <vector>
15 
16 
23 class GroupPath final {
24 
25  public:
26 
29 
33  typedef typename GroupRoadmapType::VID VID;
34 
38 
41  GroupPath(GroupRoadmapType* const _r = nullptr);
42 
46 
48  GroupRoadmapType* GetRoadmap() const noexcept;
49 
51  size_t Size() const noexcept;
52 
54  bool Empty() const noexcept;
55 
57  double Length() const;
58 
59  size_t TimeSteps() const;
60 
62  const std::vector<VID>& VIDs() const noexcept;
63 
65  const std::pair<std::vector<VID>,std::vector<size_t>> VIDsWaiting() const noexcept;
66 
70  const std::vector<GroupCfgType>& Cfgs() const;
71 
78  template <typename MPLibrary>
79  const std::vector<GroupCfgType> FullCfgs(MPLibrary* const _lib) const;
80 
87  template <typename MPLibrary>
88  const std::vector<GroupCfgType> FullCfgsWithWait(MPLibrary* const _lib) const;
89 
92  GroupPath& operator+=(const GroupPath& _p);
93 
96  GroupPath operator+(const GroupPath& _p) const;
97 
100  GroupPath& operator+=(const std::vector<VID>& _vids);
101 
104  GroupPath operator+(const std::vector<VID>& _vids) const;
105 
107  GroupPath& operator=(const GroupPath& _p);
108 
110  void Clear();
111 
113  void FlushCache();
114 
117  void SetWaitTimes(std::vector<size_t> _waitTimes);
118 
120  std::vector<size_t> GetWaitTimes();
121 
125  std::pair<size_t,size_t> GetEdgeAtTimestep(size_t _timestep);
126 
128 
129  private:
130 
133 
136  void AssertSameMap(const GroupPath& _p) const;
137 
141 
142  GroupRoadmapType* const m_roadmap;
143  std::vector<VID> m_vids;
144  std::vector<size_t> m_waitingTimesteps;
145  size_t m_finalWaitTimeSteps{0};
146 
147  mutable std::vector<GroupCfgType> m_cfgs;
148  mutable bool m_cfgsCached{false};
149 
150  mutable double m_length{0};
151  mutable bool m_lengthCached{false};
152 
153  mutable double m_timesteps{0};
154  mutable bool m_timestepsCached{false};
156 };
157 
158 
159 template <typename MPLibrary>
160 const std::vector<typename GroupPath::GroupCfgType>
162 FullCfgs(MPLibrary* const _lib) const {
163  if(m_vids.empty())
164  return std::vector<GroupCfgType>();
165 
166  // Insert the first vertex.
167  std::vector<GroupCfgType> out = {m_roadmap->GetVertex(m_vids.front())};
168 
169  for(auto it = m_vids.begin(); it + 1 < m_vids.end(); ++it) {
170  const VID source = *it,
171  target = *(it + 1);
172  // const auto& edge = m_roadmap->GetEdge(source, target);
173 
174  // Insert intermediates between vertices. For assembly planning (skip edge):
175  // don't reconstruct the edge when it's for a part that has been placed off
176  // to the side, just use the two cfgs. This edge will just be (start, end).
177  // if(!edge.SkipEdge()) {
178  auto e = m_roadmap->GetEdge(source,target);
179  auto edge = !e.GetIntermediates().empty() ? e.GetIntermediates()
180  : _lib->ReconstructEdge(m_roadmap, source, target);
181 
182  if(!edge.empty()) {
183  // Only grab the intermediate cfgs.
184  auto startIter = edge.begin();
185 
186  auto endIter = edge.end();
187 
188  out.insert(out.end(), startIter, endIter);
189  }
190  // }
191 
192  // Insert the next vertex.
193  out.push_back(m_roadmap->GetVertex(target));
194  }
195  return out;
196 }
197 
198 
199 template <typename MPLibrary>
200 const std::vector<typename GroupPath::GroupCfgType>
202 FullCfgsWithWait(MPLibrary* const _lib) const {
203  if(m_vids.empty())
204  return std::vector<GroupCfgType>();
205 
206  if(m_waitingTimesteps.empty())
207  return FullCfgs(_lib);
208 
209  // Insert the first vertex.
210  size_t vid = m_vids.front();
211  GroupCfgType vertex = m_roadmap->GetVertex(vid);
212  std::vector<GroupCfgType> out = {vertex};
213 
214  // Insert first vertex however many timesteps it waits
215  //for(size_t i = 0; i < m_waitingTimesteps[0]; ++i) {
216  for(size_t i = 0; i < m_waitingTimesteps[0]; ++i) {
217  out.push_back(vertex);
218  }
219 
220  auto cnt = 1;
221  for(auto it = m_vids.begin(); it + 1 < m_vids.end(); ++it) {
222  // Insert intermediates between vertices.
223 
224  //std::vector<GroupCfgType> edge = _lib->ReconstructEdge(m_roadmap, *it, *(it+1));
225  auto e = m_roadmap->GetEdge(*it,*(it+1));
226  auto edge = !e.GetIntermediates().empty() ? e.GetIntermediates()
227  : _lib->ReconstructEdge(m_roadmap,*it,*(it+1));
228  out.insert(out.end(), edge.begin(), edge.end());
229 
230  // Insert the next vertex.
231  vid = *(it+1);
232  vertex = m_roadmap->GetVertex(vid);
233  out.push_back(vertex);
234  for(size_t i = 0; i < m_waitingTimesteps[cnt]; ++i) {
235  out.push_back(vertex);
236  }
237 
238  cnt++;
239  }
240 
241  auto last = out.back();
242  for(size_t i = 0; i < m_finalWaitTimeSteps; i++) {
243  out.push_back(last);
244  }
245  return out;
246 }
247 
248 #endif
Definition: GenericStateGraph.h:67
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
bool GetEdge(const VID _source, const VID _target, EI &_ei) noexcept
Definition: GenericStateGraph.h:1145
VP & GetVertex(T &_t) noexcept
Retrieve a reference to a vertex property by descriptor or iterator.
Definition: GenericStateGraph.h:1034
Definition: GroupCfg.h:39
Definition: GroupPath.h:23
size_t TimeSteps() const
Definition: GroupPath.cpp:61
const std::vector< GroupCfgType > FullCfgsWithWait(MPLibrary *const _lib) const
GenericStateGraph< Cfg, DefaultWeight< Cfg > > RoadmapType
Definition: GroupPath.h:30
GroupRoadmap< GroupCfgType, GroupLocalPlan< RoadmapType > > GroupRoadmapType
Definition: GroupPath.h:32
GroupPath(GroupRoadmapType *const _r=nullptr)
Definition: GroupPath.cpp:9
void SetWaitTimes(std::vector< size_t > _waitTimes)
Definition: GroupPath.cpp:187
std::pair< size_t, size_t > GetEdgeAtTimestep(size_t _timestep)
Definition: GroupPath.cpp:207
const std::pair< std::vector< VID >, std::vector< size_t > > VIDsWaiting() const noexcept
Get the VIDs and timesteps waiting in the path.
std::vector< size_t > GetWaitTimes()
Get the wait times at each vertex in the path.
Definition: GroupPath.cpp:200
const std::vector< GroupCfgType > FullCfgs(MPLibrary *const _lib) const
void Clear()
Clear all data in the path.
Definition: GroupPath.cpp:168
const std::vector< GroupCfgType > & Cfgs() const
Definition: GroupPath.cpp:97
void FlushCache()
Clear cached data, but leave the VIDs.
Definition: GroupPath.cpp:177
const std::vector< VID > & VIDs() const noexcept
Get the VIDs in the path.
Definition: GroupPath.cpp:90
GroupCfg< RoadmapType > GroupCfgType
Definition: GroupPath.h:31
GroupRoadmapType * GetRoadmap() const noexcept
Get the roadmap used by this path.
Definition: GroupPath.cpp:15
size_t Size() const noexcept
Get the number of cfgs in the path.
Definition: GroupPath.cpp:22
GroupRoadmapType::VID VID
Definition: GroupPath.h:33
bool Empty() const noexcept
Check if the path is empty.
Definition: GroupPath.cpp:29
double Length() const
Get the total edge weight.
Definition: GroupPath.cpp:36
Definition: GroupRoadmap.h:25
Definition: MPLibrary.h:47
std::vector< typename RoadmapType::VP > ReconstructEdge(RoadmapType *const _roadmap, const VID _source, const VID _target, const double _posRes, const double _oriRes)
Definition: MPLibrary.cpp:410