pgr_withPointsKSP - Propuesto

pgr_withPointsKSP — Yen’s algorithm for K shortest paths using Dijkstra.

Advertencia

Funciones propuestas para la próxima versión mayor.

  • No están oficialmente en la versión actual.

  • Es probable que oficialmente formen parte del próximo lanzamiento:

    • Las funciones hacen uso de ENTEROS y FLOTANTES

    • Es posible que el nombre no cambie. (Pero todavía puede)

    • Es posible que la firma no cambie. (Pero todavía puede)

    • Es posible que la funcionalidad no cambie. (Pero todavía puede)

    • Se han hecho pruebas con pgTap. Pero tal vez se necesiten más.

    • Es posible que la documentación necesite un refinamiento.

_images/boost-inside.jpeg

Adentro: Boost Graph

Disponibilidad

  • Version 2.2.0

    • Nueva función propuesta

Descripción

Modifies the graph to include the points defined in the Points SQL and using Yen algorithm, finds the \(K\) shortest paths.

Firmas

pgr_withPointsKSP(Edges SQL, Points SQL start_pid, end_pid, K
  [, directed] [, heap_paths] [, driving_side] [, details])
RETURNS SET OF (seq, path_id, path_seq, node, edge, cost, agg_cost)
Ejemplo:

Get 2 paths from Point \(1\) to point \(2\) on a directed graph.

  • For a directed graph.

  • Ambos lados de conducción se establecen como b. Así que llegar/partir hacia/desde el o los puntos, puede ser en cualquier dirección.

  • No details are given about distance of other points of the query.

  • No heap paths are returned.

SELECT * FROM pgr_withPointsKSP(
    'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
    'SELECT pid, edge_id, fraction, side from pointsOfInterest',
    -1, -2, 2);
 seq | path_id | path_seq | node | edge | cost | agg_cost
-----+---------+----------+------+------+------+----------
   1 |       1 |        1 |   -1 |    1 |  0.6 |        0
   2 |       1 |        2 |    6 |    4 |    1 |      0.6
   3 |       1 |        3 |    7 |    8 |    1 |      1.6
   4 |       1 |        4 |   11 |    9 |    1 |      2.6
   5 |       1 |        5 |   16 |   15 |  0.4 |      3.6
   6 |       1 |        6 |   -2 |   -1 |    0 |        4
   7 |       2 |        1 |   -1 |    1 |  0.6 |        0
   8 |       2 |        2 |    6 |    4 |    1 |      0.6
   9 |       2 |        3 |    7 |    8 |    1 |      1.6
  10 |       2 |        4 |   11 |   11 |    1 |      2.6
  11 |       2 |        5 |   12 |   13 |    1 |      3.6
  12 |       2 |        6 |   17 |   15 |  0.6 |      4.6
  13 |       2 |        7 |   -2 |   -1 |    0 |      5.2
(13 rows)

Parámetros

Columna

Tipo

Descripción

Edges SQL

TEXT

Edges SQL query as described.

Points SQL

TEXT

Points SQL query as described.

start vid

ANY-INTEGER

Identifier of the departure vertex.

end vid

ANY-INTEGER

Identifier of the departure vertex.

K

ANY-INTEGER

Number of required paths

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

Optional parameters

Columna

Tipo

x Defecto

Descripción

directed

BOOLEAN

true

  • When true the graph is considered Directed

  • When false the graph is considered as Undirected.

KSP Optional parameters

Columna

Tipo

x Defecto

Descripción

heap_paths

BOOLEAN

false

  • When false Returns at most K paths

  • When true all the calculated paths while processing are returned.

  • Roughly, when the shortest path has N edges, the heap will contain about than N * K paths for small value of K and K > 5.

With points optional parameters

Parámetro

Tipo

x Defecto

Descripción

driving_side

CHAR

b

Value in [r, l, b] indicating if the driving side is:

  • r for right driving side.

  • l for left driving side.

  • b for both.

details

BOOLEAN

false

  • When true the results will include the points that are in the path.

  • When false the results will not include the points that are in the path.

Inner Queries

Edges SQL

Columna

Tipo

x Defecto

