Parasol Planning Library (PPL)
GenericStateGraph.h
Go to the documentation of this file.
1 #ifndef PPL_STATE_GRAPH_H_
2 #define PPL_STATE_GRAPH_H_
3 
7 
8 #ifdef _PARALLEL
9 #include <containers/graph/dynamic_graph.hpp>
10 //#include "graph/view/graph_view_property_adaptor.h"
11 //#include <containers/graph/view/graph_view_property_adaptor.hpp>
12 #include <containers/sequential/graph/algorithms/connected_components.h>
13 #include <containers/graph/algorithms/graph_io.hpp>
14 #else
15 #include <containers/sequential/graph/graph.h>
16 #include <containers/sequential/graph/graph_util.h>
17 #include <containers/sequential/graph/vertex_iterator_adaptor.h>
18 #include <containers/sequential/graph/algorithms/connected_components.h>
19 #include <containers/sequential/graph/algorithms/graph_input_output.h>
20 #endif
21 
22 #ifndef INVALID_VID
23 #define INVALID_VID (std::numeric_limits<size_t>::max())
24 #endif
25 
26 #ifndef INVALID_EID
27 #define INVALID_EID (std::numeric_limits<size_t>::max())
28 #endif
29 
30 // #include "MPLibrary/MPBaseObject.h"
31 #include "Utilities/CCTracker.h"
32 
33 #include <fstream>
34 #include <functional>
35 #include <iostream>
36 #include <string>
37 #include <unordered_map>
38 #include <unordered_set>
39 #include <vector>
40 
41 class Robot;
42 
43 
59 template <typename Vertex, typename Edge>
60 class GenericStateGraph: public
61 #ifdef _PARALLEL
62  stapl::dynamic_graph<stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex, Edge>
63 #else
64  stapl::sequential::graph<stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex,
65  Edge>
66 #endif
67 {
68 
69  public:
70 
73 
74  using STAPLGraph =
75 #ifdef _PARALLEL
76  stapl::dynamic_graph<stapl::DIRECTED,stapl::NONMULTIEDGES,Vertex, Edge>
77 #else
78  stapl::sequential::graph<stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex, Edge>
79 #endif
80  ;
81 
82  // Descriptor types.
83  typedef typename STAPLGraph::vertex_descriptor VID;
84  typedef typename STAPLGraph::edge_descriptor EID;
85  typedef typename EID::edge_id_type EdgeID;
86  typedef typename std::unordered_set<VID> VertexSet;
87 
88  // Iterator types.
89  typedef typename STAPLGraph::vertex_iterator VI;
90  typedef typename STAPLGraph::adj_edge_iterator EI;
91  typedef typename STAPLGraph::const_vertex_iterator CVI;
92  typedef typename STAPLGraph::const_adj_edge_iterator CEI;
93 
94  // Property types.
95  typedef typename STAPLGraph::vertex_property VP;
96  typedef typename STAPLGraph::edge_property EP;
97  // Useful names for the property types.
98  typedef Vertex CfgType;
99  typedef Edge EdgeType;
100 
101  typedef stapl::sequential::vector_property_map<STAPLGraph, size_t> ColorMap;
102 
103  // Hook function types.
104  typedef std::function<void(VI)> VertexHook;
105  typedef std::function<void(EI)> EdgeHook;
107 
108  // CC Tracker.
110 
114 
117 
122 
125 
128 
132 
133  bool operator==(const GenericStateGraph& _r) const noexcept;
134  bool operator!=(const GenericStateGraph& _r) const noexcept;
135 
139 
144  virtual VID AddVertex(const Vertex& _v) noexcept;
145 
152  virtual VID AddVertex(const VID _vid, const Vertex& _v) noexcept;
153 
157  virtual VID AddDuplicateVertex(const Vertex& _v) noexcept;
158 
161  virtual void DeleteVertex(const VID _v) noexcept;
162 
167  virtual EID AddEdge(const VID _source, const VID _target, const Edge& _w)
168  noexcept;
169 
174  virtual std::pair<EID, EID> AddEdge(const VID _source, const VID _target,
175  const std::pair<Edge, Edge>& _w) noexcept;
176 
177  virtual EID AddEdge(const EID _eid, const Edge& _w) noexcept;
178 
179  virtual EID AddEdge(const VID _source, const VID _target) noexcept;
180 
184  virtual void DeleteEdge(const VID _source, const VID _target) noexcept;
185 
188  virtual void DeleteEdge(EI _iterator) noexcept;
189 
191  void SetRobot(Robot* const _r) noexcept;
192 
197 
200  void SetCCTracker(StatClass* const _stats = nullptr);
201 
205 
207  size_t Size() const noexcept;
208 
212  bool IsVertex(const VID _vid) const noexcept;
213 
217  bool IsVertex(const Vertex& _v) const noexcept;
218 
225  bool IsVertex(const Vertex& _v, CVI& _vi) const noexcept;
226 
231  bool IsEdge(const VID _source, const VID _target) const noexcept;
232 
235  template <typename T>
236  VID GetVID(const T& _t) const noexcept;
237  VID GetVID(const VI& _t) const noexcept;
238  VID GetVID(const Vertex& _t) const noexcept;
239 
243  const VertexSet& GetPredecessors(const VID _vid) const noexcept;
244 
246  VID GetLastVID() const noexcept;
247 
249  size_t GetTimestamp() const noexcept;
250 
252  const VertexSet& GetAllVIDs() const noexcept;
253 
257 
259  Robot* GetRobot() const noexcept;
260 
262  CCTrackerType* GetCCTracker() const noexcept;
263 
265  template <typename T>
266  VP& GetVertex(T& _t) noexcept;
267  VP& GetVertex(VI& _t) noexcept;
268  VP& GetVertex(VID _t) noexcept;
269 
272  template <typename T>
273  const VP& GetVertex(T& _t) const noexcept;
274  const VP& GetVertex(CVI& _t) const noexcept;
275  const VP& GetVertex(VID _t) const noexcept;
276 
280  std::vector<VID> GetChildren(const VID _vid) const noexcept;
281 
282  size_t GetInDegree(const VID _vid) noexcept;
283 
284  std::vector<EI> FindInboundEdges(const VID _vid);
285 
292  bool GetEdge(const VID _source, const VID _target, EI& _ei) noexcept;
293 
295  bool GetEdge(const VID _source, const VID _target, CEI& _ei) const noexcept;
296 
297  EP& GetEdge(const VID _source, const VID _target) noexcept;
298  EP& GetEdge(const EID _descriptor) noexcept;
299 
316 
321  bool IsHook(const HookType, const std::string& _label) const;
322 
328  void InstallHook(const HookType _type, const std::string& _label,
329  const VertexHook& _h);
330 
335  void InstallHook(const HookType _type, const std::string& _label,
336  const EdgeHook& _h);
337 
341  void RemoveHook(const HookType _type, const std::string& _label);
342 
347  void DisableHooks() noexcept;
348 
350  void EnableHooks() noexcept;
351 
354  virtual void ClearHooks() noexcept;
355 
359 
363  //virtual void Read(const std::string& _filename);
364 
365  // Temporary work-around for calling the add vertex/edge hooks.
366  template <typename RG>
367  friend void Read(RG* _g, const std::string& _filename);
368 
369  template <typename RG>
370  friend void ReadMessage(RG* _g, const std::string& _msg);
371  //void ReadMessage(GenericStateGraph* _g, const std::string& _msg);
375  virtual void Write(const std::string& _filename, Environment* _env) const;
376 
378 
379 #ifdef _PARALLEL
380  // Temporarily wrapper for some graph methods
381  // Until full migration and change of names in STAPL is completed
382  size_t get_num_edges() {return this->num_edges();}
383  size_t get_num_vertices() const {return this->num_vertices();}
384  size_t get_degree(const VID& _vd) {return this->find_vertex(_vd)->size();}
385  size_t get_out_degree(const VID& _vd) {return this->get_degree(_vd);}
386 #endif
387 
388  protected:
389 
392 
396  using STAPLGraph::add_vertex;
397  using STAPLGraph::add_edge;
398  using STAPLGraph::delete_vertex;
399  using STAPLGraph::delete_edge;
400 
404 
407  void ExecuteAddVertexHooks(const VI _iterator) noexcept;
408 
411  void ExecuteDeleteVertexHooks(const VI _iterator) noexcept;
412 
415  void ExecuteAddEdgeHooks(const EI _iterator) noexcept;
416 
419  void ExecuteDeleteEdgeHooks(const EI _iterator) noexcept;
420 
424  std::string ToString(const HookType& _t) const noexcept;
425 
429 
430  Robot* m_robot{nullptr};
431 
432  size_t m_timestamp{0};
433 
434  bool m_enableHooks{true};
435 
437  std::unordered_map<std::string, VertexHook> m_addVertexHooks;
439  std::unordered_map<std::string, VertexHook> m_deleteVertexHooks;
440 
442  std::unordered_map<std::string, EdgeHook> m_addEdgeHooks;
444  std::unordered_map<std::string, EdgeHook> m_deleteEdgeHooks;
445 
447  std::unique_ptr<CCTrackerType> m_ccTracker;
448 
454  std::unordered_map<VID, VertexSet> m_predecessors;
455 
459 
461 
462 };
463 
464 /*------------------------------- Construction -------------------------------*/
465 
466 template <typename Vertex, typename Edge>
468 GenericStateGraph() { }
469 
470 template <typename Vertex, typename Edge>
472 GenericStateGraph(Robot* const _r) : m_robot(_r) { }
473 
474 /*------------------------------ Move and Copy -------------------------------*/
475 
476 template <typename Vertex, typename Edge>
478 GenericStateGraph(const GenericStateGraph& _r) : GenericStateGraph(_r.m_robot) {
479  *this = _r;
480 }
481 
482 
483 template <typename Vertex, typename Edge>
486  *this = std::move(_r);
487 }
488 
489 
490 template <typename Vertex, typename Edge>
493 operator=(const GenericStateGraph& _r) {
494  // Clear any hooks installed on this map.
495  ClearHooks();
496 
497  // Copy the stapl graph and our add-ons.
498  STAPLGraph::operator=(_r);
499  m_robot = _r.m_robot;
500  m_timestamp = _r.m_timestamp;
501  m_predecessors = _r.m_predecessors;
502  m_allVIDs = _r.m_allVIDs;
503 
504  // If the other graph had a CC tracker, copy it and point at this roadmap.
505  if(_r.m_ccTracker) {
506  m_ccTracker.reset(new CCTrackerType(*_r.m_ccTracker));
507  m_ccTracker->SetRoadmap(this);
508 
509  // Old CC tracker hooks are reinstalled in first call.
510  // These need to be cleared and the new CC tracker hooks installed.
511  ClearHooks();
512  }
513 
514  return *this;
515 }
516 
517 
518 template <typename Vertex, typename Edge>
522  // Clear any hooks installed on this map.
523  ClearHooks();
524 
525  // Move the stapl graph and our add-ons.
526  STAPLGraph::operator=(std::move(_r));
527  m_robot = _r.m_robot;
528  m_timestamp = _r.m_timestamp;
529  m_predecessors = std::move(_r.m_predecessors);
530  m_allVIDs = _r.m_allVIDs;
531 
532  // If the other graph had a CC tracker, move it and point at this roadmap.
533  if(_r.m_ccTracker) {
534  m_ccTracker = std::move(_r.m_ccTracker);
535  m_ccTracker->SetRoadmap(this);
536  }
537 
538  // Clear any hooks on the other to prevent cross-talk with the CCTracker.
539  _r.ClearHooks();
540 
541  return *this;
542 }
543 
544 /*------------------------------- Equality -----------------------------------*/
545 
546 template <typename Vertex, typename Edge>
547 bool
549 operator==(const GenericStateGraph& _r) const noexcept {
550  // First do fast checks on addess and sizes.
551  if(this == &_r)
552  return true;
553  if(this->Size() != _r.Size() or this->get_num_edges() != _r.get_num_edges())
554  return false;
555 
556  // Check vertices and edges.
557  for(auto va = this->begin(); va != this->end(); ++va) {
558  // Find the matching descriptor in _r.
559  auto vb = _r.find_vertex(va->descriptor());
560 
561  // Check that the property and number of edges are the same.
562  if(va->property() != vb->property() or va->size() != vb->size())
563  return false;
564 
565  // Check that the edges are the same. Do not assume the edge ordering is
566  // the same, only worry about source/target correspondance.
567  for(auto ea = va->begin(); ea != va->end(); ++ea) {
568  CEI eb;
569  if(!_r.GetEdge(ea->source(), ea->target(), eb)
570  or ea->property() != eb->property())
571  return false;
572  }
573  }
574 
575  return true;
576 }
577 
578 
579 template <typename Vertex, typename Edge>
580 bool
582 operator!=(const GenericStateGraph& _r) const noexcept {
583  return !(*this == _r);
584 }
585 
586 /*------------------------------- Modifiers ----------------------------------*/
587 
588 template <typename Vertex, typename Edge>
591 AddVertex(const Vertex& _v) noexcept {
592  // Find the vertex and ensure it does not already exist.
593  CVI vi;
594  if(IsVertex(_v, vi)) {
595  //std::cerr << "\nGenericStateGraph::AddVertex: vertex " << vi->descriptor()
596  // << " already in graph, not adding again."
597  // << std::endl;
598  return vi->descriptor();
599  }
600 
601  // The vertex does not exist. Add it now.
602  const VID vid = this->add_vertex(_v);
603  m_predecessors[vid];
604  m_allVIDs.insert(vid);
605  ++m_timestamp;
606 
607  // Execute post-add hooks and update vizmo debug.
608  ExecuteAddVertexHooks(this->find_vertex(vid));
609 
610  return vid;
611 }
612 
613 template <typename Vertex, typename Edge>
616 AddVertex(const VID _vid, const Vertex& _v) noexcept {
617  // Find the vertex and ensure it does not already exist.
618  CVI vi;
619  if(IsVertex(_v, vi)) {
620  //std::cerr << "\nGenericStateGraph::AddVertex: vertex " << vi->descriptor()
621  // << " already in graph, not adding again."
622  // << std::endl;
623  return vi->descriptor();
624  }
625 
626  if(m_allVIDs.count(_vid) > 0) {
627  //std::cerr << "\nGenericStateGraph::AddVertex: vertex " << _vid
628  // << " already in graph, not adding again."
629  // << std::endl;
630  return _vid;
631  }
632 
633  // The vertex does not exist. Add it now.
634  const VID vid = this->add_vertex(_vid, _v);
635  m_predecessors[vid];
636  m_allVIDs.insert(vid);
637  ++m_timestamp;
638 
639  // Execute post-add hooks and update vizmo debug.
640  ExecuteAddVertexHooks(this->find_vertex(vid));
641 
642  return vid;
643 }
644 
645 template <typename Vertex, typename Edge>
648 AddDuplicateVertex(const Vertex& _v) noexcept {
649 
650  const VID vid = this->add_vertex(_v);
651  ++m_timestamp;
652 
653  // Execute post-add hooks and update vizmo debug.
654  ExecuteAddVertexHooks(this->find_vertex(vid));
655  VDAddNode(_v);
656 
657  return vid;
658 }
659 
660 template <typename Vertex, typename Edge>
661 void
663 DeleteVertex(const VID _v) noexcept {
664  // Find the vertex and crash if it doesn't exist.
665  VI vi = this->find_vertex(_v);
666  if(vi == this->end())
667  throw RunTimeException(WHERE) << "VID " << _v << " is not in the graph.";
668 
669  // We must manually delete the edges rather than letting STAPL do this in
670  // order to call the DeleteEdge hooks.
671 
672  // Delete the outbound edges.
673  for(auto edge = vi->begin(); edge != vi->end(); edge = vi->begin())
674  DeleteEdge(edge);
675 
676  // Delete the inbound edges.
677  auto predIter = m_predecessors.find(_v);
678  VertexSet& preds = predIter->second;
679  while(!preds.empty()) {
680  const VID predecessor = *preds.begin();
681  DeleteEdge(predecessor, _v);
682  }
683 
684  // Execute pre-delete hooks.
685  ExecuteDeleteVertexHooks(vi);
686 
687  // Delete the vertex.
688  this->delete_vertex(vi->descriptor());
689  m_predecessors.erase(predIter);
690  m_allVIDs.erase(_v);
691  ++m_timestamp;
692 }
693 
694 
695 template <class Vertex, class Edge>
698 AddEdge(const VID _source, const VID _target, const Edge& _w) noexcept {
699  // Let the add_edge function handle checking for existance incase we are using
700  // a multigraph.
701  const auto edgeDescriptor = this->add_edge(_source, _target, _w);
702  const bool notNew = edgeDescriptor.id() == INVALID_EID;
703 
704  if(notNew) {
705  /*
706  std::cerr << "\nGenericStateGraph::AddEdge: edge (" << _source << ", "
707  << _target << ") already exists, not adding."
708  << std::endl;
709  */
710 
711  return edgeDescriptor;
712  }
713 
714  // Add the source as a predecessor of target.
715  m_predecessors[_target].insert(_source);
716  ++m_timestamp;
717 
718  // Execute post-add hooks.
719  VI vi;
720  EI ei;
721  this->find_edge(edgeDescriptor, vi, ei);
722  ExecuteAddEdgeHooks(ei);
723  return edgeDescriptor;
724 }
725 
726 
727 template <class Vertex, class Edge>
730 AddEdge(const VID _source, const VID _target) noexcept {
731  // Let the add_edge function handle checking for existance incase we are using
732  // a multigraph.
733  const auto edgeDescriptor = this->add_edge(_source, _target);
734  const bool notNew = edgeDescriptor.id() == INVALID_EID;
735 
736  if(notNew) {
737  /*
738  std::cerr << "\nGenericStateGraph::AddEdge: edge (" << _source << ", "
739  << _target << ") already exists, not adding."
740  << std::endl;
741  */
742  return edgeDescriptor;
743  }
744 
745  // Add the source as a predecessor of target.
746  m_predecessors[_target].insert(_source);
747  ++m_timestamp;
748 
749  // Execute post-add hooks.
750  VI vi;
751  EI ei;
752  this->find_edge(edgeDescriptor, vi, ei);
753  ExecuteAddEdgeHooks(ei);
754  return edgeDescriptor;
755 }
756 
757 
758 template <class Vertex, class Edge>
759 std::pair<typename GenericStateGraph<Vertex, Edge>::EID, typename GenericStateGraph<Vertex, Edge>::EID>
761 AddEdge(const VID _source, const VID _target, const std::pair<Edge, Edge>& _w)
762  noexcept {
763  EID e1 = AddEdge(_source, _target, _w.first);
764  EID e2 = AddEdge(_target, _source, _w.second);
765  return std::make_pair(e1, e2);
766 }
767 
768 
769 template <class Vertex, class Edge>
772 AddEdge(const EID _eid, const Edge& _w) noexcept {
773  // Let the add_edge function handle checking for existance incase we are using
774  // a multigraph.
775  const auto edgeDescriptor = this->add_edge(_eid, _w);
776  const bool notNew = edgeDescriptor.id() == INVALID_EID;
777 
778  auto source = _eid.source();
779  auto target = _eid.target();
780 
781  if(notNew) {
782  /*
783  std::cerr << "\nGenericStateGraph::AddEdge: edge (" << source << ", "
784  << target << ") already exists, not adding."
785  << std::endl;
786  */
787  return edgeDescriptor;
788  }
789 
790  // Add the source as a predecessor of target.
791  m_predecessors[target].insert(source);
792  ++m_timestamp;
793 
794  // Execute post-add hooks.
795  VI vi;
796  EI ei;
797  this->find_edge(edgeDescriptor, vi, ei);
798  ExecuteAddEdgeHooks(ei);
799  return edgeDescriptor;
800 }
801 
802 
803 template <class Vertex, class Edge>
804 void
806 DeleteEdge(const VID _source, const VID _target) noexcept {
807  // Find the edge and crash if it isn't found.
808  const EID edgeDescriptor(_source, _target);
809  VI dummy;
810  EI edgeIterator;
811 
812  const bool found = this->find_edge(edgeDescriptor, dummy, edgeIterator);
813  if(!found)
814  throw RunTimeException(WHERE) << "Edge (" << _source << ", " << _target
815  << ") does not exist.";
816 
817  DeleteEdge(edgeIterator);
818 }
819 
820 
821 template <class Vertex, class Edge>
822 void
824 DeleteEdge(EI _iterator) noexcept {
825  // Execute pre-delete hooks.
826  const VID source = _iterator->source(),
827  target = _iterator->target();
828  ExecuteDeleteEdgeHooks(_iterator);
829 
830  // Delete the edge.
831  this->delete_edge(_iterator->descriptor());
832  m_predecessors[target].erase(source);
833  ++m_timestamp;
834 }
835 
836 
837 template <typename Vertex, typename Edge>
838 void
840 SetRobot(Robot* const _r) noexcept {
841  m_robot = _r;
842  for(VI vi = this->begin(); vi != this->end(); ++vi)
843  vi->property().SetRobot(_r);
844 }
845 
846 
847 template <typename Vertex, typename Edge>
848 void
850 AppendRoadmap(const GenericStateGraph& _r) {
851  // Copy vertices and map the change in VIDs.
852  std::unordered_map<VID, VID> oldToNew;
853  for(auto vit = _r.begin(); vit != _r.end(); ++vit) {
854  const VID oldVID = vit->descriptor();
855  const VID newVID = AddVertex(vit->property());
856  oldToNew[oldVID] = newVID;
857  }
858 
859  // Copy edges.
860  for(auto vit = _r.begin(); vit != _r.end(); ++vit) {
861  for(auto eit = vit->begin(); eit != vit->end(); ++eit) {
862  const VID source = oldToNew[eit->source()];
863  const VID target = oldToNew[eit->target()];
864  if(!IsEdge(source, target))
865  AddEdge(source, target, eit->property());
866  }
867  }
868 }
869 
870 
871 template <typename Vertex, typename Edge>
872 inline
873 void
875 SetCCTracker(StatClass* const _stats) {
876  m_ccTracker.reset(new CCTrackerType(this));
877  if(_stats)
878  m_ccTracker->SetStatClass(_stats);
879 }
880 
881 /*-------------------------------- Queries -----------------------------------*/
882 
883 template <typename Vertex, typename Edge>
884 inline
885 size_t
887 Size() const noexcept {
888  return this->get_num_vertices();
889 }
890 
891 
892 template <typename Vertex, typename Edge>
893 inline
894 bool
896 IsVertex(const VID _vid) const noexcept {
897  return this->find_vertex(_vid) != this->end();
898 }
899 
900 template <typename Vertex, typename Edge>
901 inline
902 bool
904 IsVertex(const Vertex& _v) const noexcept {
905  CVI vi;
906  return IsVertex(_v, vi);
907 }
908 
909 
910 template <typename Vertex, typename Edge>
911 inline
912 bool
914 IsVertex(const Vertex& _v, CVI& _vi) const noexcept {
915 #ifndef _PARALLEL
916  for(CVI vi = this->begin(); vi != this->end(); ++vi){
917  if(vi->property() == _v){
918  _vi = vi;
919  return true;
920  }
921  }
922 #else
923  std::cerr << "WARNING::STAPL working on fixing problem with const iterators\n";
924 #endif
925  return false;
926 }
927 
928 
929 template <typename Vertex, typename Edge>
930 inline
931 bool
933 IsEdge(const VID _source, const VID _target) const noexcept {
934  CEI ei;
935  CVI vi;
936  return this->find_edge(EID(_source, _target), vi, ei);
937 }
938 
939 
940 template <typename Vertex, typename Edge>
941 template <typename T>
942 inline
945 GetVID(const T& _t) const noexcept {
946  return *_t;
947 }
948 
949 
950 template <typename Vertex, typename Edge>
951 inline
954 GetVID(const VI& _t) const noexcept {
955  return _t->descriptor();
956 }
957 
958 
959 template <typename Vertex, typename Edge>
960 inline
963 GetVID(const Vertex& _t) const noexcept {
964  CVI vi;
965  if(IsVertex(_t, vi))
966  return vi->descriptor();
967  return INVALID_VID;
968 }
969 
970 
971 template <typename Vertex, typename Edge>
972 inline
975 GetPredecessors(const VID _vid) const noexcept {
976  return m_predecessors.at(_vid);
977 }
978 
979 
980 template <typename Vertex, typename Edge>
981 inline
984 GetLastVID() const noexcept {
985  if(this->get_num_vertices() == 0)
986  return INVALID_VID;
987 
988  return (--this->end())->descriptor();
989 }
990 
991 
992 template <typename Vertex, typename Edge>
993 inline
994 size_t
996 GetTimestamp() const noexcept {
997  return m_timestamp;
998 }
999 
1000 
1001 template <typename Vertex, typename Edge>
1002 inline
1005 GetAllVIDs() const noexcept {
1006  return m_allVIDs;
1007 }
1008 
1009 /*------------------------------- Accessors ----------------------------------*/
1010 
1011 template <typename Vertex, typename Edge>
1012 inline
1013 Robot*
1015 GetRobot() const noexcept {
1016  return m_robot;
1017 }
1018 
1019 
1020 template <typename Vertex, typename Edge>
1021 inline
1024 GetCCTracker() const noexcept {
1025  return m_ccTracker.get();
1026 }
1027 
1028 
1029 template <typename Vertex, typename Edge>
1030 template <typename T>
1031 inline
1034 GetVertex(T& _t) noexcept {
1035  return GetVertex(VID(*_t));
1036 }
1037 
1038 
1039 template <typename Vertex, typename Edge>
1040 inline
1043 GetVertex(VI& _t) noexcept {
1044  return _t->property();
1045 }
1046 
1047 
1048 template <typename Vertex, typename Edge>
1049 inline
1052 GetVertex(VID _t) noexcept {
1053  VI iter = this->find_vertex(_t);
1054  if(iter == this->end())
1055  throw RunTimeException(WHERE) << "Requested node '" << _t
1056  << "', which is not in the graph.";
1057 
1058  return iter->property();
1059 }
1060 
1061 
1062 template <typename Vertex, typename Edge>
1063 template <typename T>
1064 inline
1067 GetVertex(T& _t) const noexcept {
1068  return GetVertex(VID(*_t));
1069 }
1070 
1071 
1072 template <typename Vertex, typename Edge>
1073 inline
1076 GetVertex(CVI& _t) const noexcept {
1077  return (*_t).property();
1078 }
1079 
1080 
1081 template <typename Vertex, typename Edge>
1082 inline
1085 GetVertex(VID _t) const noexcept {
1086  CVI iter = this->find_vertex(_t);
1087  if(iter == this->end())
1088  throw RunTimeException(WHERE) << "Requested node '" << _t
1089  << "', which is not in the graph.";
1090 
1091  return (*iter).property();
1092 }
1093 
1094 
1095 template <typename Vertex, typename Edge>
1096 std::vector<typename GenericStateGraph<Vertex, Edge>::VID>
1098 GetChildren(const VID _vid) const noexcept {
1099  auto vi = this->find_vertex(_vid);
1100  if(vi == this->end())
1101  throw RunTimeException(WHERE) << "Requested children of node '" << _vid
1102  << "', which is not in the graph.";
1103 
1104  std::vector<VID> output;
1105  for(const auto& e : *vi)
1106  output.push_back(e.target());
1107  return output;
1108 }
1109 
1110 
1111 template <typename Vertex, typename Edge>
1112 size_t
1114 GetInDegree(const VID _vid) noexcept {
1115  auto predIter = m_predecessors.find(_vid);
1116  VertexSet& preds = predIter->second;
1117  return preds.size();
1118 }
1119 
1120 
1121 template <typename Vertex, typename Edge>
1122 std::vector<typename GenericStateGraph<Vertex, Edge>::EI>
1124 FindInboundEdges(const VID _vid) {
1125  std::vector<EI> inEdges;
1126 
1127  auto predIter = m_predecessors.find(_vid);
1128  VertexSet& predecessors = predIter->second;
1129 
1130  for(const auto pred : predecessors) {
1131  auto predIter = this->find_vertex(pred);
1132  for(auto eit = predIter->begin(); eit != predIter->end(); ++eit)
1133  if(eit->target() == _vid)
1134  inEdges.push_back(eit);
1135  }
1136 
1137  return inEdges;
1138 }
1139 
1140 
1141 template <typename Vertex, typename Edge>
1142 inline
1143 bool
1145 GetEdge(const VID _source, const VID _target, EI& _ei) noexcept {
1146  VI vi;
1147  return this->find_edge(EID(_source, _target), vi, _ei);
1148 }
1149 
1150 
1151 template <typename Vertex, typename Edge>
1152 inline
1153 bool
1155 GetEdge(const VID _source, const VID _target, CEI& _ei) const noexcept {
1156  CVI vi;
1157  return this->find_edge(EID(_source, _target), vi, _ei);
1158 }
1159 
1160 
1161 template <typename Vertex, typename Edge>
1162 inline
1165 GetEdge(const VID _source, const VID _target) noexcept {
1166  EI ei;
1167  if(!GetEdge(_source, _target, ei))
1168  throw RunTimeException(WHERE) << "Requested non-existent edge ("
1169  << _source << ", " << _target << ").";
1170 
1171  return ei->property();
1172 }
1173 
1174 
1175 template <typename Vertex, typename Edge>
1176 inline
1179 GetEdge(const EID _descriptor) noexcept {
1180  return GetEdge(_descriptor.source(), _descriptor.target());
1181 }
1182 
1183 /*--------------------------------- Hooks ------------------------------------*/
1184 
1185 template <typename Vertex, typename Edge>
1186 bool
1188 IsHook(const HookType _type, const std::string& _label) const {
1189  switch(_type) {
1190  case HookType::AddVertex:
1191  return m_addVertexHooks.count(_label);
1192  case HookType::DeleteVertex:
1193  return m_deleteVertexHooks.count(_label);
1194  case HookType::AddEdge:
1195  return m_addEdgeHooks.count(_label);
1196  case HookType::DeleteEdge:
1197  return m_deleteEdgeHooks.count(_label);
1198  default:
1199  throw RunTimeException(WHERE) << "Unrecognized hook type '"
1200  << ToString(_type) << "'.";
1201  }
1202 }
1203 
1204 
1205 template <typename Vertex, typename Edge>
1206 void
1208 InstallHook(const HookType _type, const std::string& _label,
1209  const VertexHook& _h) {
1210  // Ensure that the hook does not already exist.
1211  if(IsHook(_type, _label))
1212  throw RunTimeException(WHERE) << "Hook of type '" << ToString(_type)
1213  << "' with label '" << _label
1214  << "' already exists.";
1215 
1216  switch(_type) {
1217  case HookType::AddVertex:
1218  m_addVertexHooks[_label] = _h;
1219  break;
1220  case HookType::DeleteVertex:
1221  m_deleteVertexHooks[_label] = _h;
1222  break;
1223  case HookType::AddEdge:
1224  case HookType::DeleteEdge:
1225  throw RunTimeException(WHERE) << "Edge hook type '" << ToString(_type)
1226  << "' used with vertex hook function "
1227  << "labeled '" << _label << "'.";
1228  default:
1229  throw RunTimeException(WHERE) << "Unrecognized hook type '"
1230  << ToString(_type)
1231  << "' with label '" << _label << "'.";
1232  }
1233 }
1234 
1235 
1236 template <typename Vertex, typename Edge>
1237 void
1239 InstallHook(const HookType _type, const std::string& _label, const EdgeHook& _h) {
1240  // Ensure that the hook does not already exist.
1241  if(IsHook(_type, _label))
1242  throw RunTimeException(WHERE) << "Hook of type '" << ToString(_type)
1243  << "' with label '" << _label
1244  << "' already exists.";
1245 
1246  switch(_type) {
1247  case HookType::AddEdge:
1248  m_addEdgeHooks[_label] = _h;
1249  break;
1250  case HookType::DeleteEdge:
1251  m_deleteEdgeHooks[_label] = _h;
1252  break;
1253  case HookType::AddVertex:
1254  case HookType::DeleteVertex:
1255  throw RunTimeException(WHERE) << "Vertex hook type '" << ToString(_type)
1256  << "' used with edge hook function labeled '"
1257  << _label << "'.";
1258  default:
1259  throw RunTimeException(WHERE) << "Unrecognized hook type '"
1260  << ToString(_type)
1261  << "' with label '" << _label << "'.";
1262  }
1263 }
1264 
1265 
1266 template <typename Vertex, typename Edge>
1267 void
1269 RemoveHook(const HookType _type, const std::string& _label) {
1270  if(!IsHook(_type, _label))
1271  throw RunTimeException(WHERE) << "Hook of type '" << ToString(_type)
1272  << "' with label '" << _label
1273  << "' does not exist.";
1274 
1275  switch(_type) {
1276  case HookType::AddVertex:
1277  m_addVertexHooks.erase(_label);
1278  break;
1279  case HookType::DeleteVertex:
1280  m_deleteVertexHooks.erase(_label);
1281  break;
1282  case HookType::AddEdge:
1283  m_addEdgeHooks.erase(_label);
1284  break;
1285  case HookType::DeleteEdge:
1286  m_deleteEdgeHooks.erase(_label);
1287  break;
1288  default:
1289  throw RunTimeException(WHERE) << "Unrecognized hook type '"
1290  << ToString(_type)
1291  << "' with label '" << _label << "'.";
1292  }
1293 }
1294 
1295 
1296 template <typename Vertex, typename Edge>
1297 inline
1298 void
1300 DisableHooks() noexcept {
1301  m_enableHooks = false;
1302 }
1303 
1304 
1305 template <typename Vertex, typename Edge>
1306 inline
1307 void
1309 EnableHooks() noexcept {
1310  m_enableHooks = true;
1311 }
1312 
1313 
1314 template <typename Vertex, typename Edge>
1315 void
1317 ClearHooks() noexcept {
1318  m_addVertexHooks.clear();
1319  m_deleteVertexHooks.clear();
1320  m_addEdgeHooks.clear();
1321  m_deleteEdgeHooks.clear();
1322 }
1323 
1324 /*----------------------------------- I/O ------------------------------------*/
1325 
1326 
1327 #if 1
1335 template <typename GenericStateGraph>
1336 void
1337 Read(GenericStateGraph* _g, const std::string& _filename) {
1338  std::ifstream ifs(_filename);
1339  if(!ifs)
1340  throw ParseException(WHERE) << "Cannot open file '" << _filename << "'.";
1341 
1342  std::string tag;
1343  bool headerParsed = false;
1344  int graphStart = 0;
1345  // Read the file until we find the GRAPHSTART tag.
1346  while(!headerParsed) {
1347  // Mark our position and read the next line.
1348  graphStart = ifs.tellg();
1349  if(!(ifs >> tag))
1350  throw ParseException(WHERE) << "Error reading map file '" << _filename
1351  << "' - GRAPHSTART tag is missing.";
1352 
1353  // If we find the GRAPHSTART tag, we are done.
1354  if(tag.find("GRAPHSTART") != std::string::npos)
1355  headerParsed = true;
1356  }
1357 
1358  if(!_g->GetRobot())
1359  RunTimeException(WHERE) << "Must specify robot when reading in roadmaps.";
1360 
1361  typedef typename GenericStateGraph::STAPLGraph STAPLGraph;
1362  typedef typename GenericStateGraph::vertex_property Vertex;
1363  typedef typename GenericStateGraph::edge_property Edge;
1364 
1365  // Set the input robot for our edge class.
1368  Edge::inputRobot = _g->GetRobot();
1369  Vertex::inputRobot = _g->GetRobot();
1370 
1371  // Set ifs back to the line with the GRAPHSTART tag and read in the graph.
1372  ifs.seekg(graphStart, ifs.beg);
1373  stapl::sequential::read_graph<STAPLGraph>(*_g, ifs);
1374 
1375  // Unset the input robot for our edge class.
1376  Edge::inputRobot = nullptr;
1377  Vertex::inputRobot = nullptr;
1378 
1379  for(auto vi = _g->begin(); vi != _g->end(); ++vi)
1380  _g->ExecuteAddVertexHooks(vi);
1381  for(auto vi = _g->begin(); vi != _g->end(); ++vi)
1382  for(auto ei = vi->begin(); ei != vi->end(); ++ei)
1383  _g->ExecuteAddEdgeHooks(ei);
1384 }
1385 #else
1386 template <typename Vertex, typename Edge>
1387 void
1389 Read(const std::string& _filename) {
1390  std::ifstream ifs(_filename);
1391  if(!ifs)
1392  throw ParseException(WHERE) << "Cannot open file '" << _filename << "'.";
1393 
1394  std::string tag;
1395  bool headerParsed = false;
1396  int graphStart = 0;
1397  // Read the file until we find the GRAPHSTART tag.
1398  while(!headerParsed) {
1399  // Mark our position and read the next line.
1400  graphStart = ifs.tellg();
1401  if(!(ifs >> tag))
1402  throw ParseException(WHERE) << "Error reading map file '" << _filename
1403  << "' - GRAPHSTART tag is missing.";
1404 
1405  // If we find the GRAPHSTART tag, we are done.
1406  if(tag.find("GRAPHSTART") != std::string::npos)
1407  headerParsed = true;
1408  }
1409 
1410  if(!GetRobot())
1411  RunTimeException(WHERE) << "Must specify robot when reading in roadmaps.";
1412 
1413  // Set the input robot for our edge class.
1416  Edge::inputRobot = GetRobot();
1417  Vertex::inputRobot = GetRobot();
1418 
1419  // Set ifs back to the line with the GRAPHSTART tag and read in the graph.
1420  ifs.seekg(graphStart, ifs.beg);
1421  stapl::sequential::read_graph<STAPLGraph>(*this, ifs);
1422 
1423  // Unset the input robot for our edge class.
1424  Edge::inputRobot = nullptr;
1425  Vertex::inputRobot = nullptr;
1426 }
1427 #endif
1428 
1436 template <typename GenericStateGraph>
1437 void
1438 ReadMessage(GenericStateGraph* _g, const std::string& _msg) {
1439  std::stringstream ss(_msg);
1440 
1441  std::string tag;
1442  bool headerParsed = false;
1443  int graphStart = 0;
1444  // Read the file until we find the GRAPHSTART tag.
1445  while(!headerParsed) {
1446  // Mark our position and read the next line.
1447  graphStart = ss.tellg();
1448  if(!(ss >> tag))
1449  throw ParseException(WHERE) << "Error reading msg '" << _msg
1450  << "' - GRAPHSTART tag is missing.";
1451 
1452  // If we find the GRAPHSTART tag, we are done.
1453  if(tag.find("GRAPHSTART") != std::string::npos)
1454  headerParsed = true;
1455  }
1456 
1457  if(!_g->GetRobot())
1458  RunTimeException(WHERE) << "Must specify robot when reading in roadmaps.";
1459 
1460  typedef typename GenericStateGraph::STAPLGraph STAPLGraph;
1461  typedef typename GenericStateGraph::vertex_property Vertex;
1462  typedef typename GenericStateGraph::edge_property Edge;
1463 
1464  // Set the input robot for our edge class.
1467  Edge::inputRobot = _g->GetRobot();
1468  Vertex::inputRobot = _g->GetRobot();
1469 
1470  // Set ss back to the line with the GRAPHSTART tag and read in the graph.
1471  ss.seekg(graphStart, ss.beg);
1472  stapl::sequential::read_graph<STAPLGraph>(*_g, ss);
1473 
1474  // Unset the input robot for our edge class.
1475  Edge::inputRobot = nullptr;
1476  Vertex::inputRobot = nullptr;
1477 
1478  for(auto vi = _g->begin(); vi != _g->end(); ++vi)
1479  _g->ExecuteAddVertexHooks(vi);
1480  for(auto vi = _g->begin(); vi != _g->end(); ++vi)
1481  for(auto ei = vi->begin(); ei != vi->end(); ++ei)
1482  _g->ExecuteAddEdgeHooks(ei);
1483 }
1484 
1485 template <typename Vertex, typename Edge>
1486 void
1488 Write(const std::string& _filename, Environment* _env) const {
1489  std::ofstream ofs(_filename);
1490  ofs << "#####ENVFILESTART#####" << std::endl
1491  << _env->GetEnvFileName() << std::endl
1492  << "#####ENVFILESTOP#####" << std::endl;
1493 
1494 #ifndef _PARALLEL
1495  stapl::sequential::write_graph(*this, ofs);
1496 #else
1497  ofs.close();
1498  stapl::graph_view<STAPLGraph> gv(*this);
1499  write_PMPL_graph(gv, _filename);
1500 #endif
1501 
1502 }
1503 
1504 /*-------------------------------- Helpers -----------------------------------*/
1505 
1506 template <typename Vertex, typename Edge>
1507 inline
1508 void
1510 ExecuteAddVertexHooks(const VI _iterator) noexcept {
1511  if(!m_enableHooks)
1512  return;
1513 
1514  if(m_ccTracker)
1515  m_ccTracker->AddVertex(_iterator);
1516 
1517  for(auto& hook : m_addVertexHooks)
1518  hook.second(_iterator);
1519 }
1520 
1521 
1522 template <typename Vertex, typename Edge>
1523 inline
1524 void
1526 ExecuteDeleteVertexHooks(const VI _iterator) noexcept {
1527  if(!m_enableHooks)
1528  return;
1529 
1530  for(auto& hook : m_deleteVertexHooks)
1531  hook.second(_iterator);
1532 
1533  if(m_ccTracker)
1534  m_ccTracker->DeleteVertex(_iterator);
1535 }
1536 
1537 
1538 template <typename Vertex, typename Edge>
1539 inline
1540 void
1542 ExecuteAddEdgeHooks(const EI _iterator) noexcept {
1543  if(!m_enableHooks)
1544  return;
1545 
1546  if(m_ccTracker)
1547  m_ccTracker->AddEdge(_iterator);
1548 
1549  for(auto& hook : m_addEdgeHooks)
1550  hook.second(_iterator);
1551 }
1552 
1553 
1554 template <typename Vertex, typename Edge>
1555 inline
1556 void
1558 ExecuteDeleteEdgeHooks(const EI _iterator) noexcept {
1559  if(!m_enableHooks)
1560  return;
1561 
1562  for(auto& hook : m_deleteEdgeHooks)
1563  hook.second(_iterator);
1564 
1565  if(m_ccTracker)
1566  m_ccTracker->DeleteEdge(_iterator);
1567 }
1568 
1569 
1570 template <typename Vertex, typename Edge>
1571 std::string
1573 ToString(const HookType& _t) const noexcept {
1574  switch(_t) {
1575  case HookType::AddVertex:
1576  return "AddVertex";
1577  case HookType::DeleteVertex:
1578  return "DeleteVertex";
1579  case HookType::AddEdge:
1580  return "AddEdge";
1581  case HookType::DeleteEdge:
1582  return "DeleteEdge";
1583  default:
1584  return std::string(1, char(_t));
1585  }
1586 }
1587 
1588 /*----------------------------------------------------------------------------*/
1589 
1594 inline
1595 std::unordered_set<size_t>
1596 VertexSetIntersection(const std::unordered_set<size_t>& _a,
1597  const std::unordered_set<size_t>& _b) {
1598  using VertexSet = std::unordered_set<size_t>;
1599 
1600  // Find the smaller of the two sets.
1601  const VertexSet* smaller{nullptr},
1602  * larger{nullptr};
1603  if(_a.size() < _b.size()) {
1604  smaller = &_a;
1605  larger = &_b;
1606  }
1607  else {
1608  smaller = &_b;
1609  larger = &_a;
1610  }
1611 
1612  // Test each element in the smaller set for membership in the larger one.
1613  VertexSet intersection;
1614  std::copy_if(smaller->begin(), smaller->end(),
1615  std::inserter(intersection, intersection.end()),
1616  [larger](const size_t _vid) {return larger->count(_vid);});
1617  return intersection;
1618 }
1619 
1620 
1625 inline
1626 bool
1627 HaveCommonVertex(const std::unordered_set<size_t>& _a,
1628  const std::unordered_set<size_t>& _b) {
1629  using VertexSet = std::unordered_set<size_t>;
1630 
1631  // Find the smaller of the two sets.
1632  const VertexSet* smaller,
1633  * larger;
1634  if(_a.size() < _b.size()) {
1635  smaller = &_a;
1636  larger = &_b;
1637  }
1638  else {
1639  smaller = &_b;
1640  larger = &_a;
1641  }
1642 
1643  // Test each element in the smaller set for membership in the larger one.
1644  return std::any_of(smaller->begin(), smaller->end(),
1645  [larger](const size_t _vid) {return larger->count(_vid);});
1646 }
1647 
1652 inline
1653 std::unordered_set<size_t>&
1654 VertexSetUnionInPlace(std::unordered_set<size_t>& _receiver,
1655  const std::unordered_set<size_t>& _source) {
1656  // Reserve sufficient space for the worst case. This wastes a bit of space
1657  // (which is inevitable anyway) but avoids more than one rehash.
1658  _receiver.reserve(_receiver.size() + _source.size());
1659  for(const size_t vid : _source)
1660  _receiver.insert(vid);
1661  return _receiver;
1662 }
1663 
1672 template <typename T, typename... Rest>
1673 inline
1674 const T&
1675 RandomElement(const std::unordered_set<T, Rest...>& _set) noexcept {
1676  if(_set.empty())
1677  throw RunTimeException(WHERE) << "Can't select a random element from an "
1678  << "empty set.";
1679 #if 1
1680  // Pick a random bucket within the set.
1681  size_t bucketIndex, bucketSize, tries = 0;
1682  do {
1683  ++tries;
1684  bucketIndex = DRand() * _set.bucket_count();
1685  bucketSize = _set.bucket_size(bucketIndex);
1686  }
1687  while(bucketSize == 0);
1688 
1689  const size_t elementIndex = DRand() * bucketSize;
1690 #if 0
1691  std::cout << "\nset size = " << _set.size()
1692  << "\ntries = " << tries
1693  << "\nbucketIndex = " << bucketIndex
1694  << "\nbucketSize = " << bucketSize
1695  << "\nelementIndex = " << elementIndex
1696  << "\nelement = "
1697  << *std::next(_set.begin(bucketIndex), elementIndex)
1698  << std::endl;
1699 #endif
1700  return *std::next(_set.begin(bucketIndex), elementIndex);
1701 #else
1702  // This is the fully linear solution, which works better for very small sets.
1703  // It is retained here for reference.
1704  return *std::next(_set.begin(), DRand() * _set.size());
1705 #endif
1706 }
1707 
1708 /*----------------------------------------------------------------------------*/
1709 
1710 #endif
void ReadMessage(GenericStateGraph *_g, const std::string &_msg)
Definition: GenericStateGraph.h:1438
void Read(GenericStateGraph *_g, const std::string &_filename)
Definition: GenericStateGraph.h:1337
#define INVALID_VID
Definition: GenericStateGraph.h:23
#define INVALID_EID
Definition: GenericStateGraph.h:27
const T & RandomElement(const std::unordered_set< T, Rest... > &_set) noexcept
Definition: GenericStateGraph.h:1675
std::unordered_set< size_t > VertexSetIntersection(const std::unordered_set< size_t > &_a, const std::unordered_set< size_t > &_b)
Definition: GenericStateGraph.h:1596
bool HaveCommonVertex(const std::unordered_set< size_t > &_a, const std::unordered_set< size_t > &_b)
Definition: GenericStateGraph.h:1627
std::unordered_set< size_t > & VertexSetUnionInPlace(std::unordered_set< size_t > &_receiver, const std::unordered_set< size_t > &_source)
Definition: GenericStateGraph.h:1654
void VDAddNode(const CfgType &_cfg)
@TODO
Definition: IOUtils.h:48
double DRand()
Definition: MPUtils.cpp:8
#define WHERE
Macro for retrieving info about file, function, and line number.
Definition: RuntimeUtils.h:32
Definition: CCTracker.h:36
Definition: Environment.h:137
const std::string & GetEnvFileName() const noexcept
Get the environment file name.
Definition: Environment.cpp:332
Definition: GenericStateGraph.h:67
virtual EID AddEdge(const VID _source, const VID _target, const Edge &_w) noexcept
Definition: GenericStateGraph.h:698
friend void ReadMessage(RG *_g, const std::string &_msg)
STAPLGraph::edge_property EP
Definition: GenericStateGraph.h:96
void InstallHook(const HookType _type, const std::string &_label, const VertexHook &_h)
Definition: GenericStateGraph.h:1208
virtual void DeleteVertex(const VID _v) noexcept
Definition: GenericStateGraph.h:663
std::unordered_map< std::string, VertexHook > m_addVertexHooks
Hook functions to call when adding a vertex.
Definition: GenericStateGraph.h:437
std::unique_ptr< CCTrackerType > m_ccTracker
Tracks weak CCs within the roadmap.
Definition: GenericStateGraph.h:447
std::function< void(VI)> VertexHook
Definition: GenericStateGraph.h:104
Edge EdgeType
Definition: GenericStateGraph.h:99
bool operator==(const GenericStateGraph &_r) const noexcept
Definition: GenericStateGraph.h:549
virtual void Write(const std::string &_filename, Environment *_env) const
Definition: GenericStateGraph.h:1488
STAPLGraph::vertex_descriptor VID
Definition: GenericStateGraph.h:83
Robot * GetRobot() const noexcept
Get the robot represented by this roadmap.
Definition: GenericStateGraph.h:1015
void SetCCTracker(StatClass *const _stats=nullptr)
Definition: GenericStateGraph.h:875
VertexSet m_allVIDs
Definition: GenericStateGraph.h:458
void ExecuteAddVertexHooks(const VI _iterator) noexcept
Definition: GenericStateGraph.h:1510
const VertexSet & GetPredecessors(const VID _vid) const noexcept
Definition: GenericStateGraph.h:975
virtual void ClearHooks() noexcept
Definition: GenericStateGraph.h:1317
size_t GetInDegree(const VID _vid) noexcept
Definition: GenericStateGraph.h:1114
Vertex CfgType
Definition: GenericStateGraph.h:98
STAPLGraph::const_vertex_iterator CVI
Definition: GenericStateGraph.h:91
GenericStateGraph & operator=(GenericStateGraph &&_r)
Definition: GenericStateGraph.h:521
stapl::sequential::vector_property_map< STAPLGraph, size_t > ColorMap
Definition: GenericStateGraph.h:101
virtual VID AddVertex(const VID _vid, const Vertex &_v) noexcept
Definition: GenericStateGraph.h:616
void ExecuteDeleteEdgeHooks(const EI _iterator) noexcept
Definition: GenericStateGraph.h:1558
GenericStateGraph & operator=(const GenericStateGraph &_r)
Definition: GenericStateGraph.h:493
const VertexSet & GetAllVIDs() const noexcept
Get the set of all VIDs in the roadmap.
Definition: GenericStateGraph.h:1005
STAPLGraph::const_adj_edge_iterator CEI
Definition: GenericStateGraph.h:92
virtual VID AddVertex(const Vertex &_v) noexcept
Definition: GenericStateGraph.h:591
void ExecuteAddEdgeHooks(const EI _iterator) noexcept
Definition: GenericStateGraph.h:1542
STAPLGraph::vertex_iterator VI
Definition: GenericStateGraph.h:89
void SetRobot(Robot *const _r) noexcept
Set the robot pointer on all configurations in the map.
Definition: GenericStateGraph.h:840
bool IsEdge(const VID _source, const VID _target) const noexcept
Definition: GenericStateGraph.h:933
size_t m_timestamp
Tracks the number of changes to the graph.
Definition: GenericStateGraph.h:432
std::vector< VID > GetChildren(const VID _vid) const noexcept
Definition: GenericStateGraph.h:1098
friend void Read(RG *_g, const std::string &_filename)
GenericStateGraph(GenericStateGraph &&_r)
Definition: GenericStateGraph.h:485
Robot * m_robot
The robot this roadmap is for.
Definition: GenericStateGraph.h:430
STAPLGraph::edge_descriptor EID
Definition: GenericStateGraph.h:84
bool operator!=(const GenericStateGraph &_r) const noexcept
Definition: GenericStateGraph.h:582
GenericStateGraph(Robot *const _r)
Definition: GenericStateGraph.h:472
size_t Size() const noexcept
Get the number of vertices in the roadmap.
Definition: GenericStateGraph.h:887
HookType
Definition: GenericStateGraph.h:106
std::function< void(EI)> EdgeHook
Definition: GenericStateGraph.h:105
STAPLGraph::adj_edge_iterator EI
Definition: GenericStateGraph.h:90
bool IsHook(const HookType, const std::string &_label) const
Definition: GenericStateGraph.h:1188
void DisableHooks() noexcept
Definition: GenericStateGraph.h:1300
std::unordered_map< std::string, VertexHook > m_deleteVertexHooks
Hook functions to call when deleting a vertex.
Definition: GenericStateGraph.h:439
void RemoveHook(const HookType _type, const std::string &_label)
Definition: GenericStateGraph.h:1269
CCTrackerType * GetCCTracker() const noexcept
Get the connected component tracker.
Definition: GenericStateGraph.h:1024
bool m_enableHooks
Use hook functions?
Definition: GenericStateGraph.h:434
void EnableHooks() noexcept
Enable the hook functions (default).
Definition: GenericStateGraph.h:1309
std::unordered_map< std::string, EdgeHook > m_addEdgeHooks
Hook functions to call when adding an edge.
Definition: GenericStateGraph.h:442
std::vector< EI > FindInboundEdges(const VID _vid)
Definition: GenericStateGraph.h:1124
std::string ToString(const HookType &_t) const noexcept
Definition: GenericStateGraph.h:1573
STAPLGraph::vertex_property VP
Definition: GenericStateGraph.h:95
std::unordered_map< VID, VertexSet > m_predecessors
Definition: GenericStateGraph.h:454
stapl::sequential::graph< stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex, Edge > STAPLGraph
Definition: GenericStateGraph.h:80
bool IsVertex(const VID _vid) const noexcept
Definition: GenericStateGraph.h:896
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
GenericStateGraph()
Definition: GenericStateGraph.h:468
virtual void DeleteEdge(const VID _source, const VID _target) noexcept
Definition: GenericStateGraph.h:806
std::unordered_set< VID > VertexSet
Definition: GenericStateGraph.h:86
EID::edge_id_type EdgeID
Definition: GenericStateGraph.h:85
std::unordered_map< std::string, EdgeHook > m_deleteEdgeHooks
Hook functions to call when deleting an edge.
Definition: GenericStateGraph.h:444
void AppendRoadmap(const GenericStateGraph &_r)
Definition: GenericStateGraph.h:850
size_t GetTimestamp() const noexcept
Each time the roadmap is modified, we update the timestamp.
Definition: GenericStateGraph.h:996
virtual VID AddDuplicateVertex(const Vertex &_v) noexcept
Definition: GenericStateGraph.h:648
virtual void DeleteEdge(EI _iterator) noexcept
Definition: GenericStateGraph.h:824
VID GetVID(const T &_t) const noexcept
Definition: GenericStateGraph.h:945
void ExecuteDeleteVertexHooks(const VI _iterator) noexcept
Definition: GenericStateGraph.h:1526
CCTracker< GenericStateGraph< Vertex, Edge > > CCTrackerType
Definition: GenericStateGraph.h:109
GenericStateGraph(const GenericStateGraph &_r)
Definition: GenericStateGraph.h:478
VID GetLastVID() const noexcept
Get the descriptor of the last vertex added to the graph.
Definition: GenericStateGraph.h:984
Definition: Robot.h:31
Definition: MetricUtils.h:29
Definition: PMPLExceptions.h:38
Definition: PMPLExceptions.h:62