/* / Author: Haytham Alsaghayer / Class: MA 5903 / Date: Aug 09, 2009 / Assignment: Optimization Function */ #include "Header.h" int main(int argc, char *argv[]) { struct timeval tim; //to get time from sys double t1, t2; //for timer ThreeIntsArry options; //how many times f got executed float fResult; //float result of f fuction Vec * DfResult; //Vec result of Df function Mat * DDfResult; //Mat result of DDf function Vec * currentVecP; //temp vector to execute functions on int counter; //counter of function //read input //i1 i2 i3 vectorfileformat //i1 i2 i3 vectorfileformat // ... while((scanf("%d", &options[0])) != EOF) //i1 { //read input scanf("%d", &options[1]); //i2 scanf("%d", &options[2]); //i3 currentVecP = readVec(stdin); //vectorfileformat //print border printf("\n=================================\n"); //get counter of f if(options[0] == 1) { //get how many times f got executed counter = *((int *) f(0.0, 0.0, 0.0, 1)); //print counter of f printf("f counter = %d\n", counter); } else //compute f { //start timer gettimeofday(&tim, NULL); t1=tim.tv_sec+(tim.tv_usec/MILLISECOND); //compute f fResult = (*((float *) f(currentVecP->p[0], currentVecP->p[1], currentVecP->p[2], 0))); //end timer gettimeofday(&tim, NULL); t2=tim.tv_sec+(tim.tv_usec/MILLISECOND); //print result of f printf("f(%-8g, %-8g, %-8g) = \n%g\n", currentVecP->p[0], currentVecP->p[1], currentVecP->p[2], fResult); //print duration printf("Duration of f = %g seconds\n", t2-t1); } //get counter of Df if(options[1] == 1) { //get how many times Df got executed counter = *((int *) Df(0.0, 0.0, 0.0, 1)); //print counter of f printf("\nDf counter = %d\n", counter); } else //compute Df { //start timer gettimeofday(&tim, NULL); t1=tim.tv_sec+(tim.tv_usec/MILLISECOND); //compute Df DfResult = (Vec *) Df(currentVecP->p[0], currentVecP->p[1], currentVecP->p[2], 0); //end timer gettimeofday(&tim, NULL); t2=tim.tv_sec+(tim.tv_usec/MILLISECOND); //print result of Df printf("\nDf(%-8g, %-8g, %-8g) = \n", currentVecP->p[0], currentVecP->p[1], currentVecP->p[2]); //print result of Df writeVec(DfResult, stdout); //print duration printf("Duration of Df = %g seconds\n", t2-t1); destroyVec(DfResult); } //get counter of DDf if(options[2] == 1) { //get how many times DDf got executed counter = *((int *) DDf(0.0, 0.0, 0.0, 1)); //print counter of f printf("\nDDf counter = %d\n", counter); } else //compute DDf { //start timer gettimeofday(&tim, NULL); t1=tim.tv_sec+(tim.tv_usec/MILLISECOND); //compute DDf DDfResult = (Mat *) DDf(currentVecP->p[0], currentVecP->p[1], currentVecP->p[2], 0); //end timer gettimeofday(&tim, NULL); t2=tim.tv_sec+(tim.tv_usec/MILLISECOND); //print result of DDf printf("\nDDf(%-8g, %-8g, %-8g) = \n", currentVecP->p[0], currentVecP->p[1], currentVecP->p[2]); //print result of DDf writeMat(DDfResult, stdout); //print duration printf("Duration of DDf = %g seconds\n", t2-t1); destroyMat(DDfResult); } //print border printf("=================================\n"); //free vector memory resources destroyVec(currentVecP); } return 0; }