Descripción

id

ANY-INTEGER

Identificador de la arista.

source

ANY-INTEGER

Identificador del primer vértice de la arista.

target

ANY-INTEGER

Identificador del segundo vértice de la arista.

cost

ANY-NUMERICAL

Weight of the edge (source, target)

reverse_cost

ANY-NUMERICAL

-1

Weight of the edge (target, source)

  • When negative: edge (target, source) does not exist, therefore it’s not part of the graph.

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Points SQL

Parámetro

Tipo

x Defecto

Descripción

pid

ANY-INTEGER

value

Identifier of the point.

  • Use with positive value, as internally will be converted to negative value

  • If column is present, it can not be NULL.

  • If column is not present, a sequential negative value will be given automatically.

edge_id

ANY-INTEGER

Identificador de la arista «más cercana» al punto.

fraction

ANY-NUMERICAL

El valor en <0,1> que indica la posición relativa desde el primer punto de la arista.

side

CHAR

b

Value in [b, r, l, NULL] indicating if the point is:

  • In the right r,

  • In the left l,

  • In both sides b, NULL

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Columnas de Resultados

Returns set of (seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)

Columna

Tipo

Descripción

seq

INTEGER

Sequential value starting from 1.

path_id

INTEGER

Path identifier.

  • Has value 1 for the first of a path from start vid to end_vid

path_seq

INTEGER

Relative position in the path. Has value 1 for the beginning of a path.

node

BIGINT

Identifier of the node in the path from start vid to end vid

edge

BIGINT

Identifier of the edge used to go from node to the next node in the path sequence. -1 for the last node of the path.

cost

FLOAT

Cost to traverse from node using edge to the next node in the path sequence.

  • \(0\) for the last node of the path.

agg_cost

FLOAT

Aggregate cost from start vid to node.

Ejemplos Adicionales

Use pgr_findCloseEdges in the Points SQL.

Get \(2\) paths using left side driving topology, from vertex \(1\) to the closest location on the graph of point (2.9, 1.8).

SELECT * FROM pgr_withPointsKSP(
  $e$ SELECT * FROM edges $e$,
  $p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side
      FROM pgr_findCloseEdges(
        $$SELECT id, geom FROM edges$$,
        (SELECT ST_POINT(2.9, 1.8)),
        0.5, cap => 2)
  $p$,
  1, -1, 2,
  driving_side := 'r');
 seq | path_id | path_seq | node | edge | cost | agg_cost
-----+---------+----------+------+------+------+----------
   1 |       1 |        1 |    1 |    6 |    1 |        0
   2 |       1 |        2 |    3 |    7 |    1 |        1
   3 |       1 |        3 |    7 |    8 |    1 |        2
   4 |       1 |        4 |   11 |    9 |    1 |        3
   5 |       1 |        5 |   16 |   16 |    1 |        4
   6 |       1 |        6 |   15 |    3 |    1 |        5
   7 |       1 |        7 |   10 |    5 |  0.8 |        6
   8 |       1 |        8 |   -1 |   -1 |    0 |      6.8
   9 |       2 |        1 |    1 |    6 |    1 |        0
  10 |       2 |        2 |    3 |    7 |    1 |        1
  11 |       2 |        3 |    7 |   10 |    1 |        2
  12 |       2 |        4 |    8 |   12 |    1 |        3
  13 |       2 |        5 |   12 |   13 |    1 |        4
  14 |       2 |        6 |   17 |   15 |    1 |        5
  15 |       2 |        7 |   16 |   16 |    1 |        6
  16 |       2 |        8 |   15 |    3 |    1 |        7
  17 |       2 |        9 |   10 |    5 |  0.8 |        8
  18 |       2 |       10 |   -1 |   -1 |    0 |      8.8
(18 rows)

  • Point \(-1\) corresponds to the closest edge from point (2.9,1.8).

Left driving side

Get \(2\) paths using left side driving topology, from point \(1\) to point \(2\) with details.

SELECT * FROM pgr_withPointsKSP(
    'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
    'SELECT pid, edge_id, fraction, side from pointsOfInterest',
    -1, -2, 2,
    driving_side := 'l', details := true);
 seq | path_id | path_seq | node | edge | cost | agg_cost
