pgr_trsp_withPoints - 拟议

pgr_trsp_withPoints 有限制的路由顶点/点。

_images/boost-inside.jpeg

Boost 图内部

Warning

下一版本的拟议功能。

  • 它们并未正式出现在当前版本中。

  • 它们可能会正式成为下一个版本的一部分:

    • 这些函数使用 ANY-INTEGER 和 ANY-NUMERICAL

    • 名字可能不会改变。(但仍然有可能改变)

    • 签名可能不会改变。(但仍然有可能改变)

    • 功能可能不会改变。(但仍然有可能改变)

    • pgTap 测试已经完成。 但可能需要更多。

    • 文档可能需要完善。

可用性

描述

Modify the graph to include points defined by points_sql. Using Dijkstra algorithm, find the shortest path

特征:

  • 图的顶点是:

  • 驾驶侧不可能为 b

  • 当存在路径时返回值。

    • 当起始顶点和结束顶点相同时,就没有路径。

      • 不包含的值 (v, v) 的 agg_cost 为 0

    • 当起始顶点和结束顶点不同且不存在路径时:

      • 不包含的值 (u, v) 的 agg_cost 为 ∞

  • 出于优化目的,start_vid 或 end_vid 中的任何重复值都将被忽略。

  • 返回值按以下顺序排列: - start_vid 升序 - end_vid 升序

  • 运行时间: \(O(|start\_vids|\times(V \log V + E))\)

签名

总结

pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vid, end vid, [options])
pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vid, end vids, [options])
pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vids, end vid, [options])
pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vids, end vids, [options])
pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Combinations SQL, Points SQL, [options])
options: [directed, driving_side, details]
Returns set of (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET

一对一

pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vid, end vid, [options])
options: [directed, driving_side, details]
Returns set of (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET
示例:

从点 \(1\) 到顶点 \(10\),在有向图上显示左侧驾驶侧配置的详细信息。

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,
  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
(12 rows)

一对多

pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vid, end vids, [options])
options: [directed, driving_side, details]
Returns set of (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET
示例:

从点 \(1\) 到点 \(3\) 和顶点 \(7\)

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]);
 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 |        -1 |       7 |   -1 |    1 |  1.4 |        0
   7 |        2 |        -1 |       7 |    6 |    4 |    1 |      1.4
   8 |        3 |        -1 |       7 |    7 |   -1 |    0 |      2.4
(8 rows)

多对一

pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vids, end vid, [options])
options: [directed, driving_side, details]
Returns set of (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET
示例:

从点 \(1\) 和顶点 \(6\) 到点 \(3\)

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);
 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)

多对多

pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Points SQL, start vids, end vids, [options])
options: [directed, driving_side, details]
Returns set of (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET
示例:

从点 \(1\) 和顶点 \(6\) 到点 \(3\) 和顶点 \(1\)

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]);
 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 |        -1 |       1 |   -1 |    1 |  1.4 |        0
   7 |        2 |        -1 |       1 |    6 |    4 |    1 |      1.4
   8 |        3 |        -1 |       1 |    7 |   10 |    1 |      2.4
   9 |        4 |        -1 |       1 |    8 |   12 |    1 |      3.4
  10 |        5 |        -1 |       1 |   12 |   13 |    1 |      4.4
  11 |        6 |        -1 |       1 |   17 |   15 |    1 |      5.4
  12 |        7 |        -1 |       1 |   16 |    9 |    1 |      6.4
  13 |        8 |        -1 |       1 |   11 |    8 |    1 |      7.4
  14 |        9 |        -1 |       1 |    7 |    7 |    1 |      8.4
  15 |       10 |        -1 |       1 |    3 |    6 |    1 |      9.4
  16 |       11 |        -1 |       1 |    1 |   -1 |    0 |     10.4
  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)

组合

