In a previous question on how to calculate many shortest paths, @dkastl pointed to the pgr_kdijkstra function, which allows to calculate each time the total cost of one source-to-many targets shortest paths, by giving an array of target nodes.
What I'd like to do is, to calculate the total cost of many sources-to-one target shortest paths. A solution could be to switch source and target, but then I'm actually calculating the total cost of a different chain of paths, given the fact I'm using a directed topology network.
@UnderDark already provided a solution for this problem, but, out of curiosity, my question is:
Is there a way of modifying the pgr_kdijkstra function such that you're able to give an 'array of sources' and 'one target' as input?
Something like (given the example of pgRouting manual):
SELECT seq, id1 AS source, id2 AS target, cost FROM pgr_kdijkstraCost( 'SELECT id, source, target, cost FROM edge_table WHERE cost >= 0', array[4,12], 10, false, false); seq | source | target | cost -----+--------+--------+------ 0 | 4 | 10 | 4 1 | 12 | 10 | 2