#include "header.h" //You'll note this takes a lot of paramaters. Let's list them all. // returns: flagbox3 Returns a copy of currentTallies. // const flagbox3 computeflag A "1" will cause the respective computation. // vector * vecin The inputed vector to be operated on. // double timer[3] Updated with the total consumed execution time. // const flagbox3 printflags A "1" will cause the respective results to print // const flagbox3 modeflags These were the display controls, as per // the given instructions. They aren't connected // to the control, like computeflags, but only // fufill a rather poorly explained part of // the project requirement to take 3 additional // arguments to control the return system. // flagbox3 *currentTallies Passed in and updated with the # funks used. //Recall: flagbox3 holds 3 unsigned ints, which relate to the computations as follows: //flagbox3.f0: initial function. //flagbox3.f1: gradient of function //flagbox3.f2: hessian of function flagbox3 processinput(const flagbox3 computeflag, vector * vecin, double timer[3], const flagbox3 printflags, const flagbox3 modeflags, flagbox3 *currentTallies) { double result=0.0; //The result of computing f() double start,stop; //For the timekeeping. int n=vecin->size; //The size of the vector coming in. double interval=INTERVAL; //The interval that the calculus works on //This defaults to .00001 //It's easier to edit in the header file. vector f =craftvecEZ( (n -2) );//Stores parts of function's evaluation vector df =craftvecEZ( n );//Stores gradient matrix ddf=craftmatEZ( n , n );//Stores Hessian if(computeflag.f0) //if asked to compute the result... { start = clock(); //Start clock result = sumfunk(vecin, &f); //Run the summation function stop = clock(); //Stop clock timer[0] += (stop - start); //Update time. currentTallies->f0++; //Update current tallies if (printflags.f0) //If asked to print... {printf("RESULT:%lf\n",result);} //Print result } if(computeflag.f1) //if asked to compute the gradient... { start = clock(); //Start clock gradfunk(vecin, &df, result, interval); //Run gradiant calc. stop = clock(); //Stop clock timer[1] += (stop - start); //Update time. currentTallies->f1 += (df.size);//Update current tallies if (printflags.f1) //If asked to print... {printvec(&df);printf("\n");} //Print gradient } if(computeflag.f2) //if asked to compute the hessian... { start = clock(); //Start clock hessfunk(vecin, &ddf, result, interval);//Run Hessain calc. stop = clock(); //Stop clock timer[2] += (stop - start); //Update time. currentTallies->f2 += (4*ddf.rows*(ddf.cols-1) + ddf.cols*2); //Update current tallies if (printflags.f2) //If asked to print... {printmat(&ddf);printf("\n");} //Print hessian } destroyvec(&f); //Free the memory of the function destroyvec(&df); //Free the memory of the gradient destroymat(&ddf); //Free the memory of the hessian flagbox3 returnthis; //Craft a flagbox3 to return //Not the modeflags are either 1 or 0 //by multiplying it by the current tallied value //You'll only get the tallies you have the mode flag on for. returnthis.f0 = (currentTallies->f0 * modeflags.f0); returnthis.f1 = (currentTallies->f1 * modeflags.f1); returnthis.f2 = (currentTallies->f2 * modeflags.f2); return returnthis; //Return the requested current tallies. }