Interactive engineering tool for building and solving Signal Flow Graphs using Mason's Gain Formula
Signal Flow Graph Solver is a web-based engineering application that lets users draw, validate, and solve signal-flow graphs interactively.
The solver detects forward paths, feedback loops, and non-touching loop combinations, then applies Mason's Gain Formula to produce the symbolic transfer function together with the intermediate calculation steps.
Try it online: sfg-solver.onrender.com
- Interactive node and directed-branch editor.
- Symbolic branch gains such as
G1,H1,G1*G2, and rational expressions. - Automatic detection of forward paths.
- Automatic detection of individual feedback loops.
- Detection of non-touching loop combinations.
- Calculation of Mason's determinant Δ and path cofactors Δk.
- Symbolic final transfer function.
- Independent verification using a linear-equation formulation.
- Validation for duplicate node names, invalid gains, missing nodes, and input/output connectivity.
- Support for parallel branches.
- Built-in example graph for instant testing.
- Save and load diagrams as JSON.
- Export diagrams as PNG.
- English and Arabic interface.
- Interactive guided tutorial.
- Responsive interface for different screen sizes.
- Set the Input Node and Output Node.
- Add the required intermediate nodes.
- Connect nodes with directed branches.
- Select a branch and enter its symbolic gain.
- Press Solve Diagram.
- Review the transfer function, forward paths, loops, non-touching loops, Δ, and Δk.
For a quick demonstration, press Load Example and then Solve Diagram.
Branch gains are parsed as symbolic mathematics, never as executable Python. Examples include:
G1*G2orG_1*G_2— multiply symbolic gains.1/(s+1)— rational transfer expressions.G^2— exponentiation (the caret is accepted).sin(s),sqrt(s^2+1),exp(-s), andRational(1,2)— supported math functions.
Allowed operations: addition, subtraction, multiplication, division, powers, parentheses, numbers, variable names, and selected mathematical functions. Other Python constructs (imports, property access, indexing, string literals, arbitrary function calls, or comprehensions) are rejected. To reduce resource abuse, gains have limits on expression length and complexity.
If the solver reports an invalid gain, replace it with a mathematical expression using the supported syntax.
The application follows the same engineering workflow used when solving a Signal Flow Graph manually:
- The graph is validated before calculation.
- NetworkX identifies forward paths and simple cycles.
- Branch gains are converted into symbolic expressions.
- Loop gains and non-touching loop combinations are calculated.
- Mason's determinant is constructed:
Δ = 1 - Σ(individual loop gains)
+ Σ(products of two non-touching loops)
- Σ(products of three non-touching loops)
+ ...
- Each forward-path cofactor
Δkis calculated. - Mason's Gain Formula is evaluated:
T = Σ(Pk × Δk) / Δ
- The result is independently cross-checked using a linear-system formulation.
| Layer | Technologies |
|---|---|
| Backend | Python, FastAPI, NetworkX, SymPy, Pydantic |
| Frontend | HTML, CSS, JavaScript, jQuery |
| Graph UI | Cytoscape.js |
| Drawing / interaction | Konva.js |
| Symbolic math display | MathJax |
| Deployment | Render |
Validates:
- node names
- branch gains
- graph structure
- input/output nodes
- connectivity
Returns:
- transfer function
- forward paths
- path gains
- individual loops
- non-touching loop combinations
ΔΔk- symbolic intermediate results
Clone the repository and install the dependencies:
git clone https://github.com/R3Dzf/Signal-Flow-Graph-Solver.git
cd Signal-Flow-Graph-Solver
pip install -r requirements.txtStart the application:
uvicorn app:app --reloadThen open:
http://127.0.0.1:8000
Signal-Flow-Graph-Solver/
├── app.py
├── requirements.txt
├── frontend/
│ ├── index.html
│ ├── i18n.js
│ ├── tutorial.js
│ └── JavaScript libraries
├── docs/
│ ├── graph-editor.png
│ └── solver-results.png
└── README.md
This project combines Control Systems, Graph Theory, Symbolic Mathematics, and Web Development in one practical application.
Instead of returning only a final transfer function, the solver exposes the intermediate engineering analysis so that the result can be inspected and understood step by step.
Ahmed Youssef Bosha
Computer & Control Engineering — Tanta University
- Email: ahmedyoussefmansourbosha@gmail.com
- GitHub: github.com/R3Dzf
- WhatsApp: Contact on WhatsApp

