pgRouting Manual (2.3)

pgr_vidsToDMatrix - Deprecated Function

«  pgr_vidsToDMatrix - Deprecated Function   ::   Contents   ::   pgr_pointsToDMatrix - Deprecated Function  »

pgr_vidsToDMatrix - Deprecated Function

Warning

This function is deprecated!!!

  • Is no longer supported.
  • May be removed from future versions.
  • There is no replacement.

Name

pgr_vidsToDMatrix - Creates a distances matrix from an array of vertex_id.

Synopsis

This function takes an array of vertex_id, a sql statement to select the edges, and some boolean arguments to control the behavior. It then computes kdijkstra() distances for each vertex to all the other vertices and creates a distance matrix suitable for TSP.

The function returns:

  • dmatrix:float8[] - the distance matrix suitable to pass to pgr_TSP() function.
pgr_vidsToDMatrix(IN sql text, IN vids integer[], IN directed boolean, IN has_reverse_cost boolean, IN want_symmetric boolean, OUT dmatrix double precision[])

Description

Parameters

sql:text - A SQL statement to select the edges needed for the solution.
vids:integer[] - An array of vertex_id.
directed:boolean - A flag to indicate if the graph is directed.
has_reverse_cost:
 boolean - A flag to indicate if the SQL has a column reverse_cost.
want_symmetric:boolean - A flag to indicate if you want a symmetric or asymmetric matrix. You will need a symmetric matrix for pgr_TSP(). If the matriix is asymmetric, the then the cell(i,j) and cell(j,i) will be set to the average of those two cells except if one or the other are -1.0 then it will take the value of the other cell. If both are negative they will be left alone.

Warning

  • kdijkstra() can fail to find a path between some of the vertex ids. We to not detect this other than the cost might get set to -1.0, so the dmatrix should be checked for this as it makes it invalid for TSP

History

  • Proposed in version 2.1.0

Examples

SELECT * FROM pgr_vidsToDMatrix(
    'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost FROM edge_table',
    array[1,2,3,5],
    true, true, false);
NOTICE:  Deprecated function pgr_vidsToDMatrix
             pgr_vidstodmatrix             
-------------------------------------------
 {{0,1,2,2},{1,0,1,1},{2,1,0,4},{2,1,4,0}}
(1 row)

SELECT * FROM pgr_vidsToDMatrix(
    'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost FROM edge_table',
    array[1,2,3,5],
    true, true, true);
NOTICE:  Deprecated function pgr_vidsToDMatrix
             pgr_vidstodmatrix             
-------------------------------------------
 {{0,1,2,2},{1,0,1,1},{2,1,0,2},{2,1,2,0}}
(1 row)

This example shows how this can be used in the context of feeding the results into pgr_tsp() function.

SELECT * FROM pgr_tsp(
    (SELECT pgr_vidsToDMatrix(
        'SELECT id::INTEGER, source::INTEGER, target::INTEGER, cost, reverse_cost FROM edge_table',
        array[1,2,3,5],
        true, true, true)
    ),
    1
);
NOTICE:  Deprecated function pgr_vidsToDMatrix
 seq | id 
-----+----
   0 |  1
   1 |  2
   2 |  3
   3 |  0
(4 rows)

This example uses the Sample Data network.

«  pgr_vidsToDMatrix - Deprecated Function   ::   Contents   ::   pgr_pointsToDMatrix - Deprecated Function  »