wavefront.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. template <typename Graph, typename VertexIndexMap>
  23. typename graph_traits<Graph>::vertices_size_type
  24. ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
  25. 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); edge_it2 != edge_it2_end; ++edge_it2)
  41. {
  42. w = target(*edge_it2, g);
  43. if( (index[w] >= index_i) && (!rows_active[index[w]]) )
  44. {
  45. b++;
  46. rows_active[index[w]] = true;
  47. }
  48. }
  49. }
  50. }
  51. return b;
  52. }
  53. template <typename Graph>
  54. typename graph_traits<Graph>::vertices_size_type
  55. ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
  56. 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
  62. max_wavefront(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(b, ith_wavefront(*i, g, index));
  69. return b;
  70. }
  71. template <typename Graph>
  72. typename graph_traits<Graph>::vertices_size_type
  73. max_wavefront(const Graph& g)
  74. {
  75. return max_wavefront(g, get(vertex_index, g));
  76. }
  77. template <typename Graph, typename VertexIndexMap>
  78. double
  79. aver_wavefront(const Graph& g, VertexIndexMap index)
  80. {
  81. double b = 0;
  82. typename graph_traits<Graph>::vertex_iterator i, end;
  83. for (boost::tie(i, end) = vertices(g); i != end; ++i)
  84. b += ith_wavefront(*i, g, index);
  85. b /= num_vertices(g);
  86. return b;
  87. }
  88. template <typename Graph>
  89. double
  90. aver_wavefront(const Graph& g)
  91. {
  92. return aver_wavefront(g, get(vertex_index, g));
  93. }
  94. template <typename Graph, typename VertexIndexMap>
  95. double
  96. rms_wavefront(const Graph& g, VertexIndexMap index)
  97. {
  98. double b = 0;
  99. typename graph_traits<Graph>::vertex_iterator i, end;
  100. for (boost::tie(i, end) = vertices(g); i != end; ++i)
  101. b += std::pow(double ( ith_wavefront(*i, g, index) ), 2.0);
  102. b /= num_vertices(g);
  103. return std::sqrt(b);
  104. }
  105. template <typename Graph>
  106. double
  107. rms_wavefront(const Graph& g)
  108. {
  109. return rms_wavefront(g, get(vertex_index, g));
  110. }
  111. } // namespace boost
  112. #endif // BOOST_GRAPH_WAVEFRONT_HPP