gen1.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_{dens}$ :
4  A complete unweighted graph with edge probability $dens$.
5  Note that we'll print -1's in the problem file since we treat minimization
6  problems in BCP!
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: gen1 <nodenum> <density> <seed>\n");
18  return -1;
19  }
20 
21  const int num = atoi(argv[1]);
22  const double dens = atof(argv[2]);
23  const int seed = atoi(argv[3]);
24 
25  srand48(seed);
26 
27  const int maxedgenum = (num*(num-1)) / 2;
28  int * pick = new int[maxedgenum];
29  int k = 0;
30  for (int i = 1; i < num; ++i) {
31  for (int j = i + 1; j <= num; ++j) {
32  pick[k++] = (i << 16) + j;
33  }
34  }
35 
36  random_shuffle(pick, pick + maxedgenum);
37  const int edgenum = static_cast<int>(maxedgenum * dens);
38 
39  printf("%i %i\n", num, edgenum);
40 
41  for (k = 0; k < edgenum; ++k) {
42  const int i = pick[k] >> 16;
43  const int j = pick[k] & 0xffff;
44  printf("%3i %3i -1\n", i-1, j-1);
45  }
46 
47  return 0;
48 }
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
static char * j
Definition: OSdtoa.cpp:3622
void fint fint * k