1

I created a distance matrix table with pgr_dijkstraCostMatrix.

This table is now holding 168.000.000 records. (id = integer, start_vid = bigint, end_vid = bigint agg_cost = double precision)

I also have a points table (these are the points to visit). Holding 13 records. (id = bigint , name = var char)

If I check whether all the points are in the matrix, I get a good result. There are 156 records returned, so: 13*13 -13. That is what I expected.

The SQL for this check:

SELECT start_vid, end_vid, agg_cost
    FROM distance AS a
       INNER JOIN
       points AS b
       ON a.start_vid = b.id
       INNER JOIN
       points AS c
       ON a.end_vid = c.id order by start_vid, end_vid 

Now, when I am using pgr_TSP on this, I am getting the error:

ERROR: A Non symmetric Matrix was given as input CONTEXT: SQL function "pgr_tsp" statement 1 SQL state: XX000

SQL used:

SELECT * FROM pgr_TSP(
    $$
    SELECT start_vid, end_vid, agg_cost
FROM distance AS a
   INNER JOIN
   points AS b
   ON a.start_vid = b.id
   INNER JOIN
   points AS c
   ON a.end_vid = c.id
         
    $$,
    start_id := 92242,
    randomize := false
);

What I am missing here? If my select produces a full matrix for my 13 points?

Using PostgreSQL 12, PostGIS 3.0.1 and pgRouting 3.0.0.

Maas
  • 25
  • 5

1 Answers1

0

Good evening,

I have encountered a similar problem with yours. My matrix was 12 X 12, and is a result of pgr_dijkstraCostMatrix with the option directed being true. This has produced a non-symmetric matrix, because of the agg_cost values non-similarity at some cells. For example, the cost of the path from the node 1 to 2 must be the same with the one from 2 to 1. I came across a deprecated documentation, which solved this problem by taking the average of those 2 cells and inserting this one instead, thus producing a symmetric matrix. Visual example below;

| Non-Symmetric |----------------------> | Symmetric with the aforementioned solution |

| X | 2 | 1 |------------------------------->| X | 1.5 | 1 |

| 1 | X | 2 |------------------------------->| 1.5 | X | 2.5 |

| 1 | 3 | X |------------------------------->| 1 | 2.5 | X |

(1,2)+(2,1)/2 = 2 + 1 / 2 = 1.5

(1,3)+(3,1)/2 = 1 + 1 / 2 = 1

(2,3)+(3,2)/2 = 2 + 3 / 2 = 2.5

However, while this solves the error that TSP produces, the results are not the most satisfying. You could try this as well, and let me know if you got any results back. Have you tried something else?

  • Good answer and when you have the necessary rep it would be better to move open-ended conversational content into Comments. – logicaldiagram Jul 30 '21 at 16:00
  • I have, but basicly repared the matrix. I just made all the entries (agg_cost) for the pairs the same. So, no real solution for the error. – Maas Aug 01 '21 at 08:24