#ifndef SA_MIRSolver_h_ #define SA_MIRSolver_h_ //#include #include //#include #include //#include //#include #include "SA_ParSolver.h" #include "util_salib.h" #define MAX_Run_number 100000 // f(x) = b*x^(-a)+z struct Funktion_Daten { float b, a, z, diff_sum; }; class SA_MIRSolver : public SA_ParSolver { private: SA_Output samirsolvoutput; protected: char processor_name[MPI_MAX_PROCESSOR_NAME]; int number_of_processors; float Alpha_MIR, MinusAlpha_MIR, Alpha_MIR_old, MinusAlpha_MIR_old, Alpha_praxis, // probability of obtaining a nonoptimal solution by the n-th iteration // falls off as (1/n)^Alpha_MIR // P[Xn is not in Ebest] -> (K_MIR/n)^Alpha_MIR // is a constant, must be calcutated K_MIR, K_MIR_old; // is a constant, must be calcutated double K_praxis; float Ebest; // the true minimum cost, estimated as the minimum of all seen costs float Ebest_user, Estar, // the average over nonoptimal final costs *EndCost, // end costs after a run // for every run length *AverageCost, // average end costs after a run // for every run length *DeltaCost, *LogDeltaCost, // difference of the average cost after a run and the true minimum cost // for every run length B_MIR, LogB_MIR, LogK_MIR, B_MIR_old, LogB_MIR_old; // DeltaCost schould also fall off as n^(-Alpha_MIR): // DeltaCost[n] = B_MIR * n^(-Alpha_MIR) // is a constant, must be calcutated int N1_MIR, N1_MIR_old; float Epsilon, // number of iterations of a single sequential run, // which provides an avearge result of sufficient quality: // DeltaCost[N1_MIR] <= Epsilon // is a parameter Derivation; int Fraction; int s_MIR; // optimal use of N iterations is to distribute them across s_MIR=floor(N/e*K_MIR) // shorter runs; this maximizes the convergence rate [Azencott] int Ns_MIR; // the total number of iterations required by s_MIR runs on a single prozessor // to obtain the same probability of convergence as a single run of N1_MIR iterations int Nq_MIR, q_MIR; int *RunLength; // hier werden alle durchlaufenen Run Laengen protokolliert int Minimum_RunLength, // mit dieser Run Laenge fangen wir an Maximum_RunLength, // so lang soll der laengste Run sein Run_number; // Anzahl der tatsaechlich durchgefuehrten Runs float Betta_Runtime, // RunLength[i+1] = Betta_Runtime * RunLength[i] RunFactor; int Samples; // Damit die Werte fuer PowerLawFit statistisch verlaesslicher sind, fuehren // wir insgesamt so viele Durchgaenge von Minimum_ bis Maximum_RunLength durch double EndSolutionQuality; struct SA_RUN_TYPE { int AnzahlRuns, RunLaenge; } MIR_Daten; float *x,*y; float Steptime, Runtime, Sigma; std::ofstream PowerLaw_average, PowerLaw_cost, // SARunfile, PowerLaw_outputfile, PowerLaw_fit, PowerLaw_fit1; // PowerLaw_runlength, // PowerLaw_real_runlength, // PowerLaw_endcost, // PowerLaw_temp, // SARun_best; // TestMIRScheduler_outputfile; public: SA_MIRSolver(int *argc, char ***argv, SA_Problem&); ~SA_MIRSolver(); SA_Output *GetSolverOutput(); virtual float RunAnnealing(void); // Den gewaehlten SA-Algo ausfuehren float PhaseTwo(int minimum_runlength, int maximum_runlength, float betta_runtime, int samples); // \****************************************************** // Phase II of MIR-algorithm // input: // minimum_runlength, maximum_runlength, betta_runtime, samples // purpose: // execute SA-run of length from minimum_runlength to maximum_runlength by betta_runtime, each samples-time // output: // Run_number - number of executed runs // RunLength[Run_number] - run legths // EndCost[Run_number] - SA-end costs // \****************************************************** float MIR(); // Phase III des MIR-Algorithmus float oldMIR(); float SequentialMIR(); float ParallelRuns(int, int, float, int); float ParallelRun(int); float SARun(int); // fuehrt einen SA-Run der gegebenen Laenge aus void Setup(void); void ComputeDeltaCost(void); // berechnet sie aus AverageCost und Ebest void ComputePowerLawFit(void); int ComputeN1_MIR(float, double); void Collect_Ebest(MPI_Comm comm = MPI_COMM_WORLD); int ReadConfig(std::istream &); void ShowConfig(void); virtual void CreateLog(std::ostream & output, MPI_Comm comm = MPI_COMM_SELF); //Ausgabe der Durchlaufdaten in die Log-Datei // float MIRTest(); // void ComputePowerLawFit(float&, float&, float&); // hier wird PowerLaw ueberprueft und fuer die Berechnung von // Alpha_MIR, B_MIR, K_MIR benutzt // float ComputeK_MIR(float); // void ComputeK(float n, float kappa_n, double emin, float K, float alpha, float deviation); // int ComputeN1_MIR_Derivation(float, float); // int ComputeNs_MIR(float, float, float, int&, int&, int&, float&); // // int ComputeNq_MIR(float, float, int, int&, int&, int&, float&); // // Funktion_Daten f(float a); // Funktion_Daten minimum(float l,float r,float e); // void fitsess(float alpha_mir, float b_mir, int n); // void Prepare_fitsess(float, float, float); // // float BestOf(float*,int); // float AverageOf(float*,int); // // // void TestMIRScheduler(void); // testet die Korrektheit der RunLaenge und der Abkuehlung // void Plot(float, float); // void Plot_Test(double, float); }; #endif