• Supported versions:

pgr_trspVia_withPoints - Proposed

pgr_trspVia_withPoints - Route that goes through a list of vertices and/or points with restrictions.

_images/boost-inside.jpeg

Adentro: Boost Graph

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

    • Probablemente el nombre no cambie. (Pero todavía puede)

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

    • Probablemente 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.

Disponibilidad

  • Versión 3.4.0

    • New proposed function:

      pgr_trspVia_withPoints (One Via)

Descripción

Given a graph, a set of restriction on the graph edges, a set of points on the graphs edges and a list of vertices, this function is equivalent to finding the shortest path between \(vertex_i\) and \(vertex_{i+1}\) (where \(vertex\) can be a vertex or a point on the graph) for all \(i < size\_of(via\;vertices)\) trying not to use restricted paths.

Route:

is a sequence of paths

Path:

is a section of the route.

The general algorithm is as follows:

  • Build the Graph with the new points.

    • The points identifiers will be converted to negative values.

    • The vertices identifiers will remain positive.

  • Execute a pgr_withPointsVia - Proposed.

  • For the set of paths of the solution that pass through a restriction then

    • Execute the TRSP algorithm with restrictions for the path.

    • NOTE when this is done, U_turn_on_edge flag is ignored.

Nota

Do not use negative values on identifiers of the inner queries.

Firmas

One Via

pgr_trspVia_withPoints(SQL de aristas, SQL de restricciones, SQL de puntos, vertices, [opciones])
opciones: [directed, strict, U_turn_on_edge]
RETURNS SET OF (seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost, route_agg_cost)
OR EMPTY SET
Ejemplo:

Find the route that visits the vertices \(\{-6, 15, -5\}\) in that order on an directed graph.

SELECT * FROM pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 15, -5]);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |        -6 |      15 |   -6 |    4 |  0.3 |        0 |              0
   2 |       1 |        2 |        -6 |      15 |    7 |   10 |    1 |      0.3 |            0.3
   3 |       1 |        3 |        -6 |      15 |    8 |   12 |    1 |      1.3 |            1.3
   4 |       1 |        4 |        -6 |      15 |   12 |   13 |    1 |      2.3 |            2.3
   5 |       1 |        5 |        -6 |      15 |   17 |   15 |    1 |      3.3 |            3.3
   6 |       1 |        6 |        -6 |      15 |   16 |   16 |    1 |      4.3 |            4.3
   7 |       1 |        7 |        -6 |      15 |   15 |   -1 |    0 |      5.3 |            5.3
   8 |       2 |        1 |        15 |      -5 |   15 |    3 |    1 |        0 |            5.3
   9 |       2 |        2 |        15 |      -5 |   10 |    5 |  0.8 |        1 |            6.3
  10 |       2 |        3 |        15 |      -5 |   -5 |   -2 |    0 |      1.8 |            7.1
(10 rows)

Parámetros

Parámetro

Tipo

x Defecto

Descripción

SQL de aristas

TEXT

Consulta SQL como se describe.

SQL de puntos

TEXT

Consulta SQL como se describe.

vértices

ARRAY [ENTEROS ]

Arreglo ordenado de identificadores de vértices que serán visitados.

  • Cuando sea positivo se considera como un identificador de vértice

  • Cuando sea negativo se considera como un identificador de punto

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Parámetros opcionales

Columna

Tipo

x Defecto

Descripción

directed

BOOLEAN

true

  • Cuando true el gráfo se considera Dirigido

  • Cuando false el gráfo se considera No Dirigido.

Parámetros opcionales Vía

Parámetro

Tipo

x Defecto

Descripción

strict

BOOLEAN

false

  • Cuando true si un camino le faltan paradas y regresa EMPTY SET

  • Cuando false, ignora las rutas faltantes y devuelve todas las rutas encontradas

U_turn_on_edge

BOOLEAN

true

  • Cuando true saliendo desde un vértice visitado no intentara esquivarlo

Parámetros opcionales para Con puntos

Parámetro

Tipo

x Defecto

Descripción

driving_side

CHAR

r

Valor en [r, l] indicando si el lado de manejo es:

  • r para el manejo del lado derecho

  • l para el manejo del lado izquierdo

  • Cualquier otro valor se considera como r

details

BOOLEAN

false

  • Cuando true los resultados incluyen los puntos que están en el camino.

  • Cuando false los resultados no incluyen los puntos que están en el camino.

