00001 00002 #include <iostream> 00003 #include <stdlib.h> 00004 00005 #define QDIST(XA,YA,XB,YB) ((XB-XA)*(XB-XA)+(YB-YA)*(YB-YA)) 00006 00007 using namespace std; 00008 00009 int main(int argc, char **argv) { 00010 00011 if(argc < 4 || argc > 5) { 00012 cout<<"Syntax: GenQF #variables #scenarios density [seed]"<<endl; 00013 return 1; 00014 } 00015 00016 int n = atoi(argv[1]); 00017 int s = atoi(argv[2]); 00018 double d = atof(argv[3]); 00019 if(argc > 4) srandom(atoi(argv[4])); 00020 else srandom(0); 00021 00022 double *posx = new double[s*n]; 00023 double *posy = new double[s*n]; 00024 00025 for(int i = 0; i < s*n; i++) { 00026 posx[i] = (double)random()/RAND_MAX; 00027 posy[i] = (double)random()/RAND_MAX; 00028 } 00029 00030 double *m = new double[s]; 00031 00032 for(int j = 0; j < s; j++) m[j] = 0; 00033 cout<<n<<" "<<(n*(n-1))/2<<" "<<s<<endl; 00034 for(int i1 = 0; i1 < n-1; i1++) { 00035 for(int i2 = i1+1; i2 < n; i2++) { 00036 cout<<i1+1<<" "<<i2+1<<" "; 00037 for(int j = 0; j < s; j++) { 00038 double qd = QDIST(posx[j*n+i1],posy[j*n+i1],posx[j*n+i2],posy[j*n+i2]); 00039 cout<<" "<<qd; 00040 if((double)random()/RAND_MAX < d && (double)random()/RAND_MAX < d) { 00041 m[j] += qd; 00042 } 00043 } 00044 cout<<endl; 00045 } 00046 } 00047 00048 delete[] posx; 00049 delete[] posy; 00050 00051 00052 for(int j = 0; j < s; j++) { 00053 cout<<" "<<m[j]; 00054 } 00055 cout<<endl; 00056 00057 delete[] m; 00058 00059 return 0; 00060 00061 }