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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue