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

Refer to previous edges for cost function #1158

Open
illpack opened this issue Nov 13, 2018 · 5 comments
Open

Refer to previous edges for cost function #1158

illpack opened this issue Nov 13, 2018 · 5 comments

Comments

@illpack
Copy link

illpack commented Nov 13, 2018

I could not find such a thing in the docs:

I want to calculate cost based on the previous edge (for instance, get the path with the least number of turns). Is there a way to do this currently?

Something along these lines:

angle(parentEdge, currentEdge) AS cost

Thanks,

@cvvergara
Copy link
Member

Nothing of the kind can be done with current pgRouting (nor in the near future)

@flother
Copy link

flother commented Nov 15, 2018

Would PostgreSQL's window functions help you out here? If you already have an ordered set of edges and their geometries, you can get the angle between the current and previous rows with something like this:

ST_Angle(LAG(the_geom) OVER (), the_geom)

You'd need to make sure that the edges themselves are in the correct order (i.e. the end point of the first edge is the start point of the second edge).

@cvvergara
Copy link
Member

maybe using trsp

@illpack
Copy link
Author

illpack commented Nov 15, 2018

@flother That was a good hint, thanks.

I tried that, first ordering the set of edges, then lagging -1 to calculate the angle.
Tested on a set of edges and it works fine.
However, it does not seem to yield valid angles when used inside pgr_dijkstra.

The following image shows the resulting route, the tiny numbers are the cost returned by pgr_dijkstra, the bold ones are angles applied to the resulting routing list (which seem to be correct)

image

Somehow lagging within the function does not yield the expected results.
Is it worth trying with a different function?

Thanks!

@cvvergara
Copy link
Member

Maybe another idea ...
there is the experimental function on version 2.6:
https://docs.pgrouting.org/2.6/en/pgr_lineGraphFull.html
have additional edges for every turn that could be made across and give a cost based on angles to those additional edges

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

No branches or pull requests

4 participants