Parasol Planning Library (PPL)
SIPPMethod.h
Go to the documentation of this file.
1 #ifndef PPL_SIPP_METHOD_H_
2 #define PPL_SIPP_METHOD_H_
3 
4 #include "MapEvaluatorMethod.h"
5 
10 
12 
16 
17 #include "MPProblem/GroupTask.h"
18 #include "MPProblem/MPProblem.h"
19 #include "MPProblem/MPTask.h"
20 #include "MPProblem/Robot/Robot.h"
22 
28 struct SIPPVertex {
29  size_t vid;
31 
32  bool operator==(const SIPPVertex& _other) const {
33  return vid == _other.vid &&
34  interval == _other.interval;
35  }
36 };
37 
38 struct SIPPEdge {
39  size_t source;
40  size_t target;
42 };
43 
45 
46  public:
47 
50 
51  typedef std::unordered_set<size_t> VIDSet;
56 
57  typedef std::map<std::pair<size_t,size_t>,
58  std::vector<Range<size_t>>> EdgeIntervalMap;
59 
60  typedef std::map<size_t,std::vector<Range<size_t>>> VertexIntervalMap;
61 
63 
67 
68  SIPPMethod();
69 
70  SIPPMethod(XMLNode& _node);
71 
72  virtual ~SIPPMethod() = default;
73 
77 
78  virtual void Print(std::ostream& _os) const override;
79 
80  virtual void Initialize() override;
81 
85 
86  virtual bool operator()() override;
87 
91 
95  std::pair<std::vector<size_t>,std::vector<size_t>>
96  GeneratePath(const size_t _start, const std::vector<size_t> _goals);
97 
99  void SetDMLabel(const std::string& _dmLabel);
100 
102  void SetStartTime(size_t _start);
103 
105  void SetMinEndTime(size_t _end);
106 
108  void SetEdgeIntervals(EdgeIntervalMap _edgeIntervals);
109 
111  void SetVertexIntervals(VertexIntervalMap _vertexIntervals);
112 
114  bool SatisfyConstraints(Range<size_t> _interval);
115 
117 
118  protected:
119 
122 
125  virtual void Reset();
126 
132  virtual bool PerformSubQuery(const size_t _start, const std::vector<size_t> _goals);
133 
144  virtual double PathWeight(typename SIPPGraph::adj_edge_iterator& _ei,
145  const double _sourceDistance, const double _targetDistance);
146 
154  double SIPPHeuristic(const SIPPGraph* _g,
155  typename SIPPGraph::vertex_descriptor _source,
156  typename SIPPGraph::vertex_descriptor _target);
157 
159  void SIPPNeighbors(SIPPGraph* _g, typename SIPPGraph::vertex_descriptor _vid);
160 
161  template <typename AbstractRoadmap>
162  void SIPPNeighbors(SIPPGraph* _g, typename SIPPGraph::vertex_descriptor _vid,
163  AbstractRoadmap* _rm);
164 
166  template <typename AbstractRoadmap>
167  void BuildNeighbors(typename SIPPGraph::vertex_descriptor _sippSource,
168  size_t _rmTarget, AbstractRoadmap* _rm);
169 
171  void InitializeCostToGo(const std::vector<size_t> _goal);
172 
176 
178  SIPPGraph* m_sippGraph{nullptr};
179 
180  size_t m_goalIndex{0};
181  size_t m_startVID{SIZE_MAX};
182 
184  std::unordered_map<size_t,double> m_costToGoMap;
185 
188 
190  std::unordered_map<size_t,std::unordered_map<size_t,size_t>> m_waitTimesteps;
191 
192  size_t m_startTime{0};
193  size_t m_minEndTime{0};
194 
195  bool m_initialized{false};
196  bool m_minTime{true};
197 
198  // James: We no longer use the SI Tool to compute intervals.
199  // More accurately, we no longer compute intervals within this class and instead
200  // set them externally. That encapsulation is fine, but we should remove this.
201  std::string m_safeIntervalLabel;
202  std::string m_dmLabel;
203 
205 };
206 
207 template <typename AbstractRoadmap>
208 void
211  typename SIPPGraph::vertex_descriptor _vid,
212  AbstractRoadmap* _rm) {
213 
214  auto vertex = _g->GetVertex(_vid);
215  auto vid = vertex.vid;
216 
217  // Get vertex iterator for vid
218  auto vit = _rm->find_vertex(vid);
219 
220  // Check that vertex is contained in roadmap
221  if(vit == _rm->end())
222  throw RunTimeException(WHERE) << vid << " does not existing in roadmap.";
223 
224  // Build SIPP Neighbors for each roadmap neighbor
225  for(auto eit = vit->begin(); eit != vit->end(); eit++) {
226  BuildNeighbors(_vid,eit->target(),_rm);
227  }
228 }
229 
230 
231 template <typename AbstractRoadmap>
232 void
234 BuildNeighbors(typename SIPPGraph::vertex_descriptor _sippSource, size_t _rmTarget,
235  AbstractRoadmap* _rm) {
236 
237  const auto vertex = m_sippGraph->GetVertex(_sippSource);
238  const size_t rmSource = vertex.vid;
239 
240  // Find candidate intervals for target vertex
241  std::vector<Range<size_t>> endIntervals;
242  if(!m_vertexIntervals.empty()) {
243  endIntervals = m_vertexIntervals[_rmTarget];
244  }
245  else {
246  endIntervals.push_back(Range<size_t>(0,SIZE_MAX));
247  }
248 
249  for(auto& inter : endIntervals) {
250 
251  // Add new sipp vertex and edge to graph
252  SIPPVertex targetVertex;
253  targetVertex.vid = _rmTarget;
254  targetVertex.interval = inter;
255 
256  auto targetVID = m_sippGraph->AddVertex(targetVertex);
257 
258  SIPPEdge newEdge;
259  newEdge.source = rmSource;
260  newEdge.target = _rmTarget;
261 
262  m_sippGraph->AddEdge(_sippSource,targetVID,newEdge);
263  }
264 
265 }
266 
267 std::istream& operator>>(std::istream& _is, SIPPVertex& _vertex);
268 
269 std::ostream& operator<<(std::ostream& _os, const SIPPVertex& _vertex);
270 
271 std::istream& operator>>(std::istream& _is, SIPPEdge& _edge);
272 
273 std::ostream& operator<<(std::ostream& _os, const SIPPEdge& _edge);
274 
275 #endif
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
std::ostream & operator<<(std::ostream &_os, const SIPPVertex &_vertex)
Definition: SIPPMethod.cpp:637
std::istream & operator>>(std::istream &_is, SIPPVertex &_vertex)
Definition: SIPPMethod.cpp:633
Definition: GenericStateGraph.h:67
virtual EID AddEdge(const VID _source, const VID _target, const Edge &_w) noexcept
Definition: GenericStateGraph.h:698
virtual VID AddVertex(const Vertex &_v) noexcept
Definition: GenericStateGraph.h:591
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: GroupLocalPlan.h:24
Definition: GroupRoadmap.h:25
Definition: MapEvaluatorMethod.h:16
Definition: SIPPMethod.h:44
virtual void Print(std::ostream &_os) const override
Definition: SIPPMethod.cpp:38
void SetEdgeIntervals(EdgeIntervalMap _edgeIntervals)
Set the edge intervals to use to generate a path.
Definition: SIPPMethod.cpp:570
MPBaseObject::GroupCfgType GroupCfgType
Definition: SIPPMethod.h:54
GenericStateGraph< SIPPVertex, SIPPEdge > SIPPGraph
Definition: SIPPMethod.h:62
virtual bool PerformSubQuery(const size_t _start, const std::vector< size_t > _goals)
Definition: SIPPMethod.cpp:344
std::map< size_t, std::vector< Range< size_t > > > VertexIntervalMap
Definition: SIPPMethod.h:60
void BuildNeighbors(typename SIPPGraph::vertex_descriptor _sippSource, size_t _rmTarget, AbstractRoadmap *_rm)
Construct the SIPP neighbors for roadmap edge.
Definition: SIPPMethod.h:234
double SIPPHeuristic(const SIPPGraph *_g, typename SIPPGraph::vertex_descriptor _source, typename SIPPGraph::vertex_descriptor _target)
Definition: SIPPMethod.cpp:493
EdgeIntervalMap m_edgeIntervals
Set of safe edge intervals.
Definition: SIPPMethod.h:186
size_t m_startTime
The start time of the path.
Definition: SIPPMethod.h:192
SIPPMethod()
Definition: SIPPMethod.cpp:16
void SetDMLabel(const std::string &_dmLabel)
Set the distance metric to use.
Definition: SIPPMethod.cpp:308
virtual bool operator()() override
Definition: SIPPMethod.cpp:64
std::map< std::pair< size_t, size_t >, std::vector< Range< size_t > > > EdgeIntervalMap
Definition: SIPPMethod.h:58
MPBaseObject::RoadmapType RoadmapType
Definition: SIPPMethod.h:52
virtual ~SIPPMethod()=default
void SetStartTime(size_t _start)
Set the start time of the query.
Definition: SIPPMethod.cpp:315
bool m_minTime
Flag indiciating if search is minimizing time or distance metric.
Definition: SIPPMethod.h:196
MPBaseObject::GroupWeightType GroupWeightType
Definition: SIPPMethod.h:55
std::string m_dmLabel
Distance metric label.
Definition: SIPPMethod.h:202
virtual double PathWeight(typename SIPPGraph::adj_edge_iterator &_ei, const double _sourceDistance, const double _targetDistance)
Definition: SIPPMethod.cpp:385
size_t m_goalIndex
Index of the current goal to extend the path to.
Definition: SIPPMethod.h:180
size_t m_minEndTime
The minimum end time of the path.
Definition: SIPPMethod.h:193
void InitializeCostToGo(const std::vector< size_t > _goal)
Initialize the cost to go from the start point to the goal.
Definition: SIPPMethod.cpp:522
std::unordered_map< size_t, double > m_costToGoMap
Cost-to-go map used for heuristic values.
Definition: SIPPMethod.h:184
bool m_initialized
Flag indicating if the object has been initialized.
Definition: SIPPMethod.h:195
void SetVertexIntervals(VertexIntervalMap _vertexIntervals)
Set the edge intervals to use to generate a path.
Definition: SIPPMethod.cpp:577
std::pair< std::vector< size_t >, std::vector< size_t > > GeneratePath(const size_t _start, const std::vector< size_t > _goals)
Definition: SIPPMethod.cpp:199
VertexIntervalMap m_vertexIntervals
Set of safe vertex intervals.
Definition: SIPPMethod.h:187
void SetMinEndTime(size_t _end)
Set the end time of the query.
Definition: SIPPMethod.cpp:322
std::string m_safeIntervalLabel
Label of the SI Tool to use.
Definition: SIPPMethod.h:201
MPBaseObject::GroupRoadmapType GroupRoadmapType
Definition: SIPPMethod.h:53
SIPPGraph * m_sippGraph
The graph representing the time-interval extended state space.
Definition: SIPPMethod.h:178
void SIPPNeighbors(SIPPGraph *_g, typename SIPPGraph::vertex_descriptor _vid)
Neighbors function for Safe interval path planning.
Definition: SIPPMethod.cpp:507
size_t m_startVID
The start vid in the sipp graph.
Definition: SIPPMethod.h:181
virtual void Initialize() override
Definition: SIPPMethod.cpp:49
virtual void Reset()
Definition: SIPPMethod.cpp:329
bool SatisfyConstraints(Range< size_t > _interval)
Check if the path satisfies all constraints.
Definition: SIPPMethod.cpp:584
std::unordered_map< size_t, std::unordered_map< size_t, size_t > > m_waitTimesteps
Compute wait timesteps at each vertex during the search process.
Definition: SIPPMethod.h:190
std::unordered_set< size_t > VIDSet
Definition: SIPPMethod.h:51
Definition: XMLNode.h:27
Definition: PMPLExceptions.h:62
Definition: SIPPMethod.h:38
size_t source
Definition: SIPPMethod.h:39
Range< double > interval
Definition: SIPPMethod.h:41
size_t target
Definition: SIPPMethod.h:40
Definition: SIPPMethod.h:28
bool operator==(const SIPPVertex &_other) const
Definition: SIPPMethod.h:32
Range< size_t > interval
Definition: SIPPMethod.h:30
size_t vid
Definition: SIPPMethod.h:29