Why generating a loop is much harder than routing from A to B
Also available in: DeutschFrançaisNederlands
Ask any route planner for the way from your home to a town 40 km away and you'll get an answer in a second. Ask it for "a nice 80 km loop from my home" and most of them can't help at all. You get a blank map and a pencil.
That's strange when you think about it, because a loop from home is what most of us actually ride. We don't usually ride to a place, we ride out and come back. So why is the most common ride the one that planners don't build?
A to B has one right answer. A loop has millions.
Routing from A to B is a well-solved problem. You have a start, a finish and a road network, and you want the cheapest path between two points. Algorithms for this have existed since the 1950s, and modern versions answer in milliseconds even on a continent-sized map.
The key detail is that there is one target. The algorithm knows where it's going, and "cheapest path" has one clear meaning.
A loop has no target. You give a start point and a distance, and every closed path of roughly that length is a candidate. In an ordinary countryside area there are millions of them. Most are bad:
- they ride the same road out and back,
- they cross themselves in a figure eight,
- they wander into a town and out again,
- they hit 80 km by doing three laps of the same village.
There's no single "cheapest" loop, because the cheapest loop of any length is not riding at all. You have to decide what a good loop is first, and then search for one.
What makes a loop good
When I started, I wrote down what I actually want from a loop when I ride. It turned into a list of rules that sound obvious, and every one of them is a separate problem for the algorithm:
- Close to the distance I asked for. 80 km should be about 80 km, not 62 or 105.
- Quiet roads. The same goal as the rest of RouteCycle: small roads with little traffic, even if they're less direct. I wrote about how that works in how do you know a road is quiet.
- A real loop, not a lollipop. Some shared road at the start and the end is often unavoidable, but riding 30 km out and the same 30 km back isn't a loop.
- No pointless detours. A route that darts down a side road, touches a point and comes back the same way is one of the most annoying things a planner can do.
- Something to ride to. When I turn on sights, the loop should actually pass a castle or a viewpoint, not just a roadside sign.
- Different options. Three loops that differ by one junction aren't three options.
Each rule fights with the others. The quietest roads might not form a loop of the right length. The best sight might be at the end of a dead-end road. The most interesting route might be 20% too long.
How a loop gets built
I won't go into every detail, but the general idea is simple. Instead of searching all possible loops, the planner picks a few points around the start, at a distance that makes sense for the length you asked for, and then routes between them on quiet roads. A good choice of points gives a good loop. A bad choice gives a lollipop or a figure eight.
So most of the work is in choosing those points well, and then checking the result honestly:
- If the loop is too short or too long, the points move and it's tried again.
- If the loop rides the same road twice for too long, it's rejected.
- If two loops are almost the same, only the better one is kept.
- Every candidate gets a score for how quiet, how direct and how interesting it is, and you see the best few.
This is also why generation takes a few seconds rather than milliseconds. A loop isn't one search, it's many searches plus a lot of checking.
The out-and-back problem
The rule that took me the longest is number 4. Out-and-back detours appeared in generated routes for two reasons. Sometimes the planner wanted a road or a sight that was only reachable by a dead end. And when you added a stop yourself, it often went to the stop and turned around instead of finding a route that passes through it.
In summer 2026 I shipped a fix for the most common cases, and since then it has worked pretty well in the vast majority of places: routes flow through stops instead of bouncing off them. If you still get a weird detour somewhere, please send me the route with the feedback button.
Why it's worth it
You could argue that drawing your own loop takes ten minutes, so why bother. In your home area, maybe. But when you're somewhere new, those ten minutes become an hour of checking roads you don't know, and the result is still a guess.
With RouteCycle you pick a start and a distance, choose Circle, and get three loops on quiet roads. That's the whole idea: you should spend your time riding, not planning.