Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ notUsed
.vscode
taptest.sh
run.sh
get_signatures.sh
ordering_example
6 changes: 3 additions & 3 deletions docqueries/ordering/kingOrdering.result
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ INSERT INTO additional_sample_1 (source, target, cost, reverse_cost) VALUES
(3, 1, 1, 1);
INSERT 0 24
SELECT * FROM pgr_kingOrdering(
'SELECT id, source, target, cost, reverse_cost FROM additional_sample_1'
);
seq | node
'SELECT id, source, target, cost, reverse_cost FROM additional_sample_1'
);
seq | node
-----+------
1 | 0
2 | 4
Expand Down
85 changes: 85 additions & 0 deletions include/ordering/kingOrdering.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*PGR-GNU*****************************************************************
File: kingOrdering.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_KINGORDERING_HPP_
#define INCLUDE_ORDERING_KINGORDERING_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/king_ordering.hpp>


namespace pgrouting {

template <class G>
std::vector<int64_t>
kingOrdering(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> colors(n);
auto color_map = boost::make_iterator_property_map(colors.begin(), index_map);
auto degree_map = boost::make_degree_map(graph.graph);
std::vector<V> inv_permutation(n);

CHECK_FOR_INTERRUPTS();
boost::king_ordering(
graph.graph,
inv_permutation.rbegin(),
color_map,
degree_map,
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_
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*PGR-GNU*****************************************************************
File: ordering.hpp
File: minDegreeOrdering.hpp

Generated with Template by:
Copyright (c) 2015 pgRouting developers
Expand Down Expand Up @@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

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

#ifndef INCLUDE_ORDERING_ORDERING_HPP_
#define INCLUDE_ORDERING_ORDERING_HPP_
#ifndef INCLUDE_ORDERING_MINDEGREEORDERING_HPP_
#define INCLUDE_ORDERING_MINDEGREEORDERING_HPP_
#pragma once

#include <vector>
Expand All @@ -44,48 +44,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

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


namespace pgrouting {

template <class G>
std::vector<int64_t>
kingOrdering(G &graph) {
using B_G = typename G::B_G;
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> colors(n);
auto color_map = boost::make_iterator_property_map(colors.begin(), index_map);
auto degree_map = boost::make_degree_map(graph.graph);
std::vector<V> inv_perm(n);

CHECK_FOR_INTERRUPTS();
boost::king_ordering(
graph.graph,
inv_perm.rbegin(),
color_map,
degree_map,
index_map);

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

return results;
}

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

size_t n = boost::num_vertices(graph.graph);
Expand All @@ -99,27 +65,26 @@ minDegreeOrdering(G &graph) {
std::vector<V> supernode_sizes(n, 1);
auto supernode_map = boost::make_iterator_property_map(supernode_sizes.begin(), index_map);

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

auto [vi, vi_end] = boost::vertices(graph.graph);
for (; vi != vi_end; ++vi) {
degree_map[*vi] = boost::degree(*vi, graph.graph);
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_perm.begin(),
perm.begin(),
inv_permutation.begin(),
permutation.begin(),
supernode_map,
0,
index_map);

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

Expand Down
Empty file added just_start_week11
Empty file.
7 changes: 5 additions & 2 deletions src/ordering/ordering_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "cpp_common/alloc.hpp"
#include "cpp_common/assert.hpp"

#include "ordering/ordering.hpp"
#include "ordering/kingOrdering.hpp"
#include "ordering/minDegreeOrdering.hpp"



Expand Down Expand Up @@ -85,8 +86,10 @@ do_ordering(
hint = "";

std::vector<int64_t> results;
UndirectedGraph undigraph;
auto vertices(pgrouting::extract_vertices(edges));
UndirectedGraph undigraph(vertices);
undigraph.insert_edges(edges);

if (which == 2) {
results = minDegreeOrdering(undigraph);
} else if (which ==3) {
Expand Down
Loading