Go to the documentation of this file.
22 #ifndef COMPUTATION_GRAPH_MANAGER_H
23 #define COMPUTATION_GRAPH_MANAGER_H
26 #include <boost/python.hpp>
27 #include <nlohmann/json.hpp>
78 if(!_nodes.count(obj->id()))
79 _nodes.emplace(obj->id(), obj);
81 else if(obj->type() != _nodes[obj->id()]->type() )
83 obj->typeStr() +
" and \"" +
84 _nodes[obj->id()]->typeStr() +
"\". This is not allowed.");
87 throw NRPException::logCreate(
"Duplicated Node Name: Attempt to register Functional Node with name \"" + obj->id() +
"\". But a node with that name already exists.");
89 obj = _nodes[obj->id()];
98 return _nodes.at(
id).get();
106 template<
class T_IN,
class T_OUT>
109 if(!source || !target)
112 if(!_nodes.count(source->
parent()->
id()) || !_nodes.count(target->
parent()->
id()))
114 target->
parent()->
id() +
", but they are not registered in the graph");
137 for(
const auto& node : _nodes)
138 if(!node.second->isVisited())
139 NRPLogger::warn(
"Graph node \"" + node.second->id() +
"\" is disconnected. It will not be executed.");
147 for(
const auto& node : _nodes)
148 node.second->graphLoadedCB();
169 static std::unique_ptr<ComputationalGraphManager> _instance;
172 std::map<std::string, std::shared_ptr<ComputationalNode> > _nodes;
176 #endif //COMPUTATION_GRAPH_MANAGER_H
void registerEdge(OutputPort< T_IN > *source, InputPort< T_IN, T_OUT > *target)
Connects an InputPort to an Output port and registers an edge in the graph between their parent nodes...
Definition: computational_graph_manager.h:107
static void warn(const FormatString &fmt, const Args &...args)
NRP logging function with message formatting for warning level.
Definition: nrp_logger.h:149
void configure()
Configure ComputationalGraph.
Definition: computational_graph_manager.h:132
void clear()
Clear graph.
Definition: computational_graph.h:86
void insert_edge(const vertex &a, const vertex &b)
Insert edge.
Definition: computational_graph.h:67
ExecMode getExecMode()
Definition: computational_graph.h:206
ComputationalNode * parent() const
Returns the port parent node.
Definition: port.h:53
void compute()
Executes all nodes in the graph in order.
Definition: computational_graph.h:149
void compute()
Executes ComputationalGraph.
Definition: computational_graph_manager.h:126
void setExecMode(ExecMode mode)
Definition: computational_graph.h:198
static ComputationalGraphManager & resetInstance()
Reset singleton instance.
Definition: computational_graph_manager.cpp:36
void registerNode(std::shared_ptr< ComputationalNode > &obj)
Register a node in the graph.
Definition: computational_graph_manager.h:75
void clear()
Resets ComputationalGraphManager.
Definition: computational_graph_manager.h:154
ComputationalGraph::ExecMode getExecMode()
Definition: computational_graph_manager.h:163
const std::string & id() const
Returns the node 'id'.
Definition: computational_node.h:57
ComputationalGraphManager & operator=(const ComputationalGraphManager &)=delete
static ComputationalGraphManager & getInstance()
Get singleton instance of ComputationalGraphManager.
Definition: computational_graph_manager.cpp:31
ComputationalNode * getNode(const std::string &id)
Retrieve a node from the graph as a pointer.
Definition: computational_graph_manager.h:95
virtual ~ComputationalGraphManager()
Definition: computational_graph_manager.cpp:26
ExecMode
Definition: computational_graph.h:62
static EXCEPTION logCreate(LOG_EXCEPTION_T &exception, const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:73
void setExecMode(ComputationalGraph::ExecMode mode)
Definition: computational_graph_manager.h:160
Implementation of an output port in the computation graph.
Definition: output_port.h:36
@ Functional
Definition: computational_node.h:38
void configure()
Creates the graph execution structure and call 'configure' on each node.
Definition: computational_graph.h:102
void graphLoadComplete()
Function to be called externally after all nodes has been added to the graph.
Definition: computational_graph_manager.h:145
Definition: computational_graph.h:53
Singleton class managing a computational graph.
Definition: computational_graph_manager.h:45
Base class implementing a node in the computational graph.
Definition: computational_node.h:31