🚆 Building a Railway Interlocking System in Python
I developed a Python-based Railway Interlocking Simulation that replicates real-world signalling logic like route setting, point locking, track occupancy, and signal control.
It ensures fail-safe operations using principles similar to Electronic Interlocking systems aligned with EN 50128.
The system checks for conflicts, locks routes, applies approach locking, and releases routes sequentially as the train moves.
(Inspired by Real-World Safety Standards like EN 50128)
Railway signalling is not just engineering—it’s safety, logic, and precision working together in real-time.
So I built a Railway Interlocking Traffic Management System in Python—a simulation that mirrors real-world signalling logic including:
👉 And yes, it follows concepts aligned with EN 50128 / IEC 62280 safety principles.
🔧 Project Overview
This system is not just code—it’s a mini digital interlocking engine that behaves like actual railway signalling systems used in networks like:
🧠 Core Architecture
📌 1. System Components (Enums & States)
class SignalAspect(Enum):
RED = "DANGER"
YELLOW = "CAUTION"
GREEN = "CLEAR"
📸 Code Snapshot 1 — Signal Logic
👉 Why it matters: Signal aspects directly control train movement authority
🚦 2. Track Circuit Logic
@dataclass
class TrackSection:
state: TrackState = TrackState.CLEAR
def occupy(self):
self.state = TrackState.OCCUPIED
📸 Code Snapshot 2 — Track Occupancy Detection
👉 This simulates:
💡 In real signalling: Track circuits are the backbone of safety
🔀 3. Point (Switch) Control — Critical Safety Logic
locking_routes: Set[str] = field(default_factory=set)
📸 Code Snapshot 3 — Multi-route Point Locking
🚨 Key Innovation (Bug Fix Highlight):
Instead of:
locked_by_route: str
We now use:
locking_routes: Set[str]
👉 Why this is powerful:
💡 Example: Two routes can share a flank protection point safely
🚦 4. Route Definition
@dataclass
class Route:
track_sections: List[str]
point_requirements: Dict[str, PointPosition]
📸 Code Snapshot 4 — Route Configuration
Each route defines:
👉 This is exactly how control tables work in real signalling design.
⚙️ Interlocking Engine — The Brain
🧠 Route Request Logic
def request_route(self, route_id: str):
📸 Code Snapshot 5 — Route Setting Engine
This function performs:
👉 Only if ALL conditions pass → route is set
⚠️ Conflict Detection (Safety Critical)
def _conflicting_sections(self, route: Route)
📸 Code Snapshot 6 — Conflict Logic
Checks:
Recommended by LinkedIn
💡 Real-world impact: Prevents:
🔒 Approach Locking
entry_sig.approach_locked = True
📸 Code Snapshot 7 — Approach Lock
👉 Once train enters:
💡 This is a fail-safe mechanism used globally
🔁 Sequential Route Release
def train_clears_section(self, section_id: str):
📸 Code Snapshot 8 — Route Release Logic
As train moves:
👉 Improves:
🏗️ Real Layout Simulation
The system simulates a 2-platform station with crossover:
Platform 1 ←→ Platform 2
| |
PT1 — PT2 — PT3
Routes Implemented:
🎯 Simulation Scenarios
The system validates real-world cases:
✅ Parallel Routes
❌ Conflict Detection
🔀 Crossover Routing
🚫 Approach Lock
⚠️ Track Failure
🚀 Why This Project Matters
This is not just Python.
This is:
✅ Railway signalling logic ✅ Safety-critical system thinking
✅ Real-world engineering simulation ✅ Interview-ready portfolio project
💡 Key Takeaways
🔥 Final Thought
“In railway signalling, you don’t just write logic… you design safety for thousands of lives every day.”
📢 If you're in Railway Signalling:
Let’s connect & discuss interlocking, control tables, and system design.
#RailwaySignalling #Interlocking #ElectronicInterlocking #RailwayEngineering
#Python #Simulation #ControlSystems #SafetyCriticalSystems
#EN50128 #CBI #SystemDesign #EngineeringProjects
#SmartMobility #Innovation #EngineersOfLinkedIn
Kudos! as you are digging to understand how it all works. Two more things, first this article is more about interlocking principles and object oriented method of implementing it. Second, article has nothing to do with EN50128 principles. Sometimes AI hypes thing, you have to discern that. Not to discourage but keeping you curious. Keep digging.
For Visual Interface Check this previous post https://www.garudax.id/posts/nikhil-kothavade-a0284259_gui-of-interlocking-using-python-activity-7447108401056100352-IAid?utm_source=social_share_send&utm_medium=android_app&rcm=ACoAAAxnhyIBsV-QjyBql_UWQFIM7ILYC7Xk0W4&utm_campaign=copy_link