00001
00002
00003
00004
00005
00006
00007
00008 #include <cstdio>
00009 #include <cstdlib>
00010 #include <algorithm>
00011
00012 int
00013 main(int argc, char* argv[])
00014 {
00015 if (argc != 4) {
00016 printf("Usage: gen2 <nodenum> <density> <seed>\n");
00017 return -1;
00018 }
00019
00020 const int num = atoi(argv[1]);
00021 const double dens = atof(argv[2]);
00022 const int seed = atoi(argv[3]);
00023
00024 srand48(seed);
00025
00026 const int maxedgenum = (num*(num-1)) / 2;
00027 int * pick = new int[maxedgenum];
00028 int k = 0;
00029 for (int i = 1; i < num; ++i) {
00030 for (int j = i + 1; j <= num; ++j) {
00031 pick[k++] = (i << 16) + j;
00032 }
00033 }
00034
00035 random_shuffle(pick, pick + maxedgenum);
00036 const int edgenum = static_cast<int>(maxedgenum * dens);
00037
00038 printf("%i %i\n", num, edgenum);
00039
00040 for (k = 0; k < edgenum; ++k) {
00041 const int i = pick[k] >> 16;
00042 const int j = pick[k] & 0xffff;
00043 if (drand48() >= .5)
00044 printf("%3i %3i -1\n", i-1, j-1);
00045 else
00046 printf("%3i %3i 1\n", i-1, j-1);
00047 }
00048
00049 return 0;
00050 }