diff --git a/eo/test/RoyalRoad.h b/eo/test/RoyalRoad.h index 35b217b94..3781d1feb 100644 --- a/eo/test/RoyalRoad.h +++ b/eo/test/RoyalRoad.h @@ -19,7 +19,7 @@ Contact: todos@geneura.ugr.es, http://geneura.ugr.es Marc.Schoenauer@polytechnique.fr -CVS Info: $Date: 2001-05-11 10:44:01 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/test/RoyalRoad.h,v 1.1 2001-05-11 10:44:01 jmerelo Exp $ $Author: jmerelo $ +CVS Info: $Date: 2001-05-17 07:29:50 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/test/RoyalRoad.h,v 1.2 2001-05-17 07:29:50 jmerelo Exp $ $Author: jmerelo $ */ #ifndef RoyalRoad_h @@ -37,7 +37,7 @@ class RoyalRoad: public eoEvalFunc { // Applies the function virtual void operator() ( EOT & _eo ) { - FitT fitness; + FitT fitness = 0; if (_eo.invalid()) { for ( unsigned i = 0; i < _eo.size()/div; i ++ ) { bool block = true; diff --git a/eo/test/t-MGE-control.cpp b/eo/test/t-MGE-control.cpp index 5e9fc58a6..61f3af612 100644 --- a/eo/test/t-MGE-control.cpp +++ b/eo/test/t-MGE-control.cpp @@ -10,7 +10,7 @@ #include #include -#include "binary_value.h" +#include "RoyalRoad.h" // Viri #include @@ -25,16 +25,17 @@ typedef eoVirus Chrom; int main() { - const unsigned POP_SIZE = 100, CHROM_SIZE = 16; + const unsigned POP_SIZE = 1000, CHROM_SIZE = 128; unsigned i; eoBooleanGenerator gen; // the populations: eoPop pop; - // Evaluation - eoEvalFuncPtr eval( binary_value ); - + // Evaluation + RoyalRoad rr( 4 ); + eoEvalFuncCounter eval( rr ); + eoInitVirus random(CHROM_SIZE, gen); for (i = 0; i < POP_SIZE; ++i) { Chrom chrom; @@ -46,31 +47,32 @@ int main() cout << "population:" << endl; for (i = 0; i < pop.size(); ++i) cout << "\t" << pop[i] << " " << pop[i].fitness() << endl; - // selection - eoDetTournamentSelect lottery( 3) ; + eoStochTournamentSelect lottery(0.9 ); // breeder - eoOneBitFlip bf; + eoOneBitFlip vm; eoUBitXover xover; eoProportionalOp propSel; eoGeneralBreeder breeder( lottery, propSel ); - propSel.add(bf, 0.75); - propSel.add(xover, 0.25); + propSel.add(vm, 0.8); + propSel.add(xover, 0.1); // Replace a single one - eoPlusReplacement replace; + eoCommaReplacement replace; // Terminators - eoGenContinue continuator1(50); - eoFitContinue continuator2(65535.f); + eoGenContinue continuator1(500); + eoFitContinue continuator2(128); eoCombinedContinue continuator(continuator1, continuator2); eoCheckPoint checkpoint(continuator); eoStdoutMonitor monitor; checkpoint.add(monitor); eoSecondMomentStats stats; + eoPopStat dumper( 10 ); monitor.add(stats); + checkpoint.add(dumper); checkpoint.add(stats); // GA generation @@ -90,7 +92,8 @@ int main() cout << "pop" << endl; for (i = 0; i < pop.size(); ++i) cout << "\t" << pop[i] << " " << pop[i].fitness() << endl; - + + cout << "\n --> Number of Evaluations = " << eval.getValue() << endl; return 0; } diff --git a/eo/test/t-MGE.cpp b/eo/test/t-MGE.cpp index 0ddfd72ba..112ca3282 100644 --- a/eo/test/t-MGE.cpp +++ b/eo/test/t-MGE.cpp @@ -33,20 +33,20 @@ int main() eoPop pop; // Evaluation - RoyalRoad rr( 4 ); - + RoyalRoad rr( 4 ); + eoEvalFuncCounter eval( rr ); + eoInitVirus random(CHROM_SIZE, gen); for (i = 0; i < POP_SIZE; ++i) { Chrom chrom; random(chrom); - rr(chrom); + eval(chrom); pop.push_back(chrom); } cout << "population:" << endl; for (i = 0; i < pop.size(); ++i) cout << "\t" << pop[i] << " " << pop[i].fitness() << endl; - // selection eoStochTournamentSelect lottery(0.9 ); @@ -58,9 +58,9 @@ int main() eoUBitXover xover; eoProportionalOp propSel; eoGeneralBreeder breeder( lottery, propSel ); - propSel.add(vm, 0.4); - propSel.add(vf, 0.4); - propSel.add(vt, 0.1); + propSel.add(vm, 0.8); + propSel.add(vf, 0.05); + propSel.add(vt, 0.05); propSel.add(xover, 0.1); // Replace a single one @@ -80,7 +80,7 @@ int main() checkpoint.add(stats); // GA generation - eoEasyEA ea(checkpoint, rr, breeder, replace ); + eoEasyEA ea(checkpoint, eval, breeder, replace ); // evolution try @@ -96,7 +96,8 @@ int main() cout << "pop" << endl; for (i = 0; i < pop.size(); ++i) cout << "\t" << pop[i] << " " << pop[i].fitness() << endl; - + + cout << "\n --> Number of Evaluations = " << eval.getValue() << endl; return 0; } diff --git a/eo/test/t-eoVirus.cpp b/eo/test/t-eoVirus.cpp new file mode 100644 index 000000000..65b39bdca --- /dev/null +++ b/eo/test/t-eoVirus.cpp @@ -0,0 +1,77 @@ +/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + + t-eoVirus.cpp + This program tests the the binary cromosomes and several genetic operators + (c) GeNeura Team, 1999 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: todos@geneura.ugr.es, http://geneura.ugr.es + +*/ +//----------------------------------------------------------------------------- + +#include // cout +#include // ostrstream, istrstream +#include // general EO +#include // bitstring representation & operators +#include +#include + +#include "binary_value.h" + +//----------------------------------------------------------------------------- + +typedef eoVirus Chrom; + +//----------------------------------------------------------------------------- + +int main() +{ + const unsigned SIZE = 8; + eoBooleanGenerator gen; + eo::rng.reseed( time( 0 ) ); + + Chrom chrom(SIZE), chrom2(SIZE); + chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2)); + cout << chrom << endl; + cout << chrom2 << endl; + + // Virus Mutation + VirusBitFlip vf; + unsigned i; + for ( i = 0; i < 10; i++ ) { + vf( chrom ); + cout << chrom << endl; + } + + // Chrom Mutation + cout << "Chrom mutation--------" << endl; + VirusMutation vm; + for ( i = 0; i < 10; i++ ) { + vm( chrom ); + cout << chrom << endl; + } + + // Chrom Transmision + cout << "Chrom transmission--------" << endl; + VirusTransmission vt; + vt( chrom2, chrom ); + cout << chrom2 << endl; + + return 0; + +} +