Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Summary of changes by function

* Combinations signature promoted to official.

* pgr_minDegreeOrdering

* New experimental function.

* pgr_pushRelabel

* Combinations signature promoted to official.
Expand Down
2 changes: 1 addition & 1 deletion doc/_static/page_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var titles = [


var newpages = [
{v: '4.0', pages: ['pgr_bandwidth', 'pgr_kingOrdering', 'pgr_sloanOrdering']},
{v: '4.0', pages: ['pgr_bandwidth', 'pgr_kingOrdering', 'pgr_minDegreeOrdering', 'pgr_sloanOrdering']},

{v: '3.8', pages: ['pgr_contractionDeadEnd', 'pgr_contractionLinear', 'pgr_separateCrossing',
'pgr_separateTouching']},
Expand Down
3 changes: 2 additions & 1 deletion doc/ordering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ SET(LOCAL_FILES
ordering-family.rst
pgr_cuthillMckeeOrdering.rst
pgr_topologicalSort.rst
pgr_sloanOrdering.rst
pgr_kingOrdering.rst
pgr_minDegreeOrdering.rst
pgr_sloanOrdering.rst
)

foreach (f ${LOCAL_FILES})
Expand Down
9 changes: 5 additions & 4 deletions doc/ordering/ordering-family.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Ordering - Family of functions
.. official-start

* :doc:`pgr_cuthillMckeeOrdering` - Return reverse Cuthill-McKee ordering of an undirected graph.
* :doc:`pgr_topologicalSort` - Linear ordering of the vertices for directed
acyclic graph.
* :doc:`pgr_sloanOrdering` - Returns the sloan ordering of an undirected graph.
* :doc:`pgr_topologicalSort` - Linear ordering of the vertices for directed acyclic graph.
* :doc:`pgr_kingOrdering` - Returns the King ordering of an undirected graph.
* :doc:`pgr_minDegreeOrdering` - Returns the Minimum Degree ordering of an undirected graph.
* :doc:`pgr_sloanOrdering` - Returns the Sloan ordering of an undirected graph.

.. official-end

Expand All @@ -34,8 +34,9 @@ Ordering - Family of functions

pgr_cuthillMckeeOrdering
pgr_topologicalSort
pgr_sloanOrdering
pgr_kingOrdering
pgr_minDegreeOrdering
pgr_sloanOrdering

See Also
-------------------------------------------------------------------------------
Expand Down
110 changes: 110 additions & 0 deletions doc/ordering/pgr_minDegreeOrdering.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
..
****************************************************************************
pgRouting Manual
Copyright(c) pgRouting Contributors

This documentation is licensed under a Creative Commons Attribution-Share
Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/
****************************************************************************

.. index::
single: Ordering Family ; pgr_minDegreeOrdering
single: minDegreeOrdering - Experimental on v4.0

|

``pgr_minDegreeOrdering`` - Experimental
===============================================================================

``pgr_minDegreeOrdering`` — Returns the minimum degree ordering of an undirected graphs

.. include:: experimental.rst
:start-after: warning-begin
:end-before: end-warning

.. rubric:: Version 4.0.0

* New experimental function.

Description
-------------------------------------------------------------------------------

In numerical linear algebra, the MinDegree ordering is a heuristic used to
reduce the amount of fill-in during sparse matrix factorization, such as
Cholesky decomposition for symmetric matrices.

When eliminating variables in a sparse system, new nonzero entries—called
fill-ins—can appear in positions that were originally zero, increasing storage
and computation costs. The minimum degree approach attempts to reorder the
vertices (or equivalently, the rows and columns of the matrix) so that,
at each elimination step, the vertex with the smallest degree is removed first,
thereby reducing potential fill-in.

The main characteristics are:

- The implementation works on undirected graphs.
- The algorithm is a heuristic; finding the true optimal ordering is NP-complete.
- The time complexity is: :math:`O(|V| \log |V| + |E|)`

- where :math:`|V|` is the number of vertices,
- :math:`|E|` is the number of edges.

|Boost| Boost Graph Inside

Signatures
------------------------------------------------------------------------------

.. index::
single: minDegreeOrdering - Experimental on v4.0

.. admonition:: \ \
:class: signatures

| pgr_minDegreeOrdering(`Edges SQL`_)

| Returns set of |result_node_order|
| OR EMPTY SET

:Example: Graph ordering of pgRouting :doc:`sampledata`

.. literalinclude:: minDegreeOrdering.queries
:start-after: -- q1
:end-before: -- q2

Parameters
-------------------------------------------------------------------------------

.. include:: pgRouting-concepts.rst
:start-after: only_edge_param_start
:end-before: only_edge_param_end

Inner Queries
-------------------------------------------------------------------------------

Edges SQL
...............................................................................

.. include:: pgRouting-concepts.rst
:start-after: basic_edges_sql_start
:end-before: basic_edges_sql_end

Result columns
-------------------------------------------------------------------------------

.. include:: pgr_cuthillMckeeOrdering.rst
:start-after: node_ordering_start
:end-before: node_ordering_end

See Also
-------------------------------------------------------------------------------

* :doc:`sampledata`
* `Boost: King Ordering
<https://www.boost.org/libs/graph/doc/minimum_degree_ordering.html>`__

.. rubric:: Indices and tables

* :ref:`genindex`
* :ref:`search`


1 change: 1 addition & 0 deletions doc/src/pgRouting-introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ This Release Contributors
Individuals in this release v4.0.0 (in alphabetical order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Aurélie Bousquet,
Bipasha Gayary,
Fan Wu,
Regina Obe,
Expand Down
6 changes: 6 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ Summary of changes by function
:start-after: Version 4.0.0
:end-before: .. rubric

* pgr_minDegreeOrdering

.. include:: pgr_minDegreeOrdering.rst
:start-after: Version 4.0.0
:end-before: Description

* pgr_pushRelabel

.. include:: pgr_pushRelabel.rst
Expand Down
3 changes: 2 additions & 1 deletion docqueries/ordering/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
SET(LOCAL_FILES
cuthillMckeeOrdering
topologicalSort
sloanOrdering
kingOrdering
minDegreeOrdering
sloanOrdering
)

foreach (f ${LOCAL_FILES})
Expand Down
7 changes: 7 additions & 0 deletions docqueries/ordering/minDegreeOrdering.pg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- CopyRight(c) pgRouting developers
-- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/
/* -- q1 */
SELECT * FROM pgr_minDegreeOrdering(
'SELECT id, source, target, cost, reverse_cost FROM edges'
);
/* -- q2 */
32 changes: 32 additions & 0 deletions docqueries/ordering/minDegreeOrdering.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BEGIN;
BEGIN
SET client_min_messages TO NOTICE;
SET
/* -- q1 */
SELECT * FROM pgr_minDegreeOrdering(
'SELECT id, source, target, cost, reverse_cost FROM edges'
);
seq | node
-----+------
1 | 8
2 | 12
3 | 1
4 | 9
5 | 16
6 | 1
7 | 15
8 | 1
9 | 4
10 | 10
11 | 8
12 | 14
13 | 3
14 | 4
15 | 1
16 | 2
17 | 6
(17 rows)

/* -- q2 */
ROLLBACK;
ROLLBACK
4 changes: 2 additions & 2 deletions docqueries/ordering/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
%main::tests = (
'any' => {
'files' => [qw(
sloanOrdering.pg
cuthillMckeeOrdering.pg
topologicalSort.pg
sloanOrdering.pg
kingOrdering.pg
minDegreeOrdering.pg
sloanOrdering.pg
)]
},

Expand Down
96 changes: 96 additions & 0 deletions include/ordering/minDegreeOrdering.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*PGR-GNU*****************************************************************
File: minDegreeOrdering.hpp

Generated with Template by:
Copyright (c) 2015 pgRouting developers
Mail: project@pgrouting.org

Developer:
Copyright (c) 2025 Fan Wu
Mail: wifiblack0131 at gmail.com

------

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

********************************************************************PGR-GNU*/

#ifndef INCLUDE_ORDERING_MINDEGREEORDERING_HPP_
#define INCLUDE_ORDERING_MINDEGREEORDERING_HPP_
#pragma once

#include <vector>
#include <limits>
#include <iterator>
#include <utility>
#include <string>

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/property_map.hpp>


#include "cpp_common/base_graph.hpp"
#include "cpp_common/interruption.hpp"
#include <boost/graph/minimum_degree_ordering.hpp>


namespace pgrouting {

template <class G>
std::vector<int64_t>
minDegreeOrdering(G &graph) {
using V = typename G::V;

size_t n = boost::num_vertices(graph.graph);
std::vector<int64_t> results(n);

auto index_map = boost::get(boost::vertex_index, graph.graph);

std::vector<V> degrees(n);
auto degree_map = boost::make_iterator_property_map(degrees.begin(), index_map);

std::vector<V> supernode_sizes(n, 1);
auto supernode_map = boost::make_iterator_property_map(supernode_sizes.begin(), index_map);

std::vector<V> permutation(n);
std::vector<V> inv_permutation(n);

for (V v = 0; v < n; ++v) {
degree_map[v] = boost::degree(v, graph.graph);
}

CHECK_FOR_INTERRUPTS();

boost::minimum_degree_ordering(
graph.graph,
degree_map,
inv_permutation.begin(),
permutation.begin(),
supernode_map,
0,
index_map);

size_t j = 0;
for (auto i = inv_permutation.begin(); i != inv_permutation.end(); ++i, ++j) {
results[j] = static_cast<int64_t>(graph.graph[index_map[*i]].id);
}

return results;
}

} // namespace pgrouting

#endif // INCLUDE_ORDERING_ORDERING_HPP_
Loading
Loading