![]() |
Parasol Planning Library (PPL)
|
#include <GenericStateGraph.h>
Public Types | |
Local Types | |
enum class | HookType { AddVertex , DeleteVertex , AddEdge , DeleteEdge } |
using | STAPLGraph = stapl::sequential::graph< stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex, Edge > |
typedef STAPLGraph::vertex_descriptor | VID |
typedef STAPLGraph::edge_descriptor | EID |
typedef EID::edge_id_type | EdgeID |
typedef std::unordered_set< VID > | VertexSet |
typedef STAPLGraph::vertex_iterator | VI |
typedef STAPLGraph::adj_edge_iterator | EI |
typedef STAPLGraph::const_vertex_iterator | CVI |
typedef STAPLGraph::const_adj_edge_iterator | CEI |
typedef STAPLGraph::vertex_property | VP |
typedef STAPLGraph::edge_property | EP |
typedef Vertex | CfgType |
typedef Edge | EdgeType |
typedef stapl::sequential::vector_property_map< STAPLGraph, size_t > | ColorMap |
typedef std::function< void(VI)> | VertexHook |
typedef std::function< void(EI)> | EdgeHook |
typedef CCTracker< GenericStateGraph< Vertex, Edge > > | CCTrackerType |
Public Member Functions | |
Construction | |
GenericStateGraph () | |
GenericStateGraph (Robot *const _r) | |
Move and Copy | |
Move and copy operations do not copy hook functions. | |
GenericStateGraph (const GenericStateGraph &_r) | |
GenericStateGraph (GenericStateGraph &&_r) | |
GenericStateGraph & | operator= (const GenericStateGraph &_r) |
GenericStateGraph & | operator= (GenericStateGraph &&_r) |
Equality | |
bool | operator== (const GenericStateGraph &_r) const noexcept |
bool | operator!= (const GenericStateGraph &_r) const noexcept |
Modifiers | |
virtual VID | AddVertex (const Vertex &_v) noexcept |
virtual VID | AddVertex (const VID _vid, const Vertex &_v) noexcept |
virtual VID | AddDuplicateVertex (const Vertex &_v) noexcept |
virtual void | DeleteVertex (const VID _v) noexcept |
virtual EID | AddEdge (const VID _source, const VID _target, const Edge &_w) noexcept |
virtual std::pair< EID, EID > | AddEdge (const VID _source, const VID _target, const std::pair< Edge, Edge > &_w) noexcept |
virtual EID | AddEdge (const EID _eid, const Edge &_w) noexcept |
virtual EID | AddEdge (const VID _source, const VID _target) noexcept |
virtual void | DeleteEdge (const VID _source, const VID _target) noexcept |
virtual void | DeleteEdge (EI _iterator) noexcept |
void | SetRobot (Robot *const _r) noexcept |
Set the robot pointer on all configurations in the map. More... | |
void | AppendRoadmap (const GenericStateGraph &_r) |
void | SetCCTracker (StatClass *const _stats=nullptr) |
Queries | |
size_t | Size () const noexcept |
Get the number of vertices in the roadmap. More... | |
bool | IsVertex (const VID _vid) const noexcept |
bool | IsVertex (const Vertex &_v) const noexcept |
bool | IsVertex (const Vertex &_v, CVI &_vi) const noexcept |
bool | IsEdge (const VID _source, const VID _target) const noexcept |
template<typename T > | |
VID | GetVID (const T &_t) const noexcept |
VID | GetVID (const VI &_t) const noexcept |
VID | GetVID (const Vertex &_t) const noexcept |
const VertexSet & | GetPredecessors (const VID _vid) const noexcept |
VID | GetLastVID () const noexcept |
Get the descriptor of the last vertex added to the graph. More... | |
size_t | GetTimestamp () const noexcept |
Each time the roadmap is modified, we update the timestamp. More... | |
const VertexSet & | GetAllVIDs () const noexcept |
Get the set of all VIDs in the roadmap. More... | |
Accessors | |
Robot * | GetRobot () const noexcept |
Get the robot represented by this roadmap. More... | |
CCTrackerType * | GetCCTracker () const noexcept |
Get the connected component tracker. More... | |
template<typename T > | |
VP & | GetVertex (T &_t) noexcept |
Retrieve a reference to a vertex property by descriptor or iterator. More... | |
VP & | GetVertex (VI &_t) noexcept |
VP & | GetVertex (VID _t) noexcept |
template<typename T > | |
const VP & | GetVertex (T &_t) const noexcept |
const VP & | GetVertex (CVI &_t) const noexcept |
const VP & | GetVertex (VID _t) const noexcept |
std::vector< VID > | GetChildren (const VID _vid) const noexcept |
size_t | GetInDegree (const VID _vid) noexcept |
std::vector< EI > | FindInboundEdges (const VID _vid) |
bool | GetEdge (const VID _source, const VID _target, EI &_ei) noexcept |
bool | GetEdge (const VID _source, const VID _target, CEI &_ei) const noexcept |
EP & | GetEdge (const VID _source, const VID _target) noexcept |
EP & | GetEdge (const EID _descriptor) noexcept |
Hooks | |
Hooks are arbitrary functions that are attached to roadmap events. I.e., whenever a vertex is added, a set of functions should be called (hooks). There is a set of hooks for each of the four modifying actions (add/delete a vertex/edge). IMPORTANT: Hooks for 'add' events execute immediately after the event, while hooks for 'delete' events execute immediately prior. This ensures that the iterator and neighbor information are valid in both cases. IMPORTANT: Dependencies between hooks create data races. To avoid problems, any piece of data that is modified by one hook should not be read or modified by any other hook. | |
bool | IsHook (const HookType, const std::string &_label) const |
void | InstallHook (const HookType _type, const std::string &_label, const VertexHook &_h) |
void | InstallHook (const HookType _type, const std::string &_label, const EdgeHook &_h) |
void | RemoveHook (const HookType _type, const std::string &_label) |
void | DisableHooks () noexcept |
void | EnableHooks () noexcept |
Enable the hook functions (default). More... | |
virtual void | ClearHooks () noexcept |
Protected Member Functions | |
Helpers | |
void | ExecuteAddVertexHooks (const VI _iterator) noexcept |
void | ExecuteDeleteVertexHooks (const VI _iterator) noexcept |
void | ExecuteAddEdgeHooks (const EI _iterator) noexcept |
void | ExecuteDeleteEdgeHooks (const EI _iterator) noexcept |
std::string | ToString (const HookType &_t) const noexcept |
Protected Attributes | |
Internal State | |
Robot * | m_robot {nullptr} |
The robot this roadmap is for. More... | |
size_t | m_timestamp {0} |
Tracks the number of changes to the graph. More... | |
bool | m_enableHooks {true} |
Use hook functions? More... | |
std::unordered_map< std::string, VertexHook > | m_addVertexHooks |
Hook functions to call when adding a vertex. More... | |
std::unordered_map< std::string, VertexHook > | m_deleteVertexHooks |
Hook functions to call when deleting a vertex. More... | |
std::unordered_map< std::string, EdgeHook > | m_addEdgeHooks |
Hook functions to call when adding an edge. More... | |
std::unordered_map< std::string, EdgeHook > | m_deleteEdgeHooks |
Hook functions to call when deleting an edge. More... | |
std::unique_ptr< CCTrackerType > | m_ccTracker |
Tracks weak CCs within the roadmap. More... | |
std::unordered_map< VID, VertexSet > | m_predecessors |
VertexSet | m_allVIDs |
I/O | |
virtual void | Write (const std::string &_filename, Environment *_env) const |
template<typename RG > | |
void | Read (RG *_g, const std::string &_filename) |
template<typename RG > | |
void | ReadMessage (RG *_g, const std::string &_msg) |
Graph data structure of robot configurations (vertices) connected by local plans (edges).
We often want to do some extra stuff whenever the roadmap is modified. To support that, this object can install hook functions for each of the four modifying events (add/delete a vertex/edge). Note that there is no particular ordering to the hook execution - this is deliberate because we will create a maintenance nightmare if hooks are allowed to depend on each other. As such, no two hooks should modify the same data. Terrible and unpredictable things will happen if you do this!
Vertex | The vertex or configuration type. |
Edge | The edge or local plan type. |
typedef CCTracker<GenericStateGraph<Vertex, Edge> > GenericStateGraph< Vertex, Edge >::CCTrackerType |
typedef STAPLGraph::const_adj_edge_iterator GenericStateGraph< Vertex, Edge >::CEI |
typedef Vertex GenericStateGraph< Vertex, Edge >::CfgType |
typedef stapl::sequential::vector_property_map<STAPLGraph, size_t> GenericStateGraph< Vertex, Edge >::ColorMap |
typedef STAPLGraph::const_vertex_iterator GenericStateGraph< Vertex, Edge >::CVI |
typedef std::function<void(EI)> GenericStateGraph< Vertex, Edge >::EdgeHook |
typedef EID::edge_id_type GenericStateGraph< Vertex, Edge >::EdgeID |
typedef Edge GenericStateGraph< Vertex, Edge >::EdgeType |
typedef STAPLGraph::adj_edge_iterator GenericStateGraph< Vertex, Edge >::EI |
typedef STAPLGraph::edge_descriptor GenericStateGraph< Vertex, Edge >::EID |
typedef STAPLGraph::edge_property GenericStateGraph< Vertex, Edge >::EP |
using GenericStateGraph< Vertex, Edge >::STAPLGraph = stapl::sequential::graph<stapl::DIRECTED, stapl::NONMULTIEDGES, Vertex, Edge> |
typedef std::function<void(VI)> GenericStateGraph< Vertex, Edge >::VertexHook |
typedef std::unordered_set<VID> GenericStateGraph< Vertex, Edge >::VertexSet |
typedef STAPLGraph::vertex_iterator GenericStateGraph< Vertex, Edge >::VI |
typedef STAPLGraph::vertex_descriptor GenericStateGraph< Vertex, Edge >::VID |
typedef STAPLGraph::vertex_property GenericStateGraph< Vertex, Edge >::VP |
|
strong |
GenericStateGraph< Vertex, Edge >::GenericStateGraph |
GenericStateGraph< Vertex, Edge >::GenericStateGraph | ( | Robot *const | _r | ) |
GenericStateGraph< Vertex, Edge >::GenericStateGraph | ( | const GenericStateGraph< Vertex, Edge > & | _r | ) |
GenericStateGraph< Vertex, Edge >::GenericStateGraph | ( | GenericStateGraph< Vertex, Edge > && | _r | ) |
|
virtualnoexcept |
Add a vertex to the graph without checking for uniqueness.
_v | The vertex to add. |
|
virtualnoexcept |
|
virtualnoexcept |
|
virtualnoexcept |
Add an edge from source to target.
_source | The source vertex. |
_target | The target vertex. |
_w | The edge property. |
Reimplemented in GroupRoadmap< Vertex, Edge >, and CompositeGraph< Vertex, Edge >.
|
virtualnoexcept |
Add edges both ways between source and target vertices.
_source | The source vertex. |
_target | The target vertex. |
_w | The edge properties (source to target first). |
|
virtualnoexcept |
Add a new unique vertex to the graph. If it already exists, a warning will be printed to cerr.
_v | The vertex to add. |
Reimplemented in GroupRoadmap< Vertex, Edge >, and CompositeGraph< Vertex, Edge >.
|
virtualnoexcept |
Add a new unique vertex to the graph with a designated descriptor. If it already exists or the descriptor is already in use, a warning will be printed to cerr.
_vid | The desired descriptor. |
_v | The vertex property. |
void GenericStateGraph< Vertex, Edge >::AppendRoadmap | ( | const GenericStateGraph< Vertex, Edge > & | _r | ) |
Copy the nodes and edges from another roadmap and append them to this. Assumes the configurations are compatible with this roadmap's robot.
_r | The roadmap to copy from. |
|
virtualnoexcept |
Uninstall all hooks. Should only be used at the end of a library run to clean the roadmap object.
Reimplemented in CompositeGraph< Vertex, Edge >.
|
virtualnoexcept |
Remove an edge from the graph if it exists.
_source | The source vertex. |
_target | The target vertex. |
Reimplemented in CompositeGraph< Vertex, Edge >.
|
virtualnoexcept |
Remove an edge from the graph if it exists.
_iterator | An iterator to the edge. |
Reimplemented in CompositeGraph< Vertex, Edge >.
|
virtualnoexcept |
Remove a vertex (and attached edges) from the graph if it exists.
_v | The vertex descriptor. |
Reimplemented in CompositeGraph< Vertex, Edge >.
|
inlinenoexcept |
Disable the hooks. This is useful for making temporary additions and deletions to the roadmap without triggering the hook functions. Be sure to re-enable them after, and to only use this in isolated code segments where you are sure that we won't miss any real nodes.
|
inlinenoexcept |
Enable the hook functions (default).
|
inlineprotectednoexcept |
Execute the AddEdge hooks.
_iterator | An iterator to the newly added edge. |
|
inlineprotectednoexcept |
Execute the AddVertex hooks.
_iterator | An iterator to the newly added vertex. |
|
inlineprotectednoexcept |
Execute the DeleteEdge hooks.
_iterator | An iterator to the to-be-deleted edge. |
|
inlineprotectednoexcept |
Execute the DeleteVertex hooks.
_iterator | An iterator to the to-be-deleted vertex. |
std::vector< typename GenericStateGraph< Vertex, Edge >::EI > GenericStateGraph< Vertex, Edge >::FindInboundEdges | ( | const VID | _vid | ) |
|
inlinenoexcept |
Get the set of all VIDs in the roadmap.
|
inlinenoexcept |
Get the connected component tracker.
|
noexcept |
Get the set of VIDs which are children of a given vertex.
_vid | The VID of the given vertex. |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Retrieve an edge from the graph.
_source | The source node VID. |
_target | The target node VID. |
_ei | An edge iterator, set to the specified edge if found or end otherwise. |
|
noexcept |
|
inlinenoexcept |
Get the descriptor of the last vertex added to the graph.
|
inlinenoexcept |
Get the set of predecessors for a given vertex.
_vid | The vertex descriptor. |
|
inlinenoexcept |
Get the robot represented by this roadmap.
|
inlinenoexcept |
Each time the roadmap is modified, we update the timestamp.
|
inlinenoexcept |
|
inlinenoexcept |
Retrieve a constant reference to a vertex property by descriptor or iterator.
|
inlinenoexcept |
Retrieve a reference to a vertex property by descriptor or iterator.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Get the descriptor of a vertex property if it exists in the graph, or INVALID_VID otherwise.
|
inlinenoexcept |
|
inlinenoexcept |
void GenericStateGraph< Vertex, Edge >::InstallHook | ( | const HookType | _type, |
const std::string & | _label, | ||
const EdgeHook & | _h | ||
) |
Install an edge hook. It will be called each time a new edge is added.
_type | The hook type (edge add/delete). |
_label | The unique label. |
_h | The hook function. |
void GenericStateGraph< Vertex, Edge >::InstallHook | ( | const HookType | _type, |
const std::string & | _label, | ||
const VertexHook & | _h | ||
) |
Install a vertex hook. It will be called each time a new vertex is added.
_type | The hook type (vertex add/delete). |
_label | The unique label. |
_h | The hook function. |
|
inlinenoexcept |
Check if an edge is present between two vertices.
_source | The source vertex. |
_target | The target vertex. |
bool GenericStateGraph< Vertex, Edge >::IsHook | ( | const HookType | _type, |
const std::string & | _label | ||
) | const |
Check if a hook with a given type and label is installed.
_type | The hook type. |
_label | The unique label. |
|
inlinenoexcept |
Check if a vertex is present in the graph.
_v | The vertex property to seek. |
|
inlinenoexcept |
Check if a vertex is present in the graph and retrieve a const iterator to it if so.
_v | The vertex property to seek. |
_vi | A vertex iterator, set to the located vertex or end if not found. |
|
inlinenoexcept |
Check if a vertex is present in the graph.
_vid | The vertex descriptor |
|
noexcept |
GenericStateGraph< Vertex, Edge > & GenericStateGraph< Vertex, Edge >::operator= | ( | const GenericStateGraph< Vertex, Edge > & | _r | ) |
GenericStateGraph< Vertex, Edge > & GenericStateGraph< Vertex, Edge >::operator= | ( | GenericStateGraph< Vertex, Edge > && | _r | ) |
|
noexcept |
void GenericStateGraph< Vertex, Edge >::RemoveHook | ( | const HookType | _type, |
const std::string & | _label | ||
) |
Remove a hook.
_type | The hook type. |
_label | The unique label. |
|
inline |
Set the CC tracker.
_stats | Optional stat class for performance profiling. |
|
noexcept |
Set the robot pointer on all configurations in the map.
|
inlinenoexcept |
Get the number of vertices in the roadmap.
|
protectednoexcept |
Helper for printing hook type names.
_t | A hook type. |
|
virtual |
Write the current roadmap out to a roadmap (.map) file.
_filename | The name of the map file to write to. |
_env | The environment for which this map was constructed. |
Reimplemented in CompositeGraph< Vertex, Edge >.
|
friend |
Read in a roadmap (.map) file.
_filename | The name of the map file to read. |
|
friend |
|
protected |
Hook functions to call when adding an edge.
|
protected |
Hook functions to call when adding a vertex.
|
protected |
A set of all VIDs in the roadmap. We track this to make nearest-neighbor queries more efficient.
|
protected |
Tracks weak CCs within the roadmap.
|
protected |
Hook functions to call when deleting an edge.
|
protected |
Hook functions to call when deleting a vertex.
|
protected |
Use hook functions?
|
protected |
Tracks predecessor information. We use this instead of switching to a STAPL directed_preds graph because (a) directed_preds uses a vector for storage of VIDs, making all changes linear-time operations in the in-degree of each vertex, and (b) the STAPL API is not interchangable as it should be, so switching causes ridiculous compiler errors.
|
protected |
The robot this roadmap is for.
|
protected |
Tracks the number of changes to the graph.