pgr_trsp_withPoints(Edges SQL, Restrictions SQL, Combinations SQL, Points SQL, [options])
options: [directed, driving_side, details]
Returns set of (seq, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)
OR EMPTY SET
示例:

从点 \(1\) 到顶点 \(10`以及从顶点 :math:`6`到点 :math:`3\),采用右侧驾驶配置。

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 t(source, target)$$,
  driving_side => '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)

参数

类型

描述

Edges SQL

TEXT

如所述的 SQL 查询。

Restrictions SQL

TEXT

如所述的 SQL 查询。

Combinations SQL

TEXT

Combinations SQL 如下所述

start vid

ANY-INTEGER

出发顶点的标识符。

start vids

ARRAY [ANY-INTEGER]

目标顶点的标识符数组。

end vid

ANY-INTEGER

出发顶点的标识符。

end vids

ARRAY [ANY-INTEGER]

目标顶点的标识符数组。

其中:

ANY-INTEGER:

SMALLINT, INTEGER, BIGINT

可选参数

类型

默认

描述

directed

BOOLEAN

true

  • true 时,该图被视为有 有向

  • 如果为 false ,则该图被视为 无向

带点可选参数

参数

类型

默认

描述

driving_side

CHAR

r

在 [r, l] 中的值表示驾驶方向是:

  • r 代表右驾驶侧

  • l 表示左驾驶侧

  • 任何其他值将被视为 r

details

BOOLEAN

false

  • 如果为 true ,结果将包括路径中的点。

  • 如果为 false ,结果将不包括路径中的点。

内部查询

Edges SQL

类型

默认

描述

id

ANY-INTEGER

边的标识符。

source

ANY-INTEGER

边的第一个端点顶点的标识符。

target

ANY-INTEGER

边的第二个端点顶点的标识符。

cost

ANY-NUMERICAL

边(source, target)的权重

reverse_cost

ANY-NUMERICAL

-1

边(target, source)的权重

  • 当为负时:边( target, source )不存在,因此它不是图的一部分。

其中:

ANY-INTEGER:

SMALLINT, INTEGER, BIGINT

ANY-NUMERICAL:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Restrictions SQL

类型

描述

path

ARRAY [ANY-INTEGER]

形成不允许采用的路径的边缘标识符序列。 - 空数组或 NULL 数组将被忽略。 - 具有 NULL 元素的数组将引发异常。

Cost

ANY-NUMERICAL

走禁路的成本。

其中:

ANY-INTEGER:

SMALLINT, INTEGER, BIGINT

ANY-NUMERICAL:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Points SQL

参数

类型

默认

描述

pid

ANY-INTEGER

value

点的标识符。

  • 使用正值,因为内部将转换为负值

  • 如果列存在,则它不能为 NULL。

  • 如果列不存在,将自动给出连续的负

edge_id

ANY-INTEGER

距离该点“最近”的边的标识符。

fraction

ANY-NUMERICAL

<0,1> 中的值指示距边缘第一个端点的相对位置。

side

CHAR

b

[b, r, l, NULL] 中的值指示该点是否为:

  • r 在右边,

  • l 在左边,

  • b, NULL 在两边

其中:

ANY-INTEGER:

SMALLINT, INTEGER, BIGINT

ANY-NUMERICAL:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

分量 SQL

参数

类型

描述

source

ANY-INTEGER

出发顶点的标识符。

target

ANY-INTEGER

到达顶点的标识符。

其中:

ANY-INTEGER:

SMALLINT, INTEGER, BIGINT

结果列

返回集合``(seq, path_id, path_seq, start_vid, end_vid, node, edge, cost, agg_cost)``

类型

描述

seq

INTEGER

1 开始的顺序值。

path_id

INTEGER

路径标识符。

  • start_vidend_vid 的第一个路径的值为 1

path_seq

INTEGER

路径中的相对位置。 路径开头的值为 1

start_vid

BIGINT

起始顶点的标识符。

end_vid

BIGINT

