void inPlaceSort(void (*funct)(int *, int), int which){ printf("Performing %s with MIN = %d, MAX = %d and STEP = %d\n\n",inPlaceSortingFunctionNames[which],MIN,MAX,STEP); FILE *fpBest,*fpWorst,*fpAverage; int currentCount; //! Bubble Sort fpBest = fopen(formFileName(inPlaceSortingFunctionNames[which],"Best"),"w"); fpAverage = fopen(formFileName(inPlaceSortingFunctionNames[which],"Average"),"w"); fpWorst = fopen(formFileName(inPlaceSortingFunctionNames[which],"Worst"),"w"); for(currentCount=MIN; currentCount<=MAX; currentCount+=STEP) { int *a; generateBest(&a,currentCount); (*funct)(a,currentCount); fprintf(fpBest,"%d,%lu,%lu,%lu\n",currentCount,assignments,comparisons,assignments+comparisons); resetCounters(); generateAverage(&a,currentCount); (*funct)(a,currentCount); fprintf(fpAverage,"%d,%lu,%lu,%lu\n",currentCount,assignments,comparisons,assignments+comparisons); resetCounters(); generateWorst(&a,currentCount); (*funct)(a,currentCount); fprintf(fpWorst,"%d,%lu,%lu,%lu\n",currentCount,assignments,comparisons,assignments+comparisons); resetCounters(); printf("N: %d\n",currentCount); } fclose(fpBest); fclose(fpAverage); fclose(fpWorst); printf("Finished %s with MIN = %d, MAX = %d and STEP = %d\n\n",inPlaceSortingFunctionNames[which],MIN,MAX,STEP); }
void EvolutionaryAlgorithm::print(int generation, int numDeaths) { cout << "\nGeneration " << generation << ": Avg=" << generateAverage() << ", Number of old-age deaths: " << numDeaths << ", Best: T=" << currentPopulation[0].getTotalValue() << " cents"; for (int count = 0; count < typesOfCoins.size(); count++) { cout << ", " <<typesOfCoins[count].name << "=" << currentPopulation[0].numberOfGenesWithValue(typesOfCoins[count].value); } }