/* ---------------------------------------------------------------------------- seed.C mbwall 16nov98 ---------------------------------------------------------------------------- */ #include #include #include #include #include float objective(GAGenome &); int main(int argc, char *argv[]) { cout << "Random Seed Test\n\n"; cout << "This program does three runs of a genetic algorithm, with the \n"; cout << "random seed resetting between each run. Each of the three runs \n"; cout << "should be identical\n\n"; cout.flush(); GAParameterList params; GASteadyStateGA::registerDefaultParameters(params); params.set(gaNnGenerations, 100); params.set(gaNflushFrequency, 5); params.set(gaNpMutation, 0.001); params.set(gaNpCrossover, 0.8); params.parse(argc, argv, gaFalse); int i,j; char filename[128] = "smiley.txt"; unsigned int seed=0; for(i=1; i= argc){ cerr << argv[0] << ": the file option needs a filename.\n"; exit(1); } else{ sprintf(filename, argv[i]); continue; } } else if(strcmp("seed", argv[i]) == 0){ if(++i >= argc){ cerr << argv[0] << ": the seed option needs a filename.\n"; exit(1); } else { seed = atoi(argv[i]); continue; } } else { cerr << argv[0] << ": unrecognized arguement: " << argv[i] << "\n\n"; cerr << "valid arguments include standard GAlib arguments plus:\n"; cerr << " f\tfilename from which to read (" << filename << ")\n"; cerr << "\n"; exit(1); } } const int n=5; cout << n << " random numbers\n"; GAResetRNG(seed); for(i=0; i> height >> width; short **target = new short*[width]; for(i=0; i> target[i][j]; inStream.close(); GA2DBinaryStringGenome genome(width, height, objective, (void *)target); GASimpleGA ga(genome); ga.parameters(params); // first run GAResetRNG(seed); genome.initialize(); cout << genome << "\n"; ga.set(gaNscoreFilename, "bog1.dat"); ga.evolve(); genome = ga.statistics().bestIndividual(); cout << "run 1: the random seed is: " << GAGetRandomSeed() << "\n"; for(j=0; j