I've a graph (no OSM) and I try with 14 of 468 nodes to resolve this problem.
System: Ubuntu Server + Postgres 14 + pgRouting 3.5
When I use pgr_TSP() function I use pgr_dijkstraCostMatrix() with Edges and my 14 Nodes, with directed=>true, but in the screenshoot is wrong the sequence 12-13-14.
I try to analize the result with pgr_dijkstraCostMatrix() and pgr_Dijkstra():
SQL1
SELECT
*
FROM
pgr_dijkstraCostMatrix(
'SELECT id, source, target, cost, reverse_cost FROM dbroute_pl_generic_edges',
(
SELECT
array_agg(id)
FROM
dbroute_pt_generic_nodes
),
directed => true
) foo
WHERE
start_vid = 13800066621912
AND end_vid = 13800002893438
SQL 2
SELECT
*
FROM
pgr_Dijkstra(
'SELECT id, source, target, cost, reverse_cost FROM dbroute_pl_generic_edges',
13800066621912, 13800002893438,
true
)
Node in screenshoot > id
-- 13 > 13800066621912
-- 14 > 13800002893438
Result SQL1
start_vid | end_vid | agg_cost |
---|---|---|
13800066621912 | 13800002893438 | 17 |
Result SQL2
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost |
---|---|---|---|---|---|---|---|
1 | 1 | 13800066621912 | 13800002893438 | 13800066621912 | 13800013628133 | 1 | 0 |
2 | 2 | 13800066621912 | 13800002893438 | 13800002442093 | 13800002073213 | 1 | 1 |
- | - | - | - | - | - | - | - |
17 | 17 | 13800066621912 | 13800002893438 | 13800002442092 | 13800001198905 | 1 | 16 |
18 | 18 | 13800066621912 | 13800002893438 | 13800002893438 | -1 | 0 | 17 |
The result is correct!
But in TSP is wrong!
SQL3
SELECT
*
FROM
pgr_TSP(
$$
SELECT
*
FROM
pgr_dijkstraCostMatrix(
'SELECT id, source, target, cost, reverse_cost FROM dbroute_pl_generic_edges',
(
SELECT
array_agg(id)
FROM
dbroute_pt_generic_nodes
),
directed => true
) bar $$
) foo
Result SQL3
seq | node | cost | agg_cost |
---|---|---|---|
... | ... | ... | ... |
13 | 17 | 13800066621912 | 4 |
14 | 18 | 13800002893438 | 1 |
... | ... | ... | ... |
This mean that the cost from 13 to 14 is only 1 and not 17!
I try in different part of graph, with few nodes and sometimes I get the same error, but this is the most highlight.
I'm expeting that pgr_TSP get result egual to pgr_dijkstraCostMatrix