pgr_edgeColoring - Experimental

pgr_edgeColoring — Returns the edge coloring of undirected and loop-free graphs

_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 3.3.0

    • New experimental signature

Description

Edge Coloring is an algorithm used for coloring of the edges for the vertices in the graph. It is an assignment of colors to the edges of the graph so that no two adjacent edges have the same color.

The main Characteristics are:

  • The implementation is for undirected and loop-free graphs

    • loop free:

      no self-loops and no parallel edges.

  • Provides the color to be assigned to all the edges present in the graph.

  • At most \(\Delta + 1\) colors are used, where \(\Delta\) is the degree of the graph.

    • This is optimal for some graphs, and by Vizing’s theorem it uses at most one color more than the optimal for all others.

    • When the graph is bipartite

      • the chromatic number \(x'(G)\) (minimum number of colors needed for proper edge coloring of graph) is equal to the degree \(\Delta + 1\) of the graph, (\(x'(G) = \Delta\))

  • The algorithm tries to assign the least possible color to every edge.

    • Does not always produce optimal coloring.

  • The returned rows are ordered in ascending order of the edge identifier.

  • Efficient graph coloring is an NP-Hard problem, and therefore:

    • In this implelentation the running time: \(O(|E|*|V|)\)

      • where \(|E|\) is the number of edges in the graph,

      • \(|V|\) is the number of vertices in the graph.

Signatures

pgr_edgeColoring(Edges SQL)
RETURNS SET OF (edge_id, color_id)
OR EMPTY SET
Example:

Graph coloring of pgRouting Sample Data

SELECT * FROM pgr_edgeColoring(
    'SELECT id, source, target, cost, reverse_cost FROM edges
    ORDER BY id'
);
 edge_id | color_id
---------+----------
       1 |        3
       2 |        2
       3 |        3
       4 |        4
       5 |        4
       6 |        1
       7 |        2
       8 |        1
       9 |        2
      10 |        5
      11 |        5
      12 |        3
      13 |        2
      14 |        1
      15 |        3
      16 |        1
      17 |        1
      18 |        1
(18 rows)

Parameters

Parameter

Type

Description

Edges SQL

TEXT

Edges SQL as described below.

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 (edge_id, color_id)

Column

Type

Description

edge_id

BIGINT

Identifier of the edge.

color_id

BIGINT

Identifier of the color of the edge.

  • The minimum value of color is 1.

See Also

Indices and tables