|
| 1 | +# include <cstddef> |
| 2 | +# include <ctime> |
| 3 | +# include <iostream> |
| 4 | + |
| 5 | +using namespace std; |
| 6 | + |
| 7 | +# include <metis.h> |
| 8 | + |
| 9 | +int main ( ); |
| 10 | +void partgraphrecursive_test ( ); |
| 11 | +void partgraphkway_test ( ); |
| 12 | +void timestamp ( ); |
| 13 | + |
| 14 | +//****************************************************************************80 |
| 15 | + |
| 16 | +int main ( ) |
| 17 | + |
| 18 | +//****************************************************************************80 |
| 19 | +// |
| 20 | +// Purpose: |
| 21 | +// |
| 22 | +// METIS_TEST tests the METIS library. |
| 23 | +// |
| 24 | +// Licensing: |
| 25 | +// |
| 26 | +// This code is distributed under the GNU LGPL license. |
| 27 | +// |
| 28 | +// Modified: |
| 29 | +// |
| 30 | +// 27 February 2017 |
| 31 | +// |
| 32 | +// Author: |
| 33 | +// |
| 34 | +// John Burkardt |
| 35 | +// |
| 36 | +{ |
| 37 | + timestamp ( ); |
| 38 | + cout << "\n"; |
| 39 | + cout << "METIS_TEST\n"; |
| 40 | + cout << " C++ version\n"; |
| 41 | + cout << " Test the METIS library for graph partitioning.\n"; |
| 42 | + |
| 43 | + partgraphrecursive_test ( ); |
| 44 | + partgraphkway_test ( ); |
| 45 | +// |
| 46 | +// Terminate. |
| 47 | +// |
| 48 | + cout << "\n"; |
| 49 | + cout << "METIS_TEST\n"; |
| 50 | + cout << " Normal end of execution.\n"; |
| 51 | + cout << "\n"; |
| 52 | + timestamp ( ); |
| 53 | + |
| 54 | + return 0; |
| 55 | +} |
| 56 | +//****************************************************************************80 |
| 57 | + |
| 58 | +void partgraphrecursive_test ( ) |
| 59 | + |
| 60 | +//****************************************************************************80 |
| 61 | +// |
| 62 | +// Purpose: |
| 63 | +// |
| 64 | +// PARTGRAPHRECURSIVE_TEST tests PARTGRAPHRECURSIVE. |
| 65 | +// |
| 66 | +// Discussion: |
| 67 | +// |
| 68 | +// The graph has the following form: |
| 69 | +// |
| 70 | +// 0 --- 1 --- 2 |
| 71 | +// | | | |
| 72 | +// 3 --- 4 --- 5 |
| 73 | +// |
| 74 | +// Licensing: |
| 75 | +// |
| 76 | +// This code is distributed under the GNU LGPL license. |
| 77 | +// |
| 78 | +// Modified: |
| 79 | +// |
| 80 | +// 27 February 2017 |
| 81 | +// |
| 82 | +// Author: |
| 83 | +// |
| 84 | +// John Burkardt |
| 85 | +// |
| 86 | +{ |
| 87 | +// |
| 88 | +// The number of vertices. |
| 89 | +// |
| 90 | + idx_t nvtxs = 6; |
| 91 | +// |
| 92 | +// Number of balancing constraints, which must be at least 1. |
| 93 | +// |
| 94 | + idx_t ncon = 1; |
| 95 | +// |
| 96 | +// Pointers to initial entries in adjacency array. |
| 97 | +// |
| 98 | + idx_t xadj[nvtxs+1] = { 0, 2, 5, 7, 9, 12, 14 }; |
| 99 | +// |
| 100 | +// Adjacent vertices in consecutive index order. |
| 101 | +// |
| 102 | + idx_t nEdges = 7; |
| 103 | + idx_t adjncy[2 * nEdges] = {1,3,0,4,2,1,5,0,4,3,1,5,4,2}; |
| 104 | +// |
| 105 | +// The number of parts requested for the partition. |
| 106 | +// |
| 107 | + idx_t nParts = 2; |
| 108 | +// |
| 109 | +// On return, the edge cut volume of the partitioning solution. |
| 110 | +// |
| 111 | + idx_t objval; |
| 112 | +// |
| 113 | +// On return, the partition vector for the graph. |
| 114 | +// |
| 115 | + idx_t part[nvtxs]; |
| 116 | + |
| 117 | + cout << "\n"; |
| 118 | + cout << "PARTGRAPHRECURSIVE_TEST:\n"; |
| 119 | + cout << " METIS_PartGraphRecursive partitions a graph into K parts\n"; |
| 120 | + cout << " using multilevel recursive bisection.\n"; |
| 121 | + |
| 122 | + int ret = METIS_PartGraphRecursive ( &nvtxs, &ncon, xadj, adjncy, NULL, NULL, |
| 123 | + NULL, &nParts, NULL, NULL, NULL, &objval, part ); |
| 124 | + |
| 125 | + cout << "\n"; |
| 126 | + cout << " Return code = " << ret << "\n"; |
| 127 | + cout << " Edge cuts for partition = " << objval << "\n"; |
| 128 | + |
| 129 | + cout << "\n"; |
| 130 | + cout << " Partition vector:\n"; |
| 131 | + cout << "\n"; |
| 132 | + cout << " Node Part\n"; |
| 133 | + cout << "\n"; |
| 134 | + for ( unsigned part_i = 0; part_i < nvtxs; part_i++ ) |
| 135 | + { |
| 136 | + std::cout << " " << part_i << " " << part[part_i] << std::endl; |
| 137 | + } |
| 138 | + |
| 139 | + return; |
| 140 | +} |
| 141 | +//****************************************************************************80 |
| 142 | + |
| 143 | +void partgraphkway_test ( ) |
| 144 | + |
| 145 | +//****************************************************************************80 |
| 146 | +// Purpose: |
| 147 | +// |
| 148 | +// PARTGRAPHKWAY_TEST tests PARTGRAPHKWAY. |
| 149 | +// |
| 150 | +// Discussion: |
| 151 | +// |
| 152 | +// The graph has the following form: |
| 153 | +// |
| 154 | +// 0 --- 1 --- 2 |
| 155 | +// | | | |
| 156 | +// 3 --- 4 --- 5 |
| 157 | +// |
| 158 | +// Licensing: |
| 159 | +// |
| 160 | +// This code is distributed under the GNU LGPL license. |
| 161 | +// |
| 162 | +// Modified: |
| 163 | +// |
| 164 | +// 27 February 2017 |
| 165 | +// |
| 166 | +// Author: |
| 167 | +// |
| 168 | +// John Burkardt |
| 169 | +// |
| 170 | +{ |
| 171 | +// |
| 172 | +// The number of vertices. |
| 173 | +// |
| 174 | + idx_t nvtxs = 6; |
| 175 | +// |
| 176 | +// Number of balancing constraints, which must be at least 1. |
| 177 | +// |
| 178 | + idx_t ncon = 1; |
| 179 | +// |
| 180 | +// Pointers to initial entries in adjacency array. |
| 181 | +// |
| 182 | + idx_t xadj[nvtxs+1] = { 0, 2, 5, 7, 9, 12, 14 }; |
| 183 | +// |
| 184 | +// Adjacent vertices in consecutive index order. |
| 185 | +// |
| 186 | + idx_t nEdges = 7; |
| 187 | + idx_t adjncy[2 * nEdges] = {1,3,0,4,2,1,5,0,4,3,1,5,4,2}; |
| 188 | +// |
| 189 | +// The number of parts requested for the partition. |
| 190 | +// |
| 191 | + idx_t nParts = 2; |
| 192 | +// |
| 193 | +// On return, the edge cut volume of the partitioning solution. |
| 194 | +// |
| 195 | + idx_t objval; |
| 196 | +// |
| 197 | +// On return, the partition vector for the graph. |
| 198 | +// |
| 199 | + idx_t part[nvtxs]; |
| 200 | + |
| 201 | + cout << "\n"; |
| 202 | + cout << "PARTGRAPHKWAY_TEST:\n"; |
| 203 | + cout << " METIS_PartGraphKway partitions a graph into K parts\n"; |
| 204 | + cout << " using multilevel K-way partition.\n"; |
| 205 | + |
| 206 | + int ret = METIS_PartGraphKway ( &nvtxs, &ncon, xadj, adjncy, NULL, NULL, |
| 207 | + NULL, &nParts, NULL, NULL, NULL, &objval, part ); |
| 208 | + |
| 209 | + cout << "\n"; |
| 210 | + cout << " Return code = " << ret << "\n"; |
| 211 | + cout << " Edge cuts for partition = " << objval << "\n"; |
| 212 | + |
| 213 | + cout << "\n"; |
| 214 | + cout << " Partition vector:\n"; |
| 215 | + cout << "\n"; |
| 216 | + cout << " Node Part\n"; |
| 217 | + cout << "\n"; |
| 218 | + for ( unsigned part_i = 0; part_i < nvtxs; part_i++ ) |
| 219 | + { |
| 220 | + std::cout << " " << part_i << " " << part[part_i] << std::endl; |
| 221 | + } |
| 222 | + |
| 223 | + return; |
| 224 | +} |
| 225 | +//****************************************************************************80 |
| 226 | + |
| 227 | +void timestamp ( ) |
| 228 | + |
| 229 | +//****************************************************************************80 |
| 230 | +// |
| 231 | +// Purpose: |
| 232 | +// |
| 233 | +// TIMESTAMP prints the current YMDHMS date as a time stamp. |
| 234 | +// |
| 235 | +// Example: |
| 236 | +// |
| 237 | +// 31 May 2001 09:45:54 AM |
| 238 | +// |
| 239 | +// Licensing: |
| 240 | +// |
| 241 | +// This code is distributed under the GNU LGPL license. |
| 242 | +// |
| 243 | +// Modified: |
| 244 | +// |
| 245 | +// 08 July 2009 |
| 246 | +// |
| 247 | +// Author: |
| 248 | +// |
| 249 | +// John Burkardt |
| 250 | +// |
| 251 | +// Parameters: |
| 252 | +// |
| 253 | +// None |
| 254 | +// |
| 255 | +{ |
| 256 | +# define TIME_SIZE 40 |
| 257 | + |
| 258 | + static char time_buffer[TIME_SIZE]; |
| 259 | + const struct std::tm *tm_ptr; |
| 260 | + size_t len; |
| 261 | + std::time_t now; |
| 262 | + |
| 263 | + now = std::time ( NULL ); |
| 264 | + tm_ptr = std::localtime ( &now ); |
| 265 | + |
| 266 | + len = std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); |
| 267 | + |
| 268 | + std::cout << time_buffer << "\n"; |
| 269 | + |
| 270 | + return; |
| 271 | +# undef TIME_SIZE |
| 272 | +} |
0 commit comments