NRP Core  1.4.1
ComputationalGraph Class Reference

#include <computational_graph.h>

Inheritance diagram for ComputationalGraph:
NGraph::tGraph< ComputationalNode * >

Public Types

enum  GraphState { EMPTY, CONFIGURING, READY, COMPUTING }
 
enum  ExecMode { ALL_NODES, OUTPUT_DRIVEN }
 
typedef std::vector< ComputationalGraph::vertexcomp_layer
 

Public Member Functions

void insert_edge (const vertex &a, const vertex &b)
 Insert edge. More...
 
void clear ()
 Clear graph. More...
 
void configure ()
 Creates the graph execution structure and call 'configure' on each node. More...
 
void compute ()
 Executes all nodes in the graph in order. More...
 
GraphState getState () const
 Returns true if the graph is configured, false otherwise. More...
 
void setExecMode (ExecMode mode)
 
ExecMode getExecMode ()
 

Detailed Description

/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 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.

Member Typedef Documentation

◆ comp_layer

Member Enumeration Documentation

◆ ExecMode

Enumerator
ALL_NODES 
OUTPUT_DRIVEN 

◆ GraphState

Enumerator
EMPTY 
CONFIGURING 
READY 
COMPUTING 

Member Function Documentation

◆ clear()

void ComputationalGraph::clear ( )
inline

Clear graph.

◆ compute()

void ComputationalGraph::compute ( )
inline

Executes all nodes in the graph in order.

◆ configure()

void ComputationalGraph::configure ( )
inline

Creates the graph execution structure and call 'configure' on each node.

◆ getExecMode()

ExecMode ComputationalGraph::getExecMode ( )
inline

◆ getState()

GraphState ComputationalGraph::getState ( ) const
inline

Returns true if the graph is configured, false otherwise.

◆ insert_edge()

void ComputationalGraph::insert_edge ( const vertex a,
const vertex b 
)
inline

Insert edge.

◆ setExecMode()

void ComputationalGraph::setExecMode ( ExecMode  mode)
inline

The documentation for this class was generated from the following file: