[857] | 1 | //
|
---|
| 2 | //=======================================================================
|
---|
| 3 | // Copyright 2002 Marc Wintermantel (wintermantel@imes.mavt.ethz.ch)
|
---|
| 4 | // ETH Zurich, Center of Structure Technologies (www.imes.ethz.ch/st)
|
---|
| 5 | //
|
---|
| 6 | // This file is part of the Boost Graph Library
|
---|
| 7 | //
|
---|
| 8 | // You should have received a copy of the License Agreement for the
|
---|
| 9 | // Boost Graph Library along with the software; see the file LICENSE.
|
---|
| 10 | // If not, contact Office of Research, University of Notre Dame, Notre
|
---|
| 11 | // Dame, IN 46556.
|
---|
| 12 | //
|
---|
| 13 | // Permission to modify the code and to distribute modified code is
|
---|
| 14 | // granted, provided the text of this NOTICE is retained, a notice that
|
---|
| 15 | // the code was modified is included with the above COPYRIGHT NOTICE and
|
---|
| 16 | // with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
|
---|
| 17 | // file is distributed with the modified code.
|
---|
| 18 | //
|
---|
| 19 | // LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
|
---|
| 20 | // By way of example, but not limitation, Licensor MAKES NO
|
---|
| 21 | // REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
|
---|
| 22 | // PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
|
---|
| 23 | // OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
|
---|
| 24 | // OR OTHER RIGHTS.
|
---|
| 25 | //=======================================================================
|
---|
| 26 | //
|
---|
| 27 |
|
---|
| 28 | #ifndef BOOST_GRAPH_WAVEFRONT_HPP
|
---|
| 29 | #define BOOST_GRAPH_WAVEFRONT_HPP
|
---|
| 30 |
|
---|
| 31 | #include <boost/config.hpp>
|
---|
| 32 | #include <boost/graph/graph_traits.hpp>
|
---|
| 33 | #include <boost/detail/numeric_traits.hpp>
|
---|
| 34 | #include <boost/graph/bandwidth.hpp>
|
---|
| 35 | #include <cmath>
|
---|
| 36 | #include <vector>
|
---|
| 37 | #include <algorithm> // for std::min and std::max
|
---|
| 38 |
|
---|
| 39 | namespace boost {
|
---|
| 40 |
|
---|
| 41 | template <typename Graph, typename VertexIndexMap>
|
---|
| 42 | typename graph_traits<Graph>::vertices_size_type
|
---|
| 43 | ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
|
---|
| 44 | const Graph& g,
|
---|
| 45 | VertexIndexMap index)
|
---|
| 46 | {
|
---|
| 47 | typename graph_traits<Graph>::vertex_descriptor v, w;
|
---|
| 48 | typename graph_traits<Graph>::vertices_size_type b = 1;
|
---|
| 49 | typename graph_traits<Graph>::out_edge_iterator edge_it2, edge_it2_end;
|
---|
| 50 | typename graph_traits<Graph>::vertices_size_type index_i = index[i];
|
---|
| 51 | std::vector<bool> rows_active(num_vertices(g), false);
|
---|
| 52 |
|
---|
| 53 | rows_active[index_i] = true;
|
---|
| 54 |
|
---|
| 55 | typename graph_traits<Graph>::vertex_iterator ui, ui_end;
|
---|
| 56 | for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
|
---|
| 57 | {
|
---|
| 58 | v = *ui;
|
---|
| 59 | if(index[v] <= index_i)
|
---|
| 60 | {
|
---|
| 61 | for (tie(edge_it2, edge_it2_end) = out_edges(v, g); edge_it2 != edge_it2_end; ++edge_it2)
|
---|
| 62 | {
|
---|
| 63 | w = target(*edge_it2, g);
|
---|
| 64 | if( (index[w] >= index_i) && (!rows_active[index[w]]) )
|
---|
| 65 | {
|
---|
| 66 | b++;
|
---|
| 67 | rows_active[index[w]] = true;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | return b;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | template <typename Graph>
|
---|
| 78 | typename graph_traits<Graph>::vertices_size_type
|
---|
| 79 | ith_wavefront(typename graph_traits<Graph>::vertex_descriptor i,
|
---|
| 80 | const Graph& g)
|
---|
| 81 | {
|
---|
| 82 | return ith_wavefront(i, g, get(vertex_index, g));
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | template <typename Graph, typename VertexIndexMap>
|
---|
| 87 | typename graph_traits<Graph>::vertices_size_type
|
---|
| 88 | max_wavefront(const Graph& g, VertexIndexMap index)
|
---|
| 89 | {
|
---|
| 90 | BOOST_USING_STD_MAX();
|
---|
| 91 | typename graph_traits<Graph>::vertices_size_type b = 0;
|
---|
| 92 | typename graph_traits<Graph>::vertex_iterator i, end;
|
---|
| 93 | for (tie(i, end) = vertices(g); i != end; ++i)
|
---|
| 94 | b = max BOOST_PREVENT_MACRO_SUBSTITUTION(b, ith_wavefront(*i, g, index));
|
---|
| 95 | return b;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | template <typename Graph>
|
---|
| 99 | typename graph_traits<Graph>::vertices_size_type
|
---|
| 100 | max_wavefront(const Graph& g)
|
---|
| 101 | {
|
---|
| 102 | return max_wavefront(g, get(vertex_index, g));
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | template <typename Graph, typename VertexIndexMap>
|
---|
| 107 | double
|
---|
| 108 | aver_wavefront(const Graph& g, VertexIndexMap index)
|
---|
| 109 | {
|
---|
| 110 | double b = 0;
|
---|
| 111 | typename graph_traits<Graph>::vertex_iterator i, end;
|
---|
| 112 | for (tie(i, end) = vertices(g); i != end; ++i)
|
---|
| 113 | b += ith_wavefront(*i, g, index);
|
---|
| 114 |
|
---|
| 115 | b /= num_vertices(g);
|
---|
| 116 | return b;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | template <typename Graph>
|
---|
| 120 | double
|
---|
| 121 | aver_wavefront(const Graph& g)
|
---|
| 122 | {
|
---|
| 123 | return aver_wavefront(g, get(vertex_index, g));
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | template <typename Graph, typename VertexIndexMap>
|
---|
| 128 | double
|
---|
| 129 | rms_wavefront(const Graph& g, VertexIndexMap index)
|
---|
| 130 | {
|
---|
| 131 | double b = 0;
|
---|
| 132 | typename graph_traits<Graph>::vertex_iterator i, end;
|
---|
| 133 | for (tie(i, end) = vertices(g); i != end; ++i)
|
---|
| 134 | b += std::pow(double ( ith_wavefront(*i, g, index) ), 2.0);
|
---|
| 135 |
|
---|
| 136 | b /= num_vertices(g);
|
---|
| 137 |
|
---|
| 138 | return std::sqrt(b);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | template <typename Graph>
|
---|
| 142 | double
|
---|
| 143 | rms_wavefront(const Graph& g)
|
---|
| 144 | {
|
---|
| 145 | return rms_wavefront(g, get(vertex_index, g));
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | } // namespace boost
|
---|
| 150 |
|
---|
| 151 | #endif // BOOST_GRAPH_WAVEFRONT_HPP
|
---|