pgr_withPointsCost
- Proposed¶
pgr_withPointsCost
- Calcula la ruta más corta y devuelve solo el costo agregado de la(s) rutas más cortas encontradas, para la combinación de puntos dados.
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.

Adentro: Boost Graph¶
Disponibilidad
Versión 3.2.0
Nueva función propuesta:
pgr_withPointsCost(Combinaciones)
Version 2.2.0
Nueva función propuesta
Descripción¶
Modifica el grafo para incluir puntos definidos por points_sql. Con el algoritmo Dijkstra, devuelva solo el costo agregado de la(s) rutas más cortas encontradas.
- Las principales características son:
No devuelve una ruta.
Devuelve la suma de los costes de la ruta más corta para la combinación de pares de vértices en el grafo modificado.
Los vértices del grafo son:
positivo cuando pertenece a edges_sql
negativo cuando pertenece a points_sql
El proceso se realiza sólo en las aristas con costos positivos.
Valores son regresados cuando hay una ruta.
Los valores devueltos tienen la forma de un conjunto de (start_vid, end_vid, agg_cost).
Cuando el vértice inicial y el vértice final son iguales, no hay camino.
El agg_cost en los valores no incluidos (v, v) es 0
Cuando el vértice inicial y el vértice final son diferentes y no hay ninguna ruta.
El agg_cost en los valores no incluidos (u, v) es \(\infty\)
Si los valores devueltos se almacenan en una tabla, el índice único sería el par: (start_vid, end_vid).
Para los grafos no dirigidos, los resultados son simétricos.
El agg_cost de (u, v) es el mismo que para (v, u).
Para fines de optimización, se omite cualquier valor duplicado en start_vids o end_vids .
Los valores regresados se ordenan:
start_vid ascendente
end_vid ascendente
Tiempo de ejecución: \(O(| start\_vids | * (V \log V + E))\)
Firmas¶
Resumen
pgr_withPointsCost(Edges SQL, 'Points SQL', start vid, end vid [, directed] [, driving_side]) pgr_withPointsCost(Edges SQL, 'Points SQL', start vid, end vids [, directed] [, driving_side]) pgr_withPointsCost(Edges SQL, 'Points SQL', start vids, end vid [, directed] [, driving_side]) pgr_withPointsCost(Edges SQL, 'Points SQL', start vids, end vids [, directed] [, driving_side]) pgr_withPointsCost(Edges SQL, 'Points SQL', Combinations SQL [, directed] [, driving_side]) RETURNS (start_vid, end_vid, agg_cost)
Nota
No hay identificador de details, a diferencia de los otros miembros de la familia de funciones withPoints.
Uno a Uno¶
pgr_withPointsCost(Edges SQL, start vid, end vid [, directed] [, driving_side]) RETURNS (start_vid, end_vid, agg_cost)
- Ejemplo:
From point \(1\) to vertex \(10\) with defaults
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, 10);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | 10 | 5.6
(1 row)
Uno a Muchos¶
pgr_withPointsCost(Edges SQL, 'Points SQL', start vid, end vids [, directed] [, driving_side]) RETURNS (start_vid, end_vid, agg_cost)
- Ejemplo:
From point \(1\) to point \(3\) and vertex \(7\) on an undirected graph
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
-1, ARRAY[-3, 7],
directed => false);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 7 | 1.6
(2 rows)
Muchos a Uno¶
pgr_withPointsCost(Edges SQL, 'Points SQL', start vids, end vid [, directed] [, driving_side]) RETURNS (start_vid, end_vid, agg_cost)
- Ejemplo:
From point \(1\) and vertex \(6\) to point \(3\)
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], -3);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
6 | -3 | 2.6
(2 rows)
Muchos a Muchos¶
pgr_withPointsCost(Edges SQL, 'Points SQL', start vids, end vids [, directed] [, driving_side]) RETURNS (start_vid, end_vid, agg_cost)
- Ejemplo:
From point \(15\) and vertex \(6\) to point \(3\) and vertex \(1\)
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], ARRAY[-3, 1]);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -3 | 3.2
-1 | 1 | 3.6
6 | -3 | 2.6
6 | 1 | 3
(4 rows)
Combinations¶
pgr_withPointsCost(Edges SQL, 'Points SQL', Combinations SQL [, directed] [, driving_side]) RETURNS (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- Ejemplo:
Two combinations
From point \(1\) to vertex \(10\), and from vertex \(6\) to point \(3\) with right side driving.
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
'SELECT * FROM (VALUES (-1, 10), (6, -3)) AS combinations(source, target)',
driving_side => 'r');
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | 10 | 6.4
6 | -3 | 2.6
(2 rows)
Parámetros¶
Columna |
Tipo |
Descripción |
---|---|---|
|
Edges SQL as described below |
|
|
Points SQL as described below |
|
|
Combinations SQL as described below |
|
start vid |
|
Identifier of the starting vertex of the path. Negative value is for point’s identifier. |
start vids |
|
Array of identifiers of starting vertices. Negative values are for point’s identifiers. |
end vid |
|
Identifier of the ending vertex of the path. Negative value is for point’s identifier. |
end vids |
|
Array of identifiers of ending vertices. Negative values are for point’s identifiers. |
Optional parameters¶
Columna |
Tipo |
x Defecto |
Descripción |
---|---|---|---|
|
|
|
|
With points optional parameters¶
Parámetro |
Tipo |
x Defecto |
Descripción |
---|---|---|---|
|
|
|
Value in [
|
Inner Queries¶
Edges SQL¶
Columna |
Tipo |
x Defecto |
Descripción |
---|---|---|---|
|
ANY-INTEGER |
Identificador de la arista. |
|
|
ANY-INTEGER |
Identificador del primer vértice de la arista. |
|
|
ANY-INTEGER |
Identificador del segundo vértice de la arista. |
|
|
ANY-NUMERICAL |
Weight of the edge ( |
|
|
ANY-NUMERICAL |
-1 |
Weight of the edge (
|
Donde:
- ENTEROS:
SMALLINT
,INTEGER
,BIGINT
- FLOTANTES:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Points SQL¶
Parámetro |
Tipo |
x Defecto |
Descripción |
---|---|---|---|
|
ANY-INTEGER |
value |
Identifier of the point.
|
|
ANY-INTEGER |
Identificador de la arista «más cercana» al punto. |
|
|
ANY-NUMERICAL |
El valor en <0,1> que indica la posición relativa desde el primer punto de la arista. |
|
|
|
|
Value in [
|
Donde:
- ENTEROS:
SMALLINT
,INTEGER
,BIGINT
- FLOTANTES:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Combinaciones SQL¶
Parámetro |
Tipo |
Descripción |
---|---|---|
|
ANY-INTEGER |
Identifier of the departure vertex. |
|
ANY-INTEGER |
Identifier of the arrival vertex. |
Donde:
- ENTEROS:
SMALLINT
,INTEGER
,BIGINT
Columnas de Resultados¶
Columna |
Tipo |
Descripción |
---|---|---|
|
|
Identifier of the starting vertex or point.
|
|
|
Identifier of the ending vertex or point.
|
|
|
Coste agregado de |
Ejemplos Adicionales¶
Use pgr_findCloseEdges in the Points SQL.¶
Find the cost of the routes from vertex \(1\) to the two closest locations on the graph of point (2.9, 1.8).
SELECT * FROM pgr_withPointsCost(
$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, ARRAY[-1, -2]);
start_pid | end_pid | agg_cost
-----------+---------+----------
1 | -2 | 2.9
1 | -1 | 6.8
(2 rows)
Point \(-1\) corresponds to the closest edge from point (2.9,1.8).
Point \(-2\) corresponds to the next close edge from point (2.9,1.8).
Being close to the graph does not mean have a shorter route.
Right side driving topology¶
Traveling from point \(1\) and vertex \(5\) to points \(\{2, 3, 6\}\) and vertices \(\{10, 11\}\)
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11],
driving_side => 'r');
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -6 | 2.1
-1 | -3 | 4
-1 | -2 | 4.8
-1 | 10 | 6.4
-1 | 11 | 3.4
5 | -6 | 1.7
5 | -3 | 3.6
5 | -2 | 4.4
5 | 10 | 6
5 | 11 | 3
(10 rows)
Left side driving topology¶
Traveling from point \(1\) and vertex \(5\) to points \(\{2, 3, 6\}\) and vertices \(\{10, 11\}\)
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11],
driving_side => 'l');
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -6 | 1.3
-1 | -3 | 3.2
-1 | -2 | 5.2
-1 | 10 | 5.6
-1 | 11 | 2.6
5 | -6 | 1.7
5 | -3 | 3.6
5 | -2 | 5.6
5 | 10 | 6
5 | 11 | 3
(10 rows)
Does not matter driving side driving topology¶
Traveling from point \(1\) and vertex \(5\) to points \(\{2, 3, 6\}\) and vertices \(\{10, 11\}\)
SELECT * FROM pgr_withPointsCost(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11]);
start_pid | end_pid | agg_cost
-----------+---------+----------
-1 | -6 | 1.3
-1 | -3 | 3.2
-1 | -2 | 4
-1 | 10 | 5.6
-1 | 11 | 2.6
5 | -6 | 1.7
5 | -3 | 3.6
5 | -2 | 4.4
5 | 10 | 6
5 | 11 | 3
(10 rows)
Las consultas utilizan la red Datos Muestra .
Ver también¶
Índices y tablas