2 //=======================================================================
3 // Copyright 2002 Marc Wintermantel (wintermantel@even-ag.ch)
4 // ETH Zurich, Center of Structure Technologies (www.imes.ethz.ch/st)
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //=======================================================================
12 #ifndef BOOST_GRAPH_WAVEFRONT_HPP
13 #define BOOST_GRAPH_WAVEFRONT_HPP
15 #include <boost/config.hpp>
16 #include <boost/graph/graph_traits.hpp>
17 #include <boost/detail/numeric_traits.hpp>
18 #include <boost/graph/bandwidth.hpp>
19 #include <boost/config/no_tr1/cmath.hpp>
21 #include <algorithm> // for std::min and std::max
25 template <typename Graph
, typename VertexIndexMap
>
26 typename graph_traits
<Graph
>::vertices_size_type
27 ith_wavefront(typename graph_traits
<Graph
>::vertex_descriptor i
,
31 typename graph_traits
<Graph
>::vertex_descriptor v
, w
;
32 typename graph_traits
<Graph
>::vertices_size_type b
= 1;
33 typename graph_traits
<Graph
>::out_edge_iterator edge_it2
, edge_it2_end
;
34 typename graph_traits
<Graph
>::vertices_size_type index_i
= index
[i
];
35 std::vector
<bool> rows_active(num_vertices(g
), false);
37 rows_active
[index_i
] = true;
39 typename graph_traits
<Graph
>::vertex_iterator ui
, ui_end
;
40 for (tie(ui
, ui_end
) = vertices(g
); ui
!= ui_end
; ++ui
)
43 if(index
[v
] <= index_i
)
45 for (tie(edge_it2
, edge_it2_end
) = out_edges(v
, g
); edge_it2
!= edge_it2_end
; ++edge_it2
)
47 w
= target(*edge_it2
, g
);
48 if( (index
[w
] >= index_i
) && (!rows_active
[index
[w
]]) )
51 rows_active
[index
[w
]] = true;
61 template <typename Graph
>
62 typename graph_traits
<Graph
>::vertices_size_type
63 ith_wavefront(typename graph_traits
<Graph
>::vertex_descriptor i
,
66 return ith_wavefront(i
, g
, get(vertex_index
, g
));
70 template <typename Graph
, typename VertexIndexMap
>
71 typename graph_traits
<Graph
>::vertices_size_type
72 max_wavefront(const Graph
& g
, VertexIndexMap index
)
74 BOOST_USING_STD_MAX();
75 typename graph_traits
<Graph
>::vertices_size_type b
= 0;
76 typename graph_traits
<Graph
>::vertex_iterator i
, end
;
77 for (tie(i
, end
) = vertices(g
); i
!= end
; ++i
)
78 b
= max
BOOST_PREVENT_MACRO_SUBSTITUTION(b
, ith_wavefront(*i
, g
, index
));
82 template <typename Graph
>
83 typename graph_traits
<Graph
>::vertices_size_type
84 max_wavefront(const Graph
& g
)
86 return max_wavefront(g
, get(vertex_index
, g
));
90 template <typename Graph
, typename VertexIndexMap
>
92 aver_wavefront(const Graph
& g
, VertexIndexMap index
)
95 typename graph_traits
<Graph
>::vertex_iterator i
, end
;
96 for (tie(i
, end
) = vertices(g
); i
!= end
; ++i
)
97 b
+= ith_wavefront(*i
, g
, index
);
103 template <typename Graph
>
105 aver_wavefront(const Graph
& g
)
107 return aver_wavefront(g
, get(vertex_index
, g
));
111 template <typename Graph
, typename VertexIndexMap
>
113 rms_wavefront(const Graph
& g
, VertexIndexMap index
)
116 typename graph_traits
<Graph
>::vertex_iterator i
, end
;
117 for (tie(i
, end
) = vertices(g
); i
!= end
; ++i
)
118 b
+= std::pow(double ( ith_wavefront(*i
, g
, index
) ), 2.0);
120 b
/= num_vertices(g
);
125 template <typename Graph
>
127 rms_wavefront(const Graph
& g
)
129 return rms_wavefront(g
, get(vertex_index
, g
));
135 #endif // BOOST_GRAPH_WAVEFRONT_HPP