pgr_sequentialVertexColoring - Experimental

pgr_sequentialVertexColoring — Returns the vertex coloring of an undirected graph, using greedy approach.

_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.2.0

    • New experimental function

Description

Sequential Vertex Coloring algorithm is a graph coloring algorithm in which color identifiers are assigned to the vertices of a graph in a sequential manner, such that no edge connects two identically colored vertices.

The main Characteristics are:

  • The implementation is applicable only for undirected graphs.

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

  • Color identifiers values are in the Range \([1, |V|]\)

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

  • Efficient graph coloring is an NP-Hard problem, and therefore, this algorithm does not always produce optimal coloring. It follows a greedy strategy by iterating through all the vertices sequentially, and assigning the smallest possible color that is not used by its neighbors, to each vertex.

  • The returned rows are ordered in ascending order of the vertex value.

  • Sequential Vertex Coloring Running Time: \(O(|V|*(d + k))\)

    • where \(|V|\) is the number of vertices,

    • \(d\) is the maximum degree of the vertices in the graph,

    • \(k\) is the number of colors used.

Signatures

pgr_sequentialVertexColoring(Edges SQL) -- Experimental on v3.2

RETURNS SET OF (vertex_id, color_id)
OR EMPTY SET
Example

Graph coloring of pgRouting Sample Data

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

Parameters

Parameter

Type

Description

Edges SQL

TEXT

Inner query as described below.

Inner query

Edges SQL

an SQL query of an undirected graph, 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

  • When positive: edge (source, target) exist on the graph.

  • When negative: edge (source, target) does not exist on the graph.

reverse_cost

ANY-NUMERICAL

-1

  • When positive: edge (target, source) exist on the graph.

  • When negative: edge (target, source) does not exist on the graph.

Where:

ANY-INTEGER

SMALLINT, INTEGER, BIGINT

ANY-NUMERICAL

SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Result Columns

Returns SET OF (vertex_id, color_id)

Column

Type

Description

vertex_id

BIGINT

Identifier of the vertex.

color_id

BIGINT

Identifier of the color of the vertex.

  • The minimum value of color is 1.

See Also

Indices and tables