.. index:: pair: class; ComputationalGraph .. _doxid-class_computational_graph: class ComputationalGraph ======================== .. toctree:: :hidden: enum_ComputationalGraph_ExecMode.rst enum_ComputationalGraph_GraphState.rst Overview ~~~~~~~~ /brief Class implementing a computation graph In the context of nrp-core a computation graph is defined as a directed, acyclic property graph in which nodes are associated to objects of type :ref:`ComputationalNode ` and which implements a 'compute' method. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class ComputationalGraph: private :ref:`NGraph::tGraph` { public: // typedefs typedef std::vector<:ref:`ComputationalGraph::vertex`> :target:`comp_layer`; // enums enum :ref:`ExecMode`; enum :ref:`GraphState`; // methods void :ref:`insert_edge`(const :ref:`vertex`& a, const :ref:`vertex`& b); void :ref:`clear`(); void :ref:`configure`(); void :ref:`compute`(); :ref:`GraphState` :ref:`getState`() const; void :target:`setExecMode`(:ref:`ExecMode` mode); :ref:`ExecMode` :target:`getExecMode`(); }; Inherited Members ----------------- .. ref-code-block:: cpp :class: doxyrest-overview-inherited-code-block public: // typedefs typedef T :ref:`vertex`; typedef T :ref:`value_type`; typedef std::pair<:ref:`vertex`, :ref:`vertex`> :ref:`edge`; typedef std::set<:ref:`vertex`> :ref:`vertex_set`; typedef std::set<:ref:`edge`> :ref:`edge_set`; typedef std::pair<:ref:`vertex_set`, :ref:`vertex_set`> :ref:`in_out_edge_sets`; typedef std::map<:ref:`vertex`, :ref:`in_out_edge_sets`> :ref:`adj_graph`; typedef edge_set::iterator :ref:`edge_iterator`; typedef edge_set::const_iterator :ref:`const_edge_iterator`; typedef vertex_set::iterator :ref:`vertex_iterator`; typedef vertex_set::const_iterator :ref:`const_vertex_iterator`; typedef vertex_set::iterator :ref:`vertex_neighbor_iterator`; typedef vertex_set::const_iterator :ref:`vertex_neighbor_const_iterator`; typedef adj_graph::iterator :ref:`iterator`; typedef adj_graph::const_iterator :ref:`const_iterator`; typedef :ref:`iterator` :ref:`node_iterator`; typedef :ref:`const_iterator` :ref:`const_node_iterator`; // enums enum :ref:`line_type`; // methods unsigned int :ref:`num_vertices`() const; unsigned int :ref:`num_nodes`() const; unsigned int :ref:`num_edges`() const; :ref:`iterator` :ref:`begin`(); :ref:`const_iterator` :ref:`begin`() const; :ref:`iterator` :ref:`end`(); :ref:`const_iterator` :ref:`end`() const; void :ref:`clear`(); :ref:`vertex_neighbor_iterator` :ref:`out_neighbors_begin`(const :ref:`vertex`& a); :ref:`vertex_neighbor_const_iterator` :ref:`out_neighbors_begin`(const :ref:`vertex`& a) const; :ref:`vertex_neighbor_iterator` :ref:`out_neighbors_end`(const :ref:`vertex`& a); :ref:`vertex_neighbor_const_iterator` :ref:`out_neighbors_end`(const :ref:`vertex`& a) const; bool :ref:`is_undirected`() const; bool :ref:`is_directed`() const; void :ref:`set_undirected`(); :ref:`iterator` :ref:`find`(const :ref:`vertex`& a); :ref:`const_iterator` :ref:`find`(const :ref:`vertex`& a) const; const :ref:`vertex_set`& :ref:`in_neighbors`(const :ref:`vertex`& a) const; :ref:`vertex_set`& :ref:`in_neighbors`(const :ref:`vertex`& a); const :ref:`vertex_set`& :ref:`out_neighbors`(const :ref:`vertex`& a) const; :ref:`vertex_set`& :ref:`out_neighbors`(const :ref:`vertex`& a); unsigned int :ref:`in_degree`(const :ref:`vertex`& a) const; unsigned int :ref:`out_degree`(const :ref:`vertex`& a) const; unsigned int :ref:`degree`(const :ref:`vertex`& a) const; bool :ref:`isolated`(const :ref:`vertex`& a) const; void :ref:`insert_vertex`(const :ref:`vertex`& a); void :ref:`insert_new_vertex_inout_list`( const :ref:`vertex`& a, const :ref:`vertex_set`& IN, const :ref:`vertex_set`& OUT ); void :ref:`insert_edge_noloop`(:ref:`iterator` pa, :ref:`iterator` pb); void :ref:`insert_edge`(:ref:`iterator` pa, :ref:`iterator` pb); void :ref:`insert_edge_noloop`(const :ref:`vertex`& a, const :ref:`vertex`& b); void :ref:`insert_edge`(const :ref:`vertex`& a, const :ref:`vertex`& b); void :ref:`insert_undirected_edge`(const :ref:`vertex`& a, const :ref:`vertex`& b); void :ref:`insert_edge`(const :ref:`edge`& E); void :ref:`insert_undirected_edge`(const :ref:`edge`& E); bool :ref:`remove_edge`(:ref:`iterator` pa, :ref:`iterator` pb); void :ref:`remove_edge`(const :ref:`vertex`& a, const :ref:`vertex`& b); void :ref:`remove_edge`(const :ref:`edge`& E); void :ref:`remove_undirected_edge`(const :ref:`vertex`& a, const :ref:`vertex`& b); void :ref:`remove_undirected_edge`(const :ref:`edge`& e); void :ref:`remove_vertex`(:ref:`iterator` pa); void :ref:`remove_vertex_set`(const :ref:`vertex_set`& V); void :ref:`remove_vertex`(const :ref:`vertex`& a); bool :ref:`includes_vertex`(const :ref:`vertex`& a) const; bool :ref:`includes_edge`(const :ref:`vertex`& a, const :ref:`vertex`& b) const; bool :ref:`includes_edge`(const :ref:`edge`& e) const; std::vector<:ref:`edge`> :ref:`edge_list`() const; :ref:`tGraph`& :ref:`plus_eq`(const :ref:`tGraph`& B); :ref:`tGraph` :ref:`intersect`(const :ref:`tGraph`& B) const; :ref:`tGraph` :ref:`operator *` (const :ref:`tGraph`& B) const; :ref:`tGraph` :ref:`minus`(const :ref:`tGraph`& B) const; :ref:`tGraph` :ref:`operator -` (const :ref:`tGraph`& B) const; :ref:`tGraph` :ref:`plus`(const :ref:`tGraph`& B) const; :ref:`tGraph` :ref:`operator +` (const :ref:`tGraph`& B) const; :ref:`tGraph`& :ref:`operator +=` (const :ref:`tGraph`& B); :ref:`tGraph` :ref:`subgraph`(const :ref:`vertex_set`& A) const; unsigned int :ref:`subgraph_size`(const :ref:`vertex_set`& A) const; double :ref:`subgraph_sparsity`(const :ref:`vertex_set`& A) const; void :ref:`print`() const; void :ref:`absorb`(:ref:`iterator` pa, :ref:`iterator` pb); :ref:`iterator` :ref:`smart_absorb`(:ref:`iterator` pa, :ref:`iterator` pb); :ref:`vertex` :ref:`smart_absorb`(:ref:`vertex` a, :ref:`vertex` b); void :ref:`absorb`(:ref:`vertex` a, :ref:`vertex` b); static const :ref:`vertex`& :ref:`node`(:ref:`const_iterator` p); static const :ref:`vertex`& :ref:`node`(:ref:`iterator` p); static const :ref:`vertex`& :ref:`node`(:ref:`const_vertex_iterator` p); static const :ref:`vertex_set`& :ref:`in_neighbors`(:ref:`const_iterator` p); static :ref:`vertex_set`& :ref:`in_neighbors`(:ref:`iterator` p); static :ref:`const_vertex_iterator` :ref:`in_begin`(:ref:`const_iterator` p); static :ref:`const_vertex_iterator` :ref:`in_end`(:ref:`const_iterator` p); static const :ref:`vertex_set`& :ref:`out_neighbors`(:ref:`const_iterator` p); static :ref:`const_vertex_iterator` :ref:`out_begin`(:ref:`const_iterator` p); static :ref:`const_vertex_iterator` :ref:`out_end`(:ref:`const_iterator` p); static :ref:`vertex_set`& :ref:`out_neighbors`(:ref:`iterator` p); static :ref:`vertex_iterator` :ref:`out_begin`(:ref:`iterator` p); static unsigned int :ref:`num_edges`(:ref:`const_iterator` p); static unsigned int :ref:`num_edges`(:ref:`iterator` p); static unsigned int :ref:`out_degree`(:ref:`const_iterator` p); static unsigned int :ref:`out_degree`(:ref:`iterator` p); static unsigned int :ref:`in_degree`(:ref:`const_iterator` p); static unsigned int :ref:`in_degree`(:ref:`iterator` p); static unsigned int :ref:`degree`(:ref:`const_iterator` p); static unsigned int :ref:`degree`(:ref:`iterator` p); static bool :ref:`isolated`(:ref:`const_iterator` p); static bool :ref:`isolated`(:ref:`iterator` p); static std::istream& :ref:`read_line`( std::istream& s, T& v1, T& v2, std::string& line, :ref:`line_type`& t ); .. _details-class_computational_graph: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ /brief Class implementing a computation graph In the context of nrp-core a computation graph is defined as a directed, acyclic property graph in which nodes are associated to objects of type :ref:`ComputationalNode ` and which implements a 'compute' method. Nodes use Ports to communicate with each other. Nodes are uniquely identified in the graph by an 'id' attribute which is of type string. Edges in the graph represent connections between nodes, ie. between ports in the source and target nodes. Nodes can be of three types: 'Input', 'Output' and 'Functional'. 'Input' nodes can only be source nodes in edges. 'Output' nodes can only be target nodes in edges. 'Functional' nodes can be both source and target. The graph itself implements a 'compute' function which calls 'compute' on all the nodes in the graph in the right order. The latter is defined as follows: within a graph 'compute' operation, a node must always be executed after all the source nodes in edges for which the former is target. The former definition on the execution order allows to divide the graph in layers which must be executed sequentially. Nodes in each layer can be executed in parallel. The first layer will always be composed of nodes which have no inputs. These include 'Input' nodes and 'Functional' with no inputs. For convenience, the latter are moved to the second layer (with no consequences) and the first layer is kept with 'Input' nodes only. In the same way, all 'Output' nodes are moved to a separate layer which is executed the last. Methods ------- .. index:: pair: function; insert_edge .. _doxid-class_computational_graph_1a67c276b6aba162c2fcecb95e9cde9e59: .. ref-code-block:: cpp :class: doxyrest-title-code-block void insert_edge(const :ref:`vertex`& a, const :ref:`vertex`& b) Insert edge. .. index:: pair: function; clear .. _doxid-class_computational_graph_1a2bb7bf0f3eac546908c4f9eeb4276e72: .. ref-code-block:: cpp :class: doxyrest-title-code-block void clear() Clear graph. .. index:: pair: function; configure .. _doxid-class_computational_graph_1a55cb7e29b50f9698e34d17b8a66e130b: .. ref-code-block:: cpp :class: doxyrest-title-code-block void configure() Creates the graph execution structure and call 'configure' on each node. .. index:: pair: function; compute .. _doxid-class_computational_graph_1abebc767f2c382d14790fa9a8debb80a7: .. ref-code-block:: cpp :class: doxyrest-title-code-block void compute() Executes all nodes in the graph in order. .. index:: pair: function; getState .. _doxid-class_computational_graph_1ab4fcb06d1ce7d144d7dabf9e08255d31: .. ref-code-block:: cpp :class: doxyrest-title-code-block :ref:`GraphState` getState() const Returns true if the graph is configured, false otherwise.