Template Class Graph
Defined in File graph.hpp
Derived Type
public holoscan::FlowGraph< NodeT, EdgeDataElementT >
(Template Class FlowGraph)
-
template<typename NodeT = OperatorNodeType, typename EdgeDataElementT = OperatorEdgeDataElementType>
class Graph Abstract base class for all graphs.
Subclassed by holoscan::FlowGraph< NodeT, EdgeDataElementT >
Public Types
-
using NodeType = NodeT
-
using NodePredicate = std::function<bool(const NodeT&)>
-
using EdgeDataElementType = EdgeDataElementT
-
using EdgeDataType = std::shared_ptr<EdgeDataElementT>
Public Functions
-
Graph() = default
-
virtual ~Graph() = default
-
Graph(const Graph&) = delete
-
virtual void add_node(const NodeT &node) = 0
Add the node to the graph.
- Parameters
node – The node to add.
-
virtual void add_flow(const NodeType &node_u, const NodeType &node_v, const EdgeDataType &port_map) = 0
Add an edge to the graph.
- Parameters
node_u – A source node.
node_v – A destination node.
port_map – A map from the source node’s port name to the destination node’s port name(s).
-
virtual std::optional<EdgeDataType> get_port_map(const NodeType &node_u, const NodeType &node_v) const = 0
Get a mapping from the source node’s port name to the destination node’s port name(s).
- Parameters
node_u – A source node.
node_v – A destination node.
- Returns
A map from the source node’s port name to the destination node’s port name(s).
-
inline virtual bool is_empty() const
Check if the graph is empty.
- Returns
true if the graph is empty. Otherwise, false.
-
virtual bool is_root(const NodeType &node) const = 0
Check if the node is a root node.
- Parameters
node – A node in the graph.
- Returns
true if the node is a root node.
-
virtual bool is_user_defined_root(const NodeType &node) const = 0
Check if the node is a user-defined root node. A user-defined root is the first node that is added to the graph.
- Parameters
node – A node in the graph.
- Returns
true if the node is a user-defined root node.
-
virtual bool is_leaf(const NodeType &node) const = 0
Check if the node is a leaf node.
- Parameters
node – A node in the graph.
- Returns
true if the node is a leaf node.
-
virtual std::vector<NodeType> has_cycle() const = 0
Returns a vector of root nodes of the cycles if the graph has cycle(s). Otherwise, an empty vector is returned.
- Returns
Returns a vector of root nodes of cycles.
-
virtual std::vector<NodeType> get_root_nodes() const = 0
Get all root nodes.
- Returns
A vector of root nodes.
-
virtual std::vector<NodeType> get_nodes() const = 0
Get all nodes.
The order of the nodes is not guaranteed.
- Returns
A vector of all nodes.
-
virtual std::vector<NodeType> get_next_nodes(const NodeType &node) const = 0
Get the next nodes of the given node.
- Parameters
node – A node in the graph.
- Returns
A vector of next nodes.
-
virtual size_t get_outdegree(const NodeType &node, const std::string &port_name) const = 0
Get the outdegree of a given node of a given port.
- Parameters
node – A node in the graph.
port_name – The name of the port in the given node.
- Returns
The outdegree of the given node of the given port.
-
virtual NodeType find_node(const NodePredicate &pred) const = 0
Find a node in the graph that satisfies the given predicate.
- Parameters
pred – A predicate.
- Returns
The node if found, otherwise nullptr.
-
virtual NodeType find_node(const NodeType &node) const = 0
Find a node in the graph that is equal to the given node.
- Parameters
node – The node to find.
- Returns
The node in the graph if found, otherwise nullptr.
-
virtual NodeType find_node(const std::string &name) const = 0
Find a node in the graph whose name is equal to the given name.
- Parameters
name – The name to find.
- Returns
The node in the graph if found, otherwise nullptr.
-
virtual std::vector<NodeType> get_previous_nodes(const NodeType &node) const = 0
Get the previous nodes of the given node.
- Parameters
node – A node in the graph.
- Returns
A vector of previous nodes.
-
inline virtual void context(void *context)
Set the context.
- Parameters
context – The context.
-
inline virtual void *context() const
Get the context.
- Returns
The context.
-
virtual void remove_node(const NodeType &node) = 0
Remove a node (and all its edges) from the graph.
- Parameters
node – The node to remove.
-
virtual std::pair<std::map<std::string, std::vector<std::string>>, std::map<std::string, std::vector<std::string>>> get_port_connectivity_maps() const = 0
Get port connectivity maps for the graph.
Returns a pair of two maps:
Input ports to connected output ports mapping
Output ports to connected input ports mapping
Each port is identified by a unique string.
- Returns
A pair containing (input_to_output_map, output_to_input_map) where:
input_to_output_map: Maps input port IDs to lists of connected output port IDs
output_to_input_map: Maps output port IDs to lists of connected input port IDs
-
virtual std::string port_map_description() const = 0
Get a YAML-formatted description of the port connectivity maps.
Returns a human-readable YAML string that describes the port connectivity of the graph.
- Returns
A YAML-formatted string describing the port connectivity maps
Protected Attributes
-
void *context_ = nullptr
The context.
-
using NodeType = NodeT