2 //=======================================================================
3 // Copyright 2002 Marc Wintermantel (wintermantel@even-ag.ch)
4 // ETH Zurich, Center of Structure Technologies
5 // (https://web.archive.org/web/20050307090307/http://www.structures.ethz.ch/)
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //=======================================================================
13 #ifndef BOOST_GRAPH_WAVEFRONT_HPP
14 #define BOOST_GRAPH_WAVEFRONT_HPP
16 #include <boost/config.hpp>
17 #include <boost/graph/graph_traits.hpp>
18 #include <boost/detail/numeric_traits.hpp>
19 #include <boost/graph/bandwidth.hpp>
20 #include <boost/config/no_tr1/cmath.hpp>
22 #include <algorithm> // for std::min and std::max
26 template <typename Graph, typename VertexIndexMap>
27 typename graph_traits<Graph>::vertices_size_type
28 ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
32 typename graph_traits<Graph>::vertex_descriptor v, w;
33 typename graph_traits<Graph>::vertices_size_type b = 1;
34 typename graph_traits<Graph>::out_edge_iterator edge_it2, edge_it2_end;
35 typename graph_traits<Graph>::vertices_size_type index_i = index[i];
36 std::vector<bool> rows_active(num_vertices(g), false);
38 rows_active[index_i] = true;
40 typename graph_traits<Graph>::vertex_iterator ui, ui_end;
41 for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
44 if(index[v] <= index_i)
46 for (boost::tie(edge_it2, edge_it2_end) = out_edges(v, g); edge_it2 != edge_it2_end; ++edge_it2)
48 w = target(*edge_it2, g);
49 if( (index[w] >= index_i) && (!rows_active[index[w]]) )
52 rows_active[index[w]] = true;
62 template <typename Graph>
63 typename graph_traits<Graph>::vertices_size_type
64 ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
67 return ith_wavefront(i, g, get(vertex_index, g));
71 template <typename Graph, typename VertexIndexMap>
72 typename graph_traits<Graph>::vertices_size_type
73 max_wavefront(const Graph& g, VertexIndexMap index)
75 BOOST_USING_STD_MAX();
76 typename graph_traits<Graph>::vertices_size_type b = 0;
77 typename graph_traits<Graph>::vertex_iterator i, end;
78 for (boost::tie(i, end) = vertices(g); i != end; ++i)
79 b = max BOOST_PREVENT_MACRO_SUBSTITUTION(b, ith_wavefront(*i, g, index));
83 template <typename Graph>
84 typename graph_traits<Graph>::vertices_size_type
85 max_wavefront(const Graph& g)
87 return max_wavefront(g, get(vertex_index, g));
91 template <typename Graph, typename VertexIndexMap>
93 aver_wavefront(const Graph& g, VertexIndexMap index)
96 typename graph_traits<Graph>::vertex_iterator i, end;
97 for (boost::tie(i, end) = vertices(g); i != end; ++i)
98 b += ith_wavefront(*i, g, index);
100 b /= num_vertices(g);
104 template <typename Graph>
106 aver_wavefront(const Graph& g)
108 return aver_wavefront(g, get(vertex_index, g));
112 template <typename Graph, typename VertexIndexMap>
114 rms_wavefront(const Graph& g, VertexIndexMap index)
117 typename graph_traits<Graph>::vertex_iterator i, end;
118 for (boost::tie(i, end) = vertices(g); i != end; ++i)
119 b += std::pow(double ( ith_wavefront(*i, g, index) ), 2.0);
121 b /= num_vertices(g);
126 template <typename Graph>
128 rms_wavefront(const Graph& g)
130 return rms_wavefront(g, get(vertex_index, g));
136 #endif // BOOST_GRAPH_WAVEFRONT_HPP