Added new RNG and test files for it

This commit is contained in:
jmerelo 1999-10-25 08:25:42 +00:00
commit 46b6a9e17a
11 changed files with 561 additions and 35 deletions

View file

@ -1,6 +1,6 @@
AC_INIT(src/eo)
AM_INIT_AUTOMAKE(eo, 0.0.3)
AM_INIT_AUTOMAKE(eo, 0.0.4)
AC_PROG_CXX

View file

@ -8,5 +8,5 @@ lib_LIBRARIES = libeo.a
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp
libeoincdir = $(includedir)/eo
libeoinc_HEADERS = eo EO.h eoDup.h eoMultiMonOp.h eoPop.h eoUniform.h eoESChrom.h eoNegExp.h eoProblem.h eoVector.h eoFitness.h eoNormal.h eoRnd.h eoXOver2.h eo1d.h eoID.h eoObject.h eoString.h eoAged.h eoKill.h eoOp.h eoTranspose.h eoBin.h eoPrintable.h eoPersistent.h eoLottery.h eoMutation.h eoPopOps.h eoUniform.h eoInsertion.h eoInclusion.h eoBitOp.h eoBitOpFactory.h eo2d.h eo2dVector.h eoData.h eoProportionalOpSel.h eoOpSelector.h eoBreeder.h eoEvalFunc.h eoEvalFuncPtr.h eoEvaluator.h eoTerm.h eoGenTerm.h eoFitTerm.h eoGeneration.h eoAlgo.h eoEasyEA.h eoNonUniform.h
libeoinc_HEADERS = eo EO.h eoDup.h eoMultiMonOp.h eoPop.h eoUniform.h eoESChrom.h eoNegExp.h eoProblem.h eoVector.h eoFitness.h eoNormal.h eoRnd.h eoXOver2.h eo1d.h eoID.h eoObject.h eoString.h eoAged.h eoKill.h eoOp.h eoTranspose.h eoBin.h eoPrintable.h eoPersistent.h eoLottery.h eoMutation.h eoPopOps.h eoUniform.h eoInsertion.h eoInclusion.h eoBitOp.h eoBitOpFactory.h eo2d.h eo2dVector.h eoData.h eoProportionalOpSel.h eoOpSelector.h eoBreeder.h eoEvalFunc.h eoEvalFuncPtr.h eoEvaluator.h eoTerm.h eoGenTerm.h eoFitTerm.h eoGeneration.h eoAlgo.h eoEasyEA.h eoNonUniform.h eoRNG.h

View file

@ -61,9 +61,9 @@ template<class Chrom> class eoBinBitFlip: public eoMonOp<Chrom>
*/
void operator()(Chrom& chrom) const
{
eoUniform<unsigned> uniform(0, chrom.size());
unsigned bit = uniform();
chrom[bit] = !chrom[bit];
eoUniform<int> uniform(0, chrom.size());
unsigned i = uniform();
chrom[i] = (chrom[i]) ? false : true;
}
};

View file

@ -27,12 +27,10 @@
//-----------------------------------------------------------------------------
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <eoRnd.h> // for base class
#include <eoRNG.h> // for base class
//-----------------------------------------------------------------------------
// Class eoNegExp
@ -56,7 +54,8 @@ class eoNegExp: public eoRnd<T>
eoNegExp( const eoNegExp& _rnd): eoRnd<T>( _rnd), mean(_rnd.mean) {};
/// Returns an uniform dandom number over the interval [min, max).
virtual T operator()() { return - mean*log((double)rand() / RAND_MAX); }
virtual T operator()() {
return T( -mean*log((double)rng.rand() / rng.rand_max())); }
private:
T mean;

View file

@ -27,9 +27,9 @@
//-----------------------------------------------------------------------------
#include <stdlib.h>
#include <math.h>
#include <eoRnd.h> // for base class
#include <eoRNG.h> // for random number generator
//-----------------------------------------------------------------------------
// Class eoNormal
@ -66,12 +66,12 @@ class eoNormal: public eoRnd<T>
double p, v;
do {
p = ((double)rand() / RAND_MAX)*2-1;
q = ((double)rand() / RAND_MAX)*2-1;
p = ((double)rng.rand() / rng.rand_max())*2-1;
q = ((double)rng.rand() / rng.rand_max())*2-1;
v = p*p + q*q;
} while(v > 1.0 || v <0.25);
sqRatio = sqrt(-2*log((double)rand() / RAND_MAX) / v);
sqRatio = sqrt(-2*log((double)rand() / rng.rand_max()) / v);
phase = true;
return T( (sqRatio * p * sd) + mean );
};

