Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Roundtrip function #759

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

afischerdev
Copy link
Collaborator

@afischerdev afischerdev commented Jan 21, 2025

Here comes the new engineMode for roundtrips.

Parameters to play with:

direction - angle around start point (default random)
roundtripDistance - distance from start point (default 1500m)
roundtripDirectionAdd - changes the angle added to the direction (default 20 degrees)
allowSamewayback - go back the same way (default false)

exportWaypoints - export the generated points (default false)
profile:correctMisplacedViaPoints - correct the results (default false)
profile:correctMisplacedViaPointsDistance - distance for correction, 0 = don'r check distance (default 40m)

some samples:

direction = 90
90

direction 360 correctMisplacedViaPoints off
360_nosnap

direction 360, correctMisplacedViaPoints on
360_snap

direction 180 roundtripDirectionAdd 45deg
180_45

direction 360 allowSamewayback true
360_back

@devemux86
Copy link
Contributor

@afischerdev Thanks for this long awaited feature! 👍

roundtripDirectionAdd - add an angle to the direction (default 20degree)

Can you explain more how this parameter works?
Does it add an angle tolerance to the direction (± 20°)?


Some routers have a seed parameter to get different tours.
See the GraphHopper documentation.

Is this something to consider for BRouter or it generates the same route for the same parameters?

@devemux86
Copy link
Contributor

roundtripDistance - distance from start point (default 1500m)

@afischerdev What is this distance? Not length of the route (as in other routers)?
Distance of the start point from the longest point of the route or something else?

@afischerdev
Copy link
Collaborator Author

@devemux86

Does it add an angle tolerance to the direction (± 20°)?

may be better: It replaces the default of 20 with e.g. 45 degree.

Is this something to consider for BRouter or it generates the same route for the same parameters?

Both are correct.
If you define a direction of 180 degrees, it will be used for all calls.
If you do not define the direction value, however, a random direction will be generated. Therefore, you will get different routes for each call with the same parameter.

@devemux86
Copy link
Contributor

@afischerdev Is it also available in BRouter test server?

@afischerdev
Copy link
Collaborator Author

@devemux86

What is this distance?

We have two via point and this is the distance start point to via point.

Is it also available in BRouter test server?

No, I could port it, but we currently don't have a web client that could take advantage of this new feature.
May be later on ;-)

@devemux86
Copy link
Contributor

devemux86 commented Jan 21, 2025

direction - angle around start point (default random)
roundtripDirectionAdd - changes the angle added to the direction (default 20 degrees)

@afischerdev So, if we set direction 90 degrees, why would we want to use roundtripDirectionAdd and change the direction again to a different value?

@afischerdev
Copy link
Collaborator Author

@devemux86

why would we want to use roundtripDirectionAdd

The direction is something like a main angle we want to place the route. E.g. North of parking space
But we want to have a more or less round trip and with the roundtripDirectionAdd we open the left and right area of the direction.

Please see:
360_snap_angle

@devemux86
Copy link
Contributor

with the roundtripDirectionAdd we open the left and right area of the direction.

@afischerdev Thanks, also for the image, now it is clear! 👍

@devemux86
Copy link
Contributor

devemux86 commented Jan 22, 2025

allowSamewayback - go back the same way (default false)

@afischerdev It would be interesting if the allowSamewayback option could also be available outside of round trips in normal route planning.

@devemux86
Copy link
Contributor

direction 360, correctMisplacedViaPoints on

@afischerdev What correctMisplacedViaPointsDistance did you use in the 3rd image?

Even if we use a large correctMisplacedViaPointsDistance, we may have via points that go back and forth on the same road with u-turns that we want to avoid.

Is it because the distance is a strict requirement in the calculation?
Or can calculate a bit longer round trips and avoid such u-turns?

@devemux86
Copy link
Contributor

Even if we use a large correctMisplacedViaPointsDistance, we may have via points that go back and forth on the same road with u-turns that we want to avoid.

@afischerdev I mean if we can avoid round trips like the following with u-turns on the via points:

@afischerdev
Copy link
Collaborator Author

@devemux86

It would be interesting if the allowSamewayback option could also be available outside of round trips in normal route planning.

Yes, I'll prepare that.

Even if we use a large correctMisplacedViaPointsDistance, we may have via points that go back and forth on the same road with u-turns that we want to avoid.

Yes, these routes doesn't look very well. I used correctMisplacedViaPointsDistance=0 to disable the distance check.
But it is also dependent on MAX_STEPS_CHECK. I set that to 20 point, but could change that again.
At the moment I am trying to find the optimal setting, e.g. 20deg add angle.

@afischerdev
Copy link
Collaborator Author

Some mere results:

The current version (add angle = 20, no misplaced correction) produces this routes (direction 0 to 315, step 45 deg):

0-315

the new version runs with an add angle of 45, missplaced correction and a nogo point in angles center

0-315_45

Not perfect but a little bit better results.

Source coming soon. I will change the new same way back function.

@mcliquid
Copy link

I'm really looking forward to this feature. I use it a lot in Garmin Connect (Web) and directly on my Garmin Edge device to just go for a new lap of running or cycling without worrying too much about the details of the route.
My use case: I want to go for a 20km run/ride, start and finish are the same, give me a route that goes in a circle.

