/usr/share/doc/postgresql-9.5-pgrouting-doc/html/en/_sources/src/common/doc/convenience/vids_to_dmatrix.txt is in postgresql-9.5-pgrouting-doc 2.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | ..
****************************************************************************
pgRouting Manual
Copyright(c) pgRouting Contributors
This documentation is licensed under a Creative Commons Attribution-Share
Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/
****************************************************************************
.. _pgr_vids_to_dmatrix:
pgr_vidsToDMatrix
==============================================================================
.. index::
single: pgr_vidsToDMatrix(IN vids integer[], IN pnts geometry[], IN edges text, tol float8 DEFAULT(0.1), OUT dmatrix double precision[], OUT ids integer[])
module: common
Name
------------------------------------------------------------------------------
``pgr_vidsToDMatrix`` - Creates a distances matrix from an array of ``vertex_id``.
Synopsis
------------------------------------------------------------------------------
This function takes an array of ``vertex_id``, the original array of points used to generate the array of ``vertex_id``, an edge table name and a tol. It then computes kdijkstra() distances for each vertex to all the other vertices and creates a symmetric distance matrix suitable for TSP. The pnt array and the tol are used to establish a BBOX for limiting selection of edges. The extents of the points is expanded by tol.
The function returns:
- ``record`` - with two fields as describe here
* :dmatrix: ``float8[]`` - the distance matrix suitable to pass to pgrTSP() function.
* :ids: ``integer[]`` - an array of ids for the distance matrix.
.. code-block:: sql
record pgr_vidsToDMatrix(IN vids integer[], IN pnts geometry[], IN edges text, tol float8 DEFAULT(0.1), OUT dmatrix double precision[], OUT ids integer[])
Description
-----------------------------------------------------------------------------
.. rubric:: Paramters
:vids: ``integer[]`` - An array of ``vertex_id``.
:pnts: ``geometry[]`` - An array of point geometries that approximates the extents of the ``vertex_id``.
:edges: ``text`` - The edge table to be used for the conversion.
:tol: ``float8`` - The amount to expand the BBOX extents of ``pnts`` when building the graph.
.. warning::
* we compute a symmetric matrix because TSP requires that so the distances are better the Euclidean but but are not perfect
* 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 shoule be checked for this as it makes it invalid for TSP
.. rubric:: History
* New in version 2.1.0
Examples
-----------------------------------------------------------------------------
This example shows how this can be used in the context of feeding the results into pgr_tsp() function. We convert a text string of ``x,y;x,y;...`` into and array of points, then convert that into an array ``vertex_id``, then create a distance matrix that gets feed into ``pgr_tsp()`` that returns the final result.
.. code-block:: sql
select * from pgr_tsp(
(select dmatrix::float8[]
from pgr_vidstodmatrix(
pgr_pointstovids(
pgr_texttopoints('2,0;2,1;3,1;2,2;4,1;4,2;2,3;3,2', 0),
'edge_table'),
pgr_texttopoints('2,0;2,1;3,1;2,2;4,1;4,2;2,3;3,2', 0),
'edge_table')
),
1
);
seq | id
-----+----
0 | 1
1 | 3
2 | 7
3 | 5
4 | 4
5 | 2
6 | 6
7 | 0
(8 rows)
This example uses the :ref:`sampledata` network.
See Also
-----------------------------------------------------------------------------
* :ref:`pgr_text_to_points` - Create an array of points from a text string.
* :ref:`pgr_tsp<pgr_tsp>` - Traveling Sales Person
|