简体   繁体   中英

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

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: 查询结果

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM