//#include //#include #include #include #include //#include #include #include "SA_SeqEasyScheduler.h" SA_SeqEasyScheduler::SA_SeqEasyScheduler(): saseqeasyoutput("SA_SeqEasyScheduler","SA_Output.rsc"), CoolingRatio(0.9), subchainfactor(1.0), // StrictShort(true), MinAccRatio(LOWER_ACCEPTANCE_RATIO), MaxChainLength(0), MaxChainLength0(0), frozen_count(0), frozen_limit(5), pos(0),full(0),FrozenSum(0),Mean(0) { LastSolutions = new float[frozen_limit]; for (int i=0; i < frozen_limit; i++) LastSolutions[i] = 0; // Connecting variables of SA_SeqEasyScheduler to output object saseqeasyoutput.EnableLevelNumbers(false); saseqeasyoutput.EnableIdentifier(true); saseqeasyoutput.SetOutputLevel(10); saseqeasyoutput.AddVariable(1,SA_FLOAT, &CoolingRatio); saseqeasyoutput.AddVariable(2,SA_FLOAT, &MinAccRatio); saseqeasyoutput.AddVariable(3,SA_FLOAT, &subchainfactor); // saseqeasyoutput.AddVariable(4,SA_BYTE, &StrictShort); saseqeasyoutput.AddVariable(5,SA_LONG, &MaxChainLength); saseqeasyoutput.AddVariable(6,SA_LONG, &MaxChainLength0); saseqeasyoutput.AddVariable(7,SA_LONG, &frozen_count); saseqeasyoutput.AddVariable(8,SA_LONG, &frozen_limit); // strcpy(SubChainReduct,"linear"); // saseqeasyoutput.AddVariable(9,SA_STRING, strictshortstr); saseqeasyoutput.SetPreviousOutput(SA_Scheduler::GetSchedulerOutput()); } SA_Output * SA_SeqEasyScheduler::GetSchedulerOutput() { return(&saseqeasyoutput); } // \****************************************************** // Destruktor // \****************************************************** SA_SeqEasyScheduler::~SA_SeqEasyScheduler() {//debug(SA_SeqEasyScheduler::Destruktor , myrank); delete [] LastSolutions; } // \****************************************************** // Methode ReadConfig - Liest die Konfigurations- // daten ( geklammert mit '{' '}' ) aus dem istream // \****************************************************** int SA_SeqEasyScheduler::ReadConfig(std::istream & config) {//debug(SA_SeqEasyScheduler::ReadConfig , myrank); char text[BUFLEN]; config >> text; if ( strcmp(text,"{") != 0) { std::cout << "In SA_SeqEasyScheduler::ReadConfig: config file section does not begin with {!\n"; return FALSE; } while (config >> text && ( strcmp(text,"}") != 0 )) { if (strcmp(text, "SA_Scheduler") == 0) { if ( ! SA_Scheduler::ReadConfig(config) ) { std::cout <<"ReadConfing for Scheduler failed!\n"; return 0; } } else if (strcmp(text, "coolingratio") == 0) { config >> text; SetCoolingRatio( atof(text) ); } else if (strcmp(text, "frozenlimit") == 0) { config >> text; SetFrozenLimit( atol(text) ); } else if (strcmp(text, "minaccratio") == 0) { config >> text; MinAccRatio = atof(text); if ( MinAccRatio < 0 || MinAccRatio >= 1) { std::cout <<"In SA_SeqEasyScheduler::ReadConfig: bad value "<< MinAccRatio<<" for minaccratio specified!\n"; MinAccRatio = -1; } } else if (strcmp(text, "subchainlength") == 0) { config >> text; MaxChainLength = MaxChainLength0 = atol(text); } else if (strcmp(text, "subchainfactor") == 0) { config >> text; subchainfactor = atof(text); } // not needed in parallel REMOVE ?! // else if (strcmp(text, "strictshort") == 0) // { // config >> text; // if (strcmp(text, "no") == 0 || strcmp(text, "yes") == 0) { // if (strcmp(text, "no") == 0) { // StrictShort = false; // strcpy(strictshortstr,"not strict"); // } // } else // { // std::cout <<"In SA_SeqEasyScheduler::ReadConfig: bad value "<< text<<" for strictshort specified! Leaving default yes\n"; // } // } else if (strcmp(text, "verboselevel") == 0) { config >> text; saseqeasyoutput.SetOutputLevel(atof(text)); } else { std::cout <<"In SA_SeqEasyScheduler::ReadConfig: unrecognized keyword \""< MaxChainLength ); // || (( n_accepts != 0) && (( EPSILON + (float)n_accepts/n_iter ) < LOWER_ACCEPTANCE_RATIO) )); } // \****************************************************** // Methode Enqueue - Speichert die letzten frozen_limit // Kostenwerte. // \****************************************************** void SA_SeqEasyScheduler::Enqueue() {//debug(SA_SeqEasyScheduler::Enqueue, myrank); FrozenSum += E - LastSolutions[pos]; LastSolutions[pos] = E; pos = (pos+1)%frozen_limit; if ( pos == 0) full = TRUE; Mean = FrozenSum / (full?frozen_limit:pos); } // \****************************************************** // Methode Frozen - Entscheidet, ob das System // zum Stillstand gekommen ist. // \****************************************************** int SA_SeqEasyScheduler::Frozen() { return (TimeExceeded() || frozen_count >= frozen_limit); } // die Bestimmung der Startwerte void SA_SeqEasyScheduler::WarmingUp(SA_Problem & P, SA_Solution &s, SA_Solution &b) { if ( MaxChainLength == 0) // if subchainlength wasn't set in .cfg-file { MaxChainLength = MaxChainLength0 = (unsigned long)ceil(P.GetLocalN()); } // use the subchainfactor (def. is 1) MaxChainLength = MaxChainLength0 = (unsigned long)ceil(MaxChainLength*subchainfactor); if( StartT < 0.0) // if StartT wasn't set in .cfg-file { SetStartT( AartsWarmingUp(P,s,b,MaxChainLength)); } }