The new libga

Apart from big changes in the src/ga dir, and the addition of the src/do dir
it also generated a few changes here and there, e.g. some include file still
missing. Also removed some warning from some test files.
This commit is contained in:
evomarc 2001-04-24 04:52:04 +00:00
commit 56c9464306
32 changed files with 1679 additions and 158 deletions

View file

@ -11,32 +11,59 @@ int main(int argc, char* argv[])
try
{
typedef eoBit<double> EoType;
typedef eoBit<double> EOT;
eoParser parser(argc, argv);
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // keeps all things allocated, including eoEasyEA and eoPop!
eoState state; // keeps all things allocated
eoEvalFuncPtr<EoType, float> eval( binary_value<EoType> );
eoGenContinue<EoType> term(20);
eoCheckPoint<EoType> checkpoint(term);
///// FIRST, problem or representation dependent stuff
//////////////////////////////////////////////////////
eoAlgo<EoType>& ga = make_ga(parser, eval, checkpoint, state);
// The evaluation fn - encapsulated into an eval counter for output
eoEvalFuncPtr<EOT, float> mainEval( binary_value<EOT> );
eoEvalFuncCounter<EOT> eval(mainEval);
eoPop<EoType>& pop = init_ga(parser, state, double());
// the genotype - through a genotype initializer
eoInit<EOT>& init = make_genotype(parser, state, double());
if (parser.userNeedsHelp())
{
parser.printHelp(cout);
return 0;
}
// Build the variation operator (any seq/prop construct)
eoGenOp<EOT>& op = make_op(parser, state, init);
//// Now the representation-independent things
//////////////////////////////////////////////
// initialize the population - and evaluate
// yes, this is representation indepedent once you have an eoInit
eoPop<EOT>& pop = make_pop(parser, state, init);
apply(eval, pop);
run_ga(ga, pop); // run the ga
// stopping criteria
eoContinue<EOT> & term = make_continue(parser, state, eval);
// output
eoCheckPoint<EOT> & checkpoint = make_checkpoint(parser, state, eval, term);
// algorithm (need the operator!)
eoAlgo<EOT>& ga = make_algo_scalar(parser, state, eval, checkpoint, op);
///// End of construction of the algorith
/////////////////////////////////////////
// to be called AFTER all parameters have been read!!!
make_help(parser);
//// GO
///////
cout << "Initial Population\n";
pop.sortedPrintOn(cout);
cout << endl;
run_ea(ga, pop); // run the ga
cout << "Final Population\n";
pop.sortedPrintOn(cout);
cout << endl;
}
catch(exception& e)
{
cout << e.what() << endl;
}
}
}

View file

@ -24,7 +24,7 @@
*/
/**
CVS Info: $Date: 2001-03-14 10:14:27 $ $Author: maartenkeijzer $ $Revision: 1.11 $
CVS Info: $Date: 2001-04-24 04:52:04 $ $Author: evomarc $ $Revision: 1.12 $
*/
//-----------------------------------------------------------------------------
@ -37,7 +37,7 @@ CVS Info: $Date: 2001-03-14 10:14:27 $ $Author: maartenkeijzer $ $Revision: 1.1
//-----------------------------------------------------------------------------
main() {
int main() {
eoUniformGenerator<float> u1(-2.5,3.5);
eoUniformGenerator<double> u2(0.003, 0.05 );
eoUniformGenerator<unsigned long> u3( 10000U, 10000000U);

View file

@ -65,7 +65,8 @@ void testSelectMany(eoSelect<EOT> & _select, string _name)
// initialize parents
for (unsigned i=0; i<pSize; i++)
// parents[i].fitness(log(i+1));
parents[i].fitness(exp(i));
// parents[i].fitness(exp(i));
parents[i].fitness(i);
cout << "Initial parents (odd)\n" << parents << endl;
// do the selection
@ -132,16 +133,16 @@ eoValueParam<unsigned int> tournamentSizeParam = parser.createParam<unsigned int
// the selection procedures under test
// eoDetSelect<Dummy> detSelect(oRate);
// testSelectMany(detSelect, "detSelect");
// eoDetSelect<Dummy> detSelect(oRate);
// testSelectMany(detSelect, "detSelect");
// Roulette
// eoProportionalSelect<Dummy> propSelect;
// testSelectOne<Dummy>(propSelect, oRate, "propSelect");
eoProportionalSelect<Dummy> propSelect;
testSelectOne<Dummy>(propSelect, oRate, "propSelect");
// Ranking
// eoRankingSelect<Dummy> rankSelect(rankingPressure);
// testSelectOne<Dummy>(rankSelect, oRate, "rankSelect");
eoRankingSelect<Dummy> rankSelect(rankingPressure);
testSelectOne<Dummy>(rankSelect, oRate, "rankSelect");
// New ranking using the perf2Worth construct
cout << "Avant appel a LinearRanking()" << endl;
@ -161,6 +162,8 @@ eoValueParam<unsigned int> tournamentSizeParam = parser.createParam<unsigned int
eoStochTournamentSelect<Dummy> stochTourSelect(tRate);
testSelectOne<Dummy>(stochTourSelect, oRate, "stochTourSelect");
exit(1);
// Fitness scaling
// eoFitnessScalingSelect<Dummy> fitScaleSelect(rankingPressure);
// testSelectOne<Dummy>(fitScaleSelect, oRate, "fitScaleSelect");

View file

@ -43,6 +43,12 @@ int the_main(int argc, char **argv)
eoValueParam<double> rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit");
eoValueParam<double> factor(0.99, "mutationFactor", "Decrease factor for mutation rate");
eoValueParam<uint32> seed(time(0), "seed", "Random number seed");
// test if user entered or if default value used
if (parser.isItThere(seed))
cout << "YES\n";
else
cout << "NO\n";
eoValueParam<string> load_name("", "Load","Load",'L');
eoValueParam<string> save_name("", "Save","Save",'S');

View file

@ -42,14 +42,14 @@ typedef eoVector<eoMinimizingFitness, int> Chrom2;
//-----------------------------------------------------------------------------
main()
int main()
{
const unsigned SIZE = 4;
// check if the appropriate ctor gets called
Chrom1 chrom(SIZE, 5);
for (int i = 0; i < chrom.size(); ++i)
for (unsigned i = 0; i < chrom.size(); ++i)
{
assert(chrom[i] == 5);
}