void Comparator::generateParametericPlots(vector<string> *vecMetrics, int noOfMetrics, vector<string> vecmetricNames,string nameOfFile){ int noOfRegions; ofstream tempFile; vector<string> vecSeperatedMetrics; stringstream queryString; Gnuplot g1; g1.reset_all(); g1.savetops(nameOfFile); vector<string> vecParametersOfComparison; vecParametersOfComparison.push_back("Mean"); vecParametersOfComparison.push_back("Median"); //vecParametersOfComparison.push_back("Variance"); vecParametersOfComparison.push_back("Standard deviation"); for(int i=1; i<noOfMetrics; i++){ double mean,median,/*variance,*/stdDeviation; double *values; int yrange=1; //create temporary file to create the histogram data queryString.str(""); queryString.clear(); queryString<<"histData"<<i; tempFile.open(queryString.str().c_str()); tempFile.precision(5); //for every method to be compared calculate the values for(unsigned int methodCount=0; methodCount<vecMethodNames.size(); methodCount++){ noOfRegions = vecMetrics[methodCount].size(); values = new double[noOfRegions]; for(int j=0; j<noOfRegions;j++){ boost::split(vecSeperatedMetrics, vecMetrics[methodCount][j], boost::is_any_of(",")); values[j]= atof(vecSeperatedMetrics[i].c_str()); } //Calculate Mean mean = calculateMean(values,noOfRegions); //Calculate Median median = calculateMedian(values,noOfRegions); //Calculate Variance // variance = calculateVariance(values,noOfRegions); //calculate Standard Deviation stdDeviation = calculateStdDeviation(values,noOfRegions); //find the yRange of the plot int tempRange = (int)(mean+ median+ stdDeviation); if(yrange < tempRange ) yrange = tempRange; //create histogram file tempFile<< vecMethodNames[methodCount] << " "<< fixed <<mean<< " " << fixed <<median<< " " << fixed << stdDeviation << endl; } tempFile.close(); //initialise the gnuplot object g1.reset_plot(); g1.set_grid(); queryString.str(""); queryString.clear(); queryString << "[" << vecmetricNames[i]<<"] over all Regions"; g1.set_title(queryString.str()); g1.set_xlabel("Method Names"); queryString.str(""); queryString.clear(); queryString << "set yrange [0:" << yrange+1 << "]"; g1.cmd(queryString.str()); g1.cmd("set boxwidth 0.30 absolute"); g1.cmd("set style fill solid 1.00 border -1").cmd("set style histogram rowstacked gap 4"); g1.cmd("set style data histograms"); g1.set_legend("outside right top"); g1.cmd("set xtic rotate by -45 scale 0"); queryString.str(""); queryString.clear(); queryString<<"plot 'histData"<<i << "' using "; unsigned int parameterCount=0; queryString <<2 <<":xtic(1)t \"" << vecParametersOfComparison[parameterCount] <<"\""; for(parameterCount =1; parameterCount<= vecParametersOfComparison.size()-1; parameterCount++){ queryString<<", '' using "<<(parameterCount+2)<< "t \"" << vecParametersOfComparison[parameterCount]<<"\""; } queryString<<endl; //cout<< "\n\n" <<queryString.str()<<endl; g1.cmd(queryString.str()); g1.reset_plot(); } }
int main() { /* //-----------------------// //-----TEST ALLOCATOR----// //-----------------------// my_initialize_heap(10000); //Test 1 //-----------------------// printf("\n***TEST 1***\n\n"); int *p, *r; p = my_alloc(sizeof(int)); printf("Address of int pointer: 0x%X in hex and %d in dec \n", p, p); my_free(p); r = my_alloc(sizeof(int)); printf("Address of int pointer: 0x%X in hex and %d in dec \n", r, r); //-----------------------// //Test 2 //-----------------------// printf("\n***TEST 2***\n\n"); int *q, *s; q = my_alloc(sizeof(int)); s = my_alloc(sizeof(int)); printf("Address of int pointer 1: 0x%X in hex and %d in dec\n", q, q); printf("Address of int pointer 2: 0x%X in hex and %d in dec\n", s, s); printf("Size of overhead + int: %d \n", SIZE_OF_OVERHEAD + sizeof(int)); //-----------------------// //Test 3 //-----------------------// printf("\n***TEST 3***\n\n"); int *x, *t, *v; x = my_alloc(sizeof(int)); t = my_alloc(sizeof(int)); v = my_alloc(sizeof(int)); printf("Address of int pointer 1: 0x%X in hex and %d in dec\n", x, x); printf("Address of int pointer 2: 0x%X in hex and %d in dec\n", t, t); printf("Address of int pointer 3: 0x%X in hex and %d in dec\n", v, v); my_free(t); double *y; y = my_alloc(sizeof(double)); printf("Address of double pointer: 0x%X in hex and %d in dec\n", y, y); int *w = my_alloc(sizeof(int)); printf("Address of int pointer: 0x%X in hex and %d in dec\n", w, w); //-----------------------// //Test 4 //-----------------------// printf("\n***TEST 4***\n\n"); char *c; int *z; c = my_alloc(sizeof(char)); z = my_alloc(sizeof(int)); printf("Address of char pointer: 0x%X in hex and %d in dec \n", c, c); printf("Address of int pointer: 0x%X in hex and %d in dec \n", z, z); //-----------------------// //Test 5 //-----------------------// printf("\n***TEST 5***\n\n"); int *myArray = my_alloc(100*sizeof(int)); int *f = my_alloc(sizeof(int)); *f = 13; printf("Address of array: 0x%X in hex and %d in dec \n", myArray, myArray); printf("Address of int: 0x%X in hex and %d in dec \n", f, f); printf("Value of int: %d in dec \n", *f); my_free(myArray); printf("Address of int: 0x%X in hex and %d in dec \n", f, f); printf("Value of int: %d in dec \n", *f); //-----------------------// */ //--------------------------------------// //---SOLVE STANDARD DEVIATION PROBLEM---// //--------------------------------------// int numberOfIntegers = 0; int currentInput = 0; double stdDeviation = 0; my_initialize_heap(10000); //First get user input //Get the size of the array printf("Please enter a positive integer: "); scanf_s("%d", &numberOfIntegers); //Allocate space for an array of entered integers int *stdDevArray = my_alloc(numberOfIntegers * sizeof(int)); //Read integers into the array for (int i = 0; i < numberOfIntegers; i++) { printf("Please enter an integer to put into the array: "); scanf_s("%d", &stdDevArray[i]); } // Calculate standard deviation of integers // Formula: // sqrt( 1/n * summation( xi - u )^2, 1 to n ), // where xi = integers entered and u = total arithmetic mean stdDeviation = calculateStdDeviation(stdDevArray, numberOfIntegers); //Print the standard deviation printf("The standard deviation is : %f ", stdDeviation); system("pause"); return 0; }