pgr_lineGraph - Experimental

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

_images/boost-inside.jpeg

Boost Graph Inside

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

Synopsis

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 following figures show a graph (left, with blue vertices) and its Line Graph (right, with green vertices).

first

Signature Summary

pgr_lineGraph(edges_sql, directed)
RETURNS SET OF (seq, source, target, cost, reverse_cost)
    OR EMPTY SET

Signatures

Minimal signature

pgr_lineGraph(edges_sql)
RETURNS SET OF (seq, source, target, cost, reverse_cost) or EMPTY SET

The minimal signature is for a directed graph:

Example:
SELECT * FROM pgr_lineGraph(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table'
);
 seq | source | target | cost | reverse_cost 
-----+--------+--------+------+--------------
   1 |    -16 |     -3 |    1 |           -1
   2 |    -15 |     -9 |    1 |            1
   3 |    -14 |    -10 |    1 |            1
   4 |    -14 |     12 |    1 |           -1
   5 |    -10 |     -7 |    1 |            1
   6 |    -10 |     -4 |    1 |            1
   7 |    -10 |      8 |    1 |            1
   8 |     -9 |     -8 |    1 |            1
   9 |     -9 |     11 |    1 |           -1
  10 |     -8 |     -7 |    1 |            1
  11 |     -8 |     -4 |    1 |            1
  12 |     -7 |     -6 |    1 |            1
  13 |     -4 |     -1 |    1 |            1
  14 |     -3 |     -2 |    1 |           -1
  15 |     -3 |      5 |    1 |           -1
  16 |     -2 |     -1 |    1 |           -1
  17 |     -2 |      4 |    1 |           -1
  18 |      5 |     -8 |    1 |           -1
  19 |      5 |      9 |    1 |           -1
  20 |      5 |     11 |    1 |           -1
  21 |      7 |     -4 |    1 |            1
  22 |      8 |     11 |    1 |           -1
  23 |     10 |     12 |    1 |           -1
  24 |     11 |     13 |    1 |           -1
  25 |     12 |     13 |    1 |           -1
  26 |     13 |    -15 |    1 |           -1
  27 |     16 |     -9 |    1 |            1
  28 |     16 |     15 |    1 |            1
(28 rows)

Complete Signature

pgr_lineGraph(edges_sql, directed);
RETURNS SET OF (seq, source, target, cost, reverse_cost) or EMPTY SET
This signature returns the Line Graph of the current graph:
  • on a directed graph when directed flag is missing or is set to true.
  • on an undirected graph when directed flag is set to false.
Example:
SELECT * FROM pgr_lineGraph(
    'SELECT id, source, target, cost, reverse_cost FROM edge_table',
    FALSE
);
 seq | source | target | cost | reverse_cost 
