File indexing completed on 2025-01-18 09:37:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_GRAPH_TOPOLOGICAL_SORT_HPP
0012 #define BOOST_GRAPH_TOPOLOGICAL_SORT_HPP
0013
0014 #include <boost/config.hpp>
0015 #include <boost/property_map/property_map.hpp>
0016 #include <boost/graph/depth_first_search.hpp>
0017 #include <boost/graph/visitors.hpp>
0018 #include <boost/graph/exception.hpp>
0019 #include <boost/throw_exception.hpp>
0020
0021 namespace boost
0022 {
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 template < typename OutputIterator >
0035 struct topo_sort_visitor : public dfs_visitor<>
0036 {
0037 topo_sort_visitor(OutputIterator _iter) : m_iter(_iter) {}
0038
0039 template < typename Edge, typename Graph >
0040 void back_edge(const Edge&, Graph&)
0041 {
0042 BOOST_THROW_EXCEPTION(not_a_dag());
0043 }
0044
0045 template < typename Vertex, typename Graph >
0046 void finish_vertex(const Vertex& u, Graph&)
0047 {
0048 *m_iter++ = u;
0049 }
0050
0051 OutputIterator m_iter;
0052 };
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 template < typename VertexListGraph, typename OutputIterator, typename P,
0064 typename T, typename R >
0065 void topological_sort(VertexListGraph& g, OutputIterator result,
0066 const bgl_named_params< P, T, R >& params)
0067 {
0068 typedef topo_sort_visitor< OutputIterator > TopoVisitor;
0069 depth_first_search(g, params.visitor(TopoVisitor(result)));
0070 }
0071
0072 template < typename VertexListGraph, typename OutputIterator >
0073 void topological_sort(VertexListGraph& g, OutputIterator result)
0074 {
0075 topological_sort(
0076 g, result, bgl_named_params< int, buffer_param_t >(0));
0077 }
0078
0079 }
0080
0081 #endif