pgr_trsp_withPoints
¶
pgr_trsp_withPoints
有限制的路由顶点/点。
可用性
Version 4.0.0
函数正式发布。
Driving side parameter is positional unnamed and compulsory.
Valid values depend on kind of graph
Breaking change, signatures no longer available:
pgr_trsp_withpoints(text,text,text,anyarray,anyarray,boolean,character,boolean)
pgr_trsp_withpoints(text,text,text,anyarray,bigint,boolean,character,boolean)
pgr_trsp_withpoints(text,text,text,bigint,anyarray,boolean,character,boolean)
pgr_trsp_withpoints(text,text,text,bigint,bigint,boolean,character,boolean)
pgr_trsp_withpoints(text,text,text,text,boolean,character,boolean)
版本 3.4.0
新提议的函数。
描述¶
Modify the graph to include points defined by Points SQL. Consider the invalid paths on Restrictions SQL. Using Dijkstra algorithm, find the shortest path.
主要特点是:
仅在具有正成本的边进行处理。
图的顶点是:
当它属于 Edges SQL 时为 正
当它属于 Points SQL 为 负
当存在路径时返回值。
当起始顶点和结束顶点相同时,就没有路径。
非包含值 (v, v) 中的 agg_cost 为 0
当起始顶点和结束顶点不同且不存在路径时:
非包含值 (u, v) 中的 agg_cost 为
For optimization purposes, any duplicated value in the input arrays of start vids or end vids or are ignored.
返回值是有序的:
start_vid 升序
end_vid 升序
运行时间:
签名¶
总结
[directed, driving_side, details]
(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
One to One¶
[directed, driving_side, details]
(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
From point
to vertex with right driving side in directed graph. (with details)
SELECT * FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
-1, 10, 'r');
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | -1 | 10 | -1 | 1 | 1.4 | 0
2 | 2 | -1 | 10 | 6 | 4 | 1 | 1.4
3 | 3 | -1 | 10 | 7 | 10 | 1 | 2.4
4 | 4 | -1 | 10 | 8 | 12 | 1 | 3.4
5 | 5 | -1 | 10 | 12 | 13 | 1 | 4.4
6 | 6 | -1 | 10 | 17 | 15 | 1 | 5.4
7 | 7 | -1 | 10 | 16 | 16 | 1 | 6.4
8 | 8 | -1 | 10 | 15 | 3 | 1 | 7.4
9 | 9 | -1 | 10 | 10 | -1 | 0 | 8.4
(9 rows)
一对多¶
[directed, details]
(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
无向图上的点
到点 和顶点
SELECT * FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
-1, ARRAY[-3, 7], 'B', directed => false);
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0
2 | 2 | -1 | -3 | 6 | 4 | 1 | 0.6
3 | 3 | -1 | -3 | 7 | 10 | 1 | 1.6
4 | 4 | -1 | -3 | 8 | 12 | 0.6 | 2.6
5 | 5 | -1 | -3 | -3 | -1 | 0 | 3.2
6 | 1 | -1 | 7 | -1 | 1 | 0.6 | 0
7 | 2 | -1 | 7 | 6 | 4 | 1 | 0.6
8 | 3 | -1 | 7 | 7 | -1 | 0 | 1.6
(8 rows)
Many to One¶
[directed, driving_side, details]
(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
From point
and vertex to point with right driving side in directed graph. (without details)
SELECT * FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
ARRAY[-1, 6], -3, 'R');
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | -1 | -3 | -1 | 1 | 1.4 | 0
2 | 2 | -1 | -3 | 6 | 4 | 1 | 1.4
3 | 3 | -1 | -3 | 7 | 10 | 1 | 2.4
4 | 4 | -1 | -3 | 8 | 12 | 0.6 | 3.4
5 | 5 | -1 | -3 | -3 | -1 | 0 | 4
6 | 1 | 6 | -3 | 6 | 4 | 1 | 0
7 | 2 | 6 | -3 | 7 | 10 | 1 | 1
8 | 3 | 6 | -3 | 8 | 12 | 0.6 | 2
9 | 4 | 6 | -3 | -3 | -1 | 0 | 2.6
(9 rows)
Many to Many¶
[directed, driving_side, details]
(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
From point
and vertex to point and vertex with left side driving.
SELECT * FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
ARRAY[-1, 6], ARRAY[-3, 1], 'L');
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | -1 | -3 | -1 | 1 | 0.6 | 0
2 | 2 | -1 | -3 | 6 | 4 | 1 | 0.6
3 | 3 | -1 | -3 | 7 | 10 | 1 | 1.6
4 | 4 | -1 | -3 | 8 | 12 | 0.6 | 2.6
5 | 5 | -1 | -3 | -3 | -1 | 0 | 3.2
6 | 1 | -1 | 1 | -1 | 1 | 0.6 | 0
7 | 2 | -1 | 1 | 6 | 4 | 1 | 0.6
8 | 3 | -1 | 1 | 7 | 10 | 1 | 1.6
9 | 4 | -1 | 1 | 8 | 12 | 1 | 2.6
10 | 5 | -1 | 1 | 12 | 13 | 1 | 3.6
11 | 6 | -1 | 1 | 17 | 15 | 1 | 4.6
12 | 7 | -1 | 1 | 16 | 9 | 1 | 5.6
13 | 8 | -1 | 1 | 11 | 8 | 1 | 6.6
14 | 9 | -1 | 1 | 7 | 7 | 1 | 7.6
15 | 10 | -1 | 1 | 3 | 6 | 1 | 8.6
16 | 11 | -1 | 1 | 1 | -1 | 0 | 9.6
17 | 1 | 6 | -3 | 6 | 4 | 1 | 0
18 | 2 | 6 | -3 | 7 | 10 | 1 | 1
19 | 3 | 6 | -3 | 8 | 12 | 0.6 | 2
20 | 4 | 6 | -3 | -3 | -1 | 0 | 2.6
21 | 1 | 6 | 1 | 6 | 4 | 1 | 0
22 | 2 | 6 | 1 | 7 | 10 | 1 | 1
23 | 3 | 6 | 1 | 8 | 12 | 1 | 2
24 | 4 | 6 | 1 | 12 | 13 | 1 | 3
25 | 5 | 6 | 1 | 17 | 15 | 1 | 4
26 | 6 | 6 | 1 | 16 | 9 | 1 | 5
27 | 7 | 6 | 1 | 11 | 8 | 1 | 6
28 | 8 | 6 | 1 | 7 | 7 | 1 | 7
29 | 9 | 6 | 1 | 3 | 6 | 1 | 8
30 | 10 | 6 | 1 | 1 | -1 | 0 | 9
(30 rows)
组合¶
[directed, driving_side, details]
(seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
- 示例:
两种组合
From point
SELECT * FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
'SELECT * FROM (VALUES (-1, 10), (6, -3)) AS combinations(source, target)',
'r', details => true);
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | -1 | 10 | -1 | 1 | 0.4 | 0
2 | 2 | -1 | 10 | 5 | 1 | 1 | 0.4
3 | 3 | -1 | 10 | 6 | 4 | 0.7 | 1.4
4 | 4 | -1 | 10 | -6 | 4 | 0.3 | 2.1
5 | 5 | -1 | 10 | 7 | 10 | 1 | 2.4
6 | 6 | -1 | 10 | 8 | 12 | 0.6 | 3.4
7 | 7 | -1 | 10 | -3 | 12 | 0.4 | 4
8 | 8 | -1 | 10 | 12 | 13 | 1 | 4.4
9 | 9 | -1 | 10 | 17 | 15 | 1 | 5.4
10 | 10 | -1 | 10 | 16 | 16 | 1 | 6.4
11 | 11 | -1 | 10 | 15 | 3 | 1 | 7.4
12 | 12 | -1 | 10 | 10 | -1 | 0 | 8.4
13 | 1 | 6 | -3 | 6 | 4 | 0.7 | 0
14 | 2 | 6 | -3 | -6 | 4 | 0.3 | 0.7
15 | 3 | 6 | -3 | 7 | 10 | 1 | 1
16 | 4 | 6 | -3 | 8 | 12 | 0.6 | 2
17 | 5 | 6 | -3 | -3 | -1 | 0 | 2.6
(17 rows)
参数¶
列 |
类型 |
描述 |
---|---|---|
|
如所述的 SQL 查询。 |
|
|
如所述的 SQL 查询。 |
|
|
Combinations SQL 如下所述 |
|
start vid |
ANY-INTEGER |
出发顶点的标识符。 |
start vids |
|
目标顶点的标识符数组。 |
end vid |
ANY-INTEGER |
出发顶点的标识符。 |
end vids |
|
目标顶点的标识符数组。 |
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
可选参数¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
带点可选参数¶
参数 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
For showing points stops.
|
内部查询¶
Edges SQL¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
ANY-INTEGER |
边的标识符。 |
|
|
ANY-INTEGER |
边的第一个端点顶点的标识符。 |
|
|
ANY-INTEGER |
边的第二个端点顶点的标识符。 |
|
|
ANY-NUMERICAL |
edge ( |
|
|
ANY-NUMERICAL |
-1 |
边(
|
其中:
- ANY-INTEGER:
SMALLINT
,INTEGER
,BIGINT
- ANY-NUMERICAL:
SMALLINT
,INTEGER
,BIGINT
,REAL
,FLOAT
Restrictions SQL¶
列 |
类型 |
描述 |
---|---|---|
|
|
形成不允许采用的路径的边缘标识符序列。 - 空数组或 |
|
ANY-NUMERICAL |
走禁路的成本。 |
其中:
- 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
结果列¶
Returns (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
列 |
类型 |
描述 |
---|---|---|
|
|
从 1 开始的顺序值。 |
|
|
路径中的相对位置。 路径开头的值为 1 。 |
|
|
当前路径起始顶点的标识符。 |
|
|
当前路径结束顶点的标识符。 |
|
|
从 |
|
|
用于从路径序列中的 |
|
|
从使用 |
|
|
从 |
其他示例¶
在 Points SQL 中使用 pgr_findCloseEdges 。¶
找到从顶点
SELECT * FROM pgr_trsp_withPoints(
$e$ SELECT * FROM edges $e$,
$r$ SELECT id, 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$,
1, ARRAY[-1, -2], 'B', false);
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | 1 | -2 | 1 | 6 | 1 | 0
2 | 2 | 1 | -2 | 3 | 7 | 1 | 1
3 | 3 | 1 | -2 | 7 | 8 | 0.9 | 2
4 | 4 | 1 | -2 | -2 | -1 | 0 | 2.9
5 | 1 | 1 | -1 | 1 | 6 | 1 | 0
6 | 2 | 1 | -1 | 3 | 7 | 1 | 1
7 | 3 | 1 | -1 | 7 | 8 | 1 | 2
8 | 4 | 1 | -1 | 11 | 5 | 0.2 | 3
9 | 5 | 1 | -1 | -1 | -1 | 0 | 3.2
(9 rows)
点
最近的边。点
的下一个闭合边。
用法变化¶
All the examples are about traveling from point
SELECT * FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side from pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11],
'r', details => true);
seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost
-----+----------+-----------+---------+------+------+------+----------
1 | 1 | -1 | -6 | -1 | 1 | 0.4 | 0
2 | 2 | -1 | -6 | 5 | 1 | 1 | 0.4
3 | 3 | -1 | -6 | 6 | 4 | 0.7 | 1.4
4 | 4 | -1 | -6 | -6 | -1 | 0 | 2.1
5 | 1 | -1 | -3 | -1 | 1 | 0.4 | 0
6 | 2 | -1 | -3 | 5 | 1 | 1 | 0.4
7 | 3 | -1 | -3 | 6 | 4 | 0.7 | 1.4
8 | 4 | -1 | -3 | -6 | 4 | 0.3 | 2.1
9 | 5 | -1 | -3 | 7 | 10 | 1 | 2.4
10 | 6 | -1 | -3 | 8 | 12 | 0.6 | 3.4
11 | 7 | -1 | -3 | -3 | -1 | 0 | 4
12 | 1 | -1 | -2 | -1 | 1 | 0.4 | 0
13 | 2 | -1 | -2 | 5 | 1 | 1 | 0.4
14 | 3 | -1 | -2 | 6 | 4 | 0.7 | 1.4
15 | 4 | -1 | -2 | -6 | 4 | 0.3 | 2.1
16 | 5 | -1 | -2 | 7 | 8 | 1 | 2.4
17 | 6 | -1 | -2 | 11 | 9 | 1 | 3.4
18 | 7 | -1 | -2 | 16 | 15 | 0.4 | 4.4
19 | 8 | -1 | -2 | -2 | -1 | 0 | 4.8
20 | 1 | -1 | 10 | -1 | 1 | 0.4 | 0
21 | 2 | -1 | 10 | 5 | 1 | 1 | 0.4
22 | 3 | -1 | 10 | 6 | 4 | 0.7 | 1.4
23 | 4 | -1 | 10 | -6 | 4 | 0.3 | 2.1
24 | 5 | -1 | 10 | 7 | 10 | 1 | 2.4
25 | 6 | -1 | 10 | 8 | 12 | 0.6 | 3.4
26 | 7 | -1 | 10 | -3 | 12 | 0.4 | 4
27 | 8 | -1 | 10 | 12 | 13 | 1 | 4.4
28 | 9 | -1 | 10 | 17 | 15 | 1 | 5.4
29 | 10 | -1 | 10 | 16 | 16 | 1 | 6.4
30 | 11 | -1 | 10 | 15 | 3 | 1 | 7.4
31 | 12 | -1 | 10 | 10 | -1 | 0 | 8.4
32 | 1 | -1 | 11 | -1 | 1 | 0.4 | 0
33 | 2 | -1 | 11 | 5 | 1 | 1 | 0.4
34 | 3 | -1 | 11 | 6 | 4 | 0.7 | 1.4
35 | 4 | -1 | 11 | -6 | 4 | 0.3 | 2.1
36 | 5 | -1 | 11 | 7 | 8 | 1 | 2.4
37 | 6 | -1 | 11 | 11 | -1 | 0 | 3.4
38 | 1 | 5 | -6 | 5 | 1 | 1 | 0
39 | 2 | 5 | -6 | 6 | 4 | 0.7 | 1
40 | 3 | 5 | -6 | -6 | -1 | 0 | 1.7
41 | 1 | 5 | -3 | 5 | 1 | 1 | 0
42 | 2 | 5 | -3 | 6 | 4 | 0.7 | 1
43 | 3 | 5 | -3 | -6 | 4 | 0.3 | 1.7
44 | 4 | 5 | -3 | 7 | 10 | 1 | 2
45 | 5 | 5 | -3 | 8 | 12 | 0.6 | 3
46 | 6 | 5 | -3 | -3 | -1 | 0 | 3.6
47 | 1 | 5 | -2 | 5 | 1 | 1 | 0
48 | 2 | 5 | -2 | 6 | 4 | 0.7 | 1
49 | 3 | 5 | -2 | -6 | 4 | 0.3 | 1.7
50 | 4 | 5 | -2 | 7 | 8 | 1 | 2
51 | 5 | 5 | -2 | 11 | 9 | 1 | 3
52 | 6 | 5 | -2 | 16 | 15 | 0.4 | 4
53 | 7 | 5 | -2 | -2 | -1 | 0 | 4.4
54 | 1 | 5 | 10 | 5 | 1 | 1 | 0
55 | 2 | 5 | 10 | 6 | 4 | 0.7 | 1
56 | 3 | 5 | 10 | -6 | 4 | 0.3 | 1.7
57 | 4 | 5 | 10 | 7 | 10 | 1 | 2
58 | 5 | 5 | 10 | 8 | 12 | 0.6 | 3
59 | 6 | 5 | 10 | -3 | 12 | 0.4 | 3.6
60 | 7 | 5 | 10 | 12 | 13 | 1 | 4
61 | 8 | 5 | 10 | 17 | 15 | 1 | 5
62 | 9 | 5 | 10 | 16 | 16 | 1 | 6
63 | 10 | 5 | 10 | 15 | 3 | 1 | 7
64 | 11 | 5 | 10 | 10 | -1 | 0 | 8
65 | 1 | 5 | 11 | 5 | 1 | 1 | 0
66 | 2 | 5 | 11 | 6 | 4 | 0.7 | 1
67 | 3 | 5 | 11 | -6 | 4 | 0.3 | 1.7
68 | 4 | 5 | 11 | 7 | 8 | 1 | 2
69 | 5 | 5 | 11 | 11 | -1 | 0 | 3
(69 rows)
从前方超车或右侧行驶来访。¶
对于点
SELECT (start_vid || ' -> ' || end_vid ||' at ' || path_seq || 'th step:')::TEXT AS path_at,
CASE WHEN edge = -1 THEN ' visits'
ELSE ' passes in front of'
END as status,
CASE WHEN node < 0 THEN 'Point'
ELSE 'Vertex'
END as is_a,
abs(node) as id
FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
ARRAY[5, -1], ARRAY[-6, -3, -6, 10, 11], 'r', details => true)
WHERE node IN (-6, 11);
path_at | status | is_a | id
-----------------------+---------------------+--------+----
-1 -> -6 at 4th step: | visits | Point | 6
-1 -> -3 at 4th step: | passes in front of | Point | 6
-1 -> 10 at 4th step: | passes in front of | Point | 6
-1 -> 11 at 4th step: | passes in front of | Point | 6
-1 -> 11 at 6th step: | visits | Vertex | 11
5 -> -6 at 3th step: | visits | Point | 6
5 -> -3 at 3th step: | passes in front of | Point | 6
5 -> 10 at 3th step: | passes in front of | Point | 6
5 -> 11 at 3th step: | passes in front of | Point | 6
5 -> 11 at 5th step: | visits | Vertex | 11
(10 rows)
从前方超车或以左侧驾驶方式行驶。¶
对于点
SELECT (start_vid || ' => ' || end_vid ||' at ' || path_seq || 'th step')::TEXT AS path_at,
CASE WHEN edge = -1 THEN ' visits'
ELSE ' passes in front of'
END as status,
CASE WHEN node < 0 THEN 'Point'
ELSE 'Vertex'
END as is_a,
abs(node) as id
FROM pgr_trsp_withPoints(
'SELECT id, source, target, cost, reverse_cost FROM edges ORDER BY id',
'SELECT id, path, cost FROM restrictions',
'SELECT pid, edge_id, fraction, side FROM pointsOfInterest',
ARRAY[5, -1], ARRAY[-2, -3, -6, 10, 11], 'l', details => true)
WHERE node IN (-6, 11);
path_at | status | is_a | id
----------------------+---------------------+--------+----
-1 => -6 at 3th step | visits | Point | 6
-1 => -3 at 3th step | passes in front of | Point | 6
-1 => -2 at 3th step | passes in front of | Point | 6
-1 => -2 at 5th step | passes in front of | Vertex | 11
-1 => 10 at 3th step | passes in front of | Point | 6
-1 => 11 at 3th step | passes in front of | Point | 6
-1 => 11 at 5th step | visits | Vertex | 11
5 => -6 at 4th step | visits | Point | 6
5 => -3 at 4th step | passes in front of | Point | 6
5 => -2 at 4th step | passes in front of | Point | 6
5 => -2 at 6th step | passes in front of | Vertex | 11
5 => 10 at 4th step | passes in front of | Point | 6
5 => 11 at 4th step | passes in front of | Point | 6
5 => 11 at 6th step | visits | Vertex | 11
(14 rows)
另请参阅¶
索引和表格