pgr_lineGraph - Proposed¶
pgr_lineGraph
— 将给定图转换为其相应的基于边的图。
Warning
下一版本的拟议功能。
它们并未正式出现在当前版本中。
它们可能会正式成为下一个版本的一部分:
这些函数使用 ANY-INTEGER 和 ANY-NUMERICAL
名字可能不会改变。(但仍然有可能改变)
签名可能不会改变。(但仍然有可能改变)
功能可能不会改变。(但仍然有可能改变)
pgTap 测试已经完成。 但可能需要更多。
文档可能需要完善。
可用性
Version 3.7.0
晋升为 拟议 签名。
适用于有向和无向图。
版本2.5.0
新的 实验 函数
描述¶
Given a graph \(G\), its line graph \(L(G)\) is a graph such that:
Each vertex of \(L(G)\) represents an edge of \(G\).
Two vertices of \(L(G)\) are adjacent if and only if their corresponding edges share a common endpoint in \(G\)
主要特点是:
适用于有向和无向图。
The
cost
andreverse_cost
columns of the result represent existence of the edge.When the graph is directed the result is directed.
To get the complete Line Graph use unique identifiers on the double way edges (See Additional Examples).
当图无向时,成本矩阵是对称的。
The
reverse_cost
is always \(-1\).
签名¶
directed
])(seq, source, target, cost, reverse_cost)
- 示例:
For an undirected graph with edges :math:'{2,4,5,8}'
SELECT * FROM pgr_lineGraph(
'SELECT id, source, target, cost, reverse_cost
FROM edges WHERE id IN (2,4,5,8)',
false);
seq | source | target | cost | reverse_cost
-----+--------+--------+------+--------------
1 | 2 | 4 | 1 | -1
2 | 2 | 5 | 1 | -1
3 | 4 | 8 | 1 | -1
4 | 5 | 8 | 1 | -1
(4 rows)
参数¶
参数 |
类型 |
描述 |
---|---|---|
|
Edges SQL 如下所述。 |
可选参数¶
列 |
类型 |
默认 |
描述 |
---|---|---|---|
|
|
|
|
内部查询¶
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
结果列¶
Returns set of (seq, source, target, cost, reverse_cost)
列 |
类型 |
描述 |
---|---|---|
|
|
从 1 开始的顺序值。
|
|
|
当前边的源顶点的标识符。
|
|
|
当前边的目标顶点的标识符。
|
|
|
边 (
|
|
|
边 (
|
其他示例¶
Given the following directed graph
\(G(V,E) = G(\{1,2,3,4\},\{ 1 \rightarrow 2, 1 \rightarrow 4, 2 \rightarrow 3, 3 \rightarrow 1, 3 \rightarrow 2, 3 \rightarrow 4, 4 \rightarrow 3\})\)
Representation as directed with unique edge identifiers¶
For the simplicity, the design of the edges table on the database, has the edge's identifiers are represented with 3 digits:
- hundreds:
the source vertex
- tens:
always 0, acts as a separator
- units:
the target vertex
In this image,
Single head arrows represent one edge (row) on the edges table.
There are no double head arrows
The numbers in the yellow shadow are the edge identifiers.
Two pair of edges share the same ending nodes and the reverse_cost
column is
not used.
Edges \({2 \rightarrow 3, 3 \rightarrow 2}\) are represented with two edges \(id=203\) and \(id=302\) respectively.
Edges \({3 \rightarrow 4, 4 \rightarrow 3}\) are represented with two edges \(id=304\) and \(id=403\) respectively.
The graph can be created as follows:
CREATE TABLE edges_unique (
id BIGINT,
source BIGINT,
target BIGINT,
cost FLOAT,
geom geometry
);
CREATE TABLE
INSERT INTO edges_unique (id, source, target, cost, geom) VALUES
(102, 1, 2, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(2, 2))),
(104, 1, 4, 1, ST_MakeLine(ST_POINT(0, 2), ST_POINT(0, 0))),
(301, 3, 1, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 2))),
(203, 2, 3, 1, ST_MakeLine(ST_POINT(2, 2), ST_POINT(2, 0))),
(304, 3, 4, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(0, 0))),
(302, 3, 2, 1, ST_MakeLine(ST_POINT(2, 0), ST_POINT(2, 2))),
(403, 4, 3, 1, ST_MakeLine(ST_POINT(0, 0), ST_POINT(2, 0)));
Line Graph of a directed graph represented with unique edges¶
SELECT seq, source, target, cost, reverse_cost
FROM pgr_lineGraph(
'SELECT id, source, target, cost FROM edges_unique',
true);
seq | source | target | cost | reverse_cost
-----+--------+--------+------+--------------
1 | 102 | 203 | 1 | -1
2 | 104 | 403 | 1 | -1
3 | 203 | 301 | 1 | -1
4 | 203 | 304 | 1 | -1
5 | 301 | 102 | 1 | -1
6 | 301 | 104 | 1 | -1
7 | 302 | 203 | 1 | 1
8 | 304 | 403 | 1 | 1
9 | 403 | 301 | 1 | -1
10 | 403 | 302 | 1 | -1
(10 rows)
The result is a directed graph.
For \(seq=7\) from \(203 \leftrightarrow 302\) represent two edges.
For \(seq=8\) from \(304 \leftrightarrow 403\) represent two edges.
For all the other values of
seq
represent one edge.The
cost
andreverse_cost
values represent the existence of the edge.When positive: the edge exists.
When negative: the edge does not exist.
另请参阅¶
wikipedia: Line Graph
mathworld: Line Graph
索引和表格