430
eo/src/eoRNG.h Normal file
View file

@ -0,0 +1,430 @@
/*
* Random number generator adapted from (see comments below)
*
* The random number generator is modified into a class
* by Maarten Keijzer (mak@dhi.dk). Also added the Box-Muller
* transformation to generate normal deviates.
*
*/
/* ************ DOCUMENTATION IN ORIGINAL FILE *********************/
// This is the ``Mersenne Twister'' random number generator MT19937, which
// generates pseudorandom integers uniformly distributed in 0..(2^32 - 1)
// starting from any odd seed in 0..(2^32 - 1). This version is a recode
// by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by
// Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in
// July-August 1997).
//
// Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha
// running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to
// generate 300 million random numbers; after recoding: 24.0 sec. for the same
// (i.e., 46.5% of original time), so speed is now about 12.5 million random
// number generations per second on this machine.
//
// According to the URL <http://www.math.keio.ac.jp/~matumoto/emt.html>
// (and paraphrasing a bit in places), the Mersenne Twister is ``designed
// with consideration of the flaws of various existing generators,'' has
// a period of 2^19937 - 1, gives a sequence that is 623-dimensionally
// equidistributed, and ``has passed many stringent tests, including the
// die-hard test of G. Marsaglia and the load test of P. Hellekalek and
// S. Wegenkittl.'' It is efficient in memory usage (typically using 2506
// to 5012 bytes of static data, depending on data type sizes, and the code
// is quite short as well). It generates random numbers in batches of 624
// at a time, so the caching and pipelining of modern systems is exploited.
// It is also divide- and mod-free.
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Library General Public License as published by
// the Free Software Foundation (either version 2 of the License or, at your
// option, any later version). This library 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 Library General Public License for more details. You should have
// received a copy of the GNU Library General Public License along with this
// library; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place, Suite 330, Boston, MA 02111-1307, USA.
//
// The code as Shawn received it included the following notice:
//
// Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When
// you use this, send an e-mail to <matumoto@math.keio.ac.jp> with
// an appropriate reference to your work.
//
// It would be nice to CC: <Cokus@math.washington.edu> when you write.
//
//
// uint32 must be an unsigned integer type capable of holding at least 32
// bits; exactly 32 should be fastest, but 64 is better on an Alpha with
// GCC at -O3 optimization so try your options and see what's best for you
//
/* ************ END DOCUMENTATION IN ORIGINAL FILE *********************/
#ifndef EO_RANDOM_NUMBER_GENERATOR
#define EO_RANDOM_NUMBER_GENERATOR
#include <eoPersistent.h>
// TODO: check for various compilers if this is exactly 32 bits
// Unfortunately MSVC's preprocessor does not comprehends sizeof()
// so neat preprocessing tricks will not work
typedef unsigned long uint32; // Compiler and platform dependent!
//-----------------------------------------------------------------------------
// eoRng
//-----------------------------------------------------------------------------
/**
eoRng is a persitent class that uses the ``Mersenne Twister'' random number generator MT19937
for generating random numbers. The various member functions implement useful functions
for evolutionary algorithms. Included are: rand(), random(), flip() and normal().
Note for people porting EO to other platforms: please make sure that the typedef
uint32 in the file eoRng.h is exactly 32 bits long. It may be longer, but not
shorter. If it is longer, file compatibility between EO on different platforms
may be broken.
*/
class eoRng : public eoObject, public eoPersistent
{
public :
/**
ctor takes a seed not unintentionally defaulted at 42.
*/
eoRng(uint32 s = 42U) : state(0), next(0), left(-1), cached(false)
{
state = new uint32[N+1];
initialize(s);
}
~eoRng(void)
{
delete [] state;
}
/**
Re-initializes the Random Number Generator.
*/
void reseed(uint32 s)
{
initialize(s);
}
/**
uniform(m = 1.0) returns a random double in the range [0, m)
*/
double uniform(double m = 1.0)
{ // random number between [0, m]
return m * double(rand()) / double(rand_max());
}
/**
random() returns a random integer in the range [0, m)
*/
uint32 random(uint32 m)
{
return uint32(uniform() * double(m));
}
/**
flip() tosses a biased coin such that flip(x/100.0) will
returns true x% of the time
*/
bool flip(float bias)
{
return uniform() < bias;
}
/**
normal() zero mean gaussian deviate with standard deviation of 1
*/
double normal(void); // gaussian mutation, stdev 1
/**
normal(stdev) zero mean gaussian deviate with user defined standard deviation
*/
double normal(double stdev)
{
return stdev * normal();
}
/**
normal(mean, stdev) user defined mean gaussian deviate with user defined standard deviation
*/
double normal(double mean, double stdev)
{
return mean + normal(stdev);
}
/**
rand() returns a random number in the range [0, rand_max)
*/
uint32 rand();
/**
rand_max() the maximum returned by rand()
*/
uint32 rand_max(void) const { return (uint32) 0xffffffff; }
/**
roulette_wheel(vec, total = 0) does a roulette wheel selection
on the input vector vec. If the total is not supplied, it is
calculated. It returns an integer denoting the selected argument.
*/
template <class T>
int roulette_wheel(const std::vector<T>& vec, T total = 0)
{
if (total == 0)
{ // count
for (int i = 0; i < vec.size(); ++i)
total += vec[i];
}
float change = uniform() * total;
int i = 0;
while (change > 0)
{
change -= vec[i++];
}
return --i;
}
///
void printOn(ostream& _os) const
{
for (int i = 0; i < N; ++i)
{
_os << state[i] << ' ';
}
_os << int(next - state) << ' ';
_os << left << ' ' << cached << ' ' << cacheValue;
}
///
void readFrom(istream& _is)
{
for (int i = 0; i < N; ++i)
{
_is >> state[i];
}
int n;
_is >> n;
next = state + n;
_is >> left;
_is >> cached;
_is >> cacheValue;
}
private :
uint32 restart(void);
void initialize(uint32 seed);
uint32* state; // the array for the state
uint32* next;
int left;
bool cached;
float cacheValue;
static const int N;
static const int M;
static const uint32 K; // a magic constant
};
// Initialization of statics
const int eoRng::N = 624;
const int eoRng::M = 397;
const uint32 eoRng::K = (0x9908B0DFU); // a magic constant
/**
The one and only global eoRng object
*/
static eoRng rng;
/**
The class uniform_generator can be used in the STL generate function
to easily generate random floats and doubles between [0, _max). _max
defaults to 1.0
*/
template <class T = double> class uniform_generator
{
public :
uniform_generator(T _max = T(1.0), eoRng& _rng = rng) : maxim(_max), uniform(_rng) {}
virtual T operator()(void) { return (T) uniform.uniform(maxim); }
private :
T maxim;
eoRng& uniform;
};
/**
The class random_generator can be used in the STL generate function
to easily generate random ints between [0, _max).
*/
template <class T = uint32> class random_generator
{
public :
random_generator(int _max, eoRng& _rng = rng) : maxim(_max), random(_rng) {}
virtual T operator()(void) { return (T) random.random(max); }
private :
T maxim;
eoRng& random;
};
/**
The class normal_generator can be used in the STL generate function
to easily generate gaussian distributed floats and doubles. The user
can supply a standard deviation which defaults to 1.
*/
template <class T = double> class normal_generator
{
public :
normal_generator(T _stdev = T(1.0), eoRng& _rng = rng) : stdev(_stdev), normal(_rng) {}
virtual T operator()(void) { return (T) normal.normal(stdev); }
private :
T stdev;
eoRng& normal;
};
// Implementation of some eoRng members.... Don't mind the mess, it does work.
#define hiBit(u) ((u) & 0x80000000U) // mask all but highest bit of u
#define loBit(u) ((u) & 0x00000001U) // mask all but lowest bit of u
#define loBits(u) ((u) & 0x7FFFFFFFU) // mask the highest bit of u
#define mixBits(u, v) (hiBit(u)|loBits(v)) // move hi bit of u to hi bit of v
inline void eoRng::initialize(uint32 seed)
{
//
// We initialize state[0..(N-1)] via the generator
//
// x_new = (69069 * x_old) mod 2^32
//
// from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth's
// _The Art of Computer Programming_, Volume 2, 3rd ed.
//
// Notes (SJC): I do not know what the initial state requirements
// of the Mersenne Twister are, but it seems this seeding generator
// could be better. It achieves the maximum period for its modulus
// (2^30) iff x_initial is odd (p. 20-21, Sec. 3.2.1.2, Knuth); if
// x_initial can be even, you have sequences like 0, 0, 0, ...;
// 2^31, 2^31, 2^31, ...; 2^30, 2^30, 2^30, ...; 2^29, 2^29 + 2^31,
// 2^29, 2^29 + 2^31, ..., etc. so I force seed to be odd below.
//
// Even if x_initial is odd, if x_initial is 1 mod 4 then
//
// the lowest bit of x is always 1,
// the next-to-lowest bit of x is always 0,
// the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... ,
// the 3rd-from-lowest bit of x 4-cycles ... 0 1 1 0 0 1 1 0 ... ,
// the 4th-from-lowest bit of x has the 8-cycle ... 0 0 0 1 1 1 1 0 ... ,
// ...
//
// and if x_initial is 3 mod 4 then
//
// the lowest bit of x is always 1,
// the next-to-lowest bit of x is always 1,
// the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... ,
// the 3rd-from-lowest bit of x 4-cycles ... 0 0 1 1 0 0 1 1 ... ,
// the 4th-from-lowest bit of x has the 8-cycle ... 0 0 1 1 1 1 0 0 ... ,
// ...
//
// The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is
// 16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth. It
// also does well in the dimension 2..5 spectral tests, but it could be
// better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth).
//
// Note that the random number user does not see the values generated
// here directly since restart() will always munge them first, so maybe
// none of all of this matters. In fact, the seed values made here could
// even be extra-special desirable if the Mersenne Twister theory says
// so-- that's why the only change I made is to restrict to odd seeds.
//
left = -1;
register uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
register int j;
for(left=0, *s++=x, j=N; --j;
*s++ = (x*=69069U) & 0xFFFFFFFFU);
}
inline uint32 eoRng::restart(void)
{
register uint32 *p0=state, *p2=state+2, *pM=state+M, s0, s1;
register int j;
left=N-1, next=state+1;
for(s0=state[0], s1=state[1], j=N-M+1; --j; s0=s1, s1=*p2++)
*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
for(pM=state, j=M; --j; s0=s1, s1=*p2++)
*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
s1=state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
s1 ^= (s1 >> 11);
s1 ^= (s1 << 7) & 0x9D2C5680U;
s1 ^= (s1 << 15) & 0xEFC60000U;
return(s1 ^ (s1 >> 18));
}
inline uint32 eoRng::rand(void)
{
uint32 y;
if(--left < 0)
return(restart());
y = *next++;
y ^= (y >> 11);
y ^= (y << 7) & 0x9D2C5680U;
y ^= (y << 15) & 0xEFC60000U;
return(y ^ (y >> 18));
}
inline double eoRng::normal(void)
{
if (cached)
{
cached = false;
return cacheValue;
}
float rSquare, factor, var1, var2;
do
{
var1 = 2.0 * uniform() - 1.0;
var2 = 2.0 * uniform() - 1.0;
rSquare = var1 * var1 + var2 * var2;
}
while (rSquare >= 1.0 || rSquare == 0.0);
factor = sqrt(-2.0 * log(rSquare) / rSquare);
cacheValue = var1 * factor;
cached = true;
return (var2 * factor);
}
#endif

