Modified eoInit so that it would use the eoRndGenerator base class.
To be able to use the primitive std::generate function, added a set of wrappers in eoSTLFunctor.h that have the copy semantics most STL functions expect (namely pass-by-value rather then pass-by-reference). Updated test/Makefile.am to also test t-eoRandom
This commit is contained in:
parent
e28211188a
commit
a79075f673
11 changed files with 240 additions and 83 deletions
|
|
@ -14,8 +14,8 @@ CXXFLAGS = -g
|
|||
###############################################################################
|
||||
|
||||
check_PROGRAMS = t-eofitness t-eoRandom t-eobin t-eoStateAndParser t-eoCheckpointing \
|
||||
t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA
|
||||
TESTS=run_tests
|
||||
t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoVector
|
||||
TESTS=run_tests t-eoVector t-eoRandom
|
||||
# removing temporarily t-eoESFull
|
||||
#noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA
|
||||
|
||||
|
|
@ -101,6 +101,13 @@ t_eoGenOp_LDADD = $(LDADDS)
|
|||
|
||||
###############################################################################
|
||||
|
||||
t_eoVector_SOURCES = t-eoVector.cpp
|
||||
t_eoVector_DEPENDENCIES = $(DEPS)
|
||||
t_eoVector_LDFLAGS = -lm
|
||||
t_eoVector_LDADD = $(LDADDS)
|
||||
|
||||
###############################################################################
|
||||
|
||||
t_eoGA_SOURCES = t-eoGA.cpp binary_value.h
|
||||
t_eoGA_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a
|
||||
t_eoGA_LDFLAGS = -lm
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
t-eoRandom.cpp
|
||||
Test program for random generator
|
||||
|
||||
(c) GeNeura Team, 1999
|
||||
|
||||
(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
|
||||
|
|
@ -18,19 +18,19 @@
|
|||
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
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
CVS Info: $Date: 2001-02-18 04:34:57 $ $Author: evomarc $ $Revision: 1.9 $
|
||||
CVS Info: $Date: 2001-02-19 12:23:13 $ $Author: maartenkeijzer $ $Revision: 1.10 $
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream> // cout
|
||||
#include <strstream> // ostrstream, istrstream
|
||||
#include <fstream> // ostrstream, istrstream
|
||||
#include <utils/eoRndGenerators.h> // eoBin
|
||||
//#include <eoNormal.h>
|
||||
//#include <eoNegExp.h>
|
||||
|
|
@ -38,27 +38,28 @@ CVS Info: $Date: 2001-02-18 04:34:57 $ $Author: evomarc $ $Revision: 1.9 $
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
main() {
|
||||
try{
|
||||
eoUniformGenerator<float> u1(-2.5,3.5);
|
||||
eoUniformGenerator<double> u2(0.0003, 0.0005 );
|
||||
eoUniformGenerator<unsigned long> u3( 100000U, 10000000U);
|
||||
eoUniformGenerator<double> u2(0.003, 0.05 );
|
||||
eoUniformGenerator<unsigned long> u3( 10000U, 10000000U);
|
||||
|
||||
eoNegExpGenerator<float> e1(3.5);
|
||||
eoNegExpGenerator<double> e2(0.003 );
|
||||
eoNegExpGenerator<long> e3( 10000U);
|
||||
/* cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; */
|
||||
for ( unsigned i = 0; i < 100; i ++) {
|
||||
cout << "Uniform: " << u1() << "\t" << u2() << "\t" << u3() << endl;
|
||||
cout << "NegExp: " << e1() << "\t" << e2() << "\t" << e3() << endl;
|
||||
try
|
||||
{ // throws an error
|
||||
eoUniformGenerator<unsigned long> utest( 10000000U, 10000U);
|
||||
}
|
||||
}
|
||||
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << "exception: " << e.what() << endl;;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
catch (logic_error& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
}
|
||||
|
||||
ofstream os("t-eoRandom.out");
|
||||
|
||||
for ( unsigned i = 0; i < 100; i ++)
|
||||
{
|
||||
os << u1() << "\t" << u2() << "\t" << u3() << endl;
|
||||
}
|
||||
|
||||
return 0; // to avoid VC++ complaints
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
t-eoVectpr.cpp
|
||||
t-eoVector.cpp
|
||||
This program tests vector-like chromosomes
|
||||
(c) GeNeura Team, 1999, 2000
|
||||
|
||||
|
||||
Modified by Maarten Keijzer 2001
|
||||
|
||||
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
|
||||
|
|
@ -17,22 +19,26 @@
|
|||
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 <eoUniform.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <utils/eoRndGenerators.h>
|
||||
#include <eoVector.h> // eoVector
|
||||
#include <eo1dWDistance.h>
|
||||
#include <eoInit.h>
|
||||
#include <eoScalarFitness.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoVector<float> Chrom;
|
||||
typedef eoVector<eoMaximizingFitness, int> Chrom1;
|
||||
typedef eoVector<eoMinimizingFitness, int> Chrom2;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -40,17 +46,27 @@ main()
|
|||
{
|
||||
const unsigned SIZE = 4;
|
||||
|
||||
eoUniform<Chrom::Type> uniform(-1,1);
|
||||
// check if the appropriate ctor gets called
|
||||
Chrom1 chrom(SIZE, 5);
|
||||
|
||||
for (int i = 0; i < chrom.size(); ++i)
|
||||
{
|
||||
assert(chrom[i] == 5);
|
||||
}
|
||||
|
||||
eoUniformGenerator<Chrom1::AtomType> uniform(-1,1);
|
||||
eoInitFixedLength<Chrom1> init(SIZE, uniform);
|
||||
|
||||
init(chrom);
|
||||
|
||||
cout << chrom << endl;
|
||||
|
||||
Chrom2 chrom2(chrom);
|
||||
|
||||
cout << chrom2 << endl;
|
||||
|
||||
// eoInitVariableLength<Chrom1> initvar(
|
||||
|
||||
Chrom chrom1(SIZE,uniform), chrom2( SIZE, uniform);
|
||||
|
||||
cout << "chrom1: " << chrom1 << endl <<
|
||||
"chrom2: " << chrom2 << endl;
|
||||
|
||||
eo1dWDistance< float, float > chromDist( chrom1 );
|
||||
cout << "Distance from chrom1 to chrom2 " << chromDist.distance( chrom2 ) << endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
t-eobin.cpp
|
||||
This program tests the the binary cromosomes and several genetic operators
|
||||
(c) GeNeura Team, 1999
|
||||
|
||||
(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
|
||||
|
|
@ -17,9 +17,9 @@
|
|||
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
|
||||
|
||||
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
#include <strstream> // ostrstream, istrstream
|
||||
#include <eo> // general EO
|
||||
#include <ga.h> // bitstring representation & operators
|
||||
#include <utils/eoRndGenerators.h>
|
||||
#include "binary_value.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -39,10 +40,11 @@ void main_function()
|
|||
{
|
||||
const unsigned SIZE = 8;
|
||||
unsigned i, j;
|
||||
eoBooleanGenerator gen;
|
||||
|
||||
Chrom chrom(SIZE), chrom2;
|
||||
chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
|
||||
|
||||
cout << "chrom: " << chrom << endl;
|
||||
chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));
|
||||
cout << "chrom: " << chrom << endl;
|
||||
|
|
@ -51,7 +53,7 @@ void main_function()
|
|||
chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));
|
||||
|
||||
cout << "chrom.className() = " << chrom.className() << endl;
|
||||
|
||||
|
||||
cout << "chrom: " << chrom << endl
|
||||
<< "chrom2: " << chrom2 << endl;
|
||||
|
||||
|
|
@ -67,10 +69,10 @@ void main_function()
|
|||
fill(chrom.begin(), chrom.end(), false);
|
||||
cout << "--------------------------------------------------"
|
||||
<< endl << "eoMonOp's aplied to .......... " << chrom << endl;
|
||||
|
||||
eoInitFixedLength<Chrom, boolean_generator>
|
||||
random(chrom.size(), boolean_generator());
|
||||
|
||||
|
||||
eoInitFixedLength<Chrom>
|
||||
random(chrom.size(), gen);
|
||||
|
||||
random(chrom); chrom.fitness(binary_value(chrom));
|
||||
cout << "after eoBinRandom ............ " << chrom << endl;
|
||||
|
||||
|
|
@ -149,10 +151,10 @@ void main_function()
|
|||
|
||||
eoProportionalSelect<Chrom> select;
|
||||
eoEvalFuncPtr<Chrom> eval(binary_value);
|
||||
|
||||
|
||||
eoSGA<Chrom> sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);
|
||||
|
||||
eoInitFixedLength<Chrom, boolean_generator> init(16, boolean_generator());
|
||||
|
||||
eoInitFixedLength<Chrom> init(16, gen);
|
||||
eoPop<Chrom> pop(100, init);
|
||||
|
||||
apply<Chrom>(eval, pop);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue