# pgr_edgeColoring - Experimental¶

pgr_edgeColoring — Returns the edge coloring of an undirected and loop-free (i.e no self-loops and no parallel edges) graph.

Possible server crash

• These functions might create a server crash

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 function

## 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 applicable only for undirected and loop-free (i.e no self-loops and no parallel edges) graphs.

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

• At most Δ + 1 colors are used, where Δ 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.

• It can tell us whether a graph is Bipartite. If in a graph, the chromatic number χ′(G) i.e. minimum number of colors needed for proper edge coloring of graph is equal to degree Δ of the graph, (i.e. χ′(G) = Δ) then graph is said to be Bipartite. But, the vice-versa is not always true.

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

• Efficient graph coloring is an NP-Hard problem, and therefore, this algorithm does not always produce optimal coloring.

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

• This algorithm is the fastest known almost-optimal algorithm for edge coloring.

• Edge Coloring 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 Datos Muestra

SELECT * FROM pgr_edgeColoring(
'SELECT id, source, target, cost, reverse_cost FROM edge_table
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

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 (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.