Supported versions: latest (3.8) 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 main dev
Unsupported versions:2.6 2.5 2.4 2.3 2.2 2.1 2.0

驾驶距离

pgr_drivingDistance - 返回起始节点的行驶距离。

可用性

版本3.6.0

  • Standardizing output columns to (seq, depth, start_vid, pred, node, edge, cost, agg_cost)

    • pgr_drivingDistance(Single vertex)

      • 添加了 depthstart_vid 结果列。

    • pgr_drivingDistance(Multiple vertices)

      • 结果列名称更改: from_v``改为 ``start_vid

      • 添加了 depth 和``pred`` 结果列。

版本2.1.0

  • 签名变更:

    • pgr_drivingDistance (单顶点)

  • 新签名:

    • pgr_drivingDistance (多顶点)

版本2.0.0

  • 官方 函数

描述

Using the Dijkstra algorithm, extracts all the nodes that have costs less than or equal to the value distance. The edges extracted will conform to the corresponding spanning tree.

Boost Graph inside Boost 图内部

签名

pgr_drivingDistance(Edges SQL, Root vid, distance, [directed])
pgr_drivingDistance(Edges SQL, Root vids, distance, [options])
options: [directed, equicost]
Returns set of (seq, depth, start_vid, pred, node, edge, cost, agg_cost)

单顶点

pgr_drivingDistance(Edges SQL, Root vid, distance, [directed])
Returns set of (seq, depth, start_vid, pred, node, edge, cost, agg_cost)
示例:

从顶点 113.0 的距离

SELECT * FROM pgr_drivingDistance(
  'SELECT id, source, target, cost, reverse_cost FROM edges',
  11, 3.0);
 seq | depth | start_vid | pred | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+------+----------
   1 |     0 |        11 |   11 |   11 |   -1 |    0 |        0
   2 |     1 |        11 |   11 |    7 |    8 |    1 |        1
   3 |     1 |        11 |   11 |   12 |   11 |    1 |        1
   4 |     1 |        11 |   11 |   16 |    9 |    1 |        1
   5 |     2 |        11 |    7 |    3 |    7 |    1 |        2
   6 |     2 |        11 |    7 |    6 |    4 |    1 |        2
   7 |     2 |        11 |    7 |    8 |   10 |    1 |        2
   8 |     2 |        11 |   16 |   15 |   16 |    1 |        2
   9 |     2 |        11 |   16 |   17 |   15 |    1 |        2
  10 |     3 |        11 |    3 |    1 |    6 |    1 |        3
  11 |     3 |        11 |    6 |    5 |    1 |    1 |        3
  12 |     3 |        11 |    8 |    9 |   14 |    1 |        3
  13 |     3 |        11 |   15 |   10 |    3 |    1 |        3
(13 rows)

多顶点

pgr_drivingDistance(Edges SQL, Root vids, distance, [options])
options: [directed, equicost]
Returns set of (seq, depth, start_vid, pred, node, edge, cost, agg_cost)
示例:

从顶点 \({11, 16\}\) 出发,距离为 3.0 且有向图上的成本相等

SELECT * FROM pgr_drivingDistance(
  'SELECT id, source, target, cost, reverse_cost FROM edges',
  array[11, 16], 3.0, equicost => true);
 seq | depth | start_vid | pred | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+------+----------
   1 |     0 |        11 |   11 |   11 |   -1 |    0 |        0
   2 |     1 |        11 |   11 |    7 |    8 |    1 |        1
   3 |     1 |        11 |   11 |   12 |   11 |    1 |        1
   4 |     2 |        11 |    7 |    3 |    7 |    1 |        2
   5 |     2 |        11 |    7 |    6 |    4 |    1 |        2
   6 |     2 |        11 |    7 |    8 |   10 |    1 |        2
   7 |     3 |        11 |    3 |    1 |    6 |    1 |        3
   8 |     3 |        11 |    6 |    5 |    1 |    1 |        3
   9 |     3 |        11 |    8 |    9 |   14 |    1 |        3
  10 |     0 |        16 |   16 |   16 |   -1 |    0 |        0
  11 |     1 |        16 |   16 |   15 |   16 |    1 |        1
  12 |     1 |        16 |   16 |   17 |   15 |    1 |        1
  13 |     2 |        16 |   15 |   10 |    3 |    1 |        2
