Chris@16: // Copyright (c) Jeremy Siek 2001, Marc Wintermantel 2002 Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GRAPH_BANDWIDTH_HPP Chris@16: #define BOOST_GRAPH_BANDWIDTH_HPP Chris@16: Chris@16: #include // for std::min and std::max Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: template Chris@16: typename graph_traits::vertices_size_type Chris@16: ith_bandwidth(typename graph_traits::vertex_descriptor i, Chris@16: const Graph& g, Chris@16: VertexIndexMap index) Chris@16: { Chris@16: BOOST_USING_STD_MAX(); Chris@16: using std::abs; Chris@16: typedef typename graph_traits::vertices_size_type vertices_size_type; Chris@16: vertices_size_type b = 0; Chris@16: typename graph_traits::out_edge_iterator e, end; Chris@16: for (boost::tie(e, end) = out_edges(i, g); e != end; ++e) { Chris@16: int f_i = get(index, i); Chris@16: int f_j = get(index, target(*e, g)); Chris@16: b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, vertices_size_type(abs(f_i - f_j))); Chris@16: } Chris@16: return b; Chris@16: } Chris@16: Chris@16: template Chris@16: typename graph_traits::vertices_size_type Chris@16: ith_bandwidth(typename graph_traits::vertex_descriptor i, Chris@16: const Graph& g) Chris@16: { Chris@16: return ith_bandwidth(i, g, get(vertex_index, g)); Chris@16: } Chris@16: Chris@16: template Chris@16: typename graph_traits::vertices_size_type Chris@16: bandwidth(const Graph& g, VertexIndexMap index) Chris@16: { Chris@16: BOOST_USING_STD_MAX(); Chris@16: using std::abs; Chris@16: typedef typename graph_traits::vertices_size_type vertices_size_type; Chris@16: vertices_size_type b = 0; Chris@16: typename graph_traits::edge_iterator i, end; Chris@16: for (boost::tie(i, end) = edges(g); i != end; ++i) { Chris@16: int f_i = get(index, source(*i, g)); Chris@16: int f_j = get(index, target(*i, g)); Chris@16: b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, vertices_size_type(abs(f_i - f_j))); Chris@16: } Chris@16: return b; Chris@16: } Chris@16: Chris@16: template Chris@16: typename graph_traits::vertices_size_type Chris@16: bandwidth(const Graph& g) Chris@16: { Chris@16: return bandwidth(g, get(vertex_index, g)); Chris@16: } Chris@16: Chris@16: template Chris@16: typename graph_traits::vertices_size_type Chris@16: edgesum(const Graph& g, VertexIndexMap index_map) Chris@16: { Chris@16: typedef typename graph_traits::vertices_size_type size_type; Chris@16: typedef typename detail::numeric_traits::difference_type diff_t; Chris@16: size_type sum = 0; Chris@16: typename graph_traits::edge_iterator i, end; Chris@16: for (boost::tie(i, end) = edges(g); i != end; ++i) { Chris@16: diff_t f_u = get(index_map, source(*i, g)); Chris@16: diff_t f_v = get(index_map, target(*i, g)); Chris@16: using namespace std; // to call abs() unqualified Chris@16: sum += abs(f_u - f_v); Chris@16: } Chris@16: return sum; Chris@16: } Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_GRAPH_BANDWIDTH_HPP