Added missing files and updated old MGE files
This commit is contained in:
parent
34cb430bd7
commit
e32c52d332
4 changed files with 106 additions and 25 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
Marc.Schoenauer@polytechnique.fr
|
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
|
#ifndef RoyalRoad_h
|
||||||
|
|
@ -37,7 +37,7 @@ class RoyalRoad: public eoEvalFunc<EOT> {
|
||||||
|
|
||||||
// Applies the function
|
// Applies the function
|
||||||
virtual void operator() ( EOT & _eo ) {
|
virtual void operator() ( EOT & _eo ) {
|
||||||
FitT fitness;
|
FitT fitness = 0;
|
||||||
if (_eo.invalid()) {
|
if (_eo.invalid()) {
|
||||||
for ( unsigned i = 0; i < _eo.size()/div; i ++ ) {
|
for ( unsigned i = 0; i < _eo.size()/div; i ++ ) {
|
||||||
bool block = true;
|
bool block = true;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <eo>
|
#include <eo>
|
||||||
#include <ga/eoBitOp.h>
|
#include <ga/eoBitOp.h>
|
||||||
|
|
||||||
#include "binary_value.h"
|
#include "RoyalRoad.h"
|
||||||
|
|
||||||
// Viri
|
// Viri
|
||||||
#include <MGE/VirusOp.h>
|
#include <MGE/VirusOp.h>
|
||||||
|
|
@ -25,7 +25,7 @@ typedef eoVirus<float> Chrom;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const unsigned POP_SIZE = 100, CHROM_SIZE = 16;
|
const unsigned POP_SIZE = 1000, CHROM_SIZE = 128;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
eoBooleanGenerator gen;
|
eoBooleanGenerator gen;
|
||||||
|
|
||||||
|
|
@ -33,7 +33,8 @@ int main()
|
||||||
eoPop<Chrom> pop;
|
eoPop<Chrom> pop;
|
||||||
|
|
||||||
// Evaluation
|
// Evaluation
|
||||||
eoEvalFuncPtr<Chrom> eval( binary_value );
|
RoyalRoad<Chrom> rr( 4 );
|
||||||
|
eoEvalFuncCounter<Chrom> eval( rr );
|
||||||
|
|
||||||
eoInitVirus<float> random(CHROM_SIZE, gen);
|
eoInitVirus<float> random(CHROM_SIZE, gen);
|
||||||
for (i = 0; i < POP_SIZE; ++i) {
|
for (i = 0; i < POP_SIZE; ++i) {
|
||||||
|
|
@ -47,30 +48,31 @@ int main()
|
||||||
for (i = 0; i < pop.size(); ++i)
|
for (i = 0; i < pop.size(); ++i)
|
||||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||||
|
|
||||||
|
|
||||||
// selection
|
// selection
|
||||||
eoDetTournamentSelect<Chrom> lottery( 3) ;
|
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||||
|
|
||||||
// breeder
|
// breeder
|
||||||
eoOneBitFlip<Chrom> bf;
|
eoOneBitFlip<Chrom> vm;
|
||||||
eoUBitXover<Chrom> xover;
|
eoUBitXover<Chrom> xover;
|
||||||
eoProportionalOp<Chrom> propSel;
|
eoProportionalOp<Chrom> propSel;
|
||||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||||
propSel.add(bf, 0.75);
|
propSel.add(vm, 0.8);
|
||||||
propSel.add(xover, 0.25);
|
propSel.add(xover, 0.1);
|
||||||
|
|
||||||
// Replace a single one
|
// Replace a single one
|
||||||
eoPlusReplacement<Chrom> replace;
|
eoCommaReplacement<Chrom> replace;
|
||||||
|
|
||||||
// Terminators
|
// Terminators
|
||||||
eoGenContinue<Chrom> continuator1(50);
|
eoGenContinue<Chrom> continuator1(500);
|
||||||
eoFitContinue<Chrom> continuator2(65535.f);
|
eoFitContinue<Chrom> continuator2(128);
|
||||||
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);
|
||||||
eoCheckPoint<Chrom> checkpoint(continuator);
|
eoCheckPoint<Chrom> checkpoint(continuator);
|
||||||
eoStdoutMonitor monitor;
|
eoStdoutMonitor monitor;
|
||||||
checkpoint.add(monitor);
|
checkpoint.add(monitor);
|
||||||
eoSecondMomentStats<Chrom> stats;
|
eoSecondMomentStats<Chrom> stats;
|
||||||
|
eoPopStat<Chrom> dumper( 10 );
|
||||||
monitor.add(stats);
|
monitor.add(stats);
|
||||||
|
checkpoint.add(dumper);
|
||||||
checkpoint.add(stats);
|
checkpoint.add(stats);
|
||||||
|
|
||||||
// GA generation
|
// GA generation
|
||||||
|
|
@ -91,6 +93,7 @@ int main()
|
||||||
for (i = 0; i < pop.size(); ++i)
|
for (i = 0; i < pop.size(); ++i)
|
||||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||||
|
|
||||||
|
cout << "\n --> Number of Evaluations = " << eval.getValue() << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,13 @@ int main()
|
||||||
|
|
||||||
// Evaluation
|
// Evaluation
|
||||||
RoyalRoad<Chrom> rr( 4 );
|
RoyalRoad<Chrom> rr( 4 );
|
||||||
|
eoEvalFuncCounter<Chrom> eval( rr );
|
||||||
|
|
||||||
eoInitVirus<float> random(CHROM_SIZE, gen);
|
eoInitVirus<float> random(CHROM_SIZE, gen);
|
||||||
for (i = 0; i < POP_SIZE; ++i) {
|
for (i = 0; i < POP_SIZE; ++i) {
|
||||||
Chrom chrom;
|
Chrom chrom;
|
||||||
random(chrom);
|
random(chrom);
|
||||||
rr(chrom);
|
eval(chrom);
|
||||||
pop.push_back(chrom);
|
pop.push_back(chrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +48,6 @@ int main()
|
||||||
for (i = 0; i < pop.size(); ++i)
|
for (i = 0; i < pop.size(); ++i)
|
||||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||||
|
|
||||||
|
|
||||||
// selection
|
// selection
|
||||||
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
eoStochTournamentSelect<Chrom> lottery(0.9 );
|
||||||
|
|
||||||
|
|
@ -58,9 +58,9 @@ int main()
|
||||||
eoUBitXover<Chrom> xover;
|
eoUBitXover<Chrom> xover;
|
||||||
eoProportionalOp<Chrom> propSel;
|
eoProportionalOp<Chrom> propSel;
|
||||||
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
eoGeneralBreeder<Chrom> breeder( lottery, propSel );
|
||||||
propSel.add(vm, 0.4);
|
propSel.add(vm, 0.8);
|
||||||
propSel.add(vf, 0.4);
|
propSel.add(vf, 0.05);
|
||||||
propSel.add(vt, 0.1);
|
propSel.add(vt, 0.05);
|
||||||
propSel.add(xover, 0.1);
|
propSel.add(xover, 0.1);
|
||||||
|
|
||||||
// Replace a single one
|
// Replace a single one
|
||||||
|
|
@ -80,7 +80,7 @@ int main()
|
||||||
checkpoint.add(stats);
|
checkpoint.add(stats);
|
||||||
|
|
||||||
// GA generation
|
// GA generation
|
||||||
eoEasyEA<Chrom> ea(checkpoint, rr, breeder, replace );
|
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace );
|
||||||
|
|
||||||
// evolution
|
// evolution
|
||||||
try
|
try
|
||||||
|
|
@ -97,6 +97,7 @@ int main()
|
||||||
for (i = 0; i < pop.size(); ++i)
|
for (i = 0; i < pop.size(); ++i)
|
||||||
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
cout << "\t" << pop[i] << " " << pop[i].fitness() << endl;
|
||||||
|
|
||||||
|
cout << "\n --> Number of Evaluations = " << eval.getValue() << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
77
eo/test/t-eoVirus.cpp
Normal file
77
eo/test/t-eoVirus.cpp
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in a new issue