View file

@ -28,10 +28,9 @@
//-----------------------------------------------------------------------------
#include <time.h>
#include <stdlib.h>
#include <eoRnd.h>
#include <eoRNG.h>
//-----------------------------------------------------------------------------
// Class eoUniform
//-----------------------------------------------------------------------------
@ -47,22 +46,23 @@ class eoUniform: public eoRnd<T>
* @param _max The maximum value in the interval.
*/
eoUniform(T _min = 0, T _max = 1)
: eoRnd<T>(), minim(_min), diff(_max - _min) {}
/**
* copy constructor.
* @param _rnd the other rnd
*/
eoUniform( const eoUniform& _rnd)
: eoRnd<T>( _rnd), minim(_rnd.minim), diff(_rnd.diff) {}
: eoRnd<T>(), min(_min), diff(_max - _min) {}
/**
* copy constructor.
* @param _rnd the other rnd
*/
eoUniform( const eoUniform& _rnd)
: eoRnd<T>( _rnd), min(_rnd.minim), diff(_rnd.diff) {}
/// Returns an uniform dandom number over the interval [min, max).
virtual T operator()() {
return minim+ T( (diff * rand() )/ RAND_MAX);
/** Returns an uniform random number over the interval [min, max)
Uses global rng object */
virtual T operator()() {
return min + T( rng.uniform( diff ) );
}
private:
T minim;
T min;
double diff;
};

