/home/coin/SVN-release/OS-2.4.0/Bcp/examples/MaxCut/Generators/gen1.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_{dens}$ :
00004    A complete unweighted graph with edge probability $dens$.
00005    Note that we'll print -1's in the problem file since we treat minimization
00006    problems in BCP!
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 }

Generated on Thu Sep 22 03:05:50 2011 by  doxygen 1.4.7