1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/graph/topological_sort.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,76 @@
1.4 +//
1.5 +//=======================================================================
1.6 +// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
1.7 +// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
1.8 +//
1.9 +// Distributed under the Boost Software License, Version 1.0. (See
1.10 +// accompanying file LICENSE_1_0.txt or copy at
1.11 +// http://www.boost.org/LICENSE_1_0.txt)
1.12 +//=======================================================================
1.13 +//
1.14 +#ifndef BOOST_GRAPH_TOPOLOGICAL_SORT_HPP
1.15 +#define BOOST_GRAPH_TOPOLOGICAL_SORT_HPP
1.16 +
1.17 +#include <boost/config.hpp>
1.18 +#include <boost/property_map.hpp>
1.19 +#include <boost/graph/depth_first_search.hpp>
1.20 +#include <boost/graph/visitors.hpp>
1.21 +#include <boost/graph/exception.hpp>
1.22 +
1.23 +namespace boost {
1.24 +
1.25 +
1.26 + // Topological sort visitor
1.27 + //
1.28 + // This visitor merely writes the linear ordering into an
1.29 + // OutputIterator. The OutputIterator could be something like an
1.30 + // ostream_iterator, or it could be a back/front_insert_iterator.
1.31 + // Note that if it is a back_insert_iterator, the recorded order is
1.32 + // the reverse topological order. On the other hand, if it is a
1.33 + // front_insert_iterator, the recorded order is the topological
1.34 + // order.
1.35 + //
1.36 + template <typename OutputIterator>
1.37 + struct topo_sort_visitor : public dfs_visitor<>
1.38 + {
1.39 + topo_sort_visitor(OutputIterator _iter)
1.40 + : m_iter(_iter) { }
1.41 +
1.42 + template <typename Edge, typename Graph>
1.43 + void back_edge(const Edge& u, Graph&) { throw not_a_dag(); }
1.44 +
1.45 + template <typename Vertex, typename Graph>
1.46 + void finish_vertex(const Vertex& u, Graph&) { *m_iter++ = u; }
1.47 +
1.48 + OutputIterator m_iter;
1.49 + };
1.50 +
1.51 +
1.52 + // Topological Sort
1.53 + //
1.54 + // The topological sort algorithm creates a linear ordering
1.55 + // of the vertices such that if edge (u,v) appears in the graph,
1.56 + // then u comes before v in the ordering. The graph must
1.57 + // be a directed acyclic graph (DAG). The implementation
1.58 + // consists mainly of a call to depth-first search.
1.59 + //
1.60 +
1.61 + template <typename VertexListGraph, typename OutputIterator,
1.62 + typename P, typename T, typename R>
1.63 + void topological_sort(VertexListGraph& g, OutputIterator result,
1.64 + const bgl_named_params<P, T, R>& params)
1.65 + {
1.66 + typedef topo_sort_visitor<OutputIterator> TopoVisitor;
1.67 + depth_first_search(g, params.visitor(TopoVisitor(result)));
1.68 + }
1.69 +
1.70 + template <typename VertexListGraph, typename OutputIterator>
1.71 + void topological_sort(VertexListGraph& g, OutputIterator result)
1.72 + {
1.73 + topological_sort(g, result,
1.74 + bgl_named_params<int, buffer_param_t>(0)); // bogus
1.75 + }
1.76 +
1.77 +} // namespace boost
1.78 +
1.79 +#endif /*BOOST_GRAPH_TOPOLOGICAL_SORT_H*/