wavefront.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  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/)
  6. //
  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. //=======================================================================
  11. //
  12. #ifndef BOOST_GRAPH_WAVEFRONT_HPP
  13. #define BOOST_GRAPH_WAVEFRONT_HPP
  14. #include <boost/config.hpp>
  15. #include <boost/graph/graph_traits.hpp>
  16. #include <boost/detail/numeric_traits.hpp>
  17. #include <boost/graph/bandwidth.hpp>
  18. #include <boost/config/no_tr1/cmath.hpp>
  19. #include <vector>
  20. #include <algorithm> // for std::min and std::max
  21. namespace boost
  22. {
  23. template < typename Graph, typename VertexIndexMap >
  24. typename graph_traits< Graph >::vertices_size_type ith_wavefront(
  25. typename graph_traits< Graph >::vertex_descriptor i, const Graph& g,
  26. VertexIndexMap index)
  27. {
  28. typename graph_traits< Graph >::vertex_descriptor v, w;
  29. typename graph_traits< Graph >::vertices_size_type b = 1;
  30. typename graph_traits< Graph >::out_edge_iterator edge_it2, edge_it2_end;
  31. typename graph_traits< Graph >::vertices_size_type index_i = index[i];
  32. std::vector< bool > rows_active(num_vertices(g), false);
  33. rows_active[index_i] = true;
  34. typename graph_traits< Graph >::vertex_iterator ui, ui_end;
  35. for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
  36. {
  37. v = *ui;
  38. if (index[v] <= index_i)
  39. {
  40. for (boost::tie(edge_it2, edge_it2_end) = out_edges(v, g);
  41. edge_it2 != edge_it2_end; ++edge_it2)
  42. {
  43. w = target(*edge_it2, g);
  44. if ((index[w] >= index_i) && (!rows_active[index[w]]))
  45. {
  46. b++;
  47. rows_active[index[w]] = true;
  48. }
  49. }
  50. }
  51. }
  52. return b;
  53. }
  54. template < typename Graph >
  55. typename graph_traits< Graph >::vertices_size_type ith_wavefront(
  56. typename graph_traits< Graph >::vertex_descriptor i, const Graph& g)
  57. {
  58. return ith_wavefront(i, g, get(vertex_index, g));
  59. }
  60. template < typename Graph, typename VertexIndexMap >
  61. typename graph_traits< Graph >::vertices_size_type max_wavefront(
  62. const Graph& g, VertexIndexMap index)
  63. {
  64. BOOST_USING_STD_MAX();
  65. typename graph_traits< Graph >::vertices_size_type b = 0;
  66. typename graph_traits< Graph >::vertex_iterator i, end;
  67. for (boost::tie(i, end) = vertices(g); i != end; ++i)
  68. b = max BOOST_PREVENT_MACRO_SUBSTITUTION(
  69. b, ith_wavefront(*i, g, index));
  70. return b;
  71. }
  72. template < typename Graph >
  73. typename graph_traits< Graph >::vertices_size_type max_wavefront(const Graph& g)
  74. {
  75. return max_wavefront(g, get(vertex_index, g));
  76. }
  77. template < typename Graph, typename VertexIndexMap >
  78. double aver_wavefront(const Graph& g, VertexIndexMap index)
  79. {
  80. double b = 0;
  81. typename graph_traits< Graph >::vertex_iterator i, end;
  82. for (boost::tie(i, end) = vertices(g); i != end; ++i)
  83. b += ith_wavefront(*i, g, index);
  84. b /= num_vertices(g);
  85. return b;
  86. }
  87. template < typename Graph > double aver_wavefront(const Graph& g)
  88. {
  89. return aver_wavefront(g, get(vertex_index, g));
  90. }
  91. template < typename Graph, typename VertexIndexMap >
  92. double rms_wavefront(const Graph& g, VertexIndexMap index)
  93. {
  94. double b = 0;
  95. typename graph_traits< Graph >::vertex_iterator i, end;
  96. for (boost::tie(i, end) = vertices(g); i != end; ++i)
  97. b += std::pow(double(ith_wavefront(*i, g, index)), 2.0);
  98. b /= num_vertices(g);
  99. return std::sqrt(b);
  100. }
  101. template < typename Graph > double rms_wavefront(const Graph& g)
  102. {
  103. return rms_wavefront(g, get(vertex_index, g));
  104. }
  105. } // namespace boost
  106. #endif // BOOST_GRAPH_WAVEFRONT_HPP