Consultas Internas

SQL aristas

Columna

Tipo

x Defecto

Descripción

id

ENTEROS

Identificador de la arista.

source

ENTEROS

Identificador del primer vértice de la arista.

target

ENTEROS

Identificador del segundo vértice de la arista.

cost

FLOTANTES

Peso de la arista (source, target)

reverse_cost

FLOTANTES

-1

Peso de la arista (target, source)

  • Cuando negativo: la arista (target, source) no existe, por lo tanto no es parte del grafo.

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

SQL restricciones

Columna

Tipo

Descripción

path

ARRAY [ENTEROS]

Secuencia de identificadores de aristas que forman un camino que no se permite tomar. - Arreglos vacios o NULL son ignorados. - Arreglos que tienen NULL arrojan una excepción.

Cost

FLOTANTES

Costo de tomar el camino prohibido.

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

SQL de puntos

Parámetro

Tipo

x Defecto

Descripción

pid

ENTEROS

valor

Identificador del punto.

  • Use con un valor positivo, dado que internamente se convertirá a un valor negativo

  • Si columna esta presente, no puede ser NULL.

  • Si columna no esta presente, un valor secuencial negativo se otorgará automáticamente.

edge_id

ENTEROS

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

fraction

FLOTANTES

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

side

CHAR

b

Valor en [b, r, l, NULL] que indica si el punto es:

  • A la derecha r,

  • A la izquierda l,

  • En ambos lados b, NULL

Donde:

ENTEROS:

SMALLINT, INTEGER, BIGINT

FLOTANTES:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Columnas de Resultados

Columna

Tipo

Descripción

seq

INTEGER

Valor secuencial a partir de 1.

path_id

INTEGER

Identificador del camino. Tiene valor 1 para el primer camino.

path_seq

INTEGER

Posición relativa en la ruta. Tiene el valor 1 para el inicio de una ruta.

start_vid

BIGINT

Identificador del vértice inicial de la ruta.

end_vid

BIGINT

Identificador del vértice final de la ruta.

node

BIGINT

Identificador del nodo en la ruta de start_vid a end_vid.

edge

BIGINT

Identificador de la arsita utilizada para ir del node al siguiente nodo de la secuencia de ruta.

  • -1 para el último nodo de la ruta.

  • -2 para el último nodo de la ruta.

cost

FLOAT

Costo para atravesar desde node usando edge hasta el siguiente nodo en la secuencia de la ruta.

agg_cost

FLOAT

Costo agregado desde start_vid hasta node.

route_agg_cost

FLOAT

Costo total desde start_vid en seq = 1 hasta end_vid del seq actual.

Nota

Cuando las columnas start_vid, end_vid y``node`` tengan valores negativos, el identificador es para un Punto.

Ejemplos Adicionales

Use pgr_findCloseEdges for points on the fly

Usa pgr_findCloseEdges:

Visit from vertex \(1\) to the two locations on the graph of point (2.9, 1.8) in order of closeness to the graph.

SELECT * FROM  pgr_trspVia_withPoints(
  $e$ SELECT * FROM edges $e$,
  $r$ SELECT path, cost FROM restrictions $r$,
  $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$,
  ARRAY[1, -1, -2], details => true);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |         1 |      -1 |    1 |    6 |    1 |        0 |              0
   2 |       1 |        2 |         1 |      -1 |    3 |    7 |    1 |        1 |              1
   3 |       1 |        3 |         1 |      -1 |    7 |    8 |  0.9 |        2 |              2
   4 |       1 |        4 |         1 |      -1 |   -2 |    8 |  0.1 |      2.9 |            2.9
   5 |       1 |        5 |         1 |      -1 |   11 |    8 |    1 |        3 |              3
   6 |       1 |        6 |         1 |      -1 |    7 |   10 |    1 |        4 |              4
   7 |       1 |        7 |         1 |      -1 |    8 |   12 |    1 |        5 |              5
   8 |       1 |        8 |         1 |      -1 |   12 |   13 |    1 |        6 |              6
   9 |       1 |        9 |         1 |      -1 |   17 |   15 |    1 |        7 |              7
  10 |       1 |       10 |         1 |      -1 |   16 |   16 |    1 |        8 |              8
  11 |       1 |       11 |         1 |      -1 |   15 |    3 |    1 |        9 |              9
  12 |       1 |       12 |         1 |      -1 |   10 |    5 |  0.8 |       10 |             10
  13 |       1 |       13 |         1 |      -1 |   -1 |   -1 |    0 |     10.8 |           10.8
  14 |       2 |        1 |        -1 |      -2 |   -1 |    5 |  0.2 |        0 |           10.8
  15 |       2 |        2 |        -1 |      -2 |   11 |    8 |    1 |      0.2 |             11
  16 |       2 |        3 |        -1 |      -2 |    7 |    8 |  0.9 |      1.2 |             12
  17 |       2 |        4 |        -1 |      -2 |   -2 |   -2 |    0 |      2.1 |           12.9
