1// Copyright (c) Jeremy Siek 2001, Marc Wintermantel 2002
2//
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)
6
7#ifndef BOOST_GRAPH_BANDWIDTH_HPP
8#define BOOST_GRAPH_BANDWIDTH_HPP
9
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>
14
15namespace boost {
16
17 template <typename Graph, typename VertexIndexMap>
18 typename graph_traits<Graph>::vertices_size_type
19 ith_bandwidth(typename graph_traits<Graph>::vertex_descriptor i,
20 const Graph& g,
21 VertexIndexMap index)
22 {
23 BOOST_USING_STD_MAX();
24 using std::abs;
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)));
32 }
33 return b;
34 }
35
36 template <typename Graph>
37 typename graph_traits<Graph>::vertices_size_type
38 ith_bandwidth(typename graph_traits<Graph>::vertex_descriptor i,
39 const Graph& g)
40 {
41 return ith_bandwidth(i, g, get(vertex_index, g));
42 }
43
44 template <typename Graph, typename VertexIndexMap>
45 typename graph_traits<Graph>::vertices_size_type
46 bandwidth(const Graph& g, VertexIndexMap index)
47 {
48 BOOST_USING_STD_MAX();
49 using std::abs;
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)));
57 }
58 return b;
59 }
60
61 template <typename Graph>
62 typename graph_traits<Graph>::vertices_size_type
63 bandwidth(const Graph& g)
64 {
65 return bandwidth(g, get(vertex_index, g));
66 }
67
68 template <typename Graph, typename VertexIndexMap>
69 typename graph_traits<Graph>::vertices_size_type
70 edgesum(const Graph& g, VertexIndexMap index_map)
71 {
72 typedef typename graph_traits<Graph>::vertices_size_type size_type;
73 typedef typename detail::numeric_traits<size_type>::difference_type diff_t;
74 size_type sum = 0;
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);
81 }
82 return sum;
83 }
84
85} // namespace boost
86
87#endif // BOOST_GRAPH_BANDWIDTH_HPP
88

source code of boost/boost/graph/bandwidth.hpp