File indexing completed on 2025-07-11 08:12:53
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_GRAPH_BANDWIDTH_HPP
0008 #define BOOST_GRAPH_BANDWIDTH_HPP
0009
0010 #include <algorithm> // for std::min and std::max
0011 #include <boost/config.hpp>
0012 #include <boost/graph/graph_traits.hpp>
0013 #include <boost/graph/properties.hpp>
0014 #include <boost/detail/numeric_traits.hpp>
0015
0016 namespace boost
0017 {
0018
0019 template < typename Graph, typename VertexIndexMap >
0020 typename graph_traits< Graph >::vertices_size_type ith_bandwidth(
0021 typename graph_traits< Graph >::vertex_descriptor i, const Graph& g,
0022 VertexIndexMap index)
0023 {
0024 BOOST_USING_STD_MAX();
0025 using std::abs;
0026 typedef
0027 typename graph_traits< Graph >::vertices_size_type vertices_size_type;
0028 vertices_size_type b = 0;
0029 typename graph_traits< Graph >::out_edge_iterator e, end;
0030 for (boost::tie(e, end) = out_edges(i, g); e != end; ++e)
0031 {
0032 int f_i = get(index, i);
0033 int f_j = get(index, target(*e, g));
0034 b = max BOOST_PREVENT_MACRO_SUBSTITUTION(
0035 b, vertices_size_type(abs(f_i - f_j)));
0036 }
0037 return b;
0038 }
0039
0040 template < typename Graph >
0041 typename graph_traits< Graph >::vertices_size_type ith_bandwidth(
0042 typename graph_traits< Graph >::vertex_descriptor i, const Graph& g)
0043 {
0044 return ith_bandwidth(i, g, get(vertex_index, g));
0045 }
0046
0047 template < typename Graph, typename VertexIndexMap >
0048 typename graph_traits< Graph >::vertices_size_type bandwidth(
0049 const Graph& g, VertexIndexMap index)
0050 {
0051 BOOST_USING_STD_MAX();
0052 using std::abs;
0053 typedef
0054 typename graph_traits< Graph >::vertices_size_type vertices_size_type;
0055 vertices_size_type b = 0;
0056 typename graph_traits< Graph >::edge_iterator i, end;
0057 for (boost::tie(i, end) = edges(g); i != end; ++i)
0058 {
0059 int f_i = get(index, source(*i, g));
0060 int f_j = get(index, target(*i, g));
0061 b = max BOOST_PREVENT_MACRO_SUBSTITUTION(
0062 b, vertices_size_type(abs(f_i - f_j)));
0063 }
0064 return b;
0065 }
0066
0067 template < typename Graph >
0068 typename graph_traits< Graph >::vertices_size_type bandwidth(const Graph& g)
0069 {
0070 return bandwidth(g, get(vertex_index, g));
0071 }
0072
0073 template < typename Graph, typename VertexIndexMap >
0074 typename graph_traits< Graph >::vertices_size_type edgesum(
0075 const Graph& g, VertexIndexMap index_map)
0076 {
0077 typedef typename graph_traits< Graph >::vertices_size_type size_type;
0078 typedef
0079 typename detail::numeric_traits< size_type >::difference_type diff_t;
0080 size_type sum = 0;
0081 typename graph_traits< Graph >::edge_iterator i, end;
0082 for (boost::tie(i, end) = edges(g); i != end; ++i)
0083 {
0084 diff_t f_u = get(index_map, source(*i, g));
0085 diff_t f_v = get(index_map, target(*i, g));
0086 using namespace std;
0087 sum += abs(f_u - f_v);
0088 }
0089 return sum;
0090 }
0091
0092 }
0093
0094 #endif