(17 rows)

  • Punto \(-1\) corresponde a la arista más cercana al punto (2.9, 1.8).

  • Punto \(-2\) corresponde a la segunda arista más cercana al punto (2.9, 1.8).

  • Point \(-2\) is visited on the route to from vertex \(1\) to Point \(-1\) (See row where \(seq = 4\)).

Variaciones de uso

All this examples are about the route that visits the vertices \(\{-6, 7, -4, 8, -2\}\) in that order on a directed graph.

SELECT * FROM pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 7, -4, 8, -2]
);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |        -6 |       7 |   -6 |    4 |  0.3 |        0 |              0
   2 |       1 |        2 |        -6 |       7 |    7 |   -1 |    0 |      0.3 |            0.3
   3 |       2 |        1 |         7 |      -4 |    7 |    7 |    1 |        0 |            0.3
   4 |       2 |        2 |         7 |      -4 |    3 |    6 |  1.3 |        1 |            1.3
   5 |       2 |        3 |         7 |      -4 |   -4 |   -1 |    0 |      2.3 |            2.6
   6 |       3 |        1 |        -4 |       8 |   -4 |    6 |  0.7 |        0 |            2.6
   7 |       3 |        2 |        -4 |       8 |    3 |    7 |    1 |      0.7 |            3.3
   8 |       3 |        3 |        -4 |       8 |    7 |    4 |  0.6 |      1.7 |            4.3
   9 |       3 |        4 |        -4 |       8 |    7 |   10 |    1 |      2.3 |            4.9
  10 |       3 |        5 |        -4 |       8 |    8 |   -1 |    0 |      3.3 |            5.9
  11 |       4 |        1 |         8 |      -2 |    8 |   10 |    1 |        0 |            5.9
  12 |       4 |        2 |         8 |      -2 |    7 |    8 |    1 |        1 |            6.9
  13 |       4 |        3 |         8 |      -2 |   11 |    9 |    1 |        2 |            7.9
  14 |       4 |        4 |         8 |      -2 |   16 |   15 |  0.4 |        3 |            8.9
  15 |       4 |        5 |         8 |      -2 |   -2 |   -2 |    0 |      3.4 |            9.3
(15 rows)

Costo agregado de la tercera ruta.

SELECT agg_cost FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 7, -4, 8, -2]
)
WHERE path_id = 3 AND edge <0;
 agg_cost
----------
      3.3
(1 row)

Costo agregado al final de la tercera ruta.

SELECT route_agg_cost FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 7, -4, 8, -2]
)
WHERE path_id = 3 AND edge < 0;
 route_agg_cost
----------------
            5.9
(1 row)

Nodos visitados en la ruta.

SELECT row_number() over () as node_seq, node
FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 7, -4, 8, -2]
)
WHERE edge <> -1 ORDER BY seq;
 node_seq | node
----------+------
        1 |   -6
        2 |    7
        3 |    3
        4 |   -4
        5 |    3
        6 |    7
        7 |    7
        8 |    8
        9 |    7
       10 |   11
       11 |   16
       12 |   -2
(12 rows)

Costo agregado de la ruta al llegar a los vértices visitados.

SELECT path_id, route_agg_cost FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 7, -4, 8, -2]
)
WHERE edge < 0;
 path_id | route_agg_cost
---------+----------------
       1 |            0.3
       2 |            2.6
       3 |            5.9
       4 |            9.3
(4 rows)

Status of «passes in front» or «visits» of the nodes and points.

SELECT seq, route_agg_cost, node, agg_cost ,
CASE WHEN edge = -1 THEN $$visits$$
ELSE $$passes in front$$
END as status
FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 7, -4, 8, -2])
WHERE agg_cost  <> 0 or seq = 1;
 seq | route_agg_cost | node | agg_cost |     status
