sl@0: // sl@0: //======================================================================= sl@0: // Copyright 2002 Marc Wintermantel (wintermantel@even-ag.ch) sl@0: // ETH Zurich, Center of Structure Technologies (www.imes.ethz.ch/st) sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: //======================================================================= sl@0: // sl@0: sl@0: #ifndef BOOST_GRAPH_WAVEFRONT_HPP sl@0: #define BOOST_GRAPH_WAVEFRONT_HPP sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include // for std::min and std::max sl@0: sl@0: namespace boost { sl@0: sl@0: template sl@0: typename graph_traits::vertices_size_type sl@0: ith_wavefront(typename graph_traits::vertex_descriptor i, sl@0: const Graph& g, sl@0: VertexIndexMap index) sl@0: { sl@0: typename graph_traits::vertex_descriptor v, w; sl@0: typename graph_traits::vertices_size_type b = 1; sl@0: typename graph_traits::out_edge_iterator edge_it2, edge_it2_end; sl@0: typename graph_traits::vertices_size_type index_i = index[i]; sl@0: std::vector rows_active(num_vertices(g), false); sl@0: sl@0: rows_active[index_i] = true; sl@0: sl@0: typename graph_traits::vertex_iterator ui, ui_end; sl@0: for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) sl@0: { sl@0: v = *ui; sl@0: if(index[v] <= index_i) sl@0: { sl@0: for (tie(edge_it2, edge_it2_end) = out_edges(v, g); edge_it2 != edge_it2_end; ++edge_it2) sl@0: { sl@0: w = target(*edge_it2, g); sl@0: if( (index[w] >= index_i) && (!rows_active[index[w]]) ) sl@0: { sl@0: b++; sl@0: rows_active[index[w]] = true; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: return b; sl@0: } sl@0: sl@0: sl@0: template sl@0: typename graph_traits::vertices_size_type sl@0: ith_wavefront(typename graph_traits::vertex_descriptor i, sl@0: const Graph& g) sl@0: { sl@0: return ith_wavefront(i, g, get(vertex_index, g)); sl@0: } sl@0: sl@0: sl@0: template sl@0: typename graph_traits::vertices_size_type sl@0: max_wavefront(const Graph& g, VertexIndexMap index) sl@0: { sl@0: BOOST_USING_STD_MAX(); sl@0: typename graph_traits::vertices_size_type b = 0; sl@0: typename graph_traits::vertex_iterator i, end; sl@0: for (tie(i, end) = vertices(g); i != end; ++i) sl@0: b = max BOOST_PREVENT_MACRO_SUBSTITUTION(b, ith_wavefront(*i, g, index)); sl@0: return b; sl@0: } sl@0: sl@0: template sl@0: typename graph_traits::vertices_size_type sl@0: max_wavefront(const Graph& g) sl@0: { sl@0: return max_wavefront(g, get(vertex_index, g)); sl@0: } sl@0: sl@0: sl@0: template sl@0: double sl@0: aver_wavefront(const Graph& g, VertexIndexMap index) sl@0: { sl@0: double b = 0; sl@0: typename graph_traits::vertex_iterator i, end; sl@0: for (tie(i, end) = vertices(g); i != end; ++i) sl@0: b += ith_wavefront(*i, g, index); sl@0: sl@0: b /= num_vertices(g); sl@0: return b; sl@0: } sl@0: sl@0: template sl@0: double sl@0: aver_wavefront(const Graph& g) sl@0: { sl@0: return aver_wavefront(g, get(vertex_index, g)); sl@0: } sl@0: sl@0: sl@0: template sl@0: double sl@0: rms_wavefront(const Graph& g, VertexIndexMap index) sl@0: { sl@0: double b = 0; sl@0: typename graph_traits::vertex_iterator i, end; sl@0: for (tie(i, end) = vertices(g); i != end; ++i) sl@0: b += std::pow(double ( ith_wavefront(*i, g, index) ), 2.0); sl@0: sl@0: b /= num_vertices(g); sl@0: sl@0: return std::sqrt(b); sl@0: } sl@0: sl@0: template sl@0: double sl@0: rms_wavefront(const Graph& g) sl@0: { sl@0: return rms_wavefront(g, get(vertex_index, g)); sl@0: } sl@0: sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_GRAPH_WAVEFRONT_HPP