| 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 | |
|---|
| 29 | #include <boost/config.hpp> |
|---|
| 30 | #include <vector> |
|---|
| 31 | #include <iostream> |
|---|
| 32 | #include <boost/graph/adjacency_list.hpp> |
|---|
| 33 | #include <boost/graph/sloan_ordering.hpp> |
|---|
| 34 | #include <boost/graph/properties.hpp> |
|---|
| 35 | #include <boost/graph/bandwidth.hpp> |
|---|
| 36 | #include <boost/graph/profile.hpp> |
|---|
| 37 | #include <boost/graph/wavefront.hpp> |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | using std::cout; |
|---|
| 41 | using std::endl; |
|---|
| 42 | |
|---|
| 43 | /* |
|---|
| 44 | Sample Output |
|---|
| 45 | ##################################### |
|---|
| 46 | ### First light of sloan-ordering ### |
|---|
| 47 | ##################################### |
|---|
| 48 | |
|---|
| 49 | original bandwidth: 8 |
|---|
| 50 | original profile: 42 |
|---|
| 51 | original max_wavefront: 7 |
|---|
| 52 | original aver_wavefront: 4.2 |
|---|
| 53 | original rms_wavefront: 4.58258 |
|---|
| 54 | |
|---|
| 55 | Starting vertex: 0 |
|---|
| 56 | Pseudoperipheral vertex: 9 |
|---|
| 57 | Pseudoperipheral radius: 4 |
|---|
| 58 | |
|---|
| 59 | Sloan ordering starting at: 0 |
|---|
| 60 | 0 8 3 7 5 2 4 6 1 9 |
|---|
| 61 | bandwidth: 4 |
|---|
| 62 | profile: 28 |
|---|
| 63 | max_wavefront: 4 |
|---|
| 64 | aver_wavefront: 2.8 |
|---|
| 65 | rms_wavefront: 2.93258 |
|---|
| 66 | |
|---|
| 67 | Sloan ordering without a start-vertex: |
|---|
| 68 | 8 0 3 7 5 2 4 6 1 9 |
|---|
| 69 | bandwidth: 4 |
|---|
| 70 | profile: 27 |
|---|
| 71 | max_wavefront: 4 |
|---|
| 72 | aver_wavefront: 2.7 |
|---|
| 73 | rms_wavefront: 2.84605 |
|---|
| 74 | |
|---|
| 75 | ############################### |
|---|
| 76 | ### sloan-ordering finished ### |
|---|
| 77 | ############################### |
|---|
| 78 | */ |
|---|
| 79 | |
|---|
| 80 | int main(int , char* []) |
|---|
| 81 | { |
|---|
| 82 | cout << endl; |
|---|
| 83 | cout << "#####################################" << endl; |
|---|
| 84 | cout << "### First light of sloan-ordering ###" << endl; |
|---|
| 85 | cout << "#####################################" << endl << endl; |
|---|
| 86 | |
|---|
| 87 | using namespace boost; |
|---|
| 88 | using namespace std; |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | //Defining the graph type |
|---|
| 92 | typedef adjacency_list< |
|---|
| 93 | setS, |
|---|
| 94 | vecS, |
|---|
| 95 | undirectedS, |
|---|
| 96 | property< |
|---|
| 97 | vertex_color_t, |
|---|
| 98 | default_color_type, |
|---|
| 99 | property< |
|---|
| 100 | vertex_degree_t, |
|---|
| 101 | int, |
|---|
| 102 | property< |
|---|
| 103 | vertex_priority_t, |
|---|
| 104 | double > > > > Graph; |
|---|
| 105 | |
|---|
| 106 | typedef graph_traits<Graph>::vertex_descriptor Vertex; |
|---|
| 107 | typedef graph_traits<Graph>::vertices_size_type size_type; |
|---|
| 108 | |
|---|
| 109 | typedef std::pair<std::size_t, std::size_t> Pair; |
|---|
| 110 | |
|---|
| 111 | Pair edges[14] = { Pair(0,3), //a-d |
|---|
| 112 | Pair(0,5), //a-f |
|---|
| 113 | Pair(1,2), //b-c |
|---|
| 114 | Pair(1,4), //b-e |
|---|
| 115 | Pair(1,6), //b-g |
|---|
| 116 | Pair(1,9), //b-j |
|---|
| 117 | Pair(2,3), //c-d |
|---|
| 118 | Pair(2,4), //c-e |
|---|
| 119 | Pair(3,5), //d-f |
|---|
| 120 | Pair(3,8), //d-i |
|---|
| 121 | Pair(4,6), //e-g |
|---|
| 122 | Pair(5,6), //f-g |
|---|
| 123 | Pair(5,7), //f-h |
|---|
| 124 | Pair(6,7) }; //g-h |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | //Creating a graph and adding the edges from above into it |
|---|
| 128 | Graph G(10); |
|---|
| 129 | for (int i = 0; i < 14; ++i) |
|---|
| 130 | add_edge(edges[i].first, edges[i].second, G); |
|---|
| 131 | |
|---|
| 132 | //Creating two iterators over the vertices |
|---|
| 133 | graph_traits<Graph>::vertex_iterator ui, ui_end; |
|---|
| 134 | |
|---|
| 135 | //Creating a property_map with the degrees of the degrees of each vertex |
|---|
| 136 | property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G); |
|---|
| 137 | for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) |
|---|
| 138 | deg[*ui] = degree(*ui, G); |
|---|
| 139 | |
|---|
| 140 | //Creating a property_map for the indices of a vertex |
|---|
| 141 | property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G); |
|---|
| 142 | |
|---|
| 143 | std::cout << "original bandwidth: " << bandwidth(G) << std::endl; |
|---|
| 144 | std::cout << "original profile: " << profile(G) << std::endl; |
|---|
| 145 | std::cout << "original max_wavefront: " << max_wavefront(G) << std::endl; |
|---|
| 146 | std::cout << "original aver_wavefront: " << aver_wavefront(G) << std::endl; |
|---|
| 147 | std::cout << "original rms_wavefront: " << rms_wavefront(G) << std::endl; |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | //Creating a vector of vertices |
|---|
| 151 | std::vector<Vertex> sloan_order(num_vertices(G)); |
|---|
| 152 | //Creating a vector of size_type |
|---|
| 153 | std::vector<size_type> perm(num_vertices(G)); |
|---|
| 154 | |
|---|
| 155 | { |
|---|
| 156 | |
|---|
| 157 | //Setting the start node |
|---|
| 158 | Vertex s = vertex(0, G); |
|---|
| 159 | int ecc; //defining a variable for the pseudoperipheral radius |
|---|
| 160 | |
|---|
| 161 | //Calculating the pseudoeperipheral node and radius |
|---|
| 162 | Vertex e = pseudo_peripheral_pair(G, s, ecc, get(vertex_color, G), get(vertex_degree, G) ); |
|---|
| 163 | |
|---|
| 164 | cout << endl; |
|---|
| 165 | cout << "Starting vertex: " << s << endl; |
|---|
| 166 | cout << "Pseudoperipheral vertex: " << e << endl; |
|---|
| 167 | cout << "Pseudoperipheral radius: " << ecc << endl << endl; |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | //Sloan ordering |
|---|
| 172 | sloan_ordering(G, s, e, sloan_order.begin(), get(vertex_color, G), |
|---|
| 173 | get(vertex_degree, G), get(vertex_priority, G)); |
|---|
| 174 | |
|---|
| 175 | cout << "Sloan ordering starting at: " << s << endl; |
|---|
| 176 | cout << " "; |
|---|
| 177 | |
|---|
| 178 | for (std::vector<Vertex>::const_iterator i = sloan_order.begin(); |
|---|
| 179 | i != sloan_order.end(); ++i) |
|---|
| 180 | cout << index_map[*i] << " "; |
|---|
| 181 | cout << endl; |
|---|
| 182 | |
|---|
| 183 | for (size_type c = 0; c != sloan_order.size(); ++c) |
|---|
| 184 | perm[index_map[sloan_order[c]]] = c; |
|---|
| 185 | std::cout << " bandwidth: " |
|---|
| 186 | << bandwidth(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 187 | << std::endl; |
|---|
| 188 | std::cout << " profile: " |
|---|
| 189 | << profile(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 190 | << std::endl; |
|---|
| 191 | std::cout << " max_wavefront: " |
|---|
| 192 | << max_wavefront(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 193 | << std::endl; |
|---|
| 194 | std::cout << " aver_wavefront: " |
|---|
| 195 | << aver_wavefront(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 196 | << std::endl; |
|---|
| 197 | std::cout << " rms_wavefront: " |
|---|
| 198 | << rms_wavefront(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 199 | << std::endl; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | ///////////////////////////////////////////////// |
|---|
| 206 | //Version including finding a good starting point |
|---|
| 207 | ///////////////////////////////////////////////// |
|---|
| 208 | |
|---|
| 209 | { |
|---|
| 210 | //sloan_ordering |
|---|
| 211 | sloan_ordering(G, sloan_order.begin(), |
|---|
| 212 | get(vertex_color, G), |
|---|
| 213 | make_degree_map(G), |
|---|
| 214 | get(vertex_priority, G) ); |
|---|
| 215 | |
|---|
| 216 | cout << endl << "Sloan ordering without a start-vertex:" << endl; |
|---|
| 217 | cout << " "; |
|---|
| 218 | for (std::vector<Vertex>::const_iterator i=sloan_order.begin(); |
|---|
| 219 | i != sloan_order.end(); ++i) |
|---|
| 220 | cout << index_map[*i] << " "; |
|---|
| 221 | cout << endl; |
|---|
| 222 | |
|---|
| 223 | for (size_type c = 0; c != sloan_order.size(); ++c) |
|---|
| 224 | perm[index_map[sloan_order[c]]] = c; |
|---|
| 225 | std::cout << " bandwidth: " |
|---|
| 226 | << bandwidth(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 227 | << std::endl; |
|---|
| 228 | std::cout << " profile: " |
|---|
| 229 | << profile(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 230 | << std::endl; |
|---|
| 231 | std::cout << " max_wavefront: " |
|---|
| 232 | << max_wavefront(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 233 | << std::endl; |
|---|
| 234 | std::cout << " aver_wavefront: " |
|---|
| 235 | << aver_wavefront(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 236 | << std::endl; |
|---|
| 237 | std::cout << " rms_wavefront: " |
|---|
| 238 | << rms_wavefront(G, make_iterator_property_map(&perm[0], index_map, perm[0])) |
|---|
| 239 | << std::endl; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | cout << endl; |
|---|
| 245 | cout << "###############################" << endl; |
|---|
| 246 | cout << "### sloan-ordering finished ###" << endl; |
|---|
| 247 | cout << "###############################" << endl << endl; |
|---|
| 248 | return 0; |
|---|
| 249 | |
|---|
| 250 | } |
|---|