123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #ifndef BOOST_GRAPH_TOPOLOGICAL_SORT_HPP
- #define BOOST_GRAPH_TOPOLOGICAL_SORT_HPP
- #include <boost/config.hpp>
- #include <boost/property_map/property_map.hpp>
- #include <boost/graph/depth_first_search.hpp>
- #include <boost/graph/visitors.hpp>
- #include <boost/graph/exception.hpp>
- #include <boost/throw_exception.hpp>
- namespace boost
- {
- template < typename OutputIterator >
- struct topo_sort_visitor : public dfs_visitor<>
- {
- topo_sort_visitor(OutputIterator _iter) : m_iter(_iter) {}
- template < typename Edge, typename Graph >
- void back_edge(const Edge&, Graph&)
- {
- BOOST_THROW_EXCEPTION(not_a_dag());
- }
- template < typename Vertex, typename Graph >
- void finish_vertex(const Vertex& u, Graph&)
- {
- *m_iter++ = u;
- }
- OutputIterator m_iter;
- };
- template < typename VertexListGraph, typename OutputIterator, typename P,
- typename T, typename R >
- void topological_sort(VertexListGraph& g, OutputIterator result,
- const bgl_named_params< P, T, R >& params)
- {
- typedef topo_sort_visitor< OutputIterator > TopoVisitor;
- depth_first_search(g, params.visitor(TopoVisitor(result)));
- }
- template < typename VertexListGraph, typename OutputIterator >
- void topological_sort(VertexListGraph& g, OutputIterator result)
- {
- topological_sort(
- g, result, bgl_named_params< int, buffer_param_t >(0));
- }
- }
- #endif
|