(13 rows)

参数

参数

类型

描述

Edges SQL

TEXT

Edges SQL如下所述。

Root vid

BIGINT

树的根顶点的标识符。

Root vids

ARRAY[ANY-INTEGER]

根顶点的标识符数组。

  • 0 值被忽略

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

distance

FLOAT

结果中包含节点的上限。

其中:

ANY-NUMERIC:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

可选参数

类型

默认

描述

directed

BOOLEAN

true

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

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

行驶距离可选参数

类型

默认

描述

equicost

BOOLEAN

true

  • true``时,节点只会出现在最近的 ``start_vid 列表中。绑定制动是任意的。

  • 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

结果列

Returns set of (seq, depth, start_vid, pred, node, edge, cost, agg_cost)

参数

类型

描述

seq

BIGINT

1 开始的顺序值。

depth

BIGINT

node 的深度。

  • 0node = start_vid

  • depth1 is the depth of pred

start_vid

BIGINT

根顶点的标识符。

pred

BIGINT

node 的前驱。

  • node 等于 start_vid 时,它的值就是 node

node

BIGINT

使用 edge 到达的``node`` 的标识符。

edge

BIGINT

pred 到达``node``所使用的 edge 的标识符。

  • 1node = start_vid

cost

FLOAT

遍历 edge 的成本。

agg_cost

FLOAT

start_vidnode 的总成本。

其他示例

示例:

在无向图上,从顶点 \({11, 16\}\) 开始的距离为 3.0

SELECT * FROM pgr_drivingDistance(
  'SELECT id, source, target, cost, reverse_cost FROM edges',
  array[11, 16], 3.0, directed => false);
 seq | depth | start_vid | pred | node | edge | cost | agg_cost
-----+-------+-----------+------+------+------+------+----------
   1 |     0 |        11 |   11 |   11 |   -1 |    0 |        0
   2 |     1 |        11 |   11 |    7 |    8 |    1 |        1
   3 |     1 |        11 |   11 |   10 |    5 |    1 |        1
   4 |     1 |        11 |   11 |   12 |   11 |    1 |        1
   5 |     1 |        11 |   11 |   16 |    9 |    1 |        1
   6 |     2 |        11 |    7 |    3 |    7 |    1 |        2
   7 |     2 |        11 |   10 |    6 |    2 |    1 |        2
   8 |     2 |        11 |    7 |    8 |   10 |    1 |        2
   9 |     2 |        11 |   10 |   15 |    3 |    1 |        2
  10 |     2 |        11 |   16 |   17 |   15 |    1 |        2
  11 |     3 |        11 |    3 |    1 |    6 |    1 |        3
  12 |     3 |        11 |    6 |    5 |    1 |    1 |        3
  13 |     3 |        11 |    8 |    9 |   14 |    1 |        3
  14 |     0 |        16 |   16 |   16 |   -1 |    0 |        0
  15 |     1 |        16 |   16 |   11 |    9 |    1 |        1
  16 |     1 |        16 |   16 |   15 |   16 |    1 |        1
  17 |     1 |        16 |   16 |   17 |   15 |    1 |        1
  18 |     2 |        16 |   11 |    7 |    8 |    1 |        2
  19 |     2 |        16 |   11 |   10 |    5 |    1 |        2
  20 |     2 |        16 |   17 |   12 |   13 |    1 |        2
  21 |     3 |        16 |    7 |    3 |    7 |    1 |        3
  22 |     3 |        16 |    7 |    6 |    4 |    1 |        3
  23 |     3 |        16 |    7 |    8 |   10 |    1 |        3
(23 rows)

另请参阅

索引和表格