View file

@ -13,7 +13,8 @@ LDADDS = $(top_builddir)/src/libeo.a
###############################################################################
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom
###############################################################################
t_eoNonUniform_SOURCES = t-eoNonUniform.cpp
@ -23,6 +24,20 @@ t_eoNonUniform_LDADD = $(LDADDS)
###############################################################################
t_eoUniform_SOURCES = t-eoUniform.cpp
t_eoUniform_DEPENDENCIES = $(DEPS)
t_eoUniform_LDFLAGS = -lm
t_eoUniform_LDADD = $(LDADDS)
###############################################################################
t_eoRandom_SOURCES = t-eoRandom.cpp
t_eoRandom_DEPENDENCIES = $(DEPS)
t_eoRandom_LDFLAGS = -lm
t_eoRandom_LDADD = $(LDADDS)
###############################################################################
t_eogeneration_SOURCES = t-eogeneration.cpp
t_eogeneration_DEPENDENCIES = $(DEPS)
t_eogeneration_LDFLAGS = -lm

View file

@ -62,11 +62,17 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
host_alias = @host_alias@
host_triplet = @host@
AS = @AS@
CC = @CC@
CXX = @CXX@
DLLTOOL = @DLLTOOL@
LD = @LD@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
NM = @NM@
OBJDUMP = @OBJDUMP@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
VERSION = @VERSION@
@ -80,7 +86,8 @@ LDADDS = $(top_builddir)/src/libeo.a
###############################################################################
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform
noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom
###############################################################################
t_eoNonUniform_SOURCES = t-eoNonUniform.cpp
@ -90,6 +97,20 @@ t_eoNonUniform_LDADD = $(LDADDS)
###############################################################################
t_eoUniform_SOURCES = t-eoUniform.cpp
t_eoUniform_DEPENDENCIES = $(DEPS)
t_eoUniform_LDFLAGS = -lm
t_eoUniform_LDADD = $(LDADDS)
###############################################################################
t_eoRandom_SOURCES = t-eoRandom.cpp
t_eoRandom_DEPENDENCIES = $(DEPS)
t_eoRandom_LDFLAGS = -lm
t_eoRandom_LDADD = $(LDADDS)
###############################################################################
t_eogeneration_SOURCES = t-eogeneration.cpp
t_eogeneration_DEPENDENCIES = $(DEPS)
t_eogeneration_LDFLAGS = -lm
@ -185,6 +206,8 @@ t_eo2dVector_OBJECTS = t-eo2dVector.o
t_eogeneration_OBJECTS = t-eogeneration.o
t_eoEasyEA_OBJECTS = t-eoEasyEA.o
t_eoNonUniform_OBJECTS = t-eoNonUniform.o
t_eoUniform_OBJECTS = t-eoUniform.o
t_eoRandom_OBJECTS = t-eoRandom.o
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
@ -203,11 +226,12 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/t-eo.P .deps/t-eo2dVector.P .deps/t-eoEasyEA.P \
.deps/t-eoNonUniform.P .deps/t-eobin.P .deps/t-eobreeder.P \
.deps/t-eofitness.P .deps/t-eogeneration.P .deps/t-eoinclusion.P \
.deps/t-eoinsertion.P .deps/t-eolottery.P .deps/t-eoproblem.P
SOURCES = $(t_eobreeder_SOURCES) $(t_eoinclusion_SOURCES) $(t_eoinsertion_SOURCES) $(t_eo_SOURCES) $(t_eofitness_SOURCES) $(t_eoproblem_SOURCES) $(t_eobin_SOURCES) $(t_eolottery_SOURCES) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES)
OBJECTS = $(t_eobreeder_OBJECTS) $(t_eoinclusion_OBJECTS) $(t_eoinsertion_OBJECTS) $(t_eo_OBJECTS) $(t_eofitness_OBJECTS) $(t_eoproblem_OBJECTS) $(t_eobin_OBJECTS) $(t_eolottery_OBJECTS) $(t_eo2dVector_OBJECTS) $(t_eogeneration_OBJECTS) $(t_eoEasyEA_OBJECTS) $(t_eoNonUniform_OBJECTS)
.deps/t-eoNonUniform.P .deps/t-eoRandom.P .deps/t-eoUniform.P \
.deps/t-eobin.P .deps/t-eobreeder.P .deps/t-eofitness.P \
.deps/t-eogeneration.P .deps/t-eoinclusion.P .deps/t-eoinsertion.P \
.deps/t-eolottery.P .deps/t-eoproblem.P
SOURCES = $(t_eobreeder_SOURCES) $(t_eoinclusion_SOURCES) $(t_eoinsertion_SOURCES) $(t_eo_SOURCES) $(t_eofitness_SOURCES) $(t_eoproblem_SOURCES) $(t_eobin_SOURCES) $(t_eolottery_SOURCES) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES) $(t_eoUniform_SOURCES) $(t_eoRandom_SOURCES)
OBJECTS = $(t_eobreeder_OBJECTS) $(t_eoinclusion_OBJECTS) $(t_eoinsertion_OBJECTS) $(t_eo_OBJECTS) $(t_eofitness_OBJECTS) $(t_eoproblem_OBJECTS) $(t_eobin_OBJECTS) $(t_eolottery_OBJECTS) $(t_eo2dVector_OBJECTS) $(t_eogeneration_OBJECTS) $(t_eoEasyEA_OBJECTS) $(t_eoNonUniform_OBJECTS) $(t_eoUniform_OBJECTS) $(t_eoRandom_OBJECTS)
all: all-redirect
.SUFFIXES:
@ -308,6 +332,14 @@ t-eoEasyEA: $(t_eoEasyEA_OBJECTS) $(t_eoEasyEA_DEPENDENCIES)
t-eoNonUniform: $(t_eoNonUniform_OBJECTS) $(t_eoNonUniform_DEPENDENCIES)
@rm -f t-eoNonUniform
$(CXXLINK) $(t_eoNonUniform_LDFLAGS) $(t_eoNonUniform_OBJECTS) $(t_eoNonUniform_LDADD) $(LIBS)
t-eoUniform: $(t_eoUniform_OBJECTS) $(t_eoUniform_DEPENDENCIES)
@rm -f t-eoUniform
$(CXXLINK) $(t_eoUniform_LDFLAGS) $(t_eoUniform_OBJECTS) $(t_eoUniform_LDADD) $(LIBS)
t-eoRandom: $(t_eoRandom_OBJECTS) $(t_eoRandom_DEPENDENCIES)
@rm -f t-eoRandom
$(CXXLINK) $(t_eoRandom_LDFLAGS) $(t_eoRandom_OBJECTS) $(t_eoRandom_LDADD) $(LIBS)
.cc.o:
$(CXXCOMPILE) -c $<
.cc.lo:

