reactor-cpp
reactor-cpp copied to clipboard
Port Graph Optimizations
About
This pull requests add functionality, so the port graph can be first optimized before instantiating.
- Graph Expansion with Path Merging
- Dead Edge Elimination by looking at triggers and dependencies and taking the shortest path
- Instantiating
Current Algorithm
Create a spanning tree for every port and then squash the edges together so ideally only a tree of depth 1 remains.
Challanges
Given a port-graph like this:
graph TD;
A-->B;
X((R1)) --> A;
B-->D;
B-->C;
C-->Y((R2));
The current graph optimizer would create something like this:
graph TD;
X((R1)) --> A;
A-->B;
A-->C;
B-->C;
B-->D;
A-->D;
C-->Y((R2));
If B just forwards data and
Dead Path Elimination
Paths: (A-->D, A-->B and B-->C) can be eliminated with the following reasoning:
- We take a look at all the ports that have triggers. Then taking all the downstream ports that have dependencies and then determine the shortest path between them.
graph TD;
X((R1)) --> A;
A-->C;
C-->Y((R2));
target Cpp;
reactor A {
output out: void;
timer t(500ms);
reaction (t) -> out {=
out.set();
=}
}
reactor C {
input in: void;
reaction(in) {=
std::cout << "C triggert" << std::endl;
=}
}
reactor D {
input in: void;
reaction(in) {=
std::cout << "D triggert" << std::endl;
=}
}
reactor B {
input in: void;
c = new C();
d = new D();
in -> c.in;
in -> d.in;
}
main reactor Forward {
a = new A();
b = new B();
a.out -> b.in;
}
TODO: Mermaid Function fixen