A lightweight Python library for creating Project Network Diagrams (CPM/PERT), calculating paths, and visualizing activity dependencies using NetworkX and Matplotlib.
- Easy Node Management: Add activities with durations and string-based predecessor lists (e.g.,
"A,B"). - Automatic Pathfinding: Detects all probable paths from Start to End.
- CPM Ready: Built on a node structure supporting All Paths, Critical Path, and ES/EF/LS/LF attributes.
- Forward & Backward Pass: Automatically calculates Early Start (ES), Early Finish (EF), Late Start (LS), and Late Finish (LF) for all nodes.
- Visualization: Generates directed graphs with arrows and duration labels using
matplotlib.
- Name: Kathan Majithia
- Contact: kathanmajithia@gmail.com
To use the visualization features, you must have the following libraries installed:
networkxmatplotlib
You can install the package directly via pip:
pip install networkdiagramHere is a complete example of how to use the networkdiagram library to build a Critical Path Method (CPM) diagram, calculate properties, and visualize the output.
from networkdiagram import CriticalPathMethod
# 1. Initialize the CPM Network
cpm = CriticalPathMethod()
# 2. Define Activities
activities = ['A', 'B', 'C', 'D']
durations = [2, 5, 4, 2]
predecessors = ['-', 'A', 'B', 'B,C']
# 3. Add Origin and Activities to the Network
cpm.add_activity('O', 0)
cpm.add_activities_relations(activities, durations, predecessors)
# 4. Perform Path Calculations
cpm.find_probable_paths()
cpm.find_critical_path()
# 5. Calculate Early & Late Start/Finish
cpm.forward_pass()
cpm.backward_pass()
# 6. Generate Network Summary
cpm.network_summary()
# 7. Visualize the Network
cpm.get_edges()
cpm.display_network()The following workflow illustrates how NetworkDiagram processes activities and computes CPM metrics.
flowchart TD
A[Define Activities] --> B[Create Network]
B --> C[Add Dependencies]
C --> D[Find Probable Paths]
D --> E[Find Critical Path]
E --> F[Forward Pass]
F --> G[Backward Pass]
G --> H[Generate Network Summary]
H --> I[Display Network]
The Forward Pass calculates the earliest possible start and finish times for each activity in the network.
ES = Maximum EF of predecessor activities
EF = ES + Duration
flowchart LR
A["Activity A<br/>ES = 0<br/>EF = 3"]
B["Activity B<br/>ES = 3<br/>EF = 5"]
C["Activity C<br/>ES = 5<br/>EF = 9"]
A --> B --> C
The Backward Pass calculates the latest possible start and finish times without delaying the project.
LF = Minimum LS of successor activities
LS = LF - Duration
flowchart RL
C["Activity C<br/>LS = 5<br/>LF = 9"]
B["Activity B<br/>LS = 3<br/>LF = 5"]
A["Activity A<br/>LS = 0<br/>LF = 3"]
C --> B --> A
Example network diagram generated using NetworkDiagram.
Network summary generated after performing CPM calculations.
The Quick Start Guide demonstrates a simple CPM network consisting of a few activities and dependencies.
- Generates a project network diagram.
- Identifies the critical path.
- Computes Early Start (ES) and Early Finish (EF).
- Computes Late Start (LS) and Late Finish (LF).
- Produces a network summary.
Suitable for projects with multiple dependencies and branching paths.
- Handles multiple activity dependencies.
- Identifies the critical path.
- Computes CPM metrics.
- Generates a visual project network.
Suitable for larger project schedules with several parallel paths.
- Supports larger project structures.
- Displays multiple probable paths.
- Highlights the critical path.
- Provides complete scheduling analysis.
After running the forward and backward passes, each activity node will have its CPM properties populated. You can access these programmatically:
node_a = cpm.nodes['A']
print(f"ES: {node_a.early_start}, EF: {node_a.early_finish}")
print(f"LS: {node_a.latest_start}, LF: {node_a.latest_finish}")We welcome contributions!
- Please read our
CONTRIBUTING.mdfor detailed guidelines. - Ensure you are assigned to an issue before submitting a Pull Request.
- PRs must be submitted against the
mainbranch. - If modifying mathematical logic, please ensure you verify your algorithms against known project networks.
Thanks to all contributors ❤️
This project is licensed under the MIT License.

