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
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.
@Richard That's brilliantly simple! Thanks for clarifying