MnaGraph
Namespace: MNALIB · Library: MNA Library
#include <mna/mna_graph.h>
class MNALIB::MnaGraph
Directed acyclic graph of processing nodes forming a computational pipeline.
In-memory DAG of MnaNode operations with validation, topological sort and JSON/CBOR persistence.
MnaGraph graph;
MnaNode source;
source.id = "source";
source.opType = "ex_constant";
source.attributes["value"] = 3.0;
const MnaPort sourceOut = port("out", MnaPortDir::Output); // name, data kind, direction
source.outputs.append(sourceOut);
graph.addNode(source);
for (const QString& id : {QStringLiteral("scale"), QStringLiteral("shift")}) {
MnaNode node;
node.id = id;
node.opType = "ex_affine";
node.inputs.append(port("in", MnaPortDir::Input));
node.outputs.append(port("out", MnaPortDir::Output));
graph.addNode(node);
}
graph.node("scale").attributes["gain"] = 2.0;
graph.connect("source", "out", "scale", "in");
graph.connect("scale", "out", "shift", "in");
Public Methods
MnaGraph()
addNode(node)
removeNode(nodeId)
node(nodeId)
node(nodeId)
nodes()
nodes()
hasNode(nodeId)
connect(srcNodeId, srcPortName, dstNodeId, dstPortName)
Connect output port of srcNode to input port of dstNode.
Sets the sourceNodeId and sourcePortName on the destination input port.
Parameters:
-
srcNodeId : const QString & Id of the node providing the output.
-
srcPortName : const QString & Name of the output port on the source node.
-
dstNodeId : const QString & Id of the node receiving the input.
-
dstPortName : const QString & Name of the input port on the destination node.
Returns:
- bool — true if connection was made, false if ports not found.
validate(errors)
Validate the graph: acyclicity, port connections, data-kind compatibility, op schema compliance, required attributes.
Parameters:
- errors : *QStringList ** Optional list to receive error messages.
Returns:
- bool — true if valid.
topologicalSort()
upstreamNodes(nodeId)
downstreamNodes(nodeId)
dirtyNodes()
toJson()
toCbor()
Static Methods
fromJson(json)
fromCbor(cbor)
Example
- Full source:
src/examples/ex_mna/main.cpp - Build target:
ex_mna(runs under CTest)
Used in examples
ex_mna
MNA library: register operations, build and run a graph, bind parameters and save a project.
MnaGraph graph;
MnaNode source;
source.id = "source";
source.opType = "ex_constant";
source.attributes["value"] = 3.0;
const MnaPort sourceOut = port("out", MnaPortDir::Output); // name, data kind, direction
source.outputs.append(sourceOut);
graph.addNode(source);
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>