pgr_withPointsKSP -拟议¶
pgr_withPointsKSP
— Yen 使用 Dijkstra 计算 K 最短路径的算法。
Warning
下一版本的拟议功能。
它们并未正式出现在当前版本中。
它们可能会正式成为下一个版本的一部分:
这些函数使用 ANY-INTEGER 和 ANY-NUMERICAL
名字可能不会改变。(但仍然有可能改变)
签名可能不会改变。(但仍然有可能改变)
功能可能不会改变。(但仍然有可能改变)
pgTap 测试已经完成。 但可能需要更多。
文档可能需要完善。
可用性
版本3.6.0
标准化输出列为
(seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
pgr_withPointsKSP
(一对一)签名更改:
driving_side
参数从已命名的可选参数改为未命名的必选参数 driving side。增加
start_vid
和end_vid
结果列。
新的重载函数
pgr_withPointsKSP
(一对多)pgr_withPointsKSP
(多对一)pgr_withPointsKSP
(多对多)pgr_withPointsKSP
(组合)
已弃用的签名
pgr_withpointsksp(text,text,bigint,bigint,integer,boolean,boolean,char,boolean)
版本 2.2.0
新 拟议 函数
描述¶
修改图以包括 Points SQL 中定义的点并使用 Yen 算法查找 \(K\) 最短路径。
签名¶
[directed, heap_paths, details]
(seq, path_id, path_seq, node, edge, cost, agg_cost)
的集合一对一¶
[directed, heap_paths, details]
(seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
在具有 左侧 驾驶的有向图上,从点 \(1\) 到点 \(2\) 获取两条路径。
有向图。
没有给出有关查询的其他点的距离的详细信息。
不返回堆路径。
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, 'l');
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | -2 | -1 | 1 | 0.6 | 0
2 | 1 | 2 | -1 | -2 | 6 | 4 | 1 | 0.6
3 | 1 | 3 | -1 | -2 | 7 | 8 | 1 | 1.6
4 | 1 | 4 | -1 | -2 | 11 | 11 | 1 | 2.6
5 | 1 | 5 | -1 | -2 | 12 | 13 | 1 | 3.6
6 | 1 | 6 | -1 | -2 | 17 | 15 | 0.6 | 4.6
7 | 1 | 7 | -1 | -2 | -2 | -1 | 0 | 5.2
8 | 2 | 1 | -1 | -2 | -1 | 1 | 0.6 | 0
9 | 2 | 2 | -1 | -2 | 6 | 4 | 1 | 0.6
10 | 2 | 3 | -1 | -2 | 7 | 8 | 1 | 1.6
11 | 2 | 4 | -1 | -2 | 11 | 9 | 1 | 2.6
12 | 2 | 5 | -1 | -2 | 16 | 15 | 1.6 | 3.6
13 | 2 | 6 | -1 | -2 | -2 | -1 | 0 | 5.2
(13 rows)
一对多¶
[directed, heap_paths, details]
(seq, path_id, path_seq, node, edge, cost, agg_cost)
的集合- 示例:
在无向图上从点 \(1\) 到点 \(3\) 和顶点 \(7\) 获取两条路径
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, ARRAY[-3, 7], 2, 'B',
directed => false);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0
2 | 1 | 2 | -1 | -3 | 6 | 4 | 1 | 0.6
3 | 1 | 3 | -1 | -3 | 7 | 10 | 1 | 1.6
4 | 1 | 4 | -1 | -3 | 8 | 12 | 0.6 | 2.6
5 | 1 | 5 | -1 | -3 | -3 | -1 | 0 | 3.2
6 | 2 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0
7 | 2 | 2 | -1 | -3 | 6 | 4 | 1 | 0.6
8 | 2 | 3 | -1 | -3 | 7 | 8 | 1 | 1.6
9 | 2 | 4 | -1 | -3 | 11 | 11 | 1 | 2.6
10 | 2 | 5 | -1 | -3 | 12 | 12 | 0.4 | 3.6
11 | 2 | 6 | -1 | -3 | -3 | -1 | 0 | 4
12 | 3 | 1 | -1 | 7 | -1 | 1 | 0.6 | 0
13 | 3 | 2 | -1 | 7 | 6 | 4 | 1 | 0.6
14 | 3 | 3 | -1 | 7 | 7 | -1 | 0 | 1.6
15 | 4 | 1 | -1 | 7 | -1 | 1 | 0.6 | 0
16 | 4 | 2 | -1 | 7 | 6 | 2 | 1 | 0.6
17 | 4 | 3 | -1 | 7 | 10 | 5 | 1 | 1.6
18 | 4 | 4 | -1 | 7 | 11 | 8 | 1 | 2.6
19 | 4 | 5 | -1 | 7 | 7 | -1 | 0 | 3.6
(19 rows)
多对一¶
[directed, heap_paths, details]
(seq, path_id, path_seq, node, edge, cost, agg_cost)
的集合- 示例:
在具有 右侧 驾驶的 有向 图上,从点 \(1\) 和顶点 \(6\) 到点 \(3\) 获取一条路径,且 details 设置为 True
SELECT * FROM pgr_withPointsKSP(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[-1, 6], -3, 1, 'r', details=> true);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | -3 | -1 | 1 | 0.4 | 0
2 | 1 | 2 | -1 | -3 | 5 | 1 | 1 | 0.4
3 | 1 | 3 | -1 | -3 | 6 | 4 | 0.7 | 1.4
4 | 1 | 4 | -1 | -3 | -6 | 4 | 0.3 | 2.1
5 | 1 | 5 | -1 | -3 | 7 | 10 | 1 | 2.4
6 | 1 | 6 | -1 | -3 | 8 | 12 | 0.6 | 3.4
7 | 1 | 7 | -1 | -3 | -3 | -1 | 0 | 4
8 | 2 | 1 | 6 | -3 | 6 | 4 | 0.7 | 0
9 | 2 | 2 | 6 | -3 | -6 | 4 | 0.3 | 0.7
10 | 2 | 3 | 6 | -3 | 7 | 10 | 1 | 1
11 | 2 | 4 | 6 | -3 | 8 | 12 | 0.6 | 2
12 | 2 | 5 | 6 | -3 | -3 | -1 | 0 | 2.6
(12 rows)
多对多¶
[directed, heap_paths, details]
(seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
在具有 左侧 驾驶的 有向 图上,从点 \(1\) 和顶点 \(6\) 到点 \(3\) 和顶点 \(1\) 获取一条路径,且 heap_paths 设置为 True
SELECT * FROM pgr_withPointsKSP(
'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], 1, 'l', heap_paths => true);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0
2 | 1 | 2 | -1 | -3 | 6 | 4 | 1 | 0.6
3 | 1 | 3 | -1 | -3 | 7 | 10 | 1 | 1.6
4 | 1 | 4 | -1 | -3 | 8 | 12 | 0.6 | 2.6
5 | 1 | 5 | -1 | -3 | -3 | -1 | 0 | 3.2
6 | 2 | 1 | -1 | 1 | -1 | 1 | 0.6 | 0
7 | 2 | 2 | -1 | 1 | 6 | 4 | 1 | 0.6
8 | 2 | 3 | -1 | 1 | 7 | 7 | 1 | 1.6
9 | 2 | 4 | -1 | 1 | 3 | 6 | 1 | 2.6
10 | 2 | 5 | -1 | 1 | 1 | -1 | 0 | 3.6
11 | 3 | 1 | 6 | -3 | 6 | 4 | 1 | 0
12 | 3 | 2 | 6 | -3 | 7 | 10 | 1 | 1
13 | 3 | 3 | 6 | -3 | 8 | 12 | 0.6 | 2
14 | 3 | 4 | 6 | -3 | -3 | -1 | 0 | 2.6
15 | 4 | 1 | 6 | 1 | 6 | 4 | 1 | 0
16 | 4 | 2 | 6 | 1 | 7 | 7 | 1 | 1
17 | 4 | 3 | 6 | 1 | 3 | 6 | 1 | 2
18 | 4 | 4 | 6 | 1 | 1 | -1 | 0 | 3
(18 rows)
组合¶
[directed, heap_paths, details]
(seq, path_id, path_seq, node, edge, cost, agg_cost)
的集合- 示例:
在 有向 图上使用组合表
SELECT * FROM pgr_withPointsKSP(
'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)',
2, 'r', details => true);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | 10 | -1 | 1 | 0.4 | 0
2 | 1 | 2 | -1 | 10 | 5 | 1 | 1 | 0.4
3 | 1 | 3 | -1 | 10 | 6 | 4 | 0.7 | 1.4
4 | 1 | 4 | -1 | 10 | -6 | 4 | 0.3 | 2.1
5 | 1 | 5 | -1 | 10 | 7 | 8 | 1 | 2.4
6 | 1 | 6 | -1 | 10 | 11 | 9 | 1 | 3.4
7 | 1 | 7 | -1 | 10 | 16 | 16 | 1 | 4.4
8 | 1 | 8 | -1 | 10 | 15 | 3 | 1 | 5.4
9 | 1 | 9 | -1 | 10 | 10 | -1 | 0 | 6.4
10 | 2 | 1 | -1 | 10 | -1 | 1 | 0.4 | 0
11 | 2 | 2 | -1 | 10 | 5 | 1 | 1 | 0.4
12 | 2 | 3 | -1 | 10 | 6 | 4 | 0.7 | 1.4
13 | 2 | 4 | -1 | 10 | -6 | 4 | 0.3 | 2.1
14 | 2 | 5 | -1 | 10 | 7 | 8 | 1 | 2.4
15 | 2 | 6 | -1 | 10 | 11 | 11 | 1 | 3.4
16 | 2 | 7 | -1 | 10 | 12 | 13 | 1 | 4.4
17 | 2 | 8 | -1 | 10 | 17 | 15 | 1 | 5.4
18 | 2 | 9 | -1 | 10 | 16 | 16 | 1 | 6.4
19 | 2 | 10 | -1 | 10 | 15 | 3 | 1 | 7.4
20 | 2 | 11 | -1 | 10 | 10 | -1 | 0 | 8.4
21 | 3 | 1 | 6 | -3 | 6 | 4 | 0.7 | 0
22 | 3 | 2 | 6 | -3 | -6 | 4 | 0.3 | 0.7
23 | 3 | 3 | 6 | -3 | 7 | 10 | 1 | 1
24 | 3 | 4 | 6 | -3 | 8 | 12 | 0.6 | 2
25 | 3 | 5 | 6 | -3 | -3 | -1 | 0 | 2.6
(25 rows)
参数¶
列 |
类型 |
描述 |
---|---|---|
|
Edges SQL 按描述查询。 |
|
|
按照描述的方式执行 Points SQL 查询。 |
|
start vid |
ANY-INTEGER |
出发顶点的标识符。
|
end vid |
ANY-INTEGER |
目标顶点的标识符。
|
K |
ANY-INTEGER |
所需路径的数量 |
driving_side |
CHAR |
值在 [
|
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
可选参数¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
KSP 可选参数¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
withPointsKSP可选参数¶
参数 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
内部查询¶
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
结果列¶
返回集合 (seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
列 |
类型 |
描述 |
---|---|---|
|
|
从 1 开始的顺序值。 |
|
|
路径标识符。
|
|
|
路径中的相对位置。 路径开头的值为 1。 |
|
|
从 |
|
|
用于从路径序列中的 |
|
|
从使用
|
|
|
从 start vid 到 |
其他示例¶
在 Points SQL 中使用 pgr_findCloseEdges。¶
使用左侧驾驶拓扑,从顶点 \(1\) 到离点 (2.9, 1.8) 最近的位置获取 \(2\) 条路径。
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,'r');
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | 1 | -1 | 1 | 6 | 1 | 0
2 | 1 | 2 | 1 | -1 | 3 | 7 | 1 | 1
3 | 1 | 3 | 1 | -1 | 7 | 8 | 1 | 2
4 | 1 | 4 | 1 | -1 | 11 | 9 | 1 | 3
5 | 1 | 5 | 1 | -1 | 16 | 16 | 1 | 4
6 | 1 | 6 | 1 | -1 | 15 | 3 | 1 | 5
7 | 1 | 7 | 1 | -1 | 10 | 5 | 0.8 | 6
8 | 1 | 8 | 1 | -1 | -1 | -1 | 0 | 6.8
9 | 2 | 1 | 1 | -1 | 1 | 6 | 1 | 0
10 | 2 | 2 | 1 | -1 | 3 | 7 | 1 | 1
11 | 2 | 3 | 1 | -1 | 7 | 10 | 1 | 2
12 | 2 | 4 | 1 | -1 | 8 | 12 | 1 | 3
13 | 2 | 5 | 1 | -1 | 12 | 13 | 1 | 4
14 | 2 | 6 | 1 | -1 | 17 | 15 | 1 | 5
15 | 2 | 7 | 1 | -1 | 16 | 16 | 1 | 6
16 | 2 | 8 | 1 | -1 | 15 | 3 | 1 | 7
17 | 2 | 9 | 1 | -1 | 10 | 5 | 0.8 | 8
18 | 2 | 10 | 1 | -1 | -1 | -1 | 0 | 8.8
(18 rows)
点 \(-1`对应于距离点`(2.9, 1.8)\) 最近的边。
左驾驶侧¶
使用左侧驾驶拓扑,从点 \(1\) 到点 \(3\) 获取 \(2\) 条路径,并包含详细信息。
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, -3, 2, 'l', details => true);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0
2 | 1 | 2 | -1 | -3 | 6 | 4 | 0.7 | 0.6
3 | 1 | 3 | -1 | -3 | -6 | 4 | 0.3 | 1.3
4 | 1 | 4 | -1 | -3 | 7 | 10 | 1 | 1.6
5 | 1 | 5 | -1 | -3 | 8 | 12 | 0.6 | 2.6
6 | 1 | 6 | -1 | -3 | -3 | -1 | 0 | 3.2
(6 rows)
右驾驶侧¶
使用右侧驾驶拓扑,从点 \(1\) 到点 \(2\) 获取 \(2\) 条路径,同时使用堆路径(heap paths)并包含详细信息。
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, 'r',
heap_paths => true, details => true);
seq | path_id | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+---------+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -1 | -2 | -1 | 1 | 0.4 | 0
2 | 1 | 2 | -1 | -2 | 5 | 1 | 1 | 0.4
3 | 1 | 3 | -1 | -2 | 6 | 4 | 0.7 | 1.4
4 | 1 | 4 | -1 | -2 | -6 | 4 | 0.3 | 2.1
5 | 1 | 5 | -1 | -2 | 7 | 8 | 1 | 2.4
6 | 1 | 6 | -1 | -2 | 11 | 9 | 1 | 3.4
7 | 1 | 7 | -1 | -2 | 16 | 15 | 0.4 | 4.4
8 | 1 | 8 | -1 | -2 | -2 | -1 | 0 | 4.8
9 | 2 | 1 | -1 | -2 | -1 | 1 | 0.4 | 0
10 | 2 | 2 | -1 | -2 | 5 | 1 | 1 | 0.4
11 | 2 | 3 | -1 | -2 | 6 | 4 | 0.7 | 1.4
12 | 2 | 4 | -1 | -2 | -6 | 4 | 0.3 | 2.1
13 | 2 | 5 | -1 | -2 | 7 | 8 | 1 | 2.4
14 | 2 | 6 | -1 | -2 | 11 | 11 | 1 | 3.4
15 | 2 | 7 | -1 | -2 | 12 | 13 | 1 | 4.4
16 | 2 | 8 | -1 | -2 | 17 | 15 | 1 | 5.4
17 | 2 | 9 | -1 | -2 | 16 | 15 | 0.4 | 6.4
18 | 2 | 10 | -1 | -2 | -2 | -1 | 0 | 6.8
19 | 3 | 1 | -1 | -2 | -1 | 1 | 0.4 | 0
20 | 3 | 2 | -1 | -2 | 5 | 1 | 1 | 0.4
21 | 3 | 3 | -1 | -2 | 6 | 4 | 0.7 | 1.4
22 | 3 | 4 | -1 | -2 | -6 | 4 | 0.3 | 2.1
23 | 3 | 5 | -1 | -2 | 7 | 10 | 1 | 2.4
24 | 3 | 6 | -1 | -2 | 8 | 12 | 0.6 | 3.4
25 | 3 | 7 | -1 | -2 | -3 | 12 | 0.4 | 4
26 | 3 | 8 | -1 | -2 | 12 | 13 | 1 | 4.4
27 | 3 | 9 | -1 | -2 | 17 | 15 | 1 | 5.4
28 | 3 | 10 | -1 | -2 | 16 | 15 | 0.4 | 6.4
29 | 3 | 11 | -1 | -2 | -2 | -1 | 0 | 6.8
(29 rows)
查询使用 示例数据 网络。
另请参阅¶
索引和表格