Featured image of the post

👨🏼‍💻 Code for Trail: Built a tool to simulate congestion in trail running races

Hello, this is Tsutsumi from GO ASIA TRAIL.

Today I’d like to share a tool I recently published on GitHub. It simulates runner congestion during trail races for organizers and race directors. It is written in Python and uses Monte Carlo methods. Below I’ll explain the background, what it does, and where it can help.

Why I built it

At Kaga Spa Trail Endurance 100 by UTMB, held in June this year, several serious operational issues drew strong criticism. Beyond on‑the‑ground anecdotes, I felt we also needed a macro, planning‑level perspective to improve. In addition to pointing out issues, I wanted to contribute something practical that supports data‑driven decisions.

If we can predict runner dispersion and congestion peaks, we can plan staffing, resupply, and DNF transport more precisely.

Rapid prototyping with Google Gemini

I used Google’s Gemini 2.5 Pro and had a prototype in about 15 minutes. For production stability, I run Gemini 2.5 Pro on Vertex AI. After pair‑programming style iterations, I open‑sourced the tool. The UX is developer‑oriented and mainly CLI, but anyone can fork or send PRs and freely “mod” it.

Thanks to the combination of 20+ years as an engineer, a trail running background, and recent AI advances, the tool came together quickly.

Code for Trail: solving problems with code

Image in a image block

You may know the “Code for X” movements like Code for America, which use technology to improve public services. In Japan there’s Code for Japan and many regional brigades. I propose “Code for Trail” as an industry‑specific brigade for trail running, applying the same civic‑tech spirit to a sector that still has room to digitize.

What the tool does

The tool simulates race congestion from a GPX course file. Key features:

  • Runner dispersion analysis: where runners are distributed on course at specific times
  • Congestion simulation: how many people crowd at points such as aid stations
  • Map‑based visualization: animated movement along the course with HTML output
Image in a image block
Image in a image block

It uses a Monte Carlo approach, modeling runner pace with a normal distribution and accounting for narrow single‑track sections where overtaking is hard. Wave starts are also considered. This lets you evaluate the impact of field size and start timing and plan resources accordingly.

A caveat: it’s a simplified model. Weather and individual condition introduce uncertainty, so treat results as reference values. That said, analyses across multiple domestic and international races suggest it broadly matches reality.

The source code is available on GitHub under MIT license. The primary docs are in English for a global audience, but there’s also a Japanese README.

In this first article I introduced the background and overview. Next time I’ll share usage details and case studies.

If there’s interest, “Code for Trail” could start as a voluntary group and perhaps incorporate in the future.