-
-
Notifications
You must be signed in to change notification settings - Fork 385
Standardize ordering functions code #3026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c1f716f
1e7b691
5ed24ee
c002755
29a0e3e
2a976d4
f1cbcca
db36916
3de0a65
3aa6a06
69f5459
70afceb
09b2ccf
81d896c
6b3812f
148f16f
f4880ac
c475364
c451475
3ee61ff
c4ab9e4
2db6b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,10 @@ Bug Fixes | |
|
|
||
| * [#2966](https://github.com/pgRouting/pgrouting/issues/2966): pgr_withPoints does not pick optimal route when fraction = 1 | ||
|
|
||
| Code enhancement | ||
|
|
||
| * [#3025](https://github.com/pgRouting/pgrouting/issues/3025): Ordering functions standardized | ||
|
Comment on lines
+19
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NEWS.md is auto-generated and should not be edited manually. The changes to NEWS.md (lines 19–21) modify an auto-generated file. Per pgRouting's workflow, changes to NEWS.md content should be implemented via the generator script Please move the "Code enhancement" entry to the source file that feeds the notes2news.pl script instead of editing NEWS.md directly. 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| ## pgRouting 4.0 | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,35 @@ | ||
| /*PGR-GNU***************************************************************** | ||
| File: i_rt.h | ||
| File: enums.h | ||
| Copyright (c) 2015 pgRouting developers | ||
| Copyright (c) 2025 pgRouting developers | ||
| Mail: [email protected] | ||
| Function's developer: | ||
| Copyright (c) 2019 Hang Wu | ||
| mail: [email protected] | ||
| ------ | ||
| 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*/ | ||
| /*! @file */ | ||
|
|
||
| #ifndef INCLUDE_C_TYPES_I_RT_H_ | ||
| #define INCLUDE_C_TYPES_I_RT_H_ | ||
| #pragma once | ||
|
|
||
| /* for int64_t */ | ||
| #ifdef __cplusplus | ||
| # include <cstdint> | ||
| #else | ||
| # include <stdint.h> | ||
| #endif | ||
|
|
||
| struct I_rt { | ||
| int64_t id; | ||
| ********************************************************************PGR-GNU*/ | ||
|
|
||
| #ifndef INCLUDE_C_COMMON_ENUMS_H_ | ||
| #define INCLUDE_C_COMMON_ENUMS_H_ | ||
|
|
||
| enum Which { | ||
| /** undirected graph + results: vertex id */ | ||
| SLOAN = 0, CUTCHILL, KING, | ||
| /** directed graph + results: vertex id */ | ||
| TOPOSORT = 11 | ||
| }; | ||
cvvergara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #endif // INCLUDE_C_TYPES_I_RT_H_ | ||
| #endif // INCLUDE_C_COMMON_ENUMS_H_ | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,128 +31,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| #define INCLUDE_ORDERING_CUTHILLMCKEEORDERING_HPP_ | ||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
| #include <vector> | ||
| #include <map> | ||
| #include <cstdint> | ||
|
|
||
| #include <boost/property_map/property_map.hpp> | ||
| #include <boost/graph/graph_traits.hpp> | ||
| #include <boost/property_map/vector_property_map.hpp> | ||
| #include <boost/type_traits.hpp> | ||
| #include <boost/graph/adjacency_list.hpp> | ||
| #include <boost/graph/cuthill_mckee_ordering.hpp> | ||
|
|
||
| #include "cpp_common/base_graph.hpp" | ||
| #include "cpp_common/interruption.hpp" | ||
| #include "cpp_common/messages.hpp" | ||
|
|
||
| #include "c_types/ii_t_rt.h" | ||
|
|
||
| /** @file cuthillMckeeOrdering.hpp | ||
| * @brief The main file which calls the respective boost function. | ||
| * | ||
| * Contains actual implementation of the function and the calling | ||
| * of the respective boost function. | ||
| */ | ||
|
|
||
|
|
||
| namespace pgrouting { | ||
| namespace functions { | ||
|
|
||
| template <class G> | ||
| class CuthillMckeeOrdering : public Pgr_messages { | ||
| public: | ||
| typedef typename G::V V; | ||
| typedef typename G::E E; | ||
| typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph; | ||
| typedef boost::graph_traits<Graph>::vertices_size_type size_type; | ||
| typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; | ||
|
|
||
| /** @name CuthillMckeeOrdering | ||
| * @{ | ||
| * | ||
| */ | ||
|
|
||
| /** @brief cuthillMckeeOrdering function | ||
| * | ||
| * It does all the processing and returns the results. | ||
| * | ||
| * @param graph the graph containing the edges | ||
| * | ||
| * @returns results, when results are found | ||
| * | ||
| * @see [boost::cuthill_mckee_ordering] | ||
| * (https://www.boost.org/libs/graph/doc/cuthill_mckee_ordering.html) | ||
| */ | ||
|
|
||
| std::vector<II_t_rt> | ||
| cuthillMckeeOrdering(G &graph) { | ||
| std::vector<II_t_rt>results; | ||
|
|
||
| // map which store the indices with their nodes. | ||
| auto i_map = boost::get(boost::vertex_index, graph.graph); | ||
|
|
||
| // vector which will store the order of the indices. | ||
| std::vector<Vertex> inv_perm(boost::num_vertices(graph.graph)); | ||
|
|
||
| // vector which will store the color of all the vertices in the graph | ||
| std::vector <boost::default_color_type> colors(boost::num_vertices(graph.graph)); | ||
|
|
||
| // An iterator property map which records the color of each vertex | ||
| auto color_map = boost::make_iterator_property_map(&colors[0], i_map, colors[0]); | ||
|
|
||
| // map which store the degree of each vertex. | ||
| auto out_deg = boost::make_out_degree_map(graph.graph); | ||
|
|
||
| /* abort in case of an interruption occurs (e.g. the query is being cancelled) */ | ||
| CHECK_FOR_INTERRUPTS(); | ||
|
|
||
| try { | ||
| boost::cuthill_mckee_ordering(graph.graph, inv_perm.rbegin(), color_map, out_deg); | ||
| } catch (boost::exception const& ex) { | ||
| (void)ex; | ||
| throw; | ||
| } catch (std::exception &e) { | ||
| (void)e; | ||
| throw; | ||
| } catch (...) { | ||
| throw; | ||
| } | ||
|
|
||
| results = get_results(inv_perm, graph); | ||
|
|
||
| return results; | ||
| } | ||
|
|
||
| //@} | ||
|
|
||
| private: | ||
| /** @brief to get the results | ||
| * | ||
| * Uses the `inv_perm` vector to get the results i.e. the ordering. | ||
| * | ||
| * @param inv_perm vector which contains the new ordering of indices. | ||
| * @param graph the graph containing the edges | ||
| * | ||
| * @returns `results` vector | ||
| */ | ||
| std::vector <II_t_rt> get_results( | ||
| std::vector <size_type> & inv_perm, | ||
| const G &graph) { | ||
| std::vector <II_t_rt> results; | ||
|
|
||
| for (std::vector<Vertex>::const_iterator i = inv_perm.begin(); | ||
| i != inv_perm.end(); ++i) { | ||
| log << inv_perm[*i] << " "; | ||
| auto seq = graph[*i].id; | ||
| results.push_back({{seq}, {static_cast<int64_t>(graph.graph[*i].id)}}); | ||
| seq++; | ||
| } | ||
| std::vector<pgrouting::UndirectedGraph::V> | ||
| cuthillMckeeOrdering(pgrouting::UndirectedGraph &graph); | ||
|
Comment on lines
+41
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check signatures of other ordering functions for consistency
echo "=== Checking kingOrdering signature ==="
ast-grep --pattern $'std::vector<$_> kingOrdering($$$)'
echo ""
echo "=== Checking sloanOrdering signature ==="
ast-grep --pattern $'std::vector<$_> sloanOrdering($$$)'
echo ""
echo "=== Checking topologicalSort signature ==="
ast-grep --pattern $'std::vector<$_> topologicalSort($$$)'
echo ""
echo "=== Checking cuthillMckeeOrdering signature ==="
ast-grep --pattern $'std::vector<$_> cuthillMckeeOrdering($$$)'Repository: pgRouting/pgrouting Length of output: 237 🏁 Script executed: #!/bin/bash
# Search for header files containing these ordering functions
echo "=== Finding ordering function headers ==="
fd -t f -e hpp . include/ordering/ 2>/dev/null | head -20
echo ""
echo "=== Contents of cuthillMckeeOrdering.hpp ==="
cat include/ordering/cuthillMckeeOrdering.hppRepository: pgRouting/pgrouting Length of output: 1794 🏁 Script executed: #!/bin/bash
# Search more broadly for function signatures
echo "=== Searching for kingOrdering ==="
rg "kingOrdering" -t hpp --max-count 5
echo ""
echo "=== Searching for sloanOrdering ==="
rg "sloanOrdering" -t hpp --max-count 5Repository: pgRouting/pgrouting Length of output: 207 🏁 Script executed: #!/bin/bash
# Read the kingOrdering header
echo "=== Contents of kingOrdering.hpp ==="
cat include/ordering/kingOrdering.hpp
echo ""
echo "=== Contents of sloanOrdering.hpp ==="
cat include/ordering/sloanOrdering.hppRepository: pgRouting/pgrouting Length of output: 3007 🏁 Script executed: #!/bin/bash
# Search for function signatures using rg with correct syntax
echo "=== Searching for all ordering function declarations ==="
rg "Ordering\(" include/ordering/ -A 1 -B 1
echo ""
echo "=== Check if any use const parameter ==="
rg "const.*UndirectedGraph" include/ordering/ -A 1Repository: pgRouting/pgrouting Length of output: 788 🏁 Script executed: #!/bin/bash
# Find and examine the implementation files
echo "=== Finding implementation files for ordering functions ==="
fd -t f -e cpp . src/ordering/ 2>/dev/null | head -20
echo ""
echo "=== Check cuthillMckeeOrdering implementation ==="
fd -t f "cuthillMckee" src/
echo ""
echo "=== Check kingOrdering implementation ==="
fd -t f "king" src/ordering/ 2>/dev/null
echo ""
echo "=== Check sloan implementation ==="
fd -t f "sloan" src/ordering/ 2>/dev/nullRepository: pgRouting/pgrouting Length of output: 643 🏁 Script executed: #!/bin/bash
# Look at the actual implementations
echo "=== cuthillMckeeOrdering.cpp ==="
find . -name "*cuthillMckee*.cpp" -exec cat {} \; 2>/dev/null | head -100
echo ""
echo "=== Check if graph is modified in any implementation ==="
find . -path "*/ordering/*.cpp" -exec grep -l "graph\." {} \; 2>/dev/nullRepository: pgRouting/pgrouting Length of output: 3332 🏁 Script executed: #!/bin/bash
# Check the other implementations to see if they also only read the graph
echo "=== kingOrdering.cpp ==="
cat src/ordering/kingOrdering.cpp | head -100
echo ""
echo "=== sloanOrdering.cpp ==="
cat src/ordering/sloanOrdering.cpp | head -100
echo ""
echo "=== Check if UndirectedGraph methods used in implementations are const-friendly ==="
rg "num_vertices|vertex_index|make_out_degree_map|make_iterator_property_map" include/cpp_common/ -A 2 | head -50Repository: pgRouting/pgrouting Length of output: 8994 🏁 Script executed: #!/bin/bash
# Check if the graph member variable is const-accessible
echo "=== Check base_graph.hpp for const-correctness support ==="
cat include/cpp_common/base_graph.hpp | head -200
echo ""
echo "=== Search for const usage in ordering algorithms ==="
rg "const.*UndirectedGraph" src/ordering/ -A 2Repository: pgRouting/pgrouting Length of output: 5905 🏁 Script executed: #!/bin/bash
# Verify Boost graph algorithms accept const references
echo "=== Check Boost algorithm signatures ==="
web_search "boost::cuthill_mckee_ordering const graph reference"Repository: pgRouting/pgrouting Length of output: 171 🌐 Web query:
💡 Result: Short answer: the graph parameter may be a const reference (signatures use const Graph& or const IncidenceGraph&). The graph type must model the required graph concepts (IncidenceGraph for the single-component APIs, or VertexListGraph+IncidenceGraph for the vertex-list variants). In addition you must supply appropriate property maps: a writable/work ColorMap (used internally), and a DegreeMap (a readable Vertex->degree map) or a VertexIndexMap for the overloads that infer maps. See Boost Graph Library docs for exact signatures and parameter requirements. [1][2] Sources:
Add const qualifier to graph parameter for all three ordering functions. The function signatures are consistent across 🤖 Prompt for AI Agents |
||
|
|
||
| return results; | ||
| } | ||
| }; | ||
| } // namespace functions | ||
| } // namespace pgrouting | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.