1 // Copyright (c) Jeremy Siek 2001, Marc Wintermantel 2002
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_GRAPH_BANDWIDTH_HPP
8 #define BOOST_GRAPH_BANDWIDTH_HPP
10 #include <algorithm> // for std::min and std::max
11 #include <boost/config.hpp>
12 #include <boost/graph/graph_traits.hpp>
13 #include <boost/detail/numeric_traits.hpp>
17 template <typename Graph, typename VertexIndexMap>
18 typename graph_traits<Graph>::vertices_size_type
19 ith_bandwidth(typename graph_traits<Graph>::vertex_descriptor i,
23 BOOST_USING_STD_MAX();
25 typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
26 vertices_size_type b = 0;
27 typename graph_traits<Graph>::out_edge_iterator e, end;
28 for (boost::tie(e, end) = out_edges(i, g); e != end; ++e) {
29 int f_i = get(index, i);
30 int f_j = get(index, target(*e, g));
31 b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, vertices_size_type(abs(f_i - f_j)));
36 template <typename Graph>
37 typename graph_traits<Graph>::vertices_size_type
38 ith_bandwidth(typename graph_traits<Graph>::vertex_descriptor i,
41 return ith_bandwidth(i, g, get(vertex_index, g));
44 template <typename Graph, typename VertexIndexMap>
45 typename graph_traits<Graph>::vertices_size_type
46 bandwidth(const Graph& g, VertexIndexMap index)
48 BOOST_USING_STD_MAX();
50 typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
51 vertices_size_type b = 0;
52 typename graph_traits<Graph>::edge_iterator i, end;
53 for (boost::tie(i, end) = edges(g); i != end; ++i) {
54 int f_i = get(index, source(*i, g));
55 int f_j = get(index, target(*i, g));
56 b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, vertices_size_type(abs(f_i - f_j)));
61 template <typename Graph>
62 typename graph_traits<Graph>::vertices_size_type
63 bandwidth(const Graph& g)
65 return bandwidth(g, get(vertex_index, g));
68 template <typename Graph, typename VertexIndexMap>
69 typename graph_traits<Graph>::vertices_size_type
70 edgesum(const Graph& g, VertexIndexMap index_map)
72 typedef typename graph_traits<Graph>::vertices_size_type size_type;
73 typedef typename detail::numeric_traits<size_type>::difference_type diff_t;
75 typename graph_traits<Graph>::edge_iterator i, end;
76 for (boost::tie(i, end) = edges(g); i != end; ++i) {
77 diff_t f_u = get(index_map, source(*i, g));
78 diff_t f_v = get(index_map, target(*i, g));
79 using namespace std; // to call abs() unqualified
80 sum += abs(f_u - f_v);
87 #endif // BOOST_GRAPH_BANDWIDTH_HPP