📄 prog.cc
字号:
//// prog.cc - The Grouping Genetic Algorithm Program//// author: J.I.v.Hemert// last updated : 07-11-1997//// This is the main file for the GGA. It has been tested and compiled on the// following systems:// * Linux 2.0.30 - gcc 2.7.2.1// * Irix 5.3 - gcc 2.6.3// * SunOS 4.1.4 - gcc 2.7.2//#include "prog.h"IniFileC inifile; // Reads the parameter file (used in other files too)static GGAC gga; // This is the Genetic Grouping Algorithmstatic StatisticsC stats; // Does all the bookkeepingvoid doexperiment (int nodes, double edgeprob, int seed, double rangevar, int startrun)// Do one experiment consisting of creating a problem, doing a// number of runs on this problem and after printing the stats// removing the problem again.{ int run = 0; if (startrun == 0) stats.Reset (); problem.CreateProblem (nodes, edgeprob, seed, inifile.ReadString ("problemdir"), inifile.ReadString ("graphtype"), inifile.ReadInt ("k-coloring")); gga.Initialize (problem.ReadProblem (), inifile.ReadInt ("Tmax"), startrun); for (run = startrun; run < inifile.ReadInt ("runs"); run++) { stats.SaveRescueFile (rangevar); gga.InitializePopulation (); if (gga.Run ()) { // Successful run stats.UpdateAES (gga.GetTotalEvaluations ()); stats.UpdateSR (1); stats.UpdateColorsUsed (gga.GetColorsUsed ()); } else { // Not so successful run stats.UpdateAES (0); stats.UpdateSR (0); stats.UpdateColorsUsed (gga.GetColorsUsed ()); } stats.Run (); } gga.Close (); stats.Print (rangevar); problem.RemoveProblem (); } // doexperiment ()int main (int argv, char *args[])// Contains main-loop for program. Reads type of test from inifile and// does the appropriate experiments.{ double i; int run = 0; bool rescue; double rangefrom = 0; if (argv != 2) { cerr << "Version " << VERSION << endl << "Please give a config file as argument" << endl; return (1); } inifile.Open (args[1]); stats.Initialize (rescue); if (inifile.ReadBool ("rangetest")) { // Do an experiment with a variable in a range if (rescue) { // Read the parameters from the last run before the // program was interrupted stats.LoadRescueFile (rangefrom, run); } else { // No rescue, so just read the settings from the inifile if (strcmp ("seed", inifile.ReadString ("rangevariable")) == 0) rangefrom = inifile.ReadInt ("rangefrom"); if (strcmp ("edgeprobability", inifile.ReadString ("rangevariable")) == 0) rangefrom = inifile.ReadDouble ("rangefrom"); if (strcmp ("nodes", inifile.ReadString ("rangevariable")) == 0) rangefrom = inifile.ReadInt ("rangefrom"); run = 0; } // Letting the seed run if (strcmp ("seed", inifile.ReadString ("rangevariable")) == 0) for (i = rangefrom; i <= inifile.ReadInt ("rangeto"); i += inifile.ReadInt ("rangestepsize")) { stats.SaveRescueFile (rangefrom); doexperiment (inifile.ReadInt ("nodes"), inifile.ReadDouble ("edgeprobability"), (int) i, i, run); run = 0; } // Varying the edgeprobability if (strcmp ("edgeprobability", inifile.ReadString ("rangevariable")) == 0) for (i = rangefrom; (int) (100000 * i) <= (int) (100000 * inifile.ReadDouble ("rangeto")); i += inifile.ReadDouble ("rangestepsize")) { stats.SaveRescueFile (rangefrom); doexperiment (inifile.ReadInt ("nodes"), i, inifile.ReadInt ("seed"), i, run); run = 0; } // One node after the other if (strcmp ("nodes", inifile.ReadString ("rangevariable")) == 0) for (i = rangefrom; i <= inifile.ReadInt ("rangeto"); i += inifile.ReadInt ("rangestepsize")) { stats.SaveRescueFile (rangefrom); doexperiment ((int) i, inifile.ReadDouble ("edgeprobability"), inifile.ReadInt ("seed"), i, run); run = 0; } } else { // Keep all parameters fixed and do a number of runs run = 0; if (rescue) stats.LoadRescueFile (rangefrom, run); doexperiment (inifile.ReadInt ("nodes"), inifile.ReadDouble ("edgeprobability"), inifile.ReadInt ("seed"), 0, run); } stats.Close (); return (0);} // main ()// eof prog.cc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -