gen4.cpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 /* This gnerator generates $G_{grid}$ :
4  An n-by-n grid with edge weigths chosen uniformly from {-maxw,+maxw}.
5  (For now we'll solve this problem by treating it as a complete graph. Sort
6  of inefficient...)
7 */
8 
9 #include <cstdio>
10 #include <cstdlib>
11 #include <algorithm>
12 
13 int
14 main(int argc, char* argv[])
15 {
16  if (argc != 4) {
17  printf("Usage: gen4 <nodenum> <maxweigth> <seed>\n");
18  return -1;
19  }
20 
21  const int num = atoi(argv[1]);
22  const int maxw = atoi(argv[2]);
23  const int seed = atoi(argv[3]);
24 
25  srand48(seed);
26 
27  printf("%i %i\n", num*num, 2*num*num-2*num);
28 
29  for (int i = 0; i < num; ++i) {
30  const int colstart = i * num + 1;
31  for (int j = 0; j < num; ++j) {
32  const int w0 = static_cast<int>((2*maxw+1) * drand48()) - maxw;
33  printf("%3i %3i %i\n", colstart+j-1, colstart+j, w0);
34  const int w1 = static_cast<int>((2*maxw+1) * drand48()) - maxw;
35  printf("%3i %3i %i\n", colstart+j-1, colstart+j+num-1, w1);
36  }
37  }
38  return 0;
39 }
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
static char * j
Definition: OSdtoa.cpp:3622