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
23 changes: 23 additions & 0 deletions docqueries/ordering/kingOrdering.pg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@ SELECT * FROM pgr_kingOrdering(
'SELECT id, source, target, cost, reverse_cost FROM edges'
);
/* -- q2 */

CREATER TABLE kot AS (
id SERIAL,
source BIGINT,
target BIGINT,
cost BIGINT defult 1)
;

INSERT INTO kot (source, target) VALUES
(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);
63 changes: 48 additions & 15 deletions include/ordering/ordering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <limits>
#include <iterator>
#include <utility>
#include <string>

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
Expand All @@ -52,34 +53,66 @@ namespace pgrouting {
template <class G>
std::vector<int64_t>
kingOrdering(G &graph) {
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
boost::property<boost::vertex_color_t, boost::default_color_type,
boost::property<boost::vertex_degree_t, int>>>
Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
using V = typename G::V;
using B_G = typename G::B_G;
using vertices_size_type = typename boost::graph_traits<B_G>::vertices_size_type;

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

auto index_map = boost::get(boost::vertex_index, graph.graph);
auto color_map = boost::get(boost::vertex_color, graph.graph);
std::vector<vertices_size_type> 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);

std::vector<Vertex> inv_perm(boost::num_vertices(graph.graph));
CHECK_FOR_INTERRUPTS();

boost::king_ordering(graph.graph, inv_perm.rbegin(), color_map, degree_map, index_map);
for (std::vector<Vertex>::const_iterator i = inv_perm.begin(); i != inv_perm.end(); ++i) {
auto seq = graph[*i].id;
results.push_back({{seq}, {static_cast<int64_t>(graph.graph[*i].id)}});
seq++;
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>(index_map[*i]);
}

throw(std::to_string(results.size()));
return results;
}

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

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<vertices_size_type> degree(n, 0);
auto degree_map = boost::make_iterator_property_map(degree.begin(), index_map);

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

std::vector<vertices_size_type> perm(n);
std::vector<vertices_size_type> inv_perm(n);

CHECK_FOR_INTERRUPTS();

boost::minimum_degree_ordering(
graph.graph,
degree_map,
inv_perm.data(),
perm.data(),
supernode_map,
0,
index_map);

for (size_t i = 0; i < n; ++i) {
results[i] = static_cast<int64_t>(inv_perm[i]);
}

return results;
}

} // namespace pgrouting
Expand Down
Empty file removed just_to_start_week6
Empty file.
6 changes: 1 addition & 5 deletions src/ordering/ordering_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,22 @@ do_ordering(
}
hint = "";

std::vector<int64_t>results;
std::vector<int64_t> results;
UndirectedGraph undigraph;
undigraph.insert_edges(edges);
#if 0
if (which == 0) {
results = minDegreeOrdering(undigraph);
} else if (which ==1) {
results = kingOrdering(undigraph);
}
#endif
auto count = results.size();

#if 0
if (count == 0) {
*err_msg = to_pg_msg("No results found \n");
*return_tuples = NULL;
*return_count = 0;
return;
}
#endif

(*return_tuples) = pgr_alloc(count, (*return_tuples));
for (size_t i = 0; i < count; i++) {
Expand Down
Loading