#ifdef MPI #include "SA_TimeScheduler.h" SA_TimeScheduler::SA_TimeScheduler() : // SA_SeqEasyScheduler(), SA_EasyScheduler(), EndT(-1.0), SQGoal(0.0), sqset(0) { } /** */ int SA_TimeScheduler::iterate(float startvalue, float endvalue, float factor) { if (factor >= 1) return -1; int count = 0; float currentvalue = startvalue; while(currentvalue > endvalue) { count++; currentvalue *= factor; } return count; } /** A fixed number of iterations is made and the time needed is stoped to determine the time for one iteration sets number of seconds for one iteration (avgitert), and average cost difference (avgdeltac); @param P */ void SA_TimeScheduler::determineAvgIterTime(SA_Problem *P, SA_Solution *State, SA_Solution *BestSolution){ clock_t time0; int n = 0; avgdeltac = 0; float cstate,cneighbor; time0 = clock(); do{ cstate = P->GetCost(*State); P->GetNeighbor(*State,GetRelativeT()); cneighbor = P->GetCost(*State); float deltac = cstate - cneighbor; if (deltac < 0) { avgdeltac -= deltac; } else { avgdeltac += deltac; } if ( Accept( P->GetCost(*State) )) { P->UpdateSolution(*State); if ( BestFound() ) { P->Copy(*State,*BestSolution); } } else { P->ResetSolution(*State); } n++; } while ( ! Equilibrium() || n < 100); avgdeltac /= n; clock_t time1; time1 = clock(); avgitert = (double)((double)(time1 - time0)/(double)CLOCKS_PER_SEC)/(double)n; double *itertbuf = new double; MPI_Allreduce(&avgitert,itertbuf,1,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); int nproc; MPI_Comm_size(MPI_COMM_WORLD, &nproc); *itertbuf /= nproc; avgitert = *itertbuf; } /** Calculation of possible temperature steps in the given time. Strategy 1: It is assumed that the acceptance ratio is proportional to the temperature, so that the cooling ratio may be used to evaluate the acceptance reduction. Strategy 2: assumption: accreduction follows the rule acc(t) = e^(-(delta c / t)) and delta c (the cost difference is constant) avgcost difference is determined in determien */ void SA_TimeScheduler::eastimateTempSteps() { if(EndT < 0) { EndT = (MinAccRatio*StartT)/100.0; } ets = iterate(StartT,EndT,CoolingRatio); } int SA_TimeScheduler::ReadConfig(std::istream & config) {//debug(SA_SeqEasyScheduler::ReadConfig , myrank); char text[BUFLEN]; config >> text; if ( strcmp(text,"{") != 0) { std::cout << "In SA_TimeScheduler::ReadConfig: config file section does not begin with {!\n"; return FALSE; } while (config >> text && ( strcmp(text,"}") != 0 )) { if (strcmp(text, "SA_EasyScheduler") == 0) // if (strcmp(text, "SA_SeqEasyScheduler") == 0) { // if ( ! SA_SeqEasyScheduler::ReadConfig(config) ) if ( ! SA_EasyScheduler::ReadConfig(config) ) { std::cout <<"ReadConfing for EasyScheduler failed!\n"; return 0; } } else if (strcmp(text, "endtemperature") == 0) { config >> text; EndT = atof(text); } else if (strcmp(text, "solutionquality") == 0) { config >> text; SQGoal = atof(text); sqset = 1; std::cerr << "DBG: solutionquality goal is set to: " << SQGoal <