How to use PostgreSQL pgrouting functions to find the shortest path between two geometry points with MOST K edges?

948 views Asked by At

I have set up tables containing vertices and edges (representing airports and the route between them). Using the following query I'm able to get the shortest path between two points.

SELECT p.seq, p.node, p.cost, r.geom as edge_geom, c.name
FROM
pgr_dijkstra(
        'SELECT id, source, target, distance AS cost FROM airport_route',
        (SELECT id FROM airport WHERE code = 'HEL'),
        (SELECT id FROM airport WHERE code = 'LAS'),
        TRUE
    ) AS p
    LEFT JOIN airport_route AS r ON p.edge = r.id
    LEFT JOIN airport AS c ON p.node = c.id
ORDER BY
p.seq;

And the result is as follows: Query result

The question is:

How can I find the shortest path between these two points with most K edges?

postgis and pgrouting are installed; network topology has been created

1

There are 1 answers

0
Majid Akbari On BEST ANSWER

After lots of research I noticed that Dijkstra can not take any limitation in number of edges by nature; So I had to create an algorithm inspired by Bellman Ford.

For detailed information have a look on the following repository:

https://github.com/majidakbari/flight