I actually asked about this feature @mjaschen last autumn (in German): https://en.osm.town/@mcliquid/113517162799095813

One thing that we could learn from Garmin (actually Strava used to offer this feature, but it's no longer available) is to take elevation into account. Where I live, I have very steep mountains on one side and a wide valley on the other.
Garmin often chooses the mountainous route because there are more suitable paths (no traffic, no traffic lights, etc.) but with extreme elevation changes. For a run, I would prefer to have it as flat as possible.
The Strava elevation setting is shown in this video at 0:34: https://www.youtube.com/watch?v=CWdYhHsFNqk&t=34s

trailrouter.com has actually a few settings, including the elevation setting. See also their help page.
image

My technical experience is probably not enough to install BRouter local and test it, but as soon as there is a beta available, I would be very happy to volunteer as a tester!

@afischerdev
Copy link
Collaborator Author

The last commits enabled a same way back function for both: normal routing and round trip routing. This will also work when via points are used. But it doesn't necessarily have to be the same route back.
And it changes the defaults: angle add 45 deg, more points to go back a line (snapp when two lines are concatenated).

@afischerdev
Copy link
Collaborator Author

@mcliquid
Thanks for your suggestion.

  • route length limit: BRouter works for roundtrip with a distance and a direction to start. I think it could be client function to calculate the distance for BRouter with e.g. desired length / pi.
  • use elevation: I guess you already be able to generate with the current profiles a less steep route.

@devemux86
Copy link
Contributor

devemux86 commented Jan 24, 2025

@afischerdev I tried the allowSamewayback in normal routing and it seems to do strange things.

allowSamewayback=1 should be like the old routing where we allow the same way back.
Then allowSamewayback=0 is the new option we meant to implement in normal routing.
But checking the code if allowSamewayback=1 then it adds no-go areas. Should be reverse?

@devemux86
Copy link
Contributor

@afischerdev Also it seems the waypoints (by user) are modified by the routing engine?

e.g. we have 2 user waypoints Start + End on a highway with distance a few kilometers.
In RoutingEngine line 207 a new waypoint (with radius) is added with the start's coordinates.
So the route goes start > end > start with the double length of the expected route.

@afischerdev
Copy link
Collaborator Author

@devemux86

allowSamewayback=1 should be like the old routing where we allow the same way back.
Then allowSamewayback=0 is the new option we meant to implement in normal routing.

May be I didn't understand allowSamewayback.
My idea was to go back a route, that means we have waypoints at start

wp from
wp to

with same way back on we have

wp from
wp via1 (the old 'to')
wp to (same as from)

if allowSamewayback=1 then it adds no-go areas

No, the nogo point is added only for roundtrip.

@devemux86
Copy link
Contributor

devemux86 commented Jan 24, 2025

My idea was to go back a route

Sorry, that's not what I meant.

What I mean is an option that in normal routing can avoid using the same roads.
For example in above image, it does not u-turn but continues forward and returns through a different road.


@afischerdev What is a waypoint with radius but with isNogo false?
If it is not a no-go, what is it?

@afischerdev
Copy link
Collaborator Author

@devemux86

avoid using the same roads

This is done by using

profile:correctMisplacedViaPoints=1 - switch the check on
profile:correctMisplacedViaPointsDistance=250  - stops going back on around 250 m, =0 don't stop, the limit for go back points is at the moment MAX_STEPS_CHECK = 250

allowSamewayback=1 - Ok, if not like, just don't use.

@afischerdev
Copy link
Collaborator Author

@devemux86

What is a waypoint with radius but with isNogo false?
If it is not a no-go, what is it?

The standard for a waypoint is isNogo=false. Please see the OsmNodeNamed

This class is used for both nogo and not nogo points. And we start with a list of OsmNodeNamed for the waypoint collection.


OsmNodeNamed onn = new OsmNodeNamed(new OsmNode(pos[0], pos[1]));
onn.name = "via1";
onn.radius = 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afischerdev Here why do we set a radius?
As this a via point, not a no-go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devemux86
The radius is also used for distance to the nearest road calculation.
I think it is from the beginning of this project, where the dynamic distance wasn't there and I tried to have a slightly larger radius.
But this is redundant now. I will remove it

@devemux86
Copy link
Contributor

@afischerdev So the recommendation when generating round trips is the following?

profile:correctMisplacedViaPoints=1
profile:correctMisplacedViaPointsDistance=250

@afischerdev
Copy link
Collaborator Author

@mcliquid
I think I jumped to short with my answer. The profile can help with better route finding for elevation or 'green area'.
But in this round trip calculation the random start brings you anywhere. And the profile has no chance to find a proper route when you start e.g. in an East direction and the forest is in the West.

The data for your wishes is available in the routing tiles. But they are only out when a route is calculated. This could mean that routing in all directions is necessary to find an optimum. I don't like that very much. So I hope to find a shorter way.

@afischerdev
Copy link
Collaborator Author

@devemux86
Yes, same rule as before. But I would use profile:correctMisplacedViaPointsDistance=0 to get out the maximum points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants