AWS Builder Center
R3LAY: Building an Intelligent Train Seat Reallocation System with Python and OR-Tools

R3LAY: Building an Intelligent Train Seat Reallocation System with Python and OR-Tools

R3LAY rethinks train seat allocation by combining real-time train state, optimization, and human-in-the-loop decision-making to help railway staff manage dynamic berth availability more efficiently.

R3LAY: Building an Intelligent Train Seat Reallocation System with Python and OR-Tools

R3LAY started with a simple question:
What if train seat reallocation could be made more systematic, intelligent, and easier for railway staff to manage?
Train occupancy can change throughout a journey. Passengers may not show up, confirmed berths can become available, RAC passengers may be waiting, and berth preferences may need to be considered.
This became the idea behind R3LAY: Rethink. Reallocate. Ride. 🚆
R3LAY is an intelligent train seat management and reallocation system designed to help railway staff make faster and more informed berth allocation decisions.

The Problem

Train seat allocation is not always a static process.
A passenger may be marked as a no-show. A confirmed booking may be cancelled. A berth may become available during the journey. At the same time, other passengers may have specific requirements such as a lower berth or may already be travelling in the same coach.
Simply finding the next empty berth is not enough.
The system needs to consider multiple factors before suggesting a suitable reassignment.
For example:
  • Which berths are currently available?
  • Which passengers are waiting for allocation?
  • Does a passenger have a berth preference?
  • Can unnecessary passenger movement be avoided?
  • Can RAC passengers be accommodated?
  • Are there any conflicting assignments?
This turns seat reallocation into an optimization problem rather than a simple booking operation.

The Idea Behind R3LAY

R3LAY is designed as a decision-support system.
Instead of completely replacing the TTE's decision, the system generates an optimized recommendation that can be reviewed by railway staff.
The basic workflow is:
Train & Passenger Data → Current Train State → Event Detection → Optimization Engine → Recommended Reallocation → TTE Review → Approve/Reject → Updated Seat State
This approach keeps the human in control while reducing the amount of manual effort required.

Turning Seat Allocation Into an Optimization Problem

One of the most interesting parts of building R3LAY was converting a real-world railway problem into a computational optimization problem.
We did not want the system to simply follow:
"If a seat is available, assign it."
Instead, the system needs to consider multiple constraints and priorities.
For the current prototype, we use Google OR-Tools CP-SAT through Python.
The optimization model considers factors such as:
  • Available berths
  • Passenger requirements
  • Lower berth preferences
  • RAC passengers
  • Coach-level allocation
  • Passenger movement
  • Conflicting assignments
  • Assignment feasibility
The optimization engine then generates a feasible recommendation that can be reviewed by the TTE.

Why Python + FastAPI?

The frontend and optimization engine have different responsibilities.
The frontend focuses on visualization and interaction, while the backend handles the operational logic and optimization.
For the backend, we use:
  • Python
  • FastAPI
  • SQLAlchemy
  • Google OR-Tools
  • CP-SAT
Our current architecture separates the web interface from the optimization layer, allowing us to improve the optimization model without redesigning the complete application.

Managing Dynamic Seat Availability

One of the important scenarios handled by R3LAY is a passenger no-show.
The process looks like this:
Passenger marked as NO-SHOW → Passenger status updated → Berth becomes available → Event recorded → Optimization triggered → New recommendation generated
This allows the system to respond to changes in train occupancy instead of treating the seat map as static data.

Keeping the TTE in Control

Automation does not mean removing humans from the process.
R3LAY follows a human-in-the-loop approach.
The optimization engine provides a recommendation, but the TTE can review it before the allocation is changed.
Optimization Engine → Recommendation → TTE Review → Approve/Reject → Allocation Updated
Approved actions can also be recorded so that operational changes can be tracked later.

Building the R3LAY Dashboard The frontend is designed around the workflow of railway staff.

The prototype includes several important sections.

Dashboard

Provides an overview of the current train state, occupancy and operational information.

Coach View

Displays berth-level information so that occupied and available berths can be viewed easily.

Passenger Management

Provides the passenger information required while reviewing allocation decisions.

Live Events

Displays events such as no-shows and manual changes.

Recommendations

Shows optimization-generated suggestions that can be reviewed by the TTE.

Reports & Analytics

Provides information about system activity and the current operational state.
Where AWS Fits
The current R3LAY prototype is being developed and tested locally using Python, FastAPI, OR-Tools and a local database.
The next stage is to move the application toward a cloud-oriented AWS architecture.
AWS can be introduced for areas such as:
  • Authentication and access management
  • Cloud-based persistent data
  • Event-driven processing
  • Application deployment
  • AI-assisted interaction
The current prototype is intentionally modular so that cloud services can be introduced without rebuilding the entire application.

Security Matters

Because R3LAY deals with passenger and operational information, security will be an important part of its future cloud deployment.
Some areas we plan to focus on include:
  • Authentication and authorization
  • Role-based access control
  • Secure API access
  • Least-privilege permissions
  • Encryption
  • Audit logging
  • Avoiding sensitive information in application logs
Building an intelligent system is important, but building one responsibly is equally important.

Learning Through the Build

Working on R3LAY has involved several areas at once:
  • Frontend development
  • Backend development
  • API integration
  • Optimization
  • Database design
  • Cloud architecture
  • Real-world problem modelling
The biggest learning for us was that solving a real-world problem is very different from implementing a simple feature.
A requirement like:
"Find a suitable berth for this passenger."
sounds straightforward.
But once we add berth preferences, RAC status, available seats, coach constraints, passenger movement and conflicting assignments, the problem becomes much more interesting.
That is where optimization becomes useful.

What's Next?

R3LAY is still evolving, and there are several areas we want to explore next.

Cloud Deployment

Move the prototype toward a production-oriented AWS architecture.

Event-Driven Processing

Introduce cloud-based event processing so changes in train and passenger state can trigger the appropriate workflows.

AI Assistant

Explore an AI-assisted interface that allows railway staff to query operational information using natural language.
For example:
"Which berths became available after the latest no-show?"
or
"Show passengers currently waiting for a suitable berth."

Better Optimization

Expand the optimization model with additional railway-specific constraints and configurable priorities.

Production Security Introduce stronger authentication, authorization and secure access controls for different operational roles.

What We Learned

R3LAY taught us that the hardest part of an intelligent system is often not the interface.
It is translating a real-world situation into a problem that software can reason about.
By combining:
Real-time state + Event Handling + Optimization + Human Decision-Making + Cloud Architecture
we are exploring how technology can support operational decisions in a complex environment.

Final Thoughts

R3LAY started with a simple question:
Can train seat reallocation be made more systematic instead of relying entirely on manual decision-making?
Our current prototype is an attempt to answer that question.
It combines a web interface, Python backend and optimization engine to create a system where technology can recommend possible reallocations while railway staff remain in control of the final decision.
This is only the beginning.
The next step is to take the working prototype toward a more complete AWS-based architecture, improve the optimization model and continue exploring how intelligent systems can solve practical problems in transportation.
Tech Stack
Frontend: Next.js, React, TypeScript
Backend: Python, FastAPI, SQLAlchemy
Optimization: Google OR-Tools, CP-SAT
Database: SQLite for local development
Cloud: AWS architecture planned for the next stage

Built by Team Ctrl + Slay

R3LAY: Rethink. Reallocate. Ride.
#BharatBuilds #AWS #AWSBuilderCenter #Python #FastAPI #ORTools #CPSAT #SmartMobility #RailwayTech #SoftwareEngineering
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article