Inspiration

Anyone who has driven through downtown Toronto knows how bad traffic gets. Most city traffic lights still run on fixed intervals that current road conditions. We wanted to see how much smarter signals could help, training a machine learning model on a traffic simulator we made which simulates an actual Toronto environment.

What it does

FlowState is an interactive traffic simulator that mimics downtown Toronto: the Entertainment District and King West. The road network comes from OpenStreetMap, with real data. Senarios are created to mimic events such as rush hour, accidents, ambulance dispatchs, and much more. Each run is reproducible as its paired with a seed. The simulator was built using SUMO, an opensource tool for traffic visualization. The best part is that you have the power, you can configure almost every aspect, such as the traffic intensity, the length of the run, the variability, and so much more. We take the initial simulations and train a machine learning model to improve traffic efficiency. This is done by it handelling the lights turning green, yellow, and red. This improves travel times and wait times by up to 10%.

How we built it

The core of FlowState is a machine learning model that controls the traffic lights. We trained it with PPO, a reinforcement learning method, where the model learns by trial and error. It watches the traffic, decides when each light should change, and gets rewarded when traffic flows better. To train it, we built a simulator using SUMO, an open-source traffic simulation tool, with a map of King West from OpenStreetMap. Every run has its own mix of drivers and traffic levels, so the model learns to handle many situations instead of just one. The backend is written in Python with FastAPI and streams the simulation live to the website. The frontend, built with React and TypeScript, draws the roads and cars straight from the simulation. We also built a rule-based smart controller to compare against the model.

Challenges we ran into

Training the reinforcement learning model was our biggest challenge. It has to learn good light timing while still following safety rules, like never skipping a yellow light. Getting it to beat other systems in a short hackathon was hard, so we tested it strictly and only counted real improvements. Ambulances and police cars also got stuck at red lights at first, so we had to make the lights and other drivers make way for them.

Accomplishments that we're proud of

We’re proud that we trained a reinforcement learning model to control traffic lights in a realistic version of downtown Toronto, with real street names, streetcars and the Rogers Centre. Our smart signal control cut the longest traffic lines by about 11% and helped ambulances get through much faster.

What we learned

We learned how reinforcement learning works in practice, and how much the training setup and rewards affect what the model learns. We also learned how traffic simulations work and how small differences in driving can cause big traffic jams. Safety rules limit how “smart” traffic lights can be, so the model has to work within them. We also learned that testing fairly means running many simulations, not just one good one.

What's next for Flowstate

If we were to grow FlowState, we would expand it to cover the whole city of Toronto instead of just King West and the Entertainment District. We would keep training our PPO model on bigger and busier parts of the city, using real City of Toronto traffic data to make it more accurate.

Built With

Share this project:

Updates

Submission history