nxpp
Header-only graph utilities on top of Boost Graph Library
Loading...
Searching...
No Matches
topological_sort.hpp
Go to the documentation of this file.
1#pragma once
2
10#include <boost/graph/topological_sort.hpp>
11
12#include "graph.hpp"
13
14namespace nxpp {
15
16template <typename GraphWrapper>
23[[deprecated("Use G.topological_sort() instead.")]]
24auto topological_sort(const GraphWrapper& G) {
25 return G.topological_sort();
26}
27
28template <typename NodeID, typename EdgeWeight, bool Directed, bool Multi, bool Weighted, typename OutEdgeSelector, typename VertexSelector>
30 std::vector<VertexDesc> rev_order;
31 std::vector<boost::default_color_type> color(boost::num_vertices(g));
32 boost::topological_sort(
33 g,
34 std::back_inserter(rev_order),
35 boost::color_map(boost::make_iterator_property_map(color.begin(), vertex_index_map))
36 );
37 std::vector<NodeID> order;
38 order.reserve(rev_order.size());
39 for (auto it = rev_order.rbegin(); it != rev_order.rend(); ++it) {
40 order.push_back(get_node_id(*it));
41 }
42 return order;
43}
44
45} // namespace nxpp
auto topological_sort() const
Returns a topological ordering for a directed acyclic graph.
Definition topological_sort.hpp:29
Core graph wrapper, proxy surface, and public alias presets.
auto topological_sort(const GraphWrapper &G)
Deprecated free-function alias for G.topological_sort().
Definition topological_sort.hpp:24