-----+---------+----------+------+------+------+----------
   1 |       1 |        1 |   -1 |    1 |  0.6 |        0
   2 |       1 |        2 |    6 |    4 |  0.7 |      0.6
   3 |       1 |        3 |   -6 |    4 |  0.3 |      1.3
   4 |       1 |        4 |    7 |    8 |    1 |      1.6
   5 |       1 |        5 |   11 |   11 |    1 |      2.6
   6 |       1 |        6 |   12 |   13 |    1 |      3.6
   7 |       1 |        7 |   17 |   15 |  0.6 |      4.6
   8 |       1 |        8 |   -2 |   -1 |    0 |      5.2
   9 |       2 |        1 |   -1 |    1 |  0.6 |        0
  10 |       2 |        2 |    6 |    4 |  0.7 |      0.6
  11 |       2 |        3 |   -6 |    4 |  0.3 |      1.3
  12 |       2 |        4 |    7 |    8 |    1 |      1.6
  13 |       2 |        5 |   11 |    9 |    1 |      2.6
  14 |       2 |        6 |   16 |   15 |    1 |      3.6
  15 |       2 |        7 |   17 |   15 |  0.6 |      4.6
  16 |       2 |        8 |   -2 |   -1 |    0 |      5.2
(16 rows)

Right driving side

Get \(2\) paths using right side driving topology from, point \(1\) to point \(2\) with heap paths and details.

SELECT * FROM pgr_withPointsKSP(
    'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
    'SELECT pid, edge_id, fraction, side from pointsOfInterest',
    -1, -2, 2,
    heap_paths := true, driving_side := 'r', details := true);
 seq | path_id | path_seq | node | edge | cost | agg_cost
-----+---------+----------+------+------+------+----------
   1 |       1 |        1 |   -1 |    1 |  0.4 |        0
   2 |       1 |        2 |    5 |    1 |    1 |      0.4
   3 |       1 |        3 |    6 |    4 |  0.7 |      1.4
   4 |       1 |        4 |   -6 |    4 |  0.3 |      2.1
   5 |       1 |        5 |    7 |    8 |    1 |      2.4
   6 |       1 |        6 |   11 |    9 |    1 |      3.4
   7 |       1 |        7 |   16 |   15 |  0.4 |      4.4
   8 |       1 |        8 |   -2 |   -1 |    0 |      4.8
   9 |       2 |        1 |   -1 |    1 |  0.4 |        0
  10 |       2 |        2 |    5 |    1 |    1 |      0.4
  11 |       2 |        3 |    6 |    4 |  0.7 |      1.4
  12 |       2 |        4 |   -6 |    4 |  0.3 |      2.1
  13 |       2 |        5 |    7 |    8 |    1 |      2.4
  14 |       2 |        6 |   11 |   11 |    1 |      3.4
  15 |       2 |        7 |   12 |   13 |    1 |      4.4
  16 |       2 |        8 |   17 |   15 |    1 |      5.4
  17 |       2 |        9 |   16 |   15 |  0.4 |      6.4
  18 |       2 |       10 |   -2 |   -1 |    0 |      6.8
  19 |       3 |        1 |   -1 |    1 |  0.4 |        0
  20 |       3 |        2 |    5 |    1 |    1 |      0.4
  21 |       3 |        3 |    6 |    4 |  0.7 |      1.4
  22 |       3 |        4 |   -6 |    4 |  0.3 |      2.1
  23 |       3 |        5 |    7 |   10 |    1 |      2.4
  24 |       3 |        6 |    8 |   12 |  0.6 |      3.4
  25 |       3 |        7 |   -3 |   12 |  0.4 |        4
  26 |       3 |        8 |   12 |   13 |    1 |      4.4
  27 |       3 |        9 |   17 |   15 |    1 |      5.4
  28 |       3 |       10 |   16 |   15 |  0.4 |      6.4
  29 |       3 |       11 |   -2 |   -1 |    0 |      6.8
(29 rows)

Las consultas utilizan la red Datos Muestra .

Ver también

Índices y tablas