File indexing completed on 2025-01-30 09:42:50
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/detail/numeric_traits.hpp>
0014
0015 namespace boost
0016 {
0017
0018 template < typename Graph, typename VertexIndexMap >
0019 typename graph_traits< Graph >::vertices_size_type ith_bandwidth(
0020 typename graph_traits< Graph >::vertex_descriptor i, const Graph& g,
0021 VertexIndexMap index)
0022 {
0023 BOOST_USING_STD_MAX();
0024 using std::abs;
0025 typedef
0026 typename graph_traits< Graph >::vertices_size_type vertices_size_type;
0027 vertices_size_type b = 0;
0028 typename graph_traits< Graph >::out_edge_iterator e, end;
0029 for (boost::tie(e, end) = out_edges(i, g); e != end; ++e)
0030 {
0031 int f_i = get(index, i);
0032 int f_j = get(index, target(*e, g));
0033 b = max BOOST_PREVENT_MACRO_SUBSTITUTION(
0034 b, vertices_size_type(abs(f_i - f_j)));
0035 }
0036 return b;
0037 }
0038
0039 template < typename Graph >
0040 typename graph_traits< Graph >::vertices_size_type ith_bandwidth(
0041 typename graph_traits< Graph >::vertex_descriptor i, const Graph& g)
0042 {
0043 return ith_bandwidth(i, g, get(vertex_index, g));
0044 }
0045
0046 template < typename Graph, typename VertexIndexMap >
0047 typename graph_traits< Graph >::vertices_size_type bandwidth(
0048 const Graph& g, VertexIndexMap index)
0049 {
0050 BOOST_USING_STD_MAX();
0051 using std::abs;
0052 typedef
0053 typename graph_traits< Graph >::vertices_size_type vertices_size_type;
0054 vertices_size_type b = 0;
0055 typename graph_traits< Graph >::edge_iterator i, end;
0056 for (boost::tie(i, end) = edges(g); i != end; ++i)
0057 {
0058 int f_i = get(index, source(*i, g));
0059 int f_j = get(index, target(*i, g));
0060 b = max BOOST_PREVENT_MACRO_SUBSTITUTION(
0061 b, vertices_size_type(abs(f_i - f_j)));
0062 }
0063 return b;
0064 }
0065
0066 template < typename Graph >
0067 typename graph_traits< Graph >::vertices_size_type bandwidth(const Graph& g)
0068 {
0069 return bandwidth(g, get(vertex_index, g));
0070 }
0071
0072 template < typename Graph, typename VertexIndexMap >
0073 typename graph_traits< Graph >::vertices_size_type edgesum(
0074 const Graph& g, VertexIndexMap index_map)
0075 {
0076 typedef typename graph_traits< Graph >::vertices_size_type size_type;
0077 typedef
0078 typename detail::numeric_traits< size_type >::difference_type diff_t;
0079 size_type sum = 0;
0080 typename graph_traits< Graph >::edge_iterator i, end;
0081 for (boost::tie(i, end) = edges(g); i != end; ++i)
0082 {
0083 diff_t f_u = get(index_map, source(*i, g));
0084 diff_t f_v = get(index_map, target(*i, g));
0085 using namespace std;
0086 sum += abs(f_u - f_v);
0087 }
0088 return sum;
0089 }
0090
0091 }
0092
0093 #endif