29 #include <boost/config.hpp>
30 #include <boost/graph/adjacency_list.hpp>
31 #include <boost/graph/bandwidth.hpp>
32 #include <boost/graph/cuthill_mckee_ordering.hpp>
33 #include <boost/graph/properties.hpp>
158 using namespace boost;
160 typedef adjacency_list<vecS, vecS, undirectedS,
161 property<vertex_color_t, default_color_type,
162 property<vertex_degree_t, int> > >
Graph;
163 typedef graph_traits<Graph>::vertex_descriptor
Vertex;
164 typedef graph_traits<Graph>::vertices_size_type
size_type;
166 typedef std::pair<std::size_t, std::size_t>
Pair;
170 size_t const nnodes = *max_element(cbegin(_edges), cend(_edges)) + 1;
171 cout <<
"NNODES = " <<
nnodes << endl;
175 for (
size_t i = 0; i < _edges.size(); i+=2)
176 add_edge(_edges[i], _edges[i+1], G);
178 graph_traits<Graph>::vertex_iterator ui, ui_end;
180 property_map<Graph, vertex_degree_t>::type deg = get(vertex_degree, G);
181 for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
182 deg[*ui] = degree(*ui, G);
184 property_map<Graph, vertex_index_t>::type
185 index_map = get(vertex_index, G);
187 std::cout <<
"original bandwidth: " << bandwidth(G) << std::endl;
189 std::vector<Vertex> inv_perm(num_vertices(G));
191 std::vector<int> perm(num_vertices(G));
196 cuthill_mckee_ordering(G, s, inv_perm.rbegin(), get(vertex_color, G),
197 get(vertex_degree, G));
205 perm[index_map[inv_perm[
c]]] =
c;
206 std::cout <<
"improved bandwidth: "
207 << bandwidth(G, make_iterator_property_map(&perm[0], index_map, perm[0]))
211 assert(perm.size()==
nnodes);