diff --git a/NEWS.md b/NEWS.md index 7708c36dcc..47d3db3f86 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/doc/_static/page_history.js b/doc/_static/page_history.js index cadff18276..3e3cd43798 100644 --- a/doc/_static/page_history.js +++ b/doc/_static/page_history.js @@ -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']}, diff --git a/doc/ordering/CMakeLists.txt b/doc/ordering/CMakeLists.txt index dcad220e9f..22f438ce02 100644 --- a/doc/ordering/CMakeLists.txt +++ b/doc/ordering/CMakeLists.txt @@ -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}) diff --git a/doc/ordering/ordering-family.rst b/doc/ordering/ordering-family.rst index 1b97a2adbb..dcada471e1 100644 --- a/doc/ordering/ordering-family.rst +++ b/doc/ordering/ordering-family.rst @@ -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 @@ -34,8 +34,9 @@ Ordering - Family of functions pgr_cuthillMckeeOrdering pgr_topologicalSort - pgr_sloanOrdering pgr_kingOrdering + pgr_minDegreeOrdering + pgr_sloanOrdering See Also ------------------------------------------------------------------------------- diff --git a/doc/ordering/pgr_minDegreeOrdering.rst b/doc/ordering/pgr_minDegreeOrdering.rst new file mode 100644 index 0000000000..b658454676 --- /dev/null +++ b/doc/ordering/pgr_minDegreeOrdering.rst @@ -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 + `__ + +.. rubric:: Indices and tables + +* :ref:`genindex` +* :ref:`search` + + diff --git a/doc/src/pgRouting-introduction.rst b/doc/src/pgRouting-introduction.rst index fa79aa18c5..bdb3c301e3 100644 --- a/doc/src/pgRouting-introduction.rst +++ b/doc/src/pgRouting-introduction.rst @@ -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, diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 30399d42ea..bb5d17cd54 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -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 diff --git a/docqueries/ordering/CMakeLists.txt b/docqueries/ordering/CMakeLists.txt index 5e23c98677..e9dfe392b8 100644 --- a/docqueries/ordering/CMakeLists.txt +++ b/docqueries/ordering/CMakeLists.txt @@ -2,8 +2,9 @@ SET(LOCAL_FILES cuthillMckeeOrdering topologicalSort - sloanOrdering kingOrdering + minDegreeOrdering + sloanOrdering ) foreach (f ${LOCAL_FILES}) diff --git a/docqueries/ordering/minDegreeOrdering.pg b/docqueries/ordering/minDegreeOrdering.pg new file mode 100644 index 0000000000..66b4bee250 --- /dev/null +++ b/docqueries/ordering/minDegreeOrdering.pg @@ -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 */ diff --git a/docqueries/ordering/minDegreeOrdering.result b/docqueries/ordering/minDegreeOrdering.result new file mode 100644 index 0000000000..453762e4f0 --- /dev/null +++ b/docqueries/ordering/minDegreeOrdering.result @@ -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 diff --git a/docqueries/ordering/test.conf b/docqueries/ordering/test.conf index 4b7a245616..30910300a2 100644 --- a/docqueries/ordering/test.conf +++ b/docqueries/ordering/test.conf @@ -3,11 +3,11 @@ %main::tests = ( 'any' => { 'files' => [qw( - sloanOrdering.pg cuthillMckeeOrdering.pg topologicalSort.pg - sloanOrdering.pg kingOrdering.pg + minDegreeOrdering.pg + sloanOrdering.pg )] }, diff --git a/include/ordering/minDegreeOrdering.hpp b/include/ordering/minDegreeOrdering.hpp new file mode 100644 index 0000000000..5040b7463a --- /dev/null +++ b/include/ordering/minDegreeOrdering.hpp @@ -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 +#include +#include +#include +#include + +#include +#include +#include + + +#include "cpp_common/base_graph.hpp" +#include "cpp_common/interruption.hpp" +#include + + +namespace pgrouting { + +template +std::vector +minDegreeOrdering(G &graph) { + using V = typename G::V; + + size_t n = boost::num_vertices(graph.graph); + std::vector results(n); + + auto index_map = boost::get(boost::vertex_index, graph.graph); + + std::vector degrees(n); + auto degree_map = boost::make_iterator_property_map(degrees.begin(), index_map); + + std::vector supernode_sizes(n, 1); + auto supernode_map = boost::make_iterator_property_map(supernode_sizes.begin(), index_map); + + std::vector permutation(n); + std::vector 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(graph.graph[index_map[*i]].id); + } + + return results; +} + +} // namespace pgrouting + +#endif // INCLUDE_ORDERING_ORDERING_HPP_ diff --git a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po index 85185c4bc9..5809048841 100644 --- a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v3.8\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-08-23 02:38+0000\n" +"POT-Creation-Date: 2025-08-26 09:58+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3403,7 +3403,17 @@ msgstr "" msgid "" ":doc:`pgr_kingOrdering` - Returns the King ordering of an undirected " -"graphs acyclic graph." +"graph." +msgstr "" + +msgid "" +":doc:`pgr_minDegreeOrdering` - Returns the Minimum Degree ordering of an " +"undirected graph." +msgstr "" + +msgid "" +":doc:`pgr_sloanOrdering` - Returns the Sloan ordering of an undirected " +"graph." msgstr "" msgid ":doc:`metrics-family`" @@ -4110,9 +4120,15 @@ msgstr "" msgid "pgr_maxFlow" msgstr "" +msgid "pgr_minDegreeOrdering" +msgstr "" + msgid "pgr_pushRelabel" msgstr "" +msgid "pgr_sloanOrdering" +msgstr "" + msgid "pgr_sequentialVertexColoring" msgstr "" @@ -4398,6 +4414,11 @@ msgid "" "pgr_kingOrdering" msgstr "" +msgid "" +"`#2955 `__: " +"pgr_sloanOrdering" +msgstr "" + msgid "SQL signatures and output standardization" msgstr "" @@ -8274,7 +8295,9 @@ msgstr "" msgid "Individuals in this release v4.0.0 (in alphabetical order)" msgstr "" -msgid "Fan Wu Regina Obe, Saloni kumari, Vicky Vergara" +msgid "" +"Aurélie Bousquet, Bipasha Gayary, Fan Wu, Regina Obe, Saloni kumari, " +"Vicky Vergara" msgstr "" msgid "" @@ -8321,17 +8344,17 @@ msgstr "" msgid "" "Aasheesh Tiwari, Abhinav Jain, Aditya Pratap Singh, Adrien Berchet, Akio " "Takubo, Andrea Nardelli, Anthony Tasca, Anton Patrushev, Aryan Gupta, " -"Ashraf Hossain, Ashish Kumar, Aurélie Bousquet, Cayetano Benavent, " -"Christian Gonzalez, Daniel Kastl, Dapeng Wang, Dave Potts, David Techer, " -"Denis Rykov, Ema Miyawaki, Esteban Zimanyi, Fan Wu, Florian Thurkow, " -"Frederic Junod, Gerald Fenoy, Gudesa Venkata Sai Akhil, Hang Wu, Himanshu" -" Raj, Imre Samu, Jay Mahadeokar, Jinfu Leng, Kai Behncke, Kishore Kumar, " -"Ko Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, Martin Wiesenhaan," -" Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed Zia, Mukul Priya, " -"Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina Obe, Rohith Reddy, " -"Saloni Kumari, Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen " -"Woodbridge, Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit " -"Kumar, Vidhan Jain, Virginia Vergara, Yige Huang" +"Ashraf Hossain, Ashish Kumar, Aurélie Bousquet, Bipasha Gayary, Cayetano " +"Benavent, Christian Gonzalez, Daniel Kastl, Dapeng Wang, Dave Potts, " +"David Techer, Denis Rykov, Ema Miyawaki, Esteban Zimanyi, Fan Wu, Florian" +" Thurkow, Frederic Junod, Gerald Fenoy, Gudesa Venkata Sai Akhil, Hang " +"Wu, Himanshu Raj, Imre Samu, Jay Mahadeokar, Jinfu Leng, Kai Behncke, " +"Kishore Kumar, Ko Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, " +"Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed " +"Zia, Mukul Priya, Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina " +"Obe, Rohith Reddy, Saloni Kumari, Sarthak Agarwal, Shobhit Chaurasia, " +"Sourabh Garg, Stephen Woodbridge, Swapnil Joshi, Sylvain Housseman, " +"Sylvain Pasche, Veenit Kumar, Vidhan Jain, Virginia Vergara, Yige Huang" msgstr "" msgid "Corporate Sponsors (in alphabetical order)" @@ -14248,6 +14271,51 @@ msgstr "" msgid "Minimum Cost Maximum Flow possible from the source(s) to the target(s)" msgstr "" +msgid "``pgr_minDegreeOrdering`` - Experimental" +msgstr "" + +msgid "" +"``pgr_minDegreeOrdering`` — Returns the minimum degree ordering of an " +"undirected graphs" +msgstr "" + +msgid "" +"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." +msgstr "" + +msgid "" +"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." +msgstr "" + +msgid "The implementation works on undirected graphs." +msgstr "" + +msgid "" +"The algorithm is a heuristic; finding the true optimal ordering is NP-" +"complete." +msgstr "" + +msgid "The time complexity is: :math:`O(|V| \\log |V| + |E|)`" +msgstr "" + +msgid ":math:`|E|` is the number of edges." +msgstr "" + +msgid "pgr_minDegreeOrdering(`Edges SQL`_)" +msgstr "" + +msgid "" +"`Boost: King Ordering " +"`__" +msgstr "" + msgid "``pgr_pickDeliver`` - Experimental" msgstr "" @@ -14673,6 +14741,94 @@ msgid "" "`__" msgstr "" +msgid "``pgr_sloanOrdering`` - Experimental" +msgstr "" + +msgid "``pgr_sloanOrdering`` — Returns the sloan ordering of an undirected graph" +msgstr "" + +msgid "" +"The Sloan ordering algorithm reorders the vertices of a graph to reduce " +"bandwidth, profile, and wavefront properties, which is particularly " +"useful for sparse matrix computations and finite element analysis." +msgstr "" + +msgid "Finds a pseudoperipheral vertex pair to determine good starting points" +msgstr "" + +msgid "" +"Uses a priority-based algorithm that balances vertex degree and distance " +"from the start vertex." +msgstr "" + +msgid "" +"Aims to mininimize bandwidth (maximum difference between connected vertex" +" indices." +msgstr "" + +msgid "Typically produces better orderings than simple breadth-first approaches." +msgstr "" + +msgid "Run time is 0.115846 seconds." +msgstr "" + +msgid "|Boost| Boost Graph inside" +msgstr "" + +msgid "..rubric::Summary" +msgstr "" + +msgid "pgr_sloanOrdering(`Edges SQL`_)" +msgstr "" + +msgid ":Example : Sloan ordering without specifying start vertex" +msgstr "" + +msgid "New sloan ordering order." +msgstr "" + +msgid "Sloan ordering of Original graph from Boost example (vertices 0-9)." +msgstr "" + +msgid "..graphviz::" +msgstr "" + +msgid "" +"graph G{ node[shape=circle, style=filled, fillcolor=lightblue, " +"color=black, fontcolor=black, fontsize=12]; edge[color=black, " +"penwidth=1.5];" +msgstr "" + +msgid "" +"0 -- 3; 0 -- 5; 1 -- 2; 1 -- 4; 1 -- 6; 1 -- 9; 2 -- 3; 2 -- 4; 3 -- 5; 3" +" -- 8; 4 -- 6; 5 -- 6; 5 -- 7; 6 -- 7;" +msgstr "" + +msgid "" +"{rank=same; 0; 8;} {rank=same; 3; 5; 7;} {rank=same; 2; 4; 6;} " +"{rank=same; 1; 9;}" +msgstr "" + +msgid "}" +msgstr "" + +msgid "..literalinclude::sloanOrdering.queries" +msgstr "" + +msgid "start-after" +msgstr "" + +msgid "--q3" +msgstr "" + +msgid "--q4" +msgstr "" + +msgid "" +"`Boost: Sloan Ordering " +"`__" +msgstr "" + msgid "``pgr_stoerWagner`` - Experimental" msgstr "" diff --git a/locale/pot/pgrouting_doc_strings.pot b/locale/pot/pgrouting_doc_strings.pot index ef8c31932d..d4efd03b38 100644 --- a/locale/pot/pgrouting_doc_strings.pot +++ b/locale/pot/pgrouting_doc_strings.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v4.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-08-23 02:38+0000\n" +"POT-Creation-Date: 2025-08-26 09:58+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3076,7 +3076,13 @@ msgstr "" msgid ":doc:`pgr_topologicalSort` - Linear ordering of the vertices for directed acyclic graph." msgstr "" -msgid ":doc:`pgr_kingOrdering` - Returns the King ordering of an undirected graphs acyclic graph." +msgid ":doc:`pgr_kingOrdering` - Returns the King ordering of an undirected graph." +msgstr "" + +msgid ":doc:`pgr_minDegreeOrdering` - Returns the Minimum Degree ordering of an undirected graph." +msgstr "" + +msgid ":doc:`pgr_sloanOrdering` - Returns the Sloan ordering of an undirected graph." msgstr "" msgid ":doc:`metrics-family`" @@ -3703,9 +3709,15 @@ msgstr "" msgid "pgr_maxFlow" msgstr "" +msgid "pgr_minDegreeOrdering" +msgstr "" + msgid "pgr_pushRelabel" msgstr "" +msgid "pgr_sloanOrdering" +msgstr "" + msgid "pgr_sequentialVertexColoring" msgstr "" @@ -3937,6 +3949,9 @@ msgstr "" msgid "`#2954 `__: pgr_kingOrdering" msgstr "" +msgid "`#2955 `__: pgr_sloanOrdering" +msgstr "" + msgid "SQL signatures and output standardization" msgstr "" @@ -7078,7 +7093,7 @@ msgstr "" msgid "Individuals in this release v4.0.0 (in alphabetical order)" msgstr "" -msgid "Fan Wu Regina Obe, Saloni kumari, Vicky Vergara" +msgid "Aurélie Bousquet, Bipasha Gayary, Fan Wu, Regina Obe, Saloni kumari, Vicky Vergara" msgstr "" msgid "And all the people that give us a little of their time making comments, finding issues, making pull requests etc. in any of our products: osm2pgrouting, pgRouting, pgRoutingLayer, workshop." @@ -7117,7 +7132,7 @@ msgstr "" msgid "Individuals (in alphabetical order)" msgstr "" -msgid "Aasheesh Tiwari, Abhinav Jain, Aditya Pratap Singh, Adrien Berchet, Akio Takubo, Andrea Nardelli, Anthony Tasca, Anton Patrushev, Aryan Gupta, Ashraf Hossain, Ashish Kumar, Aurélie Bousquet, Cayetano Benavent, Christian Gonzalez, Daniel Kastl, Dapeng Wang, Dave Potts, David Techer, Denis Rykov, Ema Miyawaki, Esteban Zimanyi, Fan Wu, Florian Thurkow, Frederic Junod, Gerald Fenoy, Gudesa Venkata Sai Akhil, Hang Wu, Himanshu Raj, Imre Samu, Jay Mahadeokar, Jinfu Leng, Kai Behncke, Kishore Kumar, Ko Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed Zia, Mukul Priya, Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina Obe, Rohith Reddy, Saloni Kumari, Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen Woodbridge, Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit Kumar, Vidhan Jain, Virginia Vergara, Yige Huang" +msgid "Aasheesh Tiwari, Abhinav Jain, Aditya Pratap Singh, Adrien Berchet, Akio Takubo, Andrea Nardelli, Anthony Tasca, Anton Patrushev, Aryan Gupta, Ashraf Hossain, Ashish Kumar, Aurélie Bousquet, Bipasha Gayary, Cayetano Benavent, Christian Gonzalez, Daniel Kastl, Dapeng Wang, Dave Potts, David Techer, Denis Rykov, Ema Miyawaki, Esteban Zimanyi, Fan Wu, Florian Thurkow, Frederic Junod, Gerald Fenoy, Gudesa Venkata Sai Akhil, Hang Wu, Himanshu Raj, Imre Samu, Jay Mahadeokar, Jinfu Leng, Kai Behncke, Kishore Kumar, Ko Nagase, Mahmoud Sakr, Manikata Kondeti, Mario Basa, Martin Wiesenhaan, Maxim Dubinin, Maoguang Wang, Mohamed Bakli, Mohamed Zia, Mukul Priya, Nitish Chauhan, Rajat Shinde, Razequl Islam, Regina Obe, Rohith Reddy, Saloni Kumari, Sarthak Agarwal, Shobhit Chaurasia, Sourabh Garg, Stephen Woodbridge, Swapnil Joshi, Sylvain Housseman, Sylvain Pasche, Veenit Kumar, Vidhan Jain, Virginia Vergara, Yige Huang" msgstr "" msgid "Corporate Sponsors (in alphabetical order)" @@ -11977,6 +11992,36 @@ msgstr "" msgid "Minimum Cost Maximum Flow possible from the source(s) to the target(s)" msgstr "" +msgid "``pgr_minDegreeOrdering`` - Experimental" +msgstr "" + +msgid "``pgr_minDegreeOrdering`` — Returns the minimum degree ordering of an undirected graphs" +msgstr "" + +msgid "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." +msgstr "" + +msgid "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." +msgstr "" + +msgid "The implementation works on undirected graphs." +msgstr "" + +msgid "The algorithm is a heuristic; finding the true optimal ordering is NP-complete." +msgstr "" + +msgid "The time complexity is: :math:`O(|V| \\log |V| + |E|)`" +msgstr "" + +msgid ":math:`|E|` is the number of edges." +msgstr "" + +msgid "pgr_minDegreeOrdering(`Edges SQL`_)" +msgstr "" + +msgid "`Boost: King Ordering `__" +msgstr "" + msgid "``pgr_pickDeliver`` - Experimental" msgstr "" @@ -12346,6 +12391,78 @@ msgstr "" msgid "`Boost: Sequential Vertex Coloring `__" msgstr "" +msgid "``pgr_sloanOrdering`` - Experimental" +msgstr "" + +msgid "``pgr_sloanOrdering`` — Returns the sloan ordering of an undirected graph" +msgstr "" + +msgid "The Sloan ordering algorithm reorders the vertices of a graph to reduce bandwidth, profile, and wavefront properties, which is particularly useful for sparse matrix computations and finite element analysis." +msgstr "" + +msgid "Finds a pseudoperipheral vertex pair to determine good starting points" +msgstr "" + +msgid "Uses a priority-based algorithm that balances vertex degree and distance from the start vertex." +msgstr "" + +msgid "Aims to mininimize bandwidth (maximum difference between connected vertex indices." +msgstr "" + +msgid "Typically produces better orderings than simple breadth-first approaches." +msgstr "" + +msgid "Run time is 0.115846 seconds." +msgstr "" + +msgid "|Boost| Boost Graph inside" +msgstr "" + +msgid "..rubric::Summary" +msgstr "" + +msgid "pgr_sloanOrdering(`Edges SQL`_)" +msgstr "" + +msgid ":Example : Sloan ordering without specifying start vertex" +msgstr "" + +msgid "New sloan ordering order." +msgstr "" + +msgid "Sloan ordering of Original graph from Boost example (vertices 0-9)." +msgstr "" + +msgid "..graphviz::" +msgstr "" + +msgid "graph G{ node[shape=circle, style=filled, fillcolor=lightblue, color=black, fontcolor=black, fontsize=12]; edge[color=black, penwidth=1.5];" +msgstr "" + +msgid "0 -- 3; 0 -- 5; 1 -- 2; 1 -- 4; 1 -- 6; 1 -- 9; 2 -- 3; 2 -- 4; 3 -- 5; 3 -- 8; 4 -- 6; 5 -- 6; 5 -- 7; 6 -- 7;" +msgstr "" + +msgid "{rank=same; 0; 8;} {rank=same; 3; 5; 7;} {rank=same; 2; 4; 6;} {rank=same; 1; 9;}" +msgstr "" + +msgid "}" +msgstr "" + +msgid "..literalinclude::sloanOrdering.queries" +msgstr "" + +msgid "start-after" +msgstr "" + +msgid "--q3" +msgstr "" + +msgid "--q4" +msgstr "" + +msgid "`Boost: Sloan Ordering `__" +msgstr "" + msgid "``pgr_stoerWagner`` - Experimental" msgstr "" diff --git a/pgtap/ordering/minDegreeOrdering/edge_cases.pg b/pgtap/ordering/minDegreeOrdering/edge_cases.pg new file mode 100644 index 0000000000..677a5146a8 --- /dev/null +++ b/pgtap/ordering/minDegreeOrdering/edge_cases.pg @@ -0,0 +1,99 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2018 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('4.0.0') THEN plan(1) ELSE plan(3) END; + + +CREATE OR REPLACE FUNCTION edge_cases() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + +IF NOT min_version('4.0.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 4.0.0'); + RETURN; +END IF; + +-- 0 edge, 0 vertex test + +PREPARE q1 AS +SELECT * FROM pgr_minDegreeOrdering( +'SELECT id, source, target, cost, reverse_cost FROM edges WHERE id > 18' +); + +RETURN QUERY +SELECT is_empty('q1', 'Graph with 0 edge and 0 vertex -> Empty row is returned'); + +-- 3 vertices test + +PREPARE q6 AS +SELECT * +FROM pgr_minDegreeOrdering('SELECT id, source, target, cost, reverse_cost FROM edges WHERE id <= 2' +); + +RETURN QUERY +SELECT set_eq('q6', $$VALUES (1, 6), (2, 10), (3, 5)$$, 'Three connected vertices are ordered as expected'); + +-- pgRouting sample data + +CREATE TABLE expected_result ( +seq BIGINT, +node BIGINT); + +INSERT INTO expected_result (seq, node) VALUES +(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); + +PREPARE q7 AS +SELECT * FROM pgr_minDegreeOrdering('SELECT id, source, target, cost, reverse_cost FROM edges' +); + +PREPARE r7 AS +SELECT * FROM expected_result; + +RETURN QUERY SELECT set_eq('q7','r7','Minimum Degree Ordering result matches expected sequence for pgRouting sample data'); + +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT edge_cases(); + + +SELECT * FROM finish(); +ROLLBACK; diff --git a/pgtap/ordering/minDegreeOrdering/inner_query.pg b/pgtap/ordering/minDegreeOrdering/inner_query.pg new file mode 100644 index 0000000000..c2139a26e2 --- /dev/null +++ b/pgtap/ordering/minDegreeOrdering/inner_query.pg @@ -0,0 +1,46 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2018 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('4.0.0') THEN plan(1) ELSE plan(54) END; + +CREATE OR REPLACE FUNCTION inner_query() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + +IF NOT min_version('4.0.0') THEN + RETURN QUERY + SELECT skip(1, 'pgr_minDegreeOrdering is new on 4.0.0'); + RETURN; +END IF; + +RETURN QUERY +SELECT style_dijkstra('pgr_minDegreeOrdering(', ')'); + +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT inner_query(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/ordering/minDegreeOrdering/no_crash_test.pg b/pgtap/ordering/minDegreeOrdering/no_crash_test.pg new file mode 100644 index 0000000000..0859a8b569 --- /dev/null +++ b/pgtap/ordering/minDegreeOrdering/no_crash_test.pg @@ -0,0 +1,74 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2018 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); +SELECT CASE WHEN NOT min_version('4.0.0') THEN plan(1) ELSE plan(7) END; + +PREPARE edges AS +SELECT id, source, target, cost, reverse_cost FROM edges; + +PREPARE null_ret AS +SELECT id FROM vertices WHERE id IN (-1); + +PREPARE null_ret_arr AS +SELECT array_agg(id) FROM vertices WHERE id IN (-1); + + + +CREATE OR REPLACE FUNCTION no_crash() +RETURNS SETOF TEXT AS +$BODY$ +DECLARE +params TEXT[]; +subs TEXT[]; +BEGIN + IF NOT min_version('4.0.0') THEN + RETURN QUERY + SELECT skip(1, 'Function is new on 4.0.0'); + RETURN; + END IF; + + RETURN QUERY + SELECT isnt_empty('edges', 'Should be not empty to tests be meaningful'); + RETURN QUERY + SELECT is_empty('null_ret', 'Should be empty to tests be meaningful'); + RETURN QUERY + SELECT set_eq('null_ret_arr', 'SELECT NULL::BIGINT[]', 'Should be empty to tests be meaningful'); + + -- pgr_minDegreeOrdering + params = ARRAY[ + '$$SELECT id, source, target, cost, reverse_cost FROM edges$$' + ]::TEXT[]; + subs = ARRAY[ + 'NULL' + ]::TEXT[]; + + RETURN query SELECT * FROM no_crash_test('pgr_minDegreeOrdering', params, subs); + +END +$BODY$ +LANGUAGE plpgsql VOLATILE; + + +SELECT * FROM no_crash(); + +SELECT finish(); +ROLLBACK; diff --git a/pgtap/ordering/minDegreeOrdering/types_check.pg b/pgtap/ordering/minDegreeOrdering/types_check.pg new file mode 100644 index 0000000000..fd499928f2 --- /dev/null +++ b/pgtap/ordering/minDegreeOrdering/types_check.pg @@ -0,0 +1,56 @@ + +/*PGR-GNU***************************************************************** + +Copyright (c) 2018 pgRouting developers +Mail: project@pgrouting.org + +------ +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*/ +BEGIN; + +SELECT CASE WHEN min_version('4.0.0') THEN plan(5) ELSE plan(1) END; + +CREATE OR REPLACE FUNCTION types_check() +RETURNS SETOF TEXT AS +$BODY$ +BEGIN + + IF NOT min_version('4.0.0') THEN + RETURN QUERY SELECT skip(1, 'pgr_minDegreeOrdering: Function is new on 4.0.0'); + RETURN; + END IF; + + RETURN QUERY SELECT has_function('pgr_mindegreeordering'); + RETURN QUERY SELECT has_function('pgr_mindegreeordering', ARRAY['text']); + RETURN QUERY SELECT function_returns('pgr_mindegreeordering', ARRAY['text'], 'setof record'); + + RETURN QUERY + SELECT function_args_eq('pgr_mindegreeordering', + $$SELECT '{"", seq, node}'::TEXT[] $$ + ); + + RETURN QUERY + SELECT function_types_eq('pgr_mindegreeordering', + $$VALUES + ('{text,int8,int8}'::TEXT[]) + $$ + ); +END; +$BODY$ +LANGUAGE plpgsql; + +SELECT types_check(); + +SELECT * FROM finish(); +ROLLBACK; diff --git a/sql/ordering/CMakeLists.txt b/sql/ordering/CMakeLists.txt index 4f86a08284..06c25eac05 100644 --- a/sql/ordering/CMakeLists.txt +++ b/sql/ordering/CMakeLists.txt @@ -1,6 +1,8 @@ SET(LOCAL_FILES _cuthillMckeeOrdering.sql cuthillMckeeOrdering.sql + _minDegreeOrdering.sql + minDegreeOrdering.sql _sloanOrdering.sql sloanOrdering.sql _kingOrdering.sql diff --git a/sql/ordering/_minDegreeOrdering.sql b/sql/ordering/_minDegreeOrdering.sql new file mode 100644 index 0000000000..de85bc564f --- /dev/null +++ b/sql/ordering/_minDegreeOrdering.sql @@ -0,0 +1,49 @@ +/*PGR-GNU***************************************************************** +File: _minDegreeOrdering.sql + +Generated with Template by: +Copyright (c) 2025 pgRouting developers +Mail: project@pgrouting.org + +Function's 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*/ + +---------------------------- +-- _pgr_minDegreeOrdering +---------------------------- + +--v4.0 +CREATE FUNCTION _pgr_minDegreeOrdering( + TEXT, + OUT seq BIGINT, + OUT node BIGINT + ) + +RETURNS SETOF RECORD AS +'MODULE_PATHNAME' +LANGUAGE C IMMUTABLE STRICT; + +-- COMMENTS + +COMMENT ON FUNCTION _pgr_minDegreeOrdering(TEXT) +IS 'pgRouting internal function'; + diff --git a/sql/ordering/minDegreeOrdering.sql b/sql/ordering/minDegreeOrdering.sql new file mode 100644 index 0000000000..246648d32e --- /dev/null +++ b/sql/ordering/minDegreeOrdering.sql @@ -0,0 +1,55 @@ +/*PGR-GNU***************************************************************** +File: minDegreeOrdering.sql + +Generated with Template by: +Copyright (c) 2025 pgRouting developers +Mail: project@pgrouting.org + +Function's 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*/ + +---------------------------- +-- pgr_minDegreeOrdering +---------------------------- + +--v4.0 +CREATE FUNCTION pgr_minDegreeOrdering( + TEXT, -- edges_sql (required) + OUT seq BIGINT, + OUT node BIGINT) +RETURNS SETOF RECORD AS +$BODY$ + SELECT seq, node + FROM _pgr_minDegreeOrdering(_pgr_get_statement($1)); +$BODY$ +LANGUAGE SQL VOLATILE STRICT; + +-- COMMENTS + +COMMENT ON FUNCTION pgr_minDegreeOrdering(TEXT) +IS 'pgr_minDegreeOrdering +- EXPERIMENTAL +- Parameters: + - Edges SQL with columns: id, source, target, cost [,reverse_cost] +- Documentation: + - ${PROJECT_DOC_LINK}/pgr_minDegreeOrdering.html +'; diff --git a/sql/sigs/pgrouting--4.0.sig b/sql/sigs/pgrouting--4.0.sig index 90ec9ccaff..2507d1bd62 100644 --- a/sql/sigs/pgrouting--4.0.sig +++ b/sql/sigs/pgrouting--4.0.sig @@ -213,6 +213,8 @@ pgr_maxflow(text,bigint,anyarray) pgr_maxflow(text,bigint,bigint) pgr_maxflow(text,text) _pgr_maxflow(text,text,integer,boolean) +_pgr_mindegreeordering(text) +pgr_mindegreeordering(text) _pgr_operating_system() _pgr_parameter_check(text,text,boolean) _pgr_pgsql_version() diff --git a/src/ordering/CMakeLists.txt b/src/ordering/CMakeLists.txt index 71f25541c5..62e0ad5f3b 100644 --- a/src/ordering/CMakeLists.txt +++ b/src/ordering/CMakeLists.txt @@ -1,5 +1,6 @@ ADD_LIBRARY(ordering OBJECT kingOrdering.c + minDegreeOrdering.c cuthillMckeeOrdering.c cuthillMckeeOrdering_driver.cpp sloanOrdering.c diff --git a/src/ordering/minDegreeOrdering.c b/src/ordering/minDegreeOrdering.c new file mode 100644 index 0000000000..2599b13b78 --- /dev/null +++ b/src/ordering/minDegreeOrdering.c @@ -0,0 +1,104 @@ +/*PGR-GNU***************************************************************** +File: minDegreeOrdering.c + +Generated with Template by: +Copyright (c) 2025 pgRouting developers +Mail: project@pgrouting.org + +Function's 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*/ + +#include +#include "c_common/postgres_connection.h" + +#include "c_common/debug_macro.h" +#include "c_common/e_report.h" +#include "c_common/time_msg.h" + +#include "process/ordering_process.h" + +PGDLLEXPORT Datum _pgr_mindegreeordering(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(_pgr_mindegreeordering); + + +PGDLLEXPORT Datum +_pgr_mindegreeordering(PG_FUNCTION_ARGS) { + FuncCallContext *funcctx; + TupleDesc tuple_desc; + + int64_t *result_tuples = NULL; + size_t result_count = 0; + + if (SRF_IS_FIRSTCALL()) { + MemoryContext oldcontext; + funcctx = SRF_FIRSTCALL_INIT(); + oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); + + + pgr_process_ordering( + text_to_cstring(PG_GETARG_TEXT_P(0)), + 2, /*MinDegree Ordering*/ + &result_tuples, + &result_count); + + funcctx->max_calls = result_count; + funcctx->user_fctx = result_tuples; + if (get_call_result_type(fcinfo, NULL, &tuple_desc) + != TYPEFUNC_COMPOSITE) { + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("function returning record called in context " + "that cannot accept type record"))); + } + + funcctx->tuple_desc = tuple_desc; + MemoryContextSwitchTo(oldcontext); + } + + funcctx = SRF_PERCALL_SETUP(); + tuple_desc = funcctx->tuple_desc; + result_tuples = (int64_t*) funcctx->user_fctx; + + if (funcctx->call_cntr < funcctx->max_calls) { + HeapTuple tuple; + Datum result; + Datum *values; + bool* nulls; + + size_t num = 2; + values = palloc(num * sizeof(Datum)); + nulls = palloc(num * sizeof(bool)); + + + size_t i; + for (i = 0; i < num; ++i) { + nulls[i] = false; + } + + values[0] = Int64GetDatum((int64_t)funcctx->call_cntr + 1); + values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr]); + + tuple = heap_form_tuple(tuple_desc, values, nulls); + result = HeapTupleGetDatum(tuple); + SRF_RETURN_NEXT(funcctx, result); + } else { + SRF_RETURN_DONE(funcctx); + } +} diff --git a/src/ordering/ordering_driver.cpp b/src/ordering/ordering_driver.cpp index 67e7e869a8..6ff53d054b 100644 --- a/src/ordering/ordering_driver.cpp +++ b/src/ordering/ordering_driver.cpp @@ -107,6 +107,8 @@ do_ordering( results = sloanOrdering(undigraph); } else if (which == 2) { results = kingOrdering(undigraph); + } else if (which == 3) { + results = minDegreeOrdering(undigraph); } auto count = results.size(); diff --git a/src/ordering/ordering_process.cpp b/src/ordering/ordering_process.cpp index 336d4b475f..6546fb72f8 100644 --- a/src/ordering/ordering_process.cpp +++ b/src/ordering/ordering_process.cpp @@ -44,6 +44,7 @@ extern "C" { which = 0 -> sloan which = 1 -> cuthillmckee which = 2 -> king + which = 3 -> mindegree This is c++ code, linked as C code, because pgr_process_foo is called from C code */ @@ -73,6 +74,8 @@ void pgr_process_ordering( time_msg(std::string("processing pgr_cuthillMckeeOrdering").c_str(), start_t, clock()); } else if (which == 2) { time_msg(std::string("processing pgr_kingOrdering").c_str(), start_t, clock()); + } else if (which == 3) { + time_msg(std::string("processing pgr_minDegreeOrdering").c_str(), start_t, clock()); } if (err_msg && (*result_tuples)) {