/home/coin/SVN-release/OS-2.4.2/Bcp/examples/MaxCut/Generators/gen4.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 /* This gnerator generates $G_{grid}$ :
00004    An n-by-n grid with edge weigths chosen uniformly from {-maxw,+maxw}.
00005    (For now we'll solve this problem by treating it as a complete graph. Sort
00006    of inefficient...)
00007 */
00008 
00009 #include <cstdio>
00010 #include <cstdlib>
00011 #include <algorithm>
00012 
00013 int
00014 main(int argc, char* argv[])
00015 {
00016    if (argc != 4) {
00017       printf("Usage: gen4 <nodenum> <maxweigth> <seed>\n");
00018       return -1;
00019    }
00020 
00021    const int num  = atoi(argv[1]);
00022    const int maxw = atoi(argv[2]);
00023    const int seed = atoi(argv[3]);
00024 
00025    srand48(seed);
00026 
00027    printf("%i %i\n", num*num, 2*num*num-2*num);
00028 
00029    for (int i = 0; i < num; ++i) {
00030       const int colstart = i * num + 1;
00031       for (int j = 0; j < num; ++j) {
00032          const int w0 = static_cast<int>((2*maxw+1) * drand48()) - maxw;
00033          printf("%3i %3i %i\n", colstart+j-1, colstart+j, w0);
00034          const int w1 = static_cast<int>((2*maxw+1) * drand48()) - maxw;
00035          printf("%3i %3i %i\n", colstart+j-1, colstart+j+num-1, w1);
00036       }
00037    }
00038    return 0;
00039 }

Generated on Wed Nov 30 03:03:46 2011 by  doxygen 1.4.7