Rund Trip idea

Hi,

I’m using GraphHopper to generate motorcycle round trips and struggling with two different approaches:

Approach 1: Using algorithm=round_trip

  • Works well for generating loops
  • Problem: Can’t control direction - the heading parameter seems to be ignored
  • In my tests, all headings (0°, 90°, 180°, 270°) produce the exact same route
  • Changing round_trip.seed creates different routes, but direction is still random

Approach 2: Using waypoints (Start → P1 → P2 → P3 → Start)

  • I calculate 3 waypoints on a circle around start (e.g. east, northeast, southeast)
  • Use normal routing between waypoints
  • Problem: Routes often use the same road back and forth (e.g. Start → P1 on Road A, then P1 → P2 also uses Road A in reverse)
  • I tried use_headings=true with heading_penalty=120 and pass_through=true, but alternatives still share too much with the main route

Question:
Is there a way to either:

  1. Make algorithm=round_trip respect the heading parameter?
  2. Prevent the waypoint approach from using the same edges in both directions?

I’ve tried the alternative_route algorithm with max_share_factor=0.4, but that only works with 2 points, not for multi-waypoint round trips.

Any suggestions would be greatly appreciated!

Thanks!

I struggled with the heading too. I seem to remember that there was perhaps a mistake in the docs somewhere, I am not sure, but eventually I figured out that the heading needs to be an array. Also, the name of the parameter is “headings”, plural. So in the request body:

headings: [90]

Check how you are using the heading parameter, maybe this will solve your problem.

By the way my application is also for creating routes for motorcycles. I have not deployed the round-trip generation yet, but I will do that sometime this winter probably. Graphhopper is awesome for these tasks, I must say.

@Mikko_Karkkainen great. That’s it. Thanks for your fast support :slight_smile:

RTFM:

Specify either one heading for the start point or as many as there are points
heading   Array of integers   (int32)

1 Like