Skip to content

GSOC 2026: New function pgr_coreNumbers to be added in pgRouting #3142

Description

@sakirr05

pgr_coreNumbers():

coreNumbers(): K-core decomposition is an algorithm that assigns to every vertex its core number: the largest value of k for which the vertex still belongs to the k-core of the graph. The k-core is the maximal subgraph in which every vertex has degree at least k within that subgraph. The decomposition repeatedly peels away vertices whose degree falls below k, raising k at each stage until no vertices remain. Core numbers measure how deeply a vertex sits in the dense part of a network: on a road network core 1 marks dead-ends and cul-de-sacs, core 2 marks corridors and cycles, and core 3 and above mark densely interconnected regions with redundant routes. This implementation follows the Batagelj-Zaversnik peeling algorithm with a time complexity of O(E) and space complexity of O(V), where V is the number of vertices and E is the number of edges. This will enhance pgRouting's capabilities in network resilience and graph degeneracy analysis.

The algorithm:

  • Works on undirected graphs.
  • Edge direction and traversal costs are ignored, only the edge endpoints matter.
  • Collapses parallel edges before peeling, so edge multiplicity does not inflate core numbers.
  • Drops self loops before peeling, as a vertex is not its own neighbour.
  • Returns every vertex of the graph, so the result has |V| rows.
  • Running time: O(E) where E is the number of edges.

Signature:

  • pgr_coreNumbers()
pgr_coreNumbers(Edges SQL)

Returns set of (seq, node, core)
OR EMPTY SET

Parameters

Parameter Type Description
Edges SQL TEXT Inner SQL query, as described below.

Inner Query

Edges SQL: An SQL query returning 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 endpoint vertex of the edge.
target ANY-INTEGER Identifier of the second endpoint vertex of the edge.
cost ANY-NUMERICAL Weight of the edge (source, target). When negative, the edge does not exist.
reverse_cost ANY-NUMERICAL -1 Weight of the edge (target, source). When negative, the edge does not exist.

Where:

  • ANY-INTEGER = SMALLINT, INTEGER, BIGINT
  • ANY-NUMERICAL = SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Result Columns

Returns SETOF (seq, node, core).

Column Type Description
seq BIGINT Sequential value starting from 1.
node BIGINT Identifier of the vertex.
core BIGINT Core number of the vertex: the largest k for which the vertex belongs to the k-core.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions