Added missing files and updated old MGE files

This commit is contained in:
jmerelo 2001-05-17 07:29:50 +00:00
commit e32c52d332
4 changed files with 106 additions and 25 deletions

View file

@ -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<EOT> {
// 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;

View file

@ -10,7 +10,7 @@
#include <eo>
#include <ga/eoBitOp.h>
#include "binary_value.h"
#include "RoyalRoad.h"
// Viri
#include <MGE/VirusOp.h>
@ -25,16 +25,17 @@ typedef eoVirus<float> 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<Chrom> pop;
// Evaluation
eoEvalFuncPtr<Chrom> eval( binary_value );
// Evaluation
RoyalRoad<Chrom> rr( 4 );
eoEvalFuncCounter<Chrom> eval( rr );
eoInitVirus<float> 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<Chrom> lottery( 3) ;
eoStochTournamentSelect<Chrom> lottery(0.9 );
// breeder
eoOneBitFlip<Chrom> bf;
eoOneBitFlip<Chrom> vm;
eoUBitXover<Chrom> xover;
eoProportionalOp<Chrom> propSel;
eoGeneralBreeder<Chrom> 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<Chrom> replace;
eoCommaReplacement<Chrom> replace;
// Terminators
eoGenContinue<Chrom> continuator1(50);
eoFitContinue<Chrom> continuator2(65535.f);
eoGenContinue<Chrom> continuator1(500);
eoFitContinue<Chrom> continuator2(128);
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
eoCheckPoint<Chrom> checkpoint(continuator);
eoStdoutMonitor monitor;
checkpoint.add(monitor);
eoSecondMomentStats<Chrom> stats;
eoPopStat<Chrom> 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;
}

View file

@ -33,20 +33,20 @@ int main()
eoPop<Chrom> pop;
// Evaluation
RoyalRoad<Chrom> rr( 4 );
RoyalRoad<Chrom> rr( 4 );
eoEvalFuncCounter<Chrom> eval( rr );
eoInitVirus<float> 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<Chrom> lottery(0.9 );
@ -58,9 +58,9 @@ int main()
eoUBitXover<Chrom> xover;
eoProportionalOp<Chrom> propSel;
eoGeneralBreeder<Chrom> 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<Chrom> ea(checkpoint, rr, breeder, replace );
eoEasyEA<Chrom> 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;
}

77
eo/test/t-eoVirus.cpp Normal file
View file

@ -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 <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eo> // general EO
#include <MGE/eoVirus.h> // bitstring representation & operators
#include <MGE/VirusOp.h>
#include <utils/eoRndGenerators.h>
#include "binary_value.h"
//-----------------------------------------------------------------------------
typedef eoVirus<float> 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<float> vf;
unsigned i;
for ( i = 0; i < 10; i++ ) {
vf( chrom );
cout << chrom << endl;
}
// Chrom Mutation
cout << "Chrom mutation--------" << endl;
VirusMutation<float> vm;
for ( i = 0; i < 10; i++ ) {
vm( chrom );
cout << chrom << endl;
}
// Chrom Transmision
cout << "Chrom transmission--------" << endl;
VirusTransmission<float> vt;
vt( chrom2, chrom );
cout << chrom2 << endl;
return 0;
}