-----+----------------+------+----------+-----------------
   1 |              0 |   -6 |        0 | passes in front
   2 |            0.3 |    7 |      0.3 | visits
   4 |            1.3 |    3 |        1 | passes in front
   5 |            2.6 |   -4 |      2.3 | visits
   7 |            3.3 |    3 |      0.7 | passes in front
   8 |            4.3 |    7 |      1.7 | passes in front
   9 |            4.9 |    7 |      2.3 | passes in front
  10 |            5.9 |    8 |      3.3 | visits
  12 |            6.9 |    7 |        1 | passes in front
  13 |            7.9 |   11 |        2 | passes in front
  14 |            8.9 |   16 |        3 | passes in front
  15 |            9.3 |   -2 |      3.4 | passes in front
(12 rows)

Sumulación del functionamiento del algoritmo.

The algorithm performs a pgr_withPointsVia - Proposed

SELECT * FROM pgr_withPointsVia(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 15, -5]);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |        -6 |      15 |   -6 |    4 |  0.3 |        0 |              0
   2 |       1 |        2 |        -6 |      15 |    7 |    8 |    1 |      0.3 |            0.3
   3 |       1 |        3 |        -6 |      15 |   11 |    9 |    1 |      1.3 |            1.3
   4 |       1 |        4 |        -6 |      15 |   16 |   16 |    1 |      2.3 |            2.3
   5 |       1 |        5 |        -6 |      15 |   15 |   -1 |    0 |      3.3 |            3.3
   6 |       2 |        1 |        15 |      -5 |   15 |    3 |    1 |        0 |            3.3
   7 |       2 |        2 |        15 |      -5 |   10 |    5 |  0.8 |        1 |            4.3
   8 |       2 |        3 |        15 |      -5 |   -5 |   -2 |    0 |      1.8 |            5.1
(8 rows)

Detects which of the paths pass through a restriction in this case is for the path_id = 1 from -6 to 15 because the path \(9 \rightarrow 16\) is restricted.

Executes the Algoritmo TRSP for the conflicting paths.

SELECT 1 AS path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost
FROM  pgr_trsp_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  -6, 15);
 path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
---------+----------+-----------+---------+------+------+------+----------
       1 |        1 |        -6 |      15 |   -6 |    4 |  0.3 |        0
       1 |        2 |        -6 |      15 |    7 |   10 |    1 |      0.3
       1 |        3 |        -6 |      15 |    8 |   12 |    1 |      1.3
       1 |        4 |        -6 |      15 |   12 |   13 |    1 |      2.3
       1 |        5 |        -6 |      15 |   17 |   15 |    1 |      3.3
       1 |        6 |        -6 |      15 |   16 |   16 |    1 |      4.3
       1 |        7 |        -6 |      15 |   15 |   -1 |    0 |      5.3
(7 rows)

From the pgr_withPointsVia - Proposed result it removes the conflicting paths and builds the solution with the results of the pgr_trsp - Proposed algorithm:

WITH
solutions AS (
  SELECT path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost
  FROM  pgr_withPointsVia(
    $$SELECT id, source, target, cost, reverse_cost FROM edges$$,
    $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
    ARRAY[-6, 15, -5]) WHERE path_id != 1
  UNION
  SELECT 1 AS path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost
  FROM  pgr_trsp_withPoints(
    $$SELECT id, source, target, cost, reverse_cost FROM edges$$,
    $$SELECT path, cost FROM restrictions$$,
    $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
    -6, 15)),
with_seq AS (
  SELECT row_number() over(ORDER BY path_id, path_seq) AS seq, *
  FROM solutions),
aggregation AS (SELECT seq, SUM(cost) OVER(ORDER BY seq) AS route_agg_cost FROM with_seq)
SELECT with_seq.*, COALESCE(route_agg_cost, 0) AS route_agg_cost
FROM with_seq LEFT JOIN aggregation ON (with_seq.seq = aggregation.seq + 1);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |        -6 |      15 |   -6 |    4 |  0.3 |        0 |              0
   2 |       1 |        2 |        -6 |      15 |    7 |   10 |    1 |      0.3 |            0.3
   3 |       1 |        3 |        -6 |      15 |    8 |   12 |    1 |      1.3 |            1.3
   4 |       1 |        4 |        -6 |      15 |   12 |   13 |    1 |      2.3 |            2.3
   5 |       1 |        5 |        -6 |      15 |   17 |   15 |    1 |      3.3 |            3.3
   6 |       1 |        6 |        -6 |      15 |   16 |   16 |    1 |      4.3 |            4.3
   7 |       1 |        7 |        -6 |      15 |   15 |   -1 |    0 |      5.3 |            5.3
   8 |       2 |        1 |        15 |      -5 |   15 |    3 |    1 |        0 |            5.3
   9 |       2 |        2 |        15 |      -5 |   10 |    5 |  0.8 |        1 |            6.3
  10 |       2 |        3 |        15 |      -5 |   -5 |   -2 |    0 |      1.8 |            7.1
