Route GuidesRoutes City GuidesCities Map Log in

Question about the algorithm behind the 'suggest a ride' feature

31 Oct 2023
Find a better bike route. Try our map & route-planner »

Become a supporter

Hello,

I use the 'Suggest a ride' feature quite often because I find that it works incredibly well! As a software developer, I can't help but be very curious about how the algorithm works behind the scenes.

I assume there is an internal graph representation of the roads/pathways, but I'm not sure what graph algorithms would be most useful from there. How are circuits found in the graph that are roughly around the target length and seem to be more or less circular so you don't end up going up and down the same road too much? It's so quick at calculating too!

Mark

Comments

Wed 1 Nov 2023, 10:39

It’s simpler than it looks! Call the start point A. It chooses a random bearing (say, 45°) and plots a point n km from A along that bearing. (We’ll call that B.) It then plots a point n km from A along that bearing + 60°, so 105° in this case. (Call that C.) The finished route is then A–B–C–A, with each leg planned using cycle.travel’s standard routing.

In practice, there’s a handful more wrinkles to it to try and ensure decent routes and minimise backtracking. But that’s the basic idea.

Thu 16 Nov 2023, 21:28

@Richard That's brilliantly simple! Thanks for clarifying