结束顶点的标识符。

node

BIGINT

start_vidend_vid 路径中节点的标识符。

edge

BIGINT

用于从路径序列中的 node 到下一个节点的边的标识符。 -1 表示路径的最后一个节点。

cost

FLOAT

从使用 edgenode 遍历到路径序列中的下一个节点的成本。

agg_cost

FLOAT

start_vidnode 的总成本。

其他示例

对动态点使用 pgr_findCloseEdges

使用 pgr_findCloseEdges:

找到从顶点 \(1\) 到点 (2.9, 1.8) 图上两个最近位置的路线。

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],
  driving_side => 'r');
 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 |    2 |        2
   8 |        4 |         1 |      -1 |    7 |   10 |    1 |        4
   9 |        5 |         1 |      -1 |    8 |   12 |    1 |        5
  10 |        6 |         1 |      -1 |   12 |   13 |    1 |        6
  11 |        7 |         1 |      -1 |   17 |   15 |    1 |        7
  12 |        8 |         1 |      -1 |   16 |   16 |    1 |        8
  13 |        9 |         1 |      -1 |   15 |    3 |    1 |        9
  14 |       10 |         1 |      -1 |   10 |    5 |  0.8 |       10
  15 |       11 |         1 |      -1 |   -1 |   -1 |    0 |     10.8
(15 rows)

  • \(-1`对应于距离点`(2.9, 1.8)\) 最近的边。

  • \(-2`对应于点`(2.9, 1.8)\) 的下一个闭合边。

从前面经过或参观。

哪条路径(如果有)通过右侧驱动拓扑的点 \(6\) 或顶点 \(11\) 前面。

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],
    driving_side => '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)

显示无向图的详细信息。

无向图上从点 \(1\) 和顶点 \(6\) 到点 \(3`到顶点 :math:`1\) 的详细信息。

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],
  directed => false,
  details => true);
 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 |  0.7 |      0.6
   3 |        3 |        -1 |      -3 |   -6 |    4 |  0.3 |      1.3
   4 |        4 |        -1 |      -3 |    7 |   10 |    1 |      1.6
   5 |        5 |        -1 |      -3 |    8 |   12 |  0.6 |      2.6
   6 |        6 |        -1 |      -3 |   -3 |   -1 |    0 |      3.2
   7 |        1 |        -1 |       1 |   -1 |    1 |  0.6 |        0
   8 |        2 |        -1 |       1 |    6 |    4 |  0.7 |      0.6
   9 |        3 |        -1 |       1 |   -6 |    4 |  0.3 |      1.3
  10 |        4 |        -1 |       1 |    7 |    7 |    1 |      1.6
  11 |        5 |        -1 |       1 |    3 |    6 |  0.7 |      2.6
  12 |        6 |        -1 |       1 |   -4 |    6 |  0.3 |      3.3
  13 |        7 |        -1 |       1 |    1 |   -1 |    0 |      3.6
  14 |        1 |         6 |      -3 |    6 |    4 |  0.7 |        0
  15 |        2 |         6 |      -3 |   -6 |    4 |  0.3 |      0.7
  16 |        3 |         6 |      -3 |    7 |   10 |    1 |        1
  17 |        4 |         6 |      -3 |    8 |   12 |  0.6 |        2
  18 |        5 |         6 |      -3 |   -3 |   -1 |    0 |      2.6
  19 |        1 |         6 |       1 |    6 |    4 |  0.7 |        0
  20 |        2 |         6 |       1 |   -6 |    4 |  0.3 |      0.7
  21 |        3 |         6 |       1 |    7 |    7 |    1 |        1
  22 |        4 |         6 |       1 |    3 |    6 |  0.7 |        2
  23 |        5 |         6 |       1 |   -4 |    6 |  0.3 |      2.7
  24 |        6 |         6 |       1 |    1 |   -1 |    0 |        3
(24 rows)

另请参阅

索引和表格