-----+--------+--------+------+--------------
   1 |     -2 |     -1 |    1 |           -1
   2 |     -4 |     -1 |    1 |           -1
   3 |      4 |     -1 |    1 |           -1
   4 |      1 |      4 |    1 |           -1
   5 |     -2 |      4 |    1 |           -1
   6 |     -1 |      4 |    1 |           -1
   7 |     -2 |      1 |    1 |           -1
   8 |     -4 |      1 |    1 |           -1
   9 |      4 |      1 |    1 |           -1
  10 |      1 |     -2 |    1 |           -1
  11 |     -4 |     -2 |    1 |           -1
  12 |     -1 |     -2 |    1 |           -1
  13 |      4 |     -2 |    1 |           -1
  14 |      1 |     -4 |    1 |           -1
  15 |     -2 |     -4 |    1 |           -1
  16 |     -1 |     -4 |    1 |           -1
  17 |     -3 |     -2 |    1 |           -1
  18 |      5 |     -2 |    1 |           -1
  19 |     -3 |      5 |    1 |           -1
  20 |     -2 |      5 |    1 |           -1
  21 |     -2 |     -3 |    1 |           -1
  22 |      5 |     -3 |    1 |           -1
  23 |    -16 |     -3 |    1 |           -1
  24 |     16 |     -3 |    1 |           -1
  25 |     -3 |     16 |    1 |           -1
  26 |     -3 |    -16 |    1 |           -1
  27 |      7 |     -4 |    1 |           -1
  28 |     -8 |     -4 |    1 |           -1
  29 |    -10 |     -4 |    1 |           -1
  30 |     -7 |     -4 |    1 |           -1
  31 |      8 |     -4 |    1 |           -1
  32 |     10 |     -4 |    1 |           -1
  33 |      4 |     -7 |    1 |           -1
  34 |     -8 |     -7 |    1 |           -1
  35 |    -10 |     -7 |    1 |           -1
  36 |     -4 |     -7 |    1 |           -1
  37 |      8 |     -7 |    1 |           -1
  38 |     10 |     -7 |    1 |           -1
  39 |      4 |      8 |    1 |           -1
  40 |      7 |      8 |    1 |           -1
  41 |    -10 |      8 |    1 |           -1
  42 |     -4 |      8 |    1 |           -1
  43 |     -7 |      8 |    1 |           -1
  44 |     10 |      8 |    1 |           -1
  45 |      4 |     10 |    1 |           -1
  46 |      7 |     10 |    1 |           -1
  47 |     -8 |     10 |    1 |           -1
  48 |     -4 |     10 |    1 |           -1
  49 |     -7 |     10 |    1 |           -1
  50 |      8 |     10 |    1 |           -1
  51 |      7 |      4 |    1 |           -1
  52 |     -8 |      4 |    1 |           -1
  53 |    -10 |      4 |    1 |           -1
  54 |     -7 |      4 |    1 |           -1
  55 |      8 |      4 |    1 |           -1
  56 |     10 |      4 |    1 |           -1
  57 |      4 |      7 |    1 |           -1
  58 |     -8 |      7 |    1 |           -1
  59 |    -10 |      7 |    1 |           -1
  60 |     -4 |      7 |    1 |           -1
  61 |      8 |      7 |    1 |           -1
  62 |     10 |      7 |    1 |           -1
  63 |      4 |     -8 |    1 |           -1
  64 |      7 |     -8 |    1 |           -1
  65 |    -10 |     -8 |    1 |           -1
  66 |     -4 |     -8 |    1 |           -1
  67 |     -7 |     -8 |    1 |           -1
  68 |     10 |     -8 |    1 |           -1
  69 |      4 |    -10 |    1 |           -1
  70 |      7 |    -10 |    1 |           -1
  71 |     -8 |    -10 |    1 |           -1
  72 |     -4 |    -10 |    1 |           -1
  73 |     -7 |    -10 |    1 |           -1
  74 |      8 |    -10 |    1 |           -1
  75 |      5 |     -8 |    1 |           -1
  76 |     -9 |     -8 |    1 |           -1
  77 |      9 |     -8 |    1 |           -1
  78 |     11 |     -8 |    1 |           -1
  79 |      5 |      9 |    1 |           -1
  80 |      8 |      9 |    1 |           -1
  81 |     -8 |      9 |    1 |           -1
  82 |     11 |      9 |    1 |           -1
  83 |      5 |     11 |    1 |           -1
  84 |      8 |     11 |    1 |           -1
  85 |     -9 |     11 |    1 |           -1
  86 |     -8 |     11 |    1 |           -1
  87 |      9 |     11 |    1 |           -1
  88 |      8 |      5 |    1 |           -1
  89 |     -9 |      5 |    1 |           -1
  90 |     -8 |      5 |    1 |           -1
  91 |      9 |      5 |    1 |           -1
  92 |     11 |      5 |    1 |           -1
  93 |      5 |      8 |    1 |           -1
  94 |     -9 |      8 |    1 |           -1
  95 |      9 |      8 |    1 |           -1
  96 |     11 |      8 |    1 |           -1
  97 |      5 |     -9 |    1 |           -1
  98 |      8 |     -9 |    1 |           -1
  99 |     -8 |     -9 |    1 |           -1
 100 |     11 |     -9 |    1 |           -1
 101 |     -7 |     -6 |    1 |           -1
 102 |      7 |     -6 |    1 |           -1
 103 |      6 |      7 |    1 |           -1
 104 |     -6 |      7 |    1 |           -1
 105 |     -7 |      6 |    1 |           -1
 106 |      7 |      6 |    1 |           -1
 107 |      6 |     -7 |    1 |           -1
 108 |     -6 |     -7 |    1 |           -1
 109 |    -15 |     -9 |    1 |           -1
 110 |     16 |     -9 |    1 |           -1
 111 |     15 |     -9 |    1 |           -1
 112 |    -16 |     -9 |    1 |           -1
 113 |      9 |     15 |    1 |           -1
 114 |     16 |     15 |    1 |           -1
 115 |     -9 |     15 |    1 |           -1
 116 |    -16 |     15 |    1 |           -1
 117 |      9 |    -16 |    1 |           -1
 118 |    -15 |    -16 |    1 |           -1
 119 |     -9 |    -16 |    1 |           -1
 120 |     15 |    -16 |    1 |           -1
 121 |    -15 |      9 |    1 |           -1
 122 |     16 |      9 |    1 |           -1
 123 |     15 |      9 |    1 |           -1
 124 |    -16 |      9 |    1 |           -1
 125 |      9 |    -15 |    1 |           -1
 126 |     16 |    -15 |    1 |           -1
 127 |     -9 |    -15 |    1 |           -1
 128 |    -16 |    -15 |    1 |           -1
 129 |      9 |     16 |    1 |           -1
 130 |    -15 |     16 |    1 |           -1
 131 |     -9 |     16 |    1 |           -1
 132 |     15 |     16 |    1 |           -1
 133 |    -14 |    -10 |    1 |           -1
 134 |     12 |    -10 |    1 |           -1
 135 |     14 |    -10 |    1 |           -1
 136 |     10 |     12 |    1 |           -1
 137 |    -14 |     12 |    1 |           -1
 138 |    -10 |     12 |    1 |           -1
 139 |     14 |     12 |    1 |           -1
 140 |     10 |     14 |    1 |           -1
 141 |    -10 |     14 |    1 |           -1
 142 |     12 |     14 |    1 |           -1
 143 |    -14 |     10 |    1 |           -1
 144 |     12 |     10 |    1 |           -1
 145 |     14 |     10 |    1 |           -1
 146 |     10 |    -14 |    1 |           -1
 147 |    -10 |    -14 |    1 |           -1
 148 |     12 |    -14 |    1 |           -1
 149 |     11 |     13 |    1 |           -1
 150 |     12 |     13 |    1 |           -1
 151 |     12 |     11 |    1 |           -1
 152 |     13 |     11 |    1 |           -1
 153 |     11 |     12 |    1 |           -1
 154 |     13 |     12 |    1 |           -1
 155 |     13 |    -15 |    1 |           -1
 156 |     15 |     13 |    1 |           -1
 157 |    -15 |     13 |    1 |           -1
 158 |     13 |     15 |    1 |           -1
(158 rows)

Description of the Signatures

Description of the edges_sql query for dijkstra like functions

edges_sql:an SQL query, which should return a set of rows with the following columns:
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)

  • When negative: edge (source, target) does not exist, therefore it’s not part of the graph.
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

Description of the parameters of the signatures

Column Type Description
edges_sql TEXT SQL query as described above.
directed BOOLEAN
  • When true the graph is considered as Directed.
  • When false the graph is considered as Undirected.

Description of the return values

RETURNS SETOF (seq, source, target, cost, reverse_cost)

Column Type Description
seq INTEGER Sequential value starting from 1.
source BIGINT

Identifier of the source vertex of the current edge id.

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

Identifier of the target vertex of the current edge id.

  • 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