28
eo/test/t-eoRandom.cpp Normal file
View file

@ -0,0 +1,28 @@
//-----------------------------------------------------------------------------
// t-eouniform
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin
#include <eoNormal.h>
#include <eoNegExp.h>
//-----------------------------------------------------------------------------
main() {
eoNormal<float> n1(-2.5,3.5);
eoNormal<double> n2(0.003, 0.0005 );
eoNormal<unsigned long> n3( 10000000U, 10000U);
eoNegExp<float> e1(3.5);
eoNegExp<double> e2(0.003 );
eoNegExp<long> e3( 10000U);
cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl;
for ( unsigned i = 0; i < 100; i ++) {
cout << n1() << "\t" << n2() << "\t" << n3() << "\t" <<
e1() << "\t" << e2() << "\t" << e3() << endl;
}
}
//-----------------------------------------------------------------------------

22
eo/test/t-eoUniform.cpp Normal file
View file

@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// t-eouniform
//-----------------------------------------------------------------------------
#include <iostream> // cout
#include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin
//-----------------------------------------------------------------------------
main() {
eoUniform<float> u1(-2.5,3.5);
eoUniform<double> u2(0.003, 0 );
eoUniform<unsigned long> u3( 10000U, 10000000U);
cout << "u1\t\tu2\t\tu3" << endl;
for ( unsigned i = 0; i < 100; i ++) {
cout << u1() << "\t" << u2() << "\t" << u3() << endl;
}
}
//-----------------------------------------------------------------------------