A Python-based tool for analyzing Reliability Block Diagrams (RBD). This project parses structured text descriptions of systems, calculates Minimal Cut Sets (MCS) to identify failure points, and generates visual diagrams of the system architecture.
Developed for the Fault Tolerant Systems course (Homework 3) at Sharif University of Technology.
In reliability engineering, understanding how component failures affect the entire system is crucial. The goal of this project is to:
- Parse a textual representation of a system's reliability logic (Block Diagram).
- Reconstruct the logical tree of dependencies.
- Identify which combinations of component failures lead to a total system failure.
- Extract Minimal Cut Sets (MCS): The smallest unique sets of components whose simultaneous failure causes the system to go down.
- Visualize the block diagram using a graphical interface.
The system supports complex structures including Series, Parallel, and k-out-of-n redundancies, allowing for nested configurations.
- Custom Recursive Parser: robustly handles nested parentheses and complex expressions without relying on external logic parsers.
- Minimal Cut Set Extraction: Automatically removes supersets to find the minimal failure combinations.
- K-out-of-N Logic: Full support for majority voting or partial redundancy logic (e.g., "2 out of 3 components must work").
- Automated Visualization: Uses
matplotlibto draw the schematic of the RBD dynamically. - Comprehensive Test Suite: Includes a runner that validates logic against multiple test scenarios.
The system accepts a Domain Specific Language (DSL) string.
| Structure | Syntax | Description |
|---|---|---|
| Component | Name |
Alphanumeric identifier (e.g., CPU, A1). |
| Series | series(A, B, ...) |
If any component fails, the block fails. |
| Parallel | parallel(A, B, ...) |
The block fails only if all components fail. |
| K-out-of-N | kofn(k; A, B, ...) |
The block works if at least k components work. Conversely, it fails if more than n-k components fail. |
Example Input:
series(
PowerSupply,
parallel(ServerA, ServerB),
kofn(2; Disk1, Disk2, Disk3)
)
This file contains the core logic for parsing and mathematical analysis.
-
Parsing: Implements a recursive descent parser (
RBDParser) that tokenizes the input string and builds a tree ofNodeobjects (SeriesNode,ParallelNode,KofNNode). -
Cut Set Calculation:
-
Series: Performs a Union of children's cut sets.
-
Parallel: Performs a Cartesian Product of children's cut sets (all paths must be cut).
-
K-out-of-N: Generates combinations of failures required to break the redundancy threshold.
-
Minimization: The
get_minimal_cut_setsfunction iterates through generated sets and removes any set that is a superset of another (e.g., if{A}is a cut set,{A, B}is discarded).
Focuses on rendering the logical tree into a PNG image.
- Preprocessing: Converts the DSL into Python objects suitable for drawing.
- Drawing Engine: Uses
matplotlib.patches. - Calculates the bounding box (
width,height) of every node recursively to ensure components don't overlap. - Draws Series blocks horizontally.
- Draws Parallel blocks vertically with branching connection lines.
- Draws K-out-of-N blocks with a distinct dashed border and label.
The entry point for running tests.
- Contains a dictionary of
test_casesranging from simple series to complex network topologies. - Bridge Function: Converts the string format used in
minimal_cut_set.pyto the format required byrbd_visualizer.py. - Executes both the analysis and drawing functions, saving the results to an
outputs/directory and generating a summary report.
The program relies on Set Theory to determine system failure:
-
Let be the collection of Cut Sets for a node.
-
Series(A, B): System fails if A fails OR B fails.
-
Parallel(A, B): System fails if A fails AND B fails.
-
Minimal Cut Set: A cut set is minimal if there is no cut set .
You need Python 3.x and the Matplotlib library for visualization.
# Clone the repository
git clone https://github.com/Mbn64/RBD-Analyzer-Visualizer.git
cd RBD-Analyzer-Visualizer
# Install dependencies
pip install matplotlib
To generate reports and diagrams for all predefined test cases:
python3 runner.py
Results will be saved in the outputs/ directory.
To analyze a custom string, you can modify the main block in minimal_cut_set.py or run:
python3 minimal_cut_set.py
To generate a diagram for a custom string:
python3 rbd_visualizer.py
The program outputs the logic tree and the identified Minimal Cut Sets:
Input: series(A, parallel(B, C))
Minimal Cut Sets:
1. {A}
2. {B, C}
Interpretation:
- {A} is a Single Point of Failure (SPOF).
Images are generated in the outputs/diagrams/ folder.
Example of a generated diagram structure:
- Series: Connected left-to-right.
- Parallel: Stacked top-to-bottom with junction nodes.
- K-out-of-N: Enclosed in a green dashed box indicating redundancy logic.