Supported versions: latest (3.8) 3.7 3.6 3.5 3.4 3.3 3.2 main dev

pgr_sequentialVertexColoring - Proposed

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

Warning

Proposed functions for next mayor release.

  • They are not officially in the current release.

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

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

    • Name might not change. (But still can)

    • Signature might not change. (But still can)

    • Functionality might not change. (But still can)

    • pgTap tests have being done. But might need more.

    • Documentation might need refinement.

Availability

Version 4.0.0

  • Output columns standardized to (node, color)

Version 3.3.0

  • Function promoted to proposed.

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.

Boost Graph inside Boost Graph Inside

Signatures

pgr_sequentialVertexColoring(Edges SQL)
Returns set of (node, color)
OR EMPTY SET
Example:

Graph coloring of pgRouting Sample Data

SELECT * FROM pgr_sequentialVertexColoring(
    'SELECT id, source, target, cost, reverse_cost FROM edges
    ORDER BY id'
);
 node | color
------+-------
    1 |     1
    2 |     1
    3 |     2
    4 |     2
    5 |     1
    6 |     2
    7 |     1
    8 |     2
    9 |     1
   10 |     1
   11 |     2
   12 |     1
   13 |     1
   14 |     2
   15 |     2
   16 |     1
   17 |     2
(17 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 (node, color)

Column

Type

Description

node

BIGINT

Identifier of the node.

color

BIGINT

Color of the node.

  • The minimum value of color is 1.

See Also

Indices and tables