pgr_bdDijkstraCost
¶
pgr_bdDijkstraCost
— Devuelve la ruta(s) más corta utilizando el algoritmo de Dijkstra Bidireccional.

Boost Graph Inside¶
Availability
Versión 3.2.0
New proposed signature:
pgr_bdDijkstraCost
(Combinations)
Versión 3.0.0
Función oficial
Versión 2.5.0
Nueva función propuesta
Descripción¶
The pgr_bdDijkstraCost
function sumarizes of the cost of the shortest path(s)
using the bidirectional Dijkstra Algorithm.
El proceso se realiza sólo en las aristas con costos positivos.
A negative value on a cost column is interpreted as the edge does not exist.
Valores son regresados cuando hay una ruta.
When there is no path:
When the starting vertex and ending vertex are the same.
The aggregate cost of the non included values \((v, v)\) is \(0\)
Cuando el vértice inicial y el vértice final son diferentes y no hay camino:
The aggregate cost the non included values \((u, v)\) is \(\infty\)
For optimization purposes, any duplicated value in the starting vertices or on the ending vertices are ignored.
Tiempo de ejecución (peor de los casos): \(O((V \log V + E))\)
Para grandes gráficos donde hay un camino entre el vértice inicial y el vértice final:
Se espera que termine más rápido que pgr_dijkstra
It does not return a path.
Returns the sum of the costs of the shortest path of each pair combination of nodes requested.
Let be the case the values returned are stored in a table, so the unique index would be the pair:
(start_vid, end_vid)
.Depending on the function and its parameters, the results can be symmetric.
The aggregate cost of \((u, v)\) is the same as for \((v, u)\).
Any duplicated value in the start or end vertex identifiers are ignored.
The returned values are ordered:
start_vid
ascendingend_vid
ascending
Firmas¶
Resumen
pgr_bdDijkstraCost(Edges SQL, start vid, end vid [, directed]) pgr_bdDijkstraCost(Edges SQL, start vid, end vids [, directed]) pgr_bdDijkstraCost(Edges SQL, start vids, end vid [, directed]) pgr_bdDijkstraCost(Edges SQL, start vids, end vids [, directed]) pgr_bdDijkstraCost(Edges SQL, Combinations SQL [, directed]) RETURNS SET OF (start_vid, end_vid, agg_cost) OR EMPTY SET
Uno a Uno¶
pgr_bdDijkstraCost(Edges SQL, start vid, end vid [, directed]) RETURNS SET OF (start_vid, end_vid, agg_cost) OR EMPTY SET
- Ejemplo
Del vértice \(2\) al vértice \(3\) en un grafo dirigido
SELECT * FROM pgr_bdDijkstraCost(
'select id, source, target, cost, reverse_cost from edge_table',
2, 3, true);
start_vid | end_vid | agg_cost
-----------+---------+----------
2 | 3 | 5
(1 row)
Uno a Muchos¶
pgr_bdDijkstraCost(Edges SQL, start vid, end vids [, directed]) RETURNS SET OF (start_vid, end_vid, agg_cost) OR EMPTY SET
- Ejemplo
From vertex \(2\) to vertices \(\{3, 12\}\) on a directed graph
SELECT * FROM pgr_bdDijkstraCost(
'select id, source, target, cost, reverse_cost from edge_table',
2, ARRAY[3, 12]);
start_vid | end_vid | agg_cost
-----------+---------+----------
2 | 3 | 5
2 | 12 | 4
(2 rows)
Muchos a Uno¶
pgr_bdDijkstraCost(Edges SQL, start vids, end vid [, directed]) RETURNS SET OF (start_vid, end_vid, agg_cost) OR EMPTY SET
- Ejemplo
From vertices \(\{2, 7\}\) to vertex \(12\) on a directed graph
SELECT * FROM pgr_bdDijkstraCost(
'select id, source, target, cost, reverse_cost from edge_table',
ARRAY[2, 7], 12);
start_vid | end_vid | agg_cost
-----------+---------+----------
2 | 12 | 4
7 | 12 | 5
(2 rows)
Muchos a Muchos¶
pgr_bdDijkstraCost(Edges SQL, start vids, end vids [, directed]) RETURNS SET OF (start_vid, end_vid, agg_cost) OR EMPTY SET
- Ejemplo
From vertices \(\{2, 7\}\) to vertices \(\{3, 12\}\) on an undirected graph
SELECT * FROM pgr_bdDijkstraCost(
'select id, source, target, cost, reverse_cost from edge_table',
ARRAY[2, 7], ARRAY[3, 12],
directed => false);
start_vid | end_vid | agg_cost
-----------+---------+----------
2 | 3 | 1
2 | 12 | 4
7 | 3 | 4
7 | 12 | 5
(4 rows)
Combinaciones¶
pgr_bdDijkstraCost(Edges SQL, Combinations SQL [, directed]) RETURNS SET OF (start_vid, end_vid, agg_cost) OR EMPTY SET
- Ejemplo
Using a combinations table on an undirected graph
The combinations table:
SELECT source, target FROM combinations_table;
source | target
--------+--------
1 | 2
1 | 3
2 | 1
2 | 4
2 | 17
(5 rows)
The query:
SELECT * FROM pgr_bdDijkstraCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
'SELECT source, target FROM combinations_table',
false);
start_vid | end_vid | agg_cost
-----------+---------+----------
1 | 2 | 1
1 | 3 | 2
2 | 1 | 1
2 | 4 | 2
(4 rows)
Parámetros¶
Columna |
Tipo |
Descripción |
---|---|---|
|
Edges SQL as described below |
|
|
Combinations SQL as described below |
|
start vid |
|
Identificador del vértice inicial de la ruta. |
start vids |
|
Arreglo de identificadores de vértices iniciales. |
end vid |
|
Identificador del vértice final de la ruta. |
end vids |
|
Arreglo de identificadores de vértices finales. |
Optional parameters¶
Columna |
Tipo |
default |
Descripción |
---|---|---|---|
|
|
|
|
Consultas internas¶
Edges SQL¶
Columna |
Tipo |
x Defecto |
Descripción |
---|---|---|---|
|
ANY-INTEGER |
Identificador de la arista. |
|
|
ANY-INTEGER |
Identificador del primer vértice extremo de la arista. |
|
|
ANY-INTEGER |
Identificador del segundo vértice extremo de la arista. |
|
|
ANY-NUMERICAL |
Weight of the edge ( |
|
|
ANY-NUMERICAL |
-1 |
Weight of the edge (
|
Donde:
- ANY-INTEGER
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Combinations SQL¶
Parámetro |
Tipo |
Descripción |
---|---|---|
|
ANY-INTEGER |
Identifier of the departure vertex. |
|
ANY-INTEGER |
Identifier of the arrival vertex. |
Donde:
- ANY-INTEGER
SMALLINT
,INTEGER
,BIGINT
Return Columns¶
Set of (start_vid, end_vid, agg_cost)
Columna |
Tipo |
Descripción |
---|---|---|
|
|
Identificador del vértice inicial. |
|
|
Identificador del vértice final. |
|
|
Coste agregado de |
Additional Examples¶
- Example 1
Demonstration of repeated values are ignored, and result is sorted.
SELECT * FROM pgr_bdDijkstraCost(
'select id, source, target, cost, reverse_cost from edge_table',
ARRAY[5, 3, 4, 3, 3, 4], ARRAY[3, 5, 3, 4]);
start_vid | end_vid | agg_cost
-----------+---------+----------
3 | 4 | 3
3 | 5 | 2
4 | 3 | 1
4 | 5 | 3
5 | 3 | 4
5 | 4 | 3
(6 rows)
- Example 2
Making
start_vids
the same asend_vids
.
SELECT * FROM pgr_bdDijkstraCost(
'select id, source, target, cost, reverse_cost from edge_table',
ARRAY[5, 3, 4], ARRAY[5, 3, 4]);
start_vid | end_vid | agg_cost
-----------+---------+----------
3 | 4 | 3
3 | 5 | 2
4 | 3 | 1
4 | 5 | 3
5 | 3 | 4
5 | 4 | 3
(6 rows)
- Example 3
Manually assigned vertex combinations.
SELECT * FROM pgr_bdDijkstraCost(
'SELECT id, source, target, cost, reverse_cost FROM edge_table',
'SELECT * FROM (VALUES (2, 3), (2, 5), (11, 3)) AS combinations (source, target)');
start_vid | end_vid | agg_cost
-----------+---------+----------
2 | 3 | 5
2 | 5 | 1
11 | 3 | 4
(3 rows)
Ver también¶
Índices y tablas