// Compile: cc measure-order.c // Execute: ./a.out < datafile.dat // // given listing of packet orders per node, generate measures // and histogram; the idea here is to separate statistics and // measuring from actual packet order generations (and simulation) // Measures implemented: // * M2 // // Input format: // // numNodes(or hops) numPackets numSuccessfulRuns(or data sets) // foreach S numSuccessfulRuns // foreach N numHodes // nodeNumber: orderPacketsReceived // #include #include #include #include int numNodes=-1,numPackets=-1,numSuccessfulRuns=-1,*packets,**m2_histogram,M2_MAX, meth2,*totalM2Score,*meth2_max,*meth2_min,nodeCount; double *meth2_avg; // dumps array to stdout void print_array( int* array, int size ) { int i; for (i = 0; i < size; i++) printf("%d ", array[i]); printf("\n"); } // sum of 'larger' packets arriving before i int calc_disorder_2 ( int* permutation ) { int i, j, disorder = 0; for (i = 0; i < numPackets; i++) { for (j = i - 1; j >= 0; j--) { if ( permutation[j] > permutation[i] ) disorder++; } } return disorder; } // tracks number of the same measures for histogram of results void makeMeasurements (int *permutation) { meth2 = calc_disorder_2 ( permutation ); totalM2Score[nodeCount] += meth2; if (meth2 > meth2_max[nodeCount]) meth2_max[nodeCount] = meth2; if (meth2 < meth2_min[nodeCount]) meth2_min[nodeCount] = meth2; // store meth2 results in m2_histogram m2_histogram[nodeCount][meth2]++; //printf("count:%d, score:%d\n",m2_histogram[nodeCount][meth2],meth2); } void SkipToEndofLine(FILE *fpInp) { while (getc(fpInp) != '\n');} void ProcessInput() { int i,j,currentNode; FILE *fp; fp = stdin; fscanf(fp, "%d %d %d",&numNodes,&numPackets,&numSuccessfulRuns); SkipToEndofLine(fp); M2_MAX=numPackets*(numPackets-1)/2; // allocate memory for tracking stats packets = (int *)malloc(numPackets*sizeof(int)); meth2_avg = (double *)malloc(numNodes*sizeof(double)); meth2_min = (int *)malloc(numNodes*sizeof(int)); meth2_max = (int *)malloc(numNodes*sizeof(int)); totalM2Score = (int *)malloc(numNodes*sizeof(int)); m2_histogram = (int**)malloc(sizeof(int*)*numNodes); for (i=0;i