Welcome to Flatland#

Flatland tackles a major problem in the transportation world:
How to efficiently manage dense traffic on complex railway networks?
This is a hard question! Driving a single train from point A to point B is easy. But how to ensure trains won’t block each other at intersections? How to handle trains that randomly break down?
Flatland is an open-source toolkit to develop and compare solutions for this problem.
⚡ Quick start#
Flatland is easy to use whether you’re a human or an AI (see Installation):
$ pip install flatland-rl
$ flatland-demo # show demonstration
$ python <<EOF # random agent
import numpy as np
from flatland.envs.rail_env import RailEnv
env = RailEnv(width=30, height=30)
obs, info = env.reset()
while True:
obs, rew, done, info = env.step({
0: np.random.randint(0, 5),
1: np.random.randint(0, 5)
})
if done["__all__"]:
break
EOF
Features#
The Flatland environment provides simplistic representation of a rail network on a grid world to address the vehicle rescheduling problem (VRSP):
🔬Flatland is used to develop reinforcement learning (RL) solutions to the VRSP
🕹️️Trains are agents with a limited action space (⏸️⬅️⬆️➡️⏹️)
⏰ Agents have schedules for their origin, destination and intermediate stops
🛤️Railway network includes switches, slips, crossings and over-/underpasses
👀 what can each agent “see”?
🌟Rewards: what is the metric used to evaluate the agents?
🗺Translation from grid representation of the network to a graph representation is implemented
🚨Agents have variable speed profiles
🔥Agents can be disrupted (in malfunction)
📑 Flatland Paper#
You can find the Flatland competition paper on arXiv: https://arxiv.org/abs/2012.05893
@misc{mohanty2020flatlandrl,
title={Flatland-RL : Multi-Agent Reinforcement Learning on Trains},
author={Sharada Mohanty and Erik Nygren and Florian Laurent and Manuel Schneider and Christian Scheller and Nilabha Bhattacharya and Jeremy Watson and Adrian Egli and Christian Eichenberger and Christian Baumberger and Gereon Vienken and Irene Sturm and Guillaume Sartoretti and Giacomo Spigler},
year={2020},
eprint={2012.05893},
archivePrefix={arXiv},
primaryClass={cs.AI}
}
🔀 The Vehicle Re-scheduling Problem#
Flatland addresses the vehicle re-scheduling problem (VRSP): rescheduling vehicle trips after a disruption, such as a breakdown, has invalidated the plan. The problems are formulated as a 2D grid environment with restricted transitions between neighboring cells to represent railway networks, on which multiple agents with different objectives must collaborate to maximize global reward. See Why Flatland? for the definition of the VRSP and the railway context.
🔖 Design principles#
Real-word, high impact problem#
Flatland was created to manage dense traffic on complex railway networks, such as the one of the Swiss Federal Railways (SBB), see Why Flatland?. It is open to any methodological approach, e.g. from the domain of reinforcement learning or of operations research.
Tunable difficulty#
Flatland aims at tunable difficulty, from settings that can be trained with limited compute resources to hard ones. Scenarios are configured through the rail, line and timetable generators and malfunctions: grid size, number of cities and tracks, number of agents, speed profiles, intermediate stops, and malfunction rate and duration. This allows to scale from a single train on a small grid to dense traffic with disruptions. Challenges use this to define levels of increasing difficulty, see for instance the ECML 2026 level configuration.
Environment diversity#
Flatland aims at environment diversity to prevent agents from overfitting to a fixed set of scenarios. Rail networks, lines and timetables are generated randomly from a seed, so agents can be trained and evaluated on different, unseen scenarios. This allows to test whether agents learn to manage traffic or merely memorize specific trajectories.
🚉 Next stops#
📱 Communication#
Use these channels if you have a problem or a question:

