pgr_withPointsCost
¶
pgr_withPointsCost
- Calculates the shortest path and returns only the
aggregate cost of the shortest path found, for the combination of points
given.
可用性
Version 4.0.0
Function promoted to official.
版本3.2.0
New proposed signature:
pgr_withPointsCost(组合)
版本 2.2.0
New proposed function.
描述¶
Modify the graph to include points defined by points_sql. Using Dijkstra algorithm, return only the aggregate cost of the shortest path found.
- 主要特点是:
它不返回路径。
返回修改图中顶点对组合的最短路径成本之和。
图的顶点是:
当它属于edges_sql时为 正
当它属于 points_sql时为 负
仅在具有正成本的边进行处理。
当存在路径时返回值。
返回值的形式为一组`(start_vid, end_vid, agg_cost)`。
当起始顶点和结束顶点相同时,就没有路径。
非包含值 (v, v) 中的 agg_cost 为`0`
当起始顶点和结束顶点不同且不存在路径时。
非包含值 (u, v) 中的 agg_cost 为 \(\infty\)
如果返回的值存储在表中,则唯一索引将是这一对:(start_vid, end_vid).。
对于 无向 图,结果是 对称 的。
(u, v) 的 agg_cost 与 (v, u) 相同。
出于优化目的, start_vids`或 `end_vids 中的任何重复值都将被忽略。
返回值是有序的:
start_vid 升序
end_vid 升序
运行时间: \(O(|start\_vids|\times(V \log V + E))\)
签名¶
总结
[directed, driving_side]
(start_pid, end_pid, agg_cost)
的集合Note
与 withPoints 函数系列的其他成员不同,没有 详细信息 标志。
一对一¶
[directed, driving_side]
(start_pid, end_pid, agg_cost)
的集合- 示例:
使用默认值从点 \(1\) 到顶点 \(10\)
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)
一对多¶
[directed, driving_side]
(start_pid, end_pid, agg_cost)
的集合- 示例:
无向图上的点 \(1\) 到点 \(3\) 和顶点 \(7\)
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)
多对一¶
[directed, driving_side]
(start_pid, end_pid, agg_cost)
的集合- 示例:
从点 \(1\) 和顶点 \(6\) 到点 \(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)
多对多¶
[directed, driving_side]
(start_pid, end_pid, agg_cost)
的集合- 示例:
从点 \(15\) 和顶点 \(6\) 到点 \(3\) 和顶点 \(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)
组合¶
[directed, driving_side]
(start_pid, end_pid, agg_cost)
的集合- 示例:
两种组合
从点 \(1\) 到顶点 \(10\),以及从顶点 \(6\) 到点 \(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',
'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)
参数¶
列 |
类型 |
描述 |
---|---|---|
|
Edges SQL 如下所述 |
|
|
Points SQL 如下所述 |
|
|
Combinations SQL 如下所述 |
|
start vid |
|
路径起始顶点的标识符。 负值用于点的标识符。 |
start vids |
|
起始顶点的标识符数组。 负值用于点的标识符。 |
end vid |
|
路径结束顶点的标识符。 负值用于点的标识符。 |
end vids |
|
结束顶点的标识符数组。 负值用于点的标识符。 |
可选参数¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
带点可选参数¶
参数 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
[
|
内部查询¶
Edges SQL¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
ANY-INTEGER |
边的标识符。 |
|
|
ANY-INTEGER |
边的第一个端点顶点的标识符。 |
|
|
ANY-INTEGER |
边的第二个端点顶点的标识符。 |
|
|
ANY-NUMERICAL |
边( |
|
|
ANY-NUMERICAL |
-1 |
边(
|
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Points SQL¶
参数 |
类型 |
默认 |
描述 |
---|---|---|---|
|
ANY-INTEGER |
value |
点的标识符。
|
|
ANY-INTEGER |
距离该点“最近”的边的标识符。 |
|
|
ANY-NUMERICAL |
<0,1> 中的值指示距边缘第一个端点的相对位置。 |
|
|
|
|
[
|
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
分量 SQL¶
参数 |
类型 |
描述 |
---|---|---|
|
ANY-INTEGER |
出发顶点的标识符。 |
|
ANY-INTEGER |
到达顶点的标识符。 |
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
结果列¶
列 |
类型 |
描述 |
---|---|---|
|
|
起始顶点或点的标识符。
|
|
|
结束顶点或点的标识符。
|
|
|
从 |
其他示例¶
在 Points SQL 中使用 pgr_findCloseEdges。¶
求从顶点 \(1\) 到图中点 (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)
点 \(-1`对应于距离点`(2.9, 1.8)\) 最近的边。
点 \(-2`对应于点`(2.9, 1.8)\) 的下一个闭合边。
靠近图表并不意味着路线更短。
右侧驾驶拓扑¶
从点 \(1\) 和顶点 \(5\) 出发,前往点 \(\{2, 3, 6\}\) 和顶点 \(\{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)
左侧驾驶拓扑¶
从点 \(1\) 和顶点 \(5\) 出发,前往点 \(\{2, 3, 6\}\) 和顶点 \(\{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)
与驱动端驱动拓扑无关¶
从点 \(1\) 和顶点 \(5\) 出发,前往点 \(\{2, 3, 6\}\) 和顶点 \(\{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)
另请参阅¶
索引和表格