(10 rows)

Getting the same result as pgr_trspVia_withPoints:

SELECT * FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[-6, 15, -5]);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |        -6 |      15 |   -6 |    4 |  0.3 |        0 |              0
   2 |       1 |        2 |        -6 |      15 |    7 |   10 |    1 |      0.3 |            0.3
   3 |       1 |        3 |        -6 |      15 |    8 |   12 |    1 |      1.3 |            1.3
   4 |       1 |        4 |        -6 |      15 |   12 |   13 |    1 |      2.3 |            2.3
   5 |       1 |        5 |        -6 |      15 |   17 |   15 |    1 |      3.3 |            3.3
   6 |       1 |        6 |        -6 |      15 |   16 |   16 |    1 |      4.3 |            4.3
   7 |       1 |        7 |        -6 |      15 |   15 |   -1 |    0 |      5.3 |            5.3
   8 |       2 |        1 |        15 |      -5 |   15 |    3 |    1 |        0 |            5.3
   9 |       2 |        2 |        15 |      -5 |   10 |    5 |  0.8 |        1 |            6.3
  10 |       2 |        3 |        15 |      -5 |   -5 |   -2 |    0 |      1.8 |            7.1
(10 rows)

Ejemplo 8:

Sometimes U_turn_on_edge flag is ignored when is set to false.

The first step, doing a pgr_withPointsVia - Proposed does consider not making a U turn on the same edge. But the path \(9 \rightarrow 16\) (Rows 4 and 5) is restricted and the result is using it.

SELECT * FROM  pgr_withPointsVia(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[6, 7, 6], U_turn_on_edge => false);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |         6 |       7 |    6 |    4 |    1 |        0 |              0
   2 |       1 |        2 |         6 |       7 |    7 |   -1 |    0 |        1 |              1
   3 |       2 |        1 |         7 |       6 |    7 |    8 |    1 |        0 |              1
   4 |       2 |        2 |         7 |       6 |   11 |    9 |    1 |        1 |              2
   5 |       2 |        3 |         7 |       6 |   16 |   16 |    1 |        2 |              3
   6 |       2 |        4 |         7 |       6 |   15 |    3 |    1 |        3 |              4
   7 |       2 |        5 |         7 |       6 |   10 |    2 |    1 |        4 |              5
   8 |       2 |        6 |         7 |       6 |    6 |   -2 |    0 |        5 |              6
(8 rows)

When executing the pgr_trsp_withPoints - Proposed algorithm for the conflicting path, there is no U_turn_on_edge flag.

SELECT 5 AS path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost
FROM  pgr_trsp_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  7, 6);
 path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
---------+----------+-----------+---------+------+------+------+----------
       5 |        1 |         7 |       6 |    7 |    4 |    1 |        0
       5 |        2 |         7 |       6 |    6 |   -1 |    0 |        1
(2 rows)

Therefore the result ignores the U_turn_on_edge flag when set to false. From the pgr_withPointsVia - Proposed result it removes the conflicting paths and builds the solution with the results of the pgr_trsp - Proposed algorithm. In this case a U turn is been done using the same edge.

SELECT * FROM  pgr_trspVia_withPoints(
  $$SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id$$,
  $$SELECT path, cost FROM restrictions$$,
  $$SELECT pid, edge_id, side, fraction FROM pointsOfInterest$$,
  ARRAY[6, 7, 6], U_turn_on_edge => false);
 seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost | route_agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------+----------------
   1 |       1 |        1 |         6 |       7 |    6 |    4 |    1 |        0 |              0
   2 |       1 |        2 |         6 |       7 |    7 |   -1 |    0 |        1 |              1
   3 |       2 |        1 |         7 |       6 |    7 |    4 |    1 |        0 |              1
   4 |       2 |        2 |         7 |       6 |    6 |   -2 |    0 |        1 |              2
(4 rows)

Ver también

Índices y tablas