Moved out of the 'obsolete' directory a couple of honest classes, which didn't harm anybody; activated also in Makefile.am the program that tested them

This commit is contained in:
jmerelo 2001-02-13 22:35:07 +00:00
commit 0dd3e27e4e
6 changed files with 388 additions and 366 deletions

View file

@ -36,7 +36,7 @@ eoParameterLoader::~eoParameterLoader()
} }
eoParser::eoParser ( int _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) : eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) :
programName( _argv[0]), programName( _argv[0]),
programDescription( _programDescription), programDescription( _programDescription),
needHelp(false, "help", "Prints this message", 'h') needHelp(false, "help", "Prints this message", 'h')

View file

@ -23,7 +23,9 @@
mkeijzer@dhi.dk mkeijzer@dhi.dk
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/eoParser.h,v 1.7 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
#ifndef eoParser_h #ifndef eoParser_h
#define eoParser_h #define eoParser_h
@ -111,7 +113,7 @@ public:
* @param _lFileParamName Name of the parameter specifying the configuration file (--param-file) * @param _lFileParamName Name of the parameter specifying the configuration file (--param-file)
* @param _shortHand Single charachter shorthand for specifying the configuration file * @param _shortHand Single charachter shorthand for specifying the configuration file
*/ */
eoParser ( int _argc, char **_argv , string _programDescription = "", eoParser ( unsigned _argc, char **_argv , string _programDescription = "",
string _lFileParamName = "param-file", char _shortHand = 'p'); string _lFileParamName = "param-file", char _shortHand = 'p');
/** /**

63
eo/src/utils/eoRnd.h Normal file
View file

@ -0,0 +1,63 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
-----------------------------------------------------------------------------
eoRnd.h
(c) GeNeura Team, 1998
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
*/
//-----------------------------------------------------------------------------
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/Attic/eoRnd.h,v 1.1 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
#ifndef _EORND_H
#define _EORND_H
//-----------------------------------------------------------------------------
#include <eoObject.h>
//-----------------------------------------------------------------------------
// Class eoRnd
//-----------------------------------------------------------------------------
#include <stdlib.h> // srand
#include <time.h> // time
#include <stdexcept> // runtime_error
//-----------------------------------------------------------------------------
#include <eoPersistent.h>
//-----------------------------------------------------------------------------
/**
* Base class for a family of random 'number' generators. These 'numbers'
* can be anything, including full-fledged chromosomes.
*/
template<class T>
class eoRnd
{
public:
/** Main function: random generators act as functors, that return random numbers.
@return return a random number
*/
virtual T operator()() = 0;
};
#endif

104
eo/src/utils/eoUniform.h Normal file
View file

@ -0,0 +1,104 @@
/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
-----------------------------------------------------------------------------
eoUniform.h
Uniform random number generator;
(c) GeNeura Team, 1998
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
*/
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/utils/Attic/eoUniform.h,v 1.1 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
//-----------------------------------------------------------------------------
#ifndef _EOUNIFORM_H
#define _EOUNIFORM_H
//-----------------------------------------------------------------------------
#include <utils/eoRnd.h>
#include <utils/eoRNG.h>
//-----------------------------------------------------------------------------
// Class eoUniform
//-----------------------------------------------------------------------------
/** Generates uniform random number over the interval [min, max)
Uses the global variable rng
*/
using eo::rng;
template<class T>
class eoUniform: public eoRnd<T>
{
public:
/**
* Default constructor.
* @param _min The minimum value in the interval.
* @param _max The maximum value in the interval.
*/
eoUniform(T _min = 0, T _max = 1)
: eoRnd<T>(), min(_min), diff(_max - _min) {}
/**
* copy constructor.
* @param _rnd the other rnd
*/
eoUniform( const eoUniform& _rnd)
: eoRnd<T>( _rnd), min(_rnd.min), diff(_rnd.diff) {}
/** 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 min;
double diff;
};
template<>
class eoUniform<bool>: public eoRnd<bool>
{
public:
/**
* Default constructor.
* @param _min The minimum value in the interval.
* @param _max The maximum value in the interval.
*/
eoUniform(bool _min = false, bool _max = true)
: eoRnd<bool>() {}
/** Returns an uniform random number over the interval [min, max)
Uses global rng object */
virtual bool operator()() {
return rng.flip(0.5);
}
private:
bool min;
double diff;
};
//-----------------------------------------------------------------------------
#endif

View file

@ -13,7 +13,8 @@ LDADDS = $(top_builddir)/src/libeo.a $(top_builddir)/src/utils/libeoutils.a
CXXFLAGS = -g CXXFLAGS = -g
############################################################################### ###############################################################################
check_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA 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 TESTS=run_tests
# removing temporarily t-eoESFull # 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 #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
@ -24,6 +25,11 @@ TESTS=run_tests
#t_eoESFull_DEPENDENCIES = $(DEPS) #t_eoESFull_DEPENDENCIES = $(DEPS)
#t_eoESFull_LDFLAGS = -lm #t_eoESFull_LDFLAGS = -lm
#t_eoESFull_LDADD = $(LDADDS) #t_eoESFull_LDADD = $(LDADDS)
###############################################################################
t_eoRandom_SOURCES = t-eoRandom.cpp
t_eoRandom_DEPENDENCIES = $(DEPS)
t_eoRandom_LDADD = $(LDADDS)
############################################################################### ###############################################################################

View file

@ -23,27 +23,29 @@
*/ */
/**
CVS Info: $Date: 2001-02-13 22:35:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/test/t-eoRandom.cpp,v 1.5 2001-02-13 22:35:07 jmerelo Exp $ $Author: jmerelo $ $Log$
*/
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <iostream> // cout #include <iostream> // cout
#include <strstream> // ostrstream, istrstream #include <strstream> // ostrstream, istrstream
#include <eoUniform.h> // eoBin #include <utils/eoUniform.h> // eoBin
#include <eoNormal.h> //#include <eoNormal.h>
#include <eoNegExp.h> //#include <eoNegExp.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
main() { main() {
eoNormal<float> n1(-2.5,3.5); eoUniform<float> u1(-2.5,3.5);
eoNormal<double> n2(0.003, 0.0005 ); eoUniform<double> u2(0.003, 0.0005 );
eoNormal<unsigned long> n3( 10000000U, 10000U); eoUniform<unsigned long> u3( 10000000U, 10000U);
eoNegExp<float> e1(3.5); /* eoNegExp<float> e1(3.5);
eoNegExp<double> e2(0.003 ); eoNegExp<double> e2(0.003 );
eoNegExp<long> e3( 10000U); eoNegExp<long> e3( 10000U);
cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; */
for ( unsigned i = 0; i < 100; i ++) { for ( unsigned i = 0; i < 100; i ++) {
cout << n1() << "\t" << n2() << "\t" << n3() << "\t" << cout << u1() << "\t" << u2() << "\t" << u3() << endl;
e1() << "\t" << e2() << "\t" << e3() << endl;
} }
return 0; // to avoid VC++ complaints return 0; // to avoid VC++ complaints