source: NonGTP/Boost/boost/graph/bandwidth.hpp @ 857

Revision 857, 2.8 KB checked in by igarcia, 19 years ago (diff)
Line 
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    typedef typename graph_traits<Graph>::vertices_size_type size_type;
25    size_type b = 0;
26    typename graph_traits<Graph>::out_edge_iterator e, end;
27    for (tie(e, end) = out_edges(i, g); e != end; ++e) {
28      int f_i = get(index, i);
29      int f_j = get(index, target(*e, g));
30      using namespace std; // to call abs() unqualified
31      if(f_i > f_j)
32          b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, size_type(f_i - f_j));
33    }
34    return b;
35  }
36
37  template <typename Graph>
38  typename graph_traits<Graph>::vertices_size_type
39  ith_bandwidth(typename graph_traits<Graph>::vertex_descriptor i,
40                const Graph& g)
41  {
42    return ith_bandwidth(i, g, get(vertex_index, g));
43  }
44
45  template <typename Graph, typename VertexIndexMap>
46  typename graph_traits<Graph>::vertices_size_type
47  bandwidth(const Graph& g, VertexIndexMap index)
48  {
49    BOOST_USING_STD_MAX();
50    typename graph_traits<Graph>::vertices_size_type b = 0;
51    typename graph_traits<Graph>::vertex_iterator i, end;
52    for (tie(i, end) = vertices(g); i != end; ++i)
53        b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, ith_bandwidth(*i, g, index));
54    return b;
55  }
56
57  template <typename Graph>
58  typename graph_traits<Graph>::vertices_size_type
59  bandwidth(const Graph& g)
60  {
61    return bandwidth(g, get(vertex_index, g));
62  }
63
64  template <typename Graph, typename VertexIndexMap>
65  typename graph_traits<Graph>::vertices_size_type
66  edgesum(const Graph& g, VertexIndexMap index_map)
67  {
68    typedef typename graph_traits<Graph>::vertices_size_type size_type;
69    typedef typename detail::numeric_traits<size_type>::difference_type diff_t;
70    size_type sum = 0;
71    typename graph_traits<Graph>::edge_iterator i, end;
72    for (tie(i, end) = edges(g); i != end; ++i) {
73      diff_t f_u = get(index_map, source(*i, g));
74      diff_t f_v = get(index_map, target(*i, g));
75      using namespace std; // to call abs() unqualified
76      sum += abs(f_u - f_v);
77    }
78    return sum;
79  }
80 
81} // namespace boost
82
83#endif // BOOST_GRAPH_BANDWIDTH_HPP
Note: See TracBrowser for help on using the repository browser.