pgr_lineGraph - Experimental

pgr_lineGraph — Transforms the given graph into its corresponding edge-based graph.

_images/boost-inside.jpeg

Boost Graph Inside

Warning

Possible server crash

  • These functions might create a server crash

Warning

Experimental functions

  • They are not officially of the current release.

  • They likely will not be officially be part of the next release:

    • The functions might not make use of ANY-INTEGER and ANY-NUMERICAL

    • Name might change.

    • Signature might change.

    • Functionality might change.

    • pgTap tests might be missing.

    • Might need c/c++ coding.

    • May lack documentation.

    • Documentation if any might need to be rewritten.

    • Documentation examples might need to be automatically generated.

    • Might need a lot of feedback from the comunity.

    • Might depend on a proposed function of pgRouting

    • Might depend on a deprecated function of pgRouting

Availability

  • Version 2.5.0

    • New Experimental function

Description

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 main characteristics are:

  • Works for directed and undirected graphs.

  • The cost and reverse_cost columns of the result represent existence of the edge.

  • When the graph is directed the result is directed.

  • When the graph is undirected the result is undirected.

    • The reverse_cost is always \(-1\).

Signatures

pgr_lineGraph(Edges SQL, [directed])
Returns set of (seq, source, target, cost, reverse_cost)
OR EMPTY SET
Example:

For an undirected graph with edges :math:’{2,4,5,8}’

SELECT * FROM pgr_lineGraph(
  'SELECT id, source, target, cost, reverse_cost FROM edges'
);
 seq | source | target | cost | reverse_cost
-----+--------+--------+------+--------------
   1 |    -18 |     18 |    1 |            1
   2 |    -17 |     17 |    1 |            1
   3 |    -16 |     -3 |    1 |           -1
   4 |    -14 |    -10 |    1 |            1
   5 |    -14 |     12 |    1 |           -1
   6 |    -14 |     14 |    1 |            1
   7 |    -10 |     -7 |    1 |            1
   8 |    -10 |     -4 |    1 |            1
   9 |    -10 |      8 |    1 |            1
  10 |    -10 |     10 |    1 |            1
  11 |     -9 |     -8 |    1 |            1
  12 |     -9 |      9 |    1 |            1
  13 |     -9 |     11 |    1 |           -1
  14 |     -8 |     -7 |    1 |            1
  15 |     -8 |     -4 |    1 |            1
  16 |     -8 |      8 |    1 |            1
  17 |     -7 |     -6 |    1 |            1
  18 |     -7 |      7 |    1 |            1
  19 |     -6 |      6 |    1 |            1
  20 |     -3 |     -2 |    1 |           -1
  21 |     -3 |      5 |    1 |           -1
  22 |     -2 |     -1 |    1 |           -1
  23 |     -2 |      4 |    1 |           -1
  24 |      1 |     -1 |    1 |            1
  25 |      1 |      4 |    1 |            1
  26 |      4 |     -7 |    1 |            1
  27 |      4 |     -4 |    1 |            1
  28 |      5 |     -8 |    1 |           -1
  29 |      5 |      9 |    1 |           -1
  30 |      5 |     11 |    1 |           -1
  31 |      8 |     11 |    1 |           -1
  32 |      9 |    -16 |    1 |            1
  33 |      9 |     15 |    1 |            1
  34 |     10 |     12 |    1 |           -1
  35 |     11 |     13 |    1 |           -1
  36 |     12 |     13 |    1 |           -1
  37 |     13 |    -15 |    1 |           -1
  38 |     15 |    -15 |    1 |            1
  39 |     16 |    -16 |    1 |            1
  40 |     16 |     15 |    1 |            1
(40 rows)

graph G {

   v6 [label=6,shape=circle;style=filled;fixedsize=true;width=.4;color=deepskyblue,pos="0,0!"];
   v7 [label=7,shape=circle;style=filled;fixedsize=true;width=.4;color=deepskyblue,pos="0,2!"];
   v10 [label=10,shape=circle;style=filled;fixedsize=true;width=.4;color=deepskyblue,pos="2,0!"];
   v11 [label=11,shape=circle;style=filled;fixedsize=true;width=.4;color=deepskyblue,pos="2,2!"];

   v7--v6 [color=blue];
   v7--v11 [color=blue];
   v10--v6 [color=blue];
   v10--v11 [color=blue];

   s2 [label="2",shape=circle;style=filled;width=.4;color=yellow,pos="1,0!"];
   s4 [label="4",shape=circle;style=filled;width=.4;color=yellow,pos="0,1!"];
   s5 [label="5",shape=circle;style=filled;width=.4;color=yellow,pos="2,1!"];
   s8 [label="8",shape=circle;style=filled;width=.4;color=yellow,pos="1,2!"];

   s2--s4 [color=red];
   s2--s5 [color=red];
   s4--s8 [color=red];
   s5--s8 [color=red];
}

Parameters

Parameter

Type

Description

Edges SQL

TEXT

Edges SQL as described below.

Optional parameters

Column

Type

Default

Description

directed

BOOLEAN

true

  • When true the graph is considered Directed

  • When false the graph is considered as Undirected.

Inner Queries

Edges SQL

Column

Type

Default

Description

id

ANY-INTEGER

Identifier of the edge.

source

ANY-INTEGER

Identifier of the first end point vertex of the edge.

target

ANY-INTEGER

Identifier of the second end point vertex of the edge.

cost

ANY-NUMERICAL

Weight of the edge (source, target)

reverse_cost

ANY-NUMERICAL

-1

Weight of the edge (target, source)

  • When negative: edge (target, source) does not exist, therefore it’s not part of the graph.

Where:

ANY-INTEGER:

SMALLINT, INTEGER, BIGINT

ANY-NUMERICAL:

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Result columns

Returns set of (seq, source, target, cost, reverse_cost)

Column

Type

Description

seq

INTEGER

Sequential value starting from 1.

  • Gives a local identifier for the edge

source

BIGINT

Identifier of the source vertex of the current edge.

  • When negative: the source is the reverse edge in the original graph.

target

BIGINT

Identifier of the target vertex of the current edge.

  • When negative: the target is the reverse edge in the original graph.

cost

FLOAT

Weight of the edge (source, target).

  • When negative: edge (source, target) does not exist, therefore it’s not part of the graph.

reverse_cost

FLOAT

Weight of the edge (target, source).

  • When negative: edge (target, source) does not exist, therefore it’s not part of the graph.

See Also

Indices and tables