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

Path not populated until routing ends #11

Open
ludohenin opened this issue Dec 8, 2022 · 6 comments · May be fixed by #17
Open

Path not populated until routing ends #11

ludohenin opened this issue Dec 8, 2022 · 6 comments · May be fixed by #17

Comments

@ludohenin
Copy link
Contributor

Hi,

Thanks for your amazing work.
I'm looking at a way to define the number of steps to iterate to end routing from here rather than reaching the destination.
Is there an easy way to do that ?

The other thing (but it's maybe more a feat request) nice to have would be the possibility to have shorter steps the 1st 24h (say 20min) and 1 hour or more after.

@dakk
Copy link
Owner

dakk commented Dec 8, 2022

Hi Ludohenin, thanks for your appreciation.
Regarding the first question, I don't really understand what are you meaning; you can stop calling Routing.step() even if you didn't reach destination.

The second thing could be a cool feature; a good start should be to add a timeDelta parameter to Router(s), and then let the library user to modify it at each step.

@ludohenin
Copy link
Contributor Author

Stop calling the routing.step() is what I did but the path property doesn't get populated. Maybe I can do that manually.

For the new feat, I think I got how to do it, I'll drop a PR for that soon.

@dakk dakk changed the title question: fix number of steps Path not populated until routing ends & timedelta customization Dec 9, 2022
@dakk
Copy link
Owner

dakk commented Dec 9, 2022

Stop calling the routing.step() is what I did but the path property doesn't get populated. Maybe I can do that manually.

Ok, now I understand. It would be great if you fix also this in your PR

For the new feat, I think I got how to do it, I'll drop a PR for that soon.

Great, thank you!
Can I ask you how are you using this library? I'm really pleased that someone is using it.

@ludohenin
Copy link
Contributor Author

ludohenin commented Nov 13, 2024

Hi @dakk
Back after a very long while.

With regard to my issue to getting the path generated, I found that in the code below, generate_path never gets called. distance_to_end_point (~3400 in my use case track = ((47.0, -3.0), (-5.0, -30.0))) is always > minIncrease param value (10.0) and nearest_solution remains falsy.

I'm lost, I don't know what I'm doing wrong.

for p in isoc[-1]:
distance_to_end_point = p.pointDistance(end)
if distance_to_end_point < self.getParamValue("minIncrease"):
# (twd,tws) = self.grib.getWindAt (time + datetime.timedelta(hours=1),
# p.pos[0], p.pos[1])
maxReachDistance = utils.maxReachDistance(p.pos, p.speed)
if distance_to_end_point < abs(maxReachDistance * 1.1):
if (
not self.pointValidity or self.pointValidity(end[0], end[1])
) and (
not self.lineValidity
or self.lineValidity(end[0], end[1], p.pos[0], p.pos[1])
):
if distance_to_end_point < nearest_dist:
nearest_dist = distance_to_end_point
nearest_solution = p
if nearest_solution:
generate_path(nearest_solution)

@ludohenin ludohenin changed the title Path not populated until routing ends & timedelta customization Path not populated until routing ends Nov 13, 2024
@ludohenin
Copy link
Contributor Author

ludohenin commented Nov 14, 2024

@dakk I found a ugly trick for now, adding an arg to step to set isLast and compute the path like this (from the code above):

            for p in isoc[-1]:
                distance_to_end_point = p.pointDistance(end)
                if distance_to_end_point < self.getParamValue("minIncrease"):
                    # (twd,tws) = self.grib.getWindAt (time + datetime.timedelta(hours=timedelta),
                    # p.pos[0], p.pos[1])
                    maxReachDistance = utils.maxReachDistance(p.pos, p.speed)
                    if distance_to_end_point < abs(maxReachDistance * 1.1):
                        if (
                            not self.pointValidity or self.pointValidity(end[0], end[1])
                        ) and (
                            not self.lineValidity
                            or self.lineValidity(end[0], end[1], p.pos[0], p.pos[1])
                        ):
                            if distance_to_end_point < nearest_dist:
                                nearest_dist = distance_to_end_point
                                nearest_solution = p
                
                # Added part to get path when ending steps before reaching the waypoint
                if isLast:
                    if not nearest_solution:
                        nearest_solution = p
                    else:
                        nearest_solution = p if distance_to_end_point < nearest_solution.pointDistance(end) else nearest_solution

            if nearest_solution:
                generate_path(nearest_solution)

@dakk dakk linked a pull request Nov 18, 2024 that will close this issue
@dakk
Copy link
Owner

dakk commented Nov 18, 2024

Your solution works but is not very elegant; I made an alternative in #17 , please give a try and see if matches your requirement

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 a pull request may close this issue.

2 participants