00001
00002
00003
00004
00005
00006
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: gen1 <nodenum> <density> <seed>\n");
00018 return -1;
00019 }
00020
00021 const int num = atoi(argv[1]);
00022 const double dens = atof(argv[2]);
00023 const int seed = atoi(argv[3]);
00024
00025 srand48(seed);
00026
00027 const int maxedgenum = (num*(num-1)) / 2;
00028 int * pick = new int[maxedgenum];
00029 int k = 0;
00030 for (int i = 1; i < num; ++i) {
00031 for (int j = i + 1; j <= num; ++j) {
00032 pick[k++] = (i << 16) + j;
00033 }
00034 }
00035
00036 random_shuffle(pick, pick + maxedgenum);
00037 const int edgenum = static_cast<int>(maxedgenum * dens);
00038
00039 printf("%i %i\n", num, edgenum);
00040
00041 for (k = 0; k < edgenum; ++k) {
00042 const int i = pick[k] >> 16;
00043 const int j = pick[k] & 0xffff;
00044 printf("%3i %3i -1\n", i-1, j-1);
00045 }
00046
00047 return 0;
00048 }