I'm using the pgr_astar function of Postgres and I want to personalize the optimal path proposed according to the preferences of the user. For example if the pg_astar propose the red path, I want to make this function propose the orange path if I specify that the user wants to go through the blue point.

enter image description here


If you know, that the route should go through the blue point, then you could use pgr_dijkstraVia: https://docs.pgrouting.org/latest/en/pgr_dijkstraVia.html#pgr-dijkstravia

SELECT * FROM pgr_dijkstraVia(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table order by id',
    ARRAY[1, 2, 3]

Where 1, 2 and 3 are your vertex ID's and "2" is the blue point.

This is function uses Dijkstra and not A-Star, but I'm not aware of a strong reason not to use Dijkstra.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.