Simplify configuration.

Remove support for (outdated) <strstream>, require <sstream>.
Require uint32_t for now, defined in stdint.h according to C99.
Some general cleanup and more documentation.
This commit is contained in:
kuepper 2005-09-28 21:49:26 +00:00
commit cf2a57dd88
46 changed files with 482 additions and 886 deletions

View file

@ -245,6 +245,9 @@ namespace mlp {
load(is); load(is);
} }
/** Virtual destructor */
virtual ~net() {};
void load(istream &is) { void load(istream &is) {
unsigned num_inputs; unsigned num_inputs;
unsigned num_outputs; unsigned num_outputs;
@ -253,7 +256,7 @@ namespace mlp {
is >> num_inputs >> num_outputs >> num_hidden_layers; is >> num_inputs >> num_outputs >> num_hidden_layers;
std::vector<unsigned> layer_sizes; std::vector<unsigned> layer_sizes;
for (int i=0; i<num_hidden_layers;i++) { for (unsigned i=0; i<num_hidden_layers;i++) {
unsigned layer_size; unsigned layer_size;
is >> layer_size; is >> layer_size;
layer_sizes.push_back(layer_size); layer_sizes.push_back(layer_size);

View file

@ -28,28 +28,27 @@ AC_PROG_MAKE_SET
AC_PROG_RANLIB AC_PROG_RANLIB
AC_CHECK_PROG(DOXYGEN, doxygen, doxygen, true) AC_CHECK_PROG(DOXYGEN, doxygen, doxygen, true)
dnl Checks for header files. dnl Checks for compiler characteristics.
AC_HEADER_STDC
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_HEADERS(limits.h)
AC_CHECK_HEADERS(values.h)
AC_CXX_HAVE_NUMERIC_LIMITS
AC_CXX_HAVE_SSTREAM
AC_CXX_NAMESPACES AC_CXX_NAMESPACES
AC_TYPE_SIZE_T
dnl Checks for header files.
AC_LANG(C)
AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h)
AC_LANG(C++)
AC_CHECK_HEADERS(sstream, [], AC_MSG_ERROR([Need sstream C++ include.]))
AC_CHECK_HEADERS(stdint.h, [], AC_MSG_WARN([Need C99 standard header.]))
AC_CXX_HAVE_NUMERIC_LIMITS
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_CHECK_SIZEOF(unsigned long)
AC_C_INLINE AC_CHECK_TYPES(uint32_t, [], AC_MSG_WARN([Need uint32_t from C99 standard.]))
AC_CHECK_SIZEOF([unsigned long])
AC_CHECK_TYPES(uint32_t)
AC_TYPE_SIZE_T
dnl Checks for libraries. dnl Checks for libraries.
AC_CHECK_LIB(m, cos) AC_CHECK_LIB(m, cos)
dnl Checks for library functions. dnl Checks for library functions.
AC_CHECK_FUNCS(select)
dnl create makefiles dnl create makefiles
AC_OUTPUT(Makefile \ AC_OUTPUT(Makefile \

View file

@ -12,8 +12,6 @@ libeo_a_SOURCES = eoFunctorStore.cpp \
eoScalarFitnessAssembled.cpp eoScalarFitnessAssembled.cpp
AM_CXXFLAGS = -I$(top_srcdir)/src
pkginclude_HEADERS = eo \ pkginclude_HEADERS = eo \
EO.h \ EO.h \
apply.h \ apply.h \
@ -114,3 +112,6 @@ pkginclude_HEADERS = eo \
es.h \ es.h \
ga.h ga.h
AM_CXXFLAGS = -I$(top_srcdir)/src
AM_LIBS = -Lutils -leoutil

View file

@ -32,11 +32,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
#include "EO.h" #include "EO.h"
#include "eoParetoFitness.h" #include "eoParetoFitness.h"
@ -124,32 +120,18 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
unsigned obj2 = atoi(fPlot.second[i+1].c_str()); unsigned obj2 = atoi(fPlot.second[i+1].c_str());
eoMOFitnessStat<EOT>* fStat; eoMOFitnessStat<EOT>* fStat;
if (!bStat[obj1]) { // not already there: create it if (!bStat[obj1]) { // not already there: create it
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << "Obj. " << obj1 << std::ends; os << "Obj. " << obj1 << std::ends;
fStat = new eoMOFitnessStat<EOT>(obj1, os.str().c_str()); fStat = new eoMOFitnessStat<EOT>(obj1, os.str().c_str());
#else
char s[1024];
std::ostrstream os(s, 1022);
os << "Obj. " << obj1 << std::ends;
fStat = new eoMOFitnessStat<EOT>(obj1, s);
#endif
_state.storeFunctor(fStat); _state.storeFunctor(fStat);
bStat[obj1]=true; bStat[obj1]=true;
theStats[obj1]=fStat; theStats[obj1]=fStat;
checkpoint.add(*fStat); checkpoint.add(*fStat);
} }
if (!bStat[obj2]) { // not already there: create it if (!bStat[obj2]) { // not already there: create it
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << "Obj. " << obj2 << std::ends; os << "Obj. " << obj2 << std::ends;
fStat = new eoMOFitnessStat<EOT>(obj2, os.str().c_str()); fStat = new eoMOFitnessStat<EOT>(obj2, os.str().c_str());
#else
char s[1024];
std::ostrstream os2(s, 1022);
os2 << "Obj. " << obj2 << std::ends;
fStat = new eoMOFitnessStat<EOT>(obj2, s);
#endif
_state.storeFunctor(fStat); _state.storeFunctor(fStat);
bStat[obj2]=true; bStat[obj2]=true;
theStats[obj2]=fStat; theStats[obj2]=fStat;
@ -157,18 +139,10 @@ eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
} }
// then the fileSnapshots // then the fileSnapshots
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << "Front." << obj1 << "." << obj2 << "." << std::ends; os << "Front." << obj1 << "." << obj2 << "." << std::ends;
eoFileSnapshot& snapshot = _state.storeFunctor( eoFileSnapshot& snapshot = _state.storeFunctor(
new eoFileSnapshot(dirName, frequency, os.str().c_str())); new eoFileSnapshot(dirName, frequency, os.str().c_str()));
#else
char s3[1024];
std::ostrstream os3(s3, 1022);
os3 << "Front." << obj1 << "." << obj2 << "." << std::ends;
eoFileSnapshot & snapshot = _state.storeFunctor(
new eoFileSnapshot(dirName, frequency, s3 ) );
#endif
checkpoint.add(snapshot); checkpoint.add(snapshot);
snapshot.add(*theStats[obj1]); snapshot.add(*theStats[obj1]);

View file

@ -34,6 +34,7 @@
* starting with best, continuing shuffled (see G3 engine) * starting with best, continuing shuffled (see G3 engine)
*/ */
#include <utils/eoData.h>
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
#include <eoSelectOne.h> #include <eoSelectOne.h>

View file

@ -155,16 +155,9 @@ public :
/** the inherited className */ /** the inherited className */
virtual std::string className() const virtual std::string className() const
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")"; os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")";
return os.str() return os.str()
#else
char s[1024];
std::ostrstream os(s, 1022);
os << "eoVlAtomExchangeQuadOp(" << atomExchange.className() << ")" << std::ends;
return std::string(s);
#endif
} }
private: private:

View file

@ -142,16 +142,9 @@ public :
virtual std::string className() const virtual std::string className() const
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << "eoVlDelMutation("<<chooser.className() << ")"; os << "eoVlDelMutation("<<chooser.className() << ")";
return os.str(); return os.str();
#else
char s[1024];
std::ostrstream os(s, 1022);
os << "eoVlDelMutation(" << chooser.className() << ")" << std::ends;
return std::string(s);
#endif
} }
private: private:

View file

@ -1,4 +1,4 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; fill-column: 80 -*-
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// eoEsMutationInit.h // eoEsMutationInit.h
@ -24,37 +24,48 @@
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef _eoEsInit_h #ifndef _eoEsMutationInit_h
#define _eoEsInit_h #define _eoEsMutationInit_h
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <utils/eoParser.h> #include <utils/eoParser.h>
/** /** Initialize Mutation operator
\ingroup EvolutionStrategies
eoESMutationInit. Proxy class that is used for initializing the mutation @ingroup EvolutionStrategies
operator. It provides an interface between eoEsMutate and the abstract
parameterLoader. It also provides the names for the parameters in this
class as virtual protected member functions.
If you have more than a single ES in a project that need different Proxy class that is used for initializing the mutation operator. It provides an
names in the configuration files, you might consider overriding this class interface between eoEsMutate and the abstract parameterLoader. It also provides
to change the names. the names for the parameters in this class as virtual protected member
functions.
@see eoEsMutate If you have more than a single ES in a project that need different names in the
configuration files, you might consider overriding this class to change the
names.
@see eoEsMutate
*/ */
class eoEsMutationInit class eoEsMutationInit
{ {
public : public :
/** Constructor
@param _parser Parser to read parameters from.
@param _section Parser section for \tau-parameters.
*/
eoEsMutationInit(eoParser& _parser, eoEsMutationInit(eoParser& _parser,
std::string _section="ES mutation parameters" ) : std::string _section="ES mutation parameters" ) :
parser(_parser), repSection(_section), parser(_parser), repSection(_section),
TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {} TauLclParam(0), TauGlbParam(0), TauBetaParam(0) {}
// because we have virtual function - size /** Virtual destructor */
virtual ~eoEsMutationInit(){} virtual ~eoEsMutationInit() {}
/** local \tau */
double TauLcl(void) double TauLcl(void)
{ {
if (TauLclParam == 0) if (TauLclParam == 0)
@ -63,10 +74,10 @@ class eoEsMutationInit
"Local Tau (before normalization)", "Local Tau (before normalization)",
TauLclShort(), section()); TauLclShort(), section());
} }
return TauLclParam->value(); return TauLclParam->value();
} }
/** global tau */
double TauGlb(void) double TauGlb(void)
{ {
if (TauGlbParam == 0) if (TauGlbParam == 0)
@ -75,10 +86,10 @@ class eoEsMutationInit
"Global Tau (before normalization)", "Global Tau (before normalization)",
TauGlbShort(), section()); TauGlbShort(), section());
} }
return TauGlbParam->value(); return TauGlbParam->value();
} }
/** correlation's tau */
double TauBeta(void) double TauBeta(void)
{ {
if (TauBetaParam == 0) if (TauBetaParam == 0)
@ -86,14 +97,12 @@ class eoEsMutationInit
TauBetaParam = &parser.getORcreateParam(0.0873, TauBetaName(), TauBetaParam = &parser.getORcreateParam(0.0873, TauBetaName(),
"Beta", TauBetaShort(), section()); "Beta", TauBetaShort(), section());
} }
return TauBetaParam->value(); return TauBetaParam->value();
} }
protected : protected :
virtual std::string section(void) virtual std::string section(void) { return repSection; }
{ return repSection; }
virtual std::string TauLclName(void) const { return "TauLoc"; } virtual std::string TauLclName(void) const { return "TauLoc"; }
virtual char TauLclShort(void) const { return 'l'; } virtual char TauLclShort(void) const { return 'l'; }
@ -104,13 +113,13 @@ class eoEsMutationInit
virtual std::string TauBetaName(void) const { return "Beta"; } virtual std::string TauBetaName(void) const { return "Beta"; }
virtual char TauBetaShort(void) const { return 'b'; } virtual char TauBetaShort(void) const { return 'b'; }
private : private:
eoParser& parser; eoParser& parser;
std::string repSection; std::string repSection;
eoValueParam<double>* TauLclParam; eoValueParam<double>* TauLclParam;
eoValueParam<double>* TauGlbParam; eoValueParam<double>* TauGlbParam;
eoValueParam<double>* TauBetaParam; eoValueParam<double>* TauBetaParam;
}; };
#endif #endif

View file

@ -27,23 +27,13 @@
#ifndef _make_genotype_h #ifndef _make_genotype_h
#define _make_genotype_h #define _make_genotype_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream>
#endif
#include <iostream> #include <iostream>
#include <sstream>
#include "es/eoReal.h" #include "es/eoReal.h"
#include "es/eoEsChromInit.h" #include "es/eoEsChromInit.h"
#include "utils/eoRealVectorBounds.h"
// also need the parser and param includes
#include "utils/eoParser.h" #include "utils/eoParser.h"
#include "utils/eoRealVectorBounds.h"
#include "utils/eoState.h" #include "utils/eoState.h"
@ -102,11 +92,7 @@ eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
to_scale = true; to_scale = true;
sigmaString.resize(pos); sigmaString.resize(pos);
} }
#ifdef HAVE_SSTREAM
std::istringstream is(sigmaString); std::istringstream is(sigmaString);
#else
std::istrstream is(sigmaString.c_str());
#endif
double sigma; double sigma;
is >> sigma; is >> sigma;
// minimum check // minimum check

View file

@ -27,33 +27,29 @@
#ifndef eoParseTree_h #ifndef eoParseTree_h
#define eoParseTree_h #define eoParseTree_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iterator> #include <iterator>
#include <list> #include <list>
#include <EO.h> #include <EO.h>
#include <eoInit.h>
#include <eoOp.h> #include <eoOp.h>
#include <gp/parse_tree.h> #include <gp/parse_tree.h>
#include <eoInit.h>
using namespace gp_parse_tree; using namespace gp_parse_tree;
/** /** @defgroup ParseTree
\defgroup ParseTree
Various functions for tree-based Genetic Programming Various functions for tree-based Genetic Programming
*/
/** eoParseTree : implementation of parse-tree for genetic programming
\class eoParseTree eoParseTree.h gp/eoParseTree.h
\ingroup ParseTree
*/ */
/** Implementation of parse-tree for genetic programming
@class eoParseTree eoParseTree.h gp/eoParseTree.h
@ingroup ParseTree
*/
template <class FType, class Node> template <class FType, class Node>
class eoParseTree : public EO<FType>, public parse_tree<Node> class eoParseTree : public EO<FType>, public parse_tree<Node>
{ {

View file

@ -18,15 +18,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <sstream>
#include "PyEO.h" #include "PyEO.h"
#include <eoPop.h> #include <eoPop.h>
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream>
#endif
using namespace std; using namespace std;
//using namespace boost::python; //using namespace boost::python;
@ -103,17 +99,9 @@ struct pyPop_pickle_suite : boost::python::pickle_suite
template <class T> template <class T>
boost::python::str to_string(T& _p) boost::python::str to_string(T& _p)
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
_p.printOn(os); _p.printOn(os);
return boost::python::str(os.str().c_str()); return boost::python::str(os.str().c_str());
#else
std::ostrstream os;
_p.printOn(os);
os << ends;
std::string s(os.str());
return boost::python::str(s.c_str());
#endif
} }
void pop_sort(eoPop<PyEO>& pop) { pop.sort(); } void pop_sort(eoPop<PyEO>& pop) { pop.sort(); }

View file

@ -24,11 +24,7 @@
#include <config.h> #include <config.h>
#include <boost/python.hpp> #include <boost/python.hpp>
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
/** Implements pickle support for eoPersistent derivatives */ /** Implements pickle support for eoPersistent derivatives */
@ -38,11 +34,7 @@ struct T_pickle_suite : boost::python::pickle_suite
static static
std::string print_to_string(const T& t) std::string print_to_string(const T& t)
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
std::ostrstream os;
#endif
t.printOn(os); t.printOn(os);
os << std::ends; os << std::ends;
return os.str(); return os.str();
@ -59,11 +51,7 @@ struct T_pickle_suite : boost::python::pickle_suite
void setstate(T& t, boost::python::tuple pickled) void setstate(T& t, boost::python::tuple pickled)
{ {
std::string s = boost::python::extract<std::string>(pickled[0]); std::string s = boost::python::extract<std::string>(pickled[0]);
#ifdef HAVE_SSTREAM
std::istringstream is(s); std::istringstream is(s);
#else
std::istrstream is(s.c_str(), s.size());
#endif
t.readFrom(is); t.readFrom(is);
} }
}; };

View file

@ -23,12 +23,7 @@
using namespace boost::python; using namespace boost::python;
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
#include <boost/python/detail/api_placeholder.hpp> #include <boost/python/detail/api_placeholder.hpp>
using namespace boost::python; using namespace boost::python;
@ -43,11 +38,7 @@ double normal(eoRng& rng) { return rng.normal(); }
std::string rng_to_string(const eoRng& _rng) std::string rng_to_string(const eoRng& _rng)
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
std::ostrstream os;
#endif
_rng.printOn(os); _rng.printOn(os);
os << std::ends; os << std::ends;
return os.str(); return os.str();
@ -56,11 +47,7 @@ std::string rng_to_string(const eoRng& _rng)
void rng_from_string(eoRng& _rng, std::string s) void rng_from_string(eoRng& _rng, std::string s)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(s); std::istringstream is(s);
#else
std::istrstream is(s.c_str(), s.size());
#endif
_rng.readFrom(is); _rng.readFrom(is);
} }

View file

@ -1,8 +1,9 @@
## Makefile.am for eo/src/utils ## Makefile.am for eo/src/utils
lib_LIBRARIES = libeoutils.a lib_LIBRARIES = libeoutils.a
libeoutils_a_SOURCES = eoParser.cpp \ libeoutils_a_SOURCES = eoData.cpp \
eoParser.cpp \
eoRNG.cpp \ eoRNG.cpp \
eoState.cpp \ eoState.cpp \
eoUpdater.cpp \ eoUpdater.cpp \
@ -12,8 +13,6 @@ libeoutils_a_SOURCES = eoParser.cpp \
eoIntBounds.cpp \ eoIntBounds.cpp \
make_help.cpp make_help.cpp
AM_CXXFLAGS = -I$(top_srcdir)/src
utilsincludedir = $(pkgincludedir)/utils utilsincludedir = $(pkgincludedir)/utils
utilsinclude_HEADERS = checkpointing \ utilsinclude_HEADERS = checkpointing \
@ -50,3 +49,6 @@ utilsinclude_HEADERS = checkpointing \
pipecom.h \ pipecom.h \
rnd_generators.h \ rnd_generators.h \
selectors.h selectors.h
AM_CXXFLAGS = -I$(top_srcdir)/src

30
eo/src/utils/eoData.cpp Normal file
View file

@ -0,0 +1,30 @@
// Copyright (C) 2005 Jochen Küpper <jochen@fhi-berlin.mpg.de>
//
// 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; see the file License. if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#include "eoData.h"
#ifdef HAVE_NUMERIC_LIMITS
int MAXINT = numeric_limits<int>::max();
#else
#include <limits.h>
int MAXINT = INT_MAX;
#endif
// Local Variables:
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -25,47 +25,17 @@
#ifndef EODATA_H #ifndef EODATA_H
#define EODATA_H #define EODATA_H
//----------------------------------------------------------------------------- #ifdef MAXINT
#undef MAXINT
#include <vector> // std::vector
#include <set> // set
#include <string> // std::string
#ifdef _MSC_VER
#include <limits> // MAXDOUBLE
#define MAXFLOAT numeric_limits<float>::max()
#define MINFLOAT numeric_limits<float>::min()
#define MAXDOUBLE numeric_limits<double>::max()
#define MAXINT numeric_limits<int>::max()
#else
#include <float.h>
#include <limits.h>
#endif
#if !defined(_WIN32) && !defined(__CYGWIN__) && !(defined(__APPLE__) || defined(MACOSX)) && !defined(__FreeBSD__)
#include <values.h>
#endif
// for cygwin and windows (and possibly MacOsX)
#ifndef MINFLOAT
#define MINFLOAT ( (float)1e-127 )
#endif
#ifndef MAXFLOAT
#define MAXFLOAT ( (float)1e127 )
#endif
#ifndef MAXINT
#define MAXINT 2147483647
#endif
#ifndef MAXDOUBLE
#define MAXDOUBLE (double)1.79769313486231570e+308
#endif #endif
extern int MAXINT;
#ifndef _MSC_VER #ifndef _MSC_VER
#include <math.h> #include <math.h>
#define _isnan isnan #define _isnan isnan
#endif #endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// some defines to make things easier to get at first sight // some defines to make things easier to get at first sight

View file

@ -27,10 +27,6 @@
#ifndef _eoFileSnapshot_h #ifndef _eoFileSnapshot_h
#define _eoFileSnapshot_h #define _eoFileSnapshot_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <utils/eoParam.h> #include <utils/eoParam.h>
@ -103,17 +99,9 @@ public :
*/ */
void setCurrentFileName() void setCurrentFileName()
{ {
#ifdef HAVE_SSTREAM std::ostringstream oscount;
std::ostringstream oscount; oscount << counter;
oscount << counter; currentFileName = dirname + "/" + filename + oscount.str();
#else
char buff[255];
std::ostrstream oscount(buff, 254);
oscount << counter;
oscount << std::ends;
#endif
currentFileName = dirname + "/" + filename + oscount.str();
} }
/** The operator(void): opens the std::ostream and calls the write method /** The operator(void): opens the std::ostream and calls the write method

View file

@ -26,10 +26,6 @@
#ifndef _eoGnuplot_H #ifndef _eoGnuplot_H
#define _eoGnuplot_H #define _eoGnuplot_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string> #include <string>
/** /**
@ -109,24 +105,13 @@ private:
inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << "250x150-0+" << numWindow*170; os << "250x150-0+" << numWindow*170;
#else
char snum[255];
std::ostrstream os(snum, 254);
os << "250x150-0+" << numWindow*170 << std::ends;
#endif
numWindow++; numWindow++;
char *args[6]; char *args[6];
args[0] = strdup( "gnuplot" ); args[0] = strdup( "gnuplot" );
args[1] = strdup( "-geometry" ); args[1] = strdup( "-geometry" );
#ifdef HAVE_SSTREAM
args[2] = strdup( os.str().c_str()); args[2] = strdup( os.str().c_str());
#else
args[2] = strdup( os.str() );
#endif
args[3] = strdup( "-title" ); args[3] = strdup( "-title" );
args[4] = strdup( _title.c_str() ); args[4] = strdup( _title.c_str() );
args[5] = 0; args[5] = 0;
@ -154,7 +139,7 @@ inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra)
* Created......: Mon Mar 13 13:50:11 1995 * Created......: Mon Mar 13 13:50:11 1995
* Description..: Communication par pipe bidirectionnel avec un autre process * Description..: Communication par pipe bidirectionnel avec un autre process
* *
* Ident........: $Id: eoGnuplot.h,v 1.12 2005-09-07 17:09:19 maartenkeijzer Exp $ * Ident........: $Id: eoGnuplot.h,v 1.13 2005-09-28 21:49:26 kuepper Exp $
* ---------------------------------------------------------------------- * ----------------------------------------------------------------------
*/ */

View file

@ -28,10 +28,6 @@
#ifndef _eoGnuplot1DMonitor_H #ifndef _eoGnuplot1DMonitor_H
#define _eoGnuplot1DMonitor_H #define _eoGnuplot1DMonitor_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string> #include <string>
#include <utils/eoMonitor.h> #include <utils/eoMonitor.h>
@ -110,13 +106,7 @@ inline void eoGnuplot1DMonitor::FirstPlot()
{ {
throw std::runtime_error("Must have some stats to plot!\n"); throw std::runtime_error("Must have some stats to plot!\n");
} }
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
char buff[1024];
std::ostrstream os(buff, 1024);
#endif
os << "plot"; os << "plot";
for (unsigned i=1; i<vec.size(); i++) { for (unsigned i=1; i<vec.size(); i++) {
os << " '" << getFileName().c_str() << os << " '" << getFileName().c_str() <<
@ -125,12 +115,7 @@ inline void eoGnuplot1DMonitor::FirstPlot()
os << ", "; os << ", ";
} }
os << '\n'; os << '\n';
#ifdef HAVE_SSTREAM
PipeComSend( gpCom, os.str().c_str()); PipeComSend( gpCom, os.str().c_str());
#else
os << std::ends;
PipeComSend( gpCom, buff );
#endif
} }
#endif #endif

View file

@ -28,14 +28,8 @@
#ifndef _eoGnuplot1DSnapshot_H #ifndef _eoGnuplot1DSnapshot_H
#define _eoGnuplot1DSnapshot_H #define _eoGnuplot1DSnapshot_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#endif #include <string>
#include <utils/eoFileSnapshot.h> #include <utils/eoFileSnapshot.h>
#include <utils/eoGnuplot.h> #include <utils/eoGnuplot.h>
@ -107,13 +101,7 @@ class eoGnuplot1DSnapshot: public eoFileSnapshot, public eoGnuplot
virtual void handleBounds(eoRealVectorBounds & _bounds) virtual void handleBounds(eoRealVectorBounds & _bounds)
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
// use strstream and not std::stringstream until strstream is in all distributions
char buf[1024];
std::ostrstream os(buf, 1023);
#endif
// std::ostrstream os; // std::ostrstream os;
os << "set autoscale\nset yrange [" ; os << "set autoscale\nset yrange [" ;
if (_bounds.isMinBounded(0)) if (_bounds.isMinBounded(0))
@ -140,25 +128,13 @@ inline eoMonitor& eoGnuplot1DSnapshot::operator() (void)
eoFileSnapshot::operator()(); eoFileSnapshot::operator()();
// sends plot order to gnuplot // sends plot order to gnuplot
#ifdef HAVE_SSTREAM
//std::string buff; // need local memory //std::string buff; // need local memory
std::ostringstream os; std::ostringstream os;
#else
char buff[1024];
std::ostrstream os(buff, 1024);
#endif
os << "set title 'Gen. " << getCounter() << "'; plot '" os << "set title 'Gen. " << getCounter() << "'; plot '"
// mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2 // mk: had to use getFilename().c_str(), because it seems the string(stream) lib is screwed in gcc3.2
<< getFileName().c_str() << "' notitle with points ps " << pointSize; << getFileName().c_str() << "' notitle with points ps " << pointSize;
os << std::endl; os << std::endl;
#ifdef HAVE_SSTREAM
PipeComSend( gpCom, os.str().c_str()); PipeComSend( gpCom, os.str().c_str());
#else
os << std::ends;
PipeComSend( gpCom, buff );
#endif
return (*this); return (*this);
} }

View file

@ -64,15 +64,7 @@
* It is an eoPersistent because we need to be able to use eoParamValue<eoHowMany> * It is an eoPersistent because we need to be able to use eoParamValue<eoHowMany>
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
class eoHowMany : public eoPersistent class eoHowMany : public eoPersistent
{ {
@ -164,11 +156,7 @@ public:
_value.resize(pos); // get rid of % _value.resize(pos); // get rid of %
} }
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
is >> rate; is >> rate;
// now store // now store
if (interpret_as_rate) if (interpret_as_rate)

View file

@ -8,12 +8,7 @@
#endif #endif
#include <ctime> #include <ctime>
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
#include "eoIntBounds.h" #include "eoIntBounds.h"

View file

@ -27,24 +27,13 @@
#ifndef eoParam_h #ifndef eoParam_h
#define eoParam_h #define eoParam_h
#ifdef HAVE_CONFIG_H #include <cmath>
#include <config.h> #include <iterator>
#endif
//-----------------------------------------------------------------------------
#include <math.h> // for floor
#include <string>
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream>
#endif
#include <vector>
#include <iterator> // for GCC 3.2
#include <stdexcept> #include <stdexcept>
#include <eoScalarFitness.h> // for specializations #include <sstream>
#include <string>
#include <vector>
#include <eoScalarFitness.h>
/** /**
@ -189,26 +178,15 @@ public :
std::string getValue(void) const std::string getValue(void) const
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << repValue; os << repValue;
#else
char buf[1024];
std::ostrstream os(buf, 1023);
os << repValue;
os << std::ends;
#endif
return os.str(); return os.str();
} }
void setValue(const std::string& _value) void setValue(const std::string& _value)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
is >> repValue; is >> repValue;
} }
@ -235,11 +213,7 @@ inline void eoValueParam<bool>::setValue(const std::string& _value)
repValue = true; repValue = true;
return; return;
} }
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
is >> repValue; is >> repValue;
} }
@ -249,14 +223,8 @@ template <>
inline std::string eoValueParam<std::pair<double, double> >::getValue(void) const inline std::string eoValueParam<std::pair<double, double> >::getValue(void) const
{ {
// use own buffer as MSVC's buffer leaks! // use own buffer as MSVC's buffer leaks!
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
os << repValue.first << ' ' << repValue.second; os << repValue.first << ' ' << repValue.second;
#else
char buff[1024];
std::ostrstream os(buff, 1024);
os << repValue.first << ' ' << repValue.second << std::ends;
#endif
return os.str(); return os.str();
} }
@ -264,11 +232,7 @@ inline std::string eoValueParam<std::pair<double, double> >::getValue(void) cons
template <> template <>
inline void eoValueParam<std::pair<double, double> >::setValue(const std::string& _value) inline void eoValueParam<std::pair<double, double> >::setValue(const std::string& _value)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
is >> repValue.first; is >> repValue.first;
is >> repValue.second; is >> repValue.second;
} }
@ -279,21 +243,13 @@ inline void eoValueParam<std::pair<double, double> >::setValue(const std::string
template <> template <>
inline std::string eoValueParam<std::vector<std::vector<double> > >::getValue(void) const inline std::string eoValueParam<std::vector<std::vector<double> > >::getValue(void) const
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
std::ostrstream os;
#endif
os << repValue.size() << ' '; os << repValue.size() << ' ';
for (unsigned i = 0; i < repValue.size(); ++i) for (unsigned i = 0; i < repValue.size(); ++i)
{ {
os << repValue[i].size() << ' '; os << repValue[i].size() << ' ';
std::copy(repValue[i].begin(), repValue[i].end(), std::ostream_iterator<double>(os, " ")); std::copy(repValue[i].begin(), repValue[i].end(), std::ostream_iterator<double>(os, " "));
} }
#ifndef HAVE_SSTREAM
os << std::ends;
#endif
return os.str(); return os.str();
} }
@ -301,11 +257,7 @@ inline std::string eoValueParam<std::vector<std::vector<double> > >::getValue(vo
template <> template <>
inline void eoValueParam<std::vector<std::vector<double> > >::setValue(const std::string& _value) inline void eoValueParam<std::vector<std::vector<double> > >::setValue(const std::string& _value)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
unsigned i,j,sz; unsigned i,j,sz;
is >> sz; is >> sz;
repValue.resize(sz); repValue.resize(sz);
@ -328,16 +280,9 @@ inline void eoValueParam<std::vector<std::vector<double> > >::setValue(const std
template <> template <>
inline std::string eoValueParam<std::vector<double> >::getValue(void) const inline std::string eoValueParam<std::vector<double> >::getValue(void) const
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
std::ostrstream os;
#endif
os << repValue.size() << ' '; os << repValue.size() << ' ';
std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<double>(os, " ")); std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<double>(os, " "));
#ifndef HAVE_SSTREAM
os << std::ends;
#endif
return os.str(); return os.str();
} }
@ -345,11 +290,7 @@ inline std::string eoValueParam<std::vector<double> >::getValue(void) const
template <> template <>
inline void eoValueParam<std::vector<double> >::setValue(const std::string& _value) inline void eoValueParam<std::vector<double> >::setValue(const std::string& _value)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
unsigned sz; unsigned sz;
is >> sz; is >> sz;
repValue.resize(sz); repValue.resize(sz);
@ -362,16 +303,9 @@ inline void eoValueParam<std::vector<double> >::setValue(const std::string& _val
template <> template <>
inline std::string eoValueParam<std::vector<eoMinimizingFitness> >::getValue(void) const inline std::string eoValueParam<std::vector<eoMinimizingFitness> >::getValue(void) const
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
std::ostrstream os;
#endif
os << repValue.size() << ' '; os << repValue.size() << ' ';
std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<eoMinimizingFitness>(os, " ")); std::copy(repValue.begin(), repValue.end(), std::ostream_iterator<eoMinimizingFitness>(os, " "));
#ifndef HAVE_SSTREAM
os<< std::ends;
#endif
return os.str(); return os.str();
} }
@ -380,11 +314,7 @@ inline std::string eoValueParam<std::vector<eoMinimizingFitness> >::getValue(voi
template <> template <>
inline void eoValueParam<std::vector<eoMinimizingFitness> >::setValue(const std::string& _value) inline void eoValueParam<std::vector<eoMinimizingFitness> >::setValue(const std::string& _value)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_value); std::istringstream is(_value);
#else
std::istrstream is(_value.c_str());
#endif
unsigned sz; unsigned sz;
is >> sz; is >> sz;
repValue.resize(sz); repValue.resize(sz);

View file

@ -90,11 +90,7 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription,
} }
} }
// now read arguments on command-line // now read arguments on command-line
#ifdef HAVE_SSTREAM
stringstream stream; stringstream stream;
#else
strstream stream;
#endif
for (i = 1; i < _argc; ++i) for (i = 1; i < _argc; ++i)
{ {
stream << _argv[i] << '\n'; stream << _argv[i] << '\n';

View file

@ -24,7 +24,7 @@
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** /**
CVS Info: $Date: 2005-09-13 10:24:50 $ $Version$ $Author: kuepper $ CVS Info: $Date: 2005-09-28 21:49:26 $ $Version$ $Author: kuepper $
*/ */
#ifndef eoParser_h #ifndef eoParser_h
#define eoParser_h #define eoParser_h
@ -222,11 +222,7 @@ public:
{ {
eoValueParam<ValueType>& param = createParam(_defaultValue, _longName, _description, eoValueParam<ValueType>& param = createParam(_defaultValue, _longName, _description,
_shortHand, _section, _required); _shortHand, _section, _required);
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
std::ostrstream os;
#endif
os << _defaultValue; os << _defaultValue;
if(isItThere(param)) { if(isItThere(param)) {
param.setValue(os.str()); param.setValue(os.str());

View file

@ -35,10 +35,6 @@ that can be used to dump to the screen
#ifndef _eoPopStat_h #ifndef _eoPopStat_h
#define _eoPopStat_h #define _eoPopStat_h
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <utils/eoStat.h> #include <utils/eoStat.h>
@ -69,7 +65,6 @@ public:
Adds a \n before so it does not get mixed up with the rest of the stats Adds a \n before so it does not get mixed up with the rest of the stats
that are written by the monitor it is probably used from. that are written by the monitor it is probably used from.
*/ */
#ifdef HAVE_SSTREAM
void operator()(const eoPop<EOT>& _pop) void operator()(const eoPop<EOT>& _pop)
{ {
value() = "\n# ====== pop dump =====\n"; value() = "\n# ====== pop dump =====\n";
@ -83,24 +78,6 @@ void operator()(const eoPop<EOT>& _pop)
value() += os.str(); value() += os.str();
} }
} }
#else
void operator()(const eoPop<EOT>& _pop)
{
char buffer[1023]; // about one k of space per member
value() = "\n# ====== pop dump =====\n";
unsigned howmany=combien?combien:_pop.size();
value() += "\n"; // otherwise, possible mix-up with other stats
for (unsigned i = 0; i < howmany; ++i)
{
std::ostrstream os(buffer, 1022); // leave space for emergency terminate
os << _pop[i] << std::endl << std::ends;
// paranoid:
buffer[1022] = '\0';
value() += buffer;
}
}
#endif
private: private:
unsigned combien; unsigned combien;
@ -136,7 +113,6 @@ public:
the rest of the stats that are written by the monitor it is the rest of the stats that are written by the monitor it is
probably used from. probably used from.
*/ */
#ifdef HAVE_SSTREAM
void operator()(const std::vector<const EOT*>& _pop) void operator()(const std::vector<const EOT*>& _pop)
{ {
value() = ""; // empty value() = ""; // empty
@ -150,23 +126,6 @@ public:
value() += os.str(); value() += os.str();
} }
} }
#else
void operator()(const std::vector<const EOT*>& _pop)
{
char buffer[1023]; // about one K of space per member
value() = ""; // empty
unsigned howMany=combien?combien:_pop.size();
for (unsigned i = 0; i < howMany; ++i)
{
std::ostrstream os(buffer, 1022); // leave space for emergency terminate
os << *_pop[i] << std::endl << std::ends;
// paranoid:
buffer[1022] = '\0';
value() += buffer;
}
}
#endif
private: private:
unsigned combien; unsigned combien;
}; };

View file

@ -1,10 +1,9 @@
/* /** Random number generator adapted from (see comments below)
* Random number generator adapted from (see comments below)
* The random number generator is modified into a class
* The random number generator is modified into a class by Maarten Keijzer (mak@dhi.dk). Also added the Box-Muller
* by Maarten Keijzer (mak@dhi.dk). Also added the Box-Muller transformation to generate normal deviates.
* transformation to generate normal deviates.
*
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
@ -22,142 +21,118 @@
Contact: todos@geneura.ugr.es, http://geneura.ugr.es Contact: todos@geneura.ugr.es, http://geneura.ugr.es
*/ */
/* ************ 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 std::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_t must be an unsigned integer type capable of holding at least 32 // uint32_t 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 // 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 // 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 #ifndef EO_RANDOM_NUMBER_GENERATOR
#define EO_RANDOM_NUMBER_GENERATOR #define EO_RANDOM_NUMBER_GENERATOR
#ifdef HAVE_CONFIG_H #include <stdint.h>
#include <config.h> #include <vector>
#endif #include "eoPersistent.h"
#ifdef HAVE_INTTYPES_H #include "eoObject.h"
#include <inttypes.h>
#endif
#include "../eoPersistent.h" /** Random Number Generator
#include "../eoObject.h"
// TODO: check for various compilers if this is exactly 32 bits @class eoRng eoRNG.h utils/eoRNG.h
// Unfortunately MSVC's preprocessor does not comprehend sizeof()
// so neat preprocessing tricks will not work
#if(! (defined HAVE_UINT32_T)) eoRng is a persistent class that uses the ``Mersenne Twister'' random
#if(SIZEOF_UNSIGNED_LONG == 4) number generator MT19937 for generating random numbers. The various
typedef unsigned long uint32_t; member functions implement useful functions for evolutionary
#else algorithms. Included are: rand(), random(), flip() and normal().
#error Need to provide a type for uint32_t in eoRNG.h.
#endif <h1>DOCUMENTATION IN ORIGINAL FILE</h1>
#endif
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 std::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.
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.
//----------------------------------------------------------------------------- <h1>Portability</h1>
// eoRng
//-----------------------------------------------------------------------------
/**
\class eoRng eoRNG.h utils/eoRNG.h
eoRng is a persistent 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 Note for people porting EO to other platforms: please make sure that the type
uint32_t in the file eoRng.h is exactly 32 bits long. It may be longer, but not uint32_t 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 shorter. If it is longer, file compatibility between EO on different platforms
may be broken. may be broken.
*/ */
class eoRng : public eoObject, public eoPersistent class eoRng : public eoObject, public eoPersistent
{ {
public : public :
/**
ctor takes a random seed; if you want another seed, use reseed
@see reseed to see why the parameter to initialize is doubled
*/
eoRng(uint32_t s) : state(0), next(0), left(-1), cached(false), N(624), M(397), K(0x9908B0DFU) { /** Constructor
state = new uint32_t[N+1];
initialize(2*s);
}
~eoRng(void) @param s Random seed; if you want another seed, use reseed.
{
delete [] state;
}
/** @see reseed for details on usage of the seeding value.
* Re-initializes the Random Number Generator. */
* WARNING: after Jeroen Eggermont <jeggermo@liacs.nl> noticed that eoRng(uint32_t s)
* initialize does not differentiate between odd and even numbers, : state(0), next(0), left(-1), cached(false), N(624), M(397), K(0x9908B0DFU)
* the argument to reseed is now doubled before being passed on. {
* state = new uint32_t[N+1];
* Manually divide the seed by 2 if you want to re-run old runs initialize(2*s);
* }
* MS. 5 Oct. 2001
*/
void reseed(uint32_t s)
{
initialize(2*s);
}
/** ~eoRng(void)
Re-initializes the Random Number Generator - old version {
*/ delete [] state;
void oldReseed(uint32_t s) }
{
initialize(s); /** Re-initializes the Random Number Generator.
}
WARNING: Jeroen Eggermont <jeggermo@liacs.nl> noticed that initialize does
not differentiate between odd and even numbers, therefore the argument to
reseed is now doubled before being passed on.
Manually divide the seed by 2 if you want to re-run old runs
@version MS. 5 Oct. 2001
*/
void reseed(uint32_t s)
{
initialize(2*s);
}
/** Re-initializes the Random Number Generator
This is the traditional seeding procedure.
@see reseed for details on usage of the seeding value.
@version old version
*/
void oldReseed(uint32_t s)
{
initialize(s);
}
/** /**
uniform(m = 1.0) returns a random double in the range [0, m) uniform(m = 1.0) returns a random double in the range [0, m)
@ -218,44 +193,52 @@ public :
*/ */
uint32_t rand(); uint32_t rand();
/** /**
rand_max() the maximum returned by rand() rand_max() the maximum returned by rand()
*/ */
uint32_t rand_max(void) const { return (uint32_t) 0xffffffff; } uint32_t rand_max(void) const { return uint32_t(0xffffffff); }
/** /**
roulette_wheel(vec, total = 0) does a roulette wheel selection roulette_wheel(vec, total = 0) does a roulette wheel selection
on the input std::vector vec. If the total is not supplied, it is on the input std::vector vec. If the total is not supplied, it is
calculated. It returns an integer denoting the selected argument. calculated. It returns an integer denoting the selected argument.
*/ */
template <class T> template <typename TYPE>
int roulette_wheel(const std::vector<T>& vec, T total = 0) int roulette_wheel(const std::vector<TYPE>& vec, TYPE total = 0)
{ {
if (total == 0) if (total == 0)
{ // count { // count
for (unsigned i = 0; i < vec.size(); ++i) for (unsigned i = 0; i < vec.size(); ++i)
total += vec[i]; total += vec[i];
} }
double fortune = uniform() * total;
int i = 0;
while (fortune > 0)
{
fortune -= vec[i++];
}
return --i;
};
double fortune = uniform() * total;
int i = 0;
while (fortune > 0) /** Randomly select element from vector.
{
fortune -= vec[i++];
}
return --i; @return Uniformly chosen element from the vector.
} */
template <typename TYPE>
const TYPE& choice(const std::vector<TYPE>& vec) const
{ return vec[random(vec.size())]; }
/**
* choice(vec), returns a uniformly chosen element from the vector
*/
template <class T>
const T& choice(const std::vector<T>& vec) { return vec[random(vec.size())]; }
template <class T> /** Randomly select element from vector.
T& choice(std::vector<T>& vec) { return vec[random(vec.size())]; }
@overload
@return Uniformly chosen element from the vector.
*/
template <typename TYPE>
TYPE& choice(std::vector<TYPE>& vec)
{ return vec[random(vec.size())]; }
/// ///
void printOn(std::ostream& _os) const void printOn(std::ostream& _os) const
@ -474,3 +457,10 @@ namespace eo {
#endif #endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -8,11 +8,7 @@
#endif #endif
#include <ctime> #include <ctime>
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
#include "eoRealBounds.h" #include "eoRealBounds.h"
#include "eoRealVectorBounds.h" #include "eoRealVectorBounds.h"
@ -37,11 +33,7 @@ bool remove_leading(std::string & _s, const std::string _delim)
double read_double(std::string _s) double read_double(std::string _s)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_s); std::istringstream is(_s);
#else
std::istrstream is(_s.c_str());
#endif
double r; double r;
is >> r; is >> r;
return r; return r;
@ -49,11 +41,7 @@ double read_double(std::string _s)
long int read_int(std::string _s) long int read_int(std::string _s)
{ {
#ifdef HAVE_SSTREAM
std::istringstream is(_s); std::istringstream is(_s);
#else
std::istrstream is(_s.c_str());
#endif
long int i; long int i;
is >> i; is >> i;
return i; return i;

View file

@ -8,11 +8,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
#include "eoState.h" #include "eoState.h"
#include "eoObject.h" #include "eoObject.h"
@ -135,11 +131,7 @@ void eoState::load(std::istream& is)
removeComment(str, getCommentString()); removeComment(str, getCommentString());
fullstring += str + "\n"; fullstring += str + "\n";
} }
#ifdef HAVE_SSTREAM
istringstream the_stream(fullstring); istringstream the_stream(fullstring);
#else
istrstream the_stream(fullstring.c_str(), fullstring.size());
#endif
object->readFrom(the_stream); object->readFrom(the_stream);
} }
} }
@ -180,11 +172,7 @@ string eoState::createObjectName(eoObject* obj)
{ {
if (obj == 0) if (obj == 0)
{ {
#ifdef HAVE_SSTREAM
ostringstream os; ostringstream os;
#else
ostrstream os;
#endif
os << objectMap.size(); os << objectMap.size();
return os.str(); return os.str();
} }
@ -196,16 +184,9 @@ string eoState::createObjectName(eoObject* obj)
unsigned count = 1; unsigned count = 1;
while (it != objectMap.end()) while (it != objectMap.end())
{ {
#ifdef HAVE_SSTREAM
ostringstream os; ostringstream os;
os << obj->className().c_str() << count++; os << obj->className().c_str() << count++;
#else
ostrstream os;
os << obj->className().c_str() << count++ << ends;
#endif
name = os.str(); name = os.str();
it = objectMap.find(name); it = objectMap.find(name);
} }

View file

@ -6,11 +6,7 @@
#include <config.h> #include <config.h>
#endif #endif
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream>
#endif
#include <utils/eoState.h> #include <utils/eoState.h>
#include <utils/eoUpdater.h> #include <utils/eoUpdater.h>
@ -24,28 +20,17 @@ void eoTimedStateSaver::operator()(void)
if (now >= last_time + interval) if (now >= last_time + interval)
{ {
last_time = now; last_time = now;
#ifdef HAVE_SSTREAM
ostringstream os; ostringstream os;
os << prefix << (now - first_time) << '.' << extension; os << prefix << (now - first_time) << '.' << extension;
#else
ostrstream os;
os << prefix << (now - first_time) << '.' << extension << ends;
#endif
state.save(os.str()); state.save(os.str());
} }
} }
void eoCountedStateSaver::doItNow(void) void eoCountedStateSaver::doItNow(void)
{ {
#ifdef HAVE_SSTREAM
ostringstream os; ostringstream os;
os << prefix << counter << '.' << extension; os << prefix << counter << '.' << extension;
#else state.save(os.str());
ostrstream os;
os << prefix << counter << '.' << extension << ends;
#endif
state.save(os.str());
} }
void eoCountedStateSaver::operator()(void) void eoCountedStateSaver::operator()(void)

View file

@ -26,6 +26,9 @@
/** test program for the general operator - millenium version! /** test program for the general operator - millenium version!
* uses dummy individuals * uses dummy individuals
*/ */
#include <sstream>
#include <eo> #include <eo>
#include <eoPopulator.h> #include <eoPopulator.h>
#include <eoOpContainer.h> #include <eoOpContainer.h>
@ -176,13 +179,7 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
} }
for (unsigned i=0; i<_pSize; i++) for (unsigned i=0; i<_pSize; i++)
{ {
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
char s[255];
std::ostrstream os(s, 254);
#endif
os << i << std::ends; os << i << std::ends;
_pop[i] = Dummy(os.str()); _pop[i] = Dummy(os.str());
_pop[i].fitness(i); _pop[i].fitness(i);

View file

@ -8,13 +8,9 @@
#endif #endif
#include <iostream> #include <iostream>
#include <sstream>
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream>
#endif
// general // general
#include <eo> #include <eo>

View file

@ -30,11 +30,6 @@
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream>
#endif
#include <utils/eoRndGenerators.h> #include <utils/eoRndGenerators.h>
#include <eoVector.h> // eoVector #include <eoVector.h> // eoVector

View file

@ -27,11 +27,7 @@
#endif #endif
#include <iostream> // std::cout #include <iostream> // std::cout
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
#include <eo> // general EO #include <eo> // general EO
#include <ga.h> // bitstring representation & operators #include <ga.h> // bitstring representation & operators
@ -65,18 +61,9 @@ void main_function()
std::cout << "chrom: " << chrom << std::endl std::cout << "chrom: " << chrom << std::endl
<< "chrom2: " << chrom2 << std::endl; << "chrom2: " << chrom2 << std::endl;
#ifdef HAVE_SSTREAM
std::ostringstream os; std::ostringstream os;
#else
char buff[1024];
std::ostrstream os(buff, 1024);
#endif
os << chrom; os << chrom;
#ifdef HAVE_SSTREAM
std::istringstream is(os.str()); std::istringstream is(os.str());
#else
std::istrstream is(os.str());
#endif
is >> chrom2; chrom.fitness(binary_value(chrom2)); is >> chrom2; chrom.fitness(binary_value(chrom2));
std::cout << "\nTesting reading, writing\n"; std::cout << "\nTesting reading, writing\n";

View file

@ -10,16 +10,8 @@
#include <config.h> #include <config.h>
#endif #endif
// standard includes #include <stdexcept>
#include <stdexcept> // runtime_error #include <iostream>
#include <iostream> // cout
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo
#include <eo> #include <eo>
#include <ga.h> #include <ga.h>

View file

@ -9,16 +9,9 @@
#include <config.h> #include <config.h>
#endif #endif
// standard includes #include <stdexcept>
#include <stdexcept> // runtime_error #include <iostream>
#include <iostream> // cout
#ifdef HAVE_SSTREAM
#include <sstream> #include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo
#include <eo> #include <eo>
#include <es.h> #include <es.h>

View file

@ -12,11 +12,6 @@
// standard includes // standard includes
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream>
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -13,11 +13,6 @@
// standard includes // standard includes
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#include <iostream> // cout #include <iostream> // cout
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -13,11 +13,6 @@
// standard includes // standard includes
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#include <iostream> // cout #include <iostream> // cout
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -13,11 +13,6 @@
// standard includes // standard includes
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#include <iostream> // cout #include <iostream> // cout
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -14,11 +14,6 @@
#include <fstream> #include <fstream>
#include <iostream> // cout #include <iostream> // cout
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -16,11 +16,6 @@
#include <fstream> #include <fstream>
#include <iostream> // cout #include <iostream> // cout
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -14,11 +14,6 @@
#include <fstream> #include <fstream>
#include <iostream> // cout #include <iostream> // cout
#include <stdexcept> // runtime_error #include <stdexcept> // runtime_error
#ifdef HAVE_SSTREAM
#include <sstream>
#else
#include <strstream> // ostrstream, istrstream
#endif
// the general include for eo // the general include for eo
#include <eo> #include <eo>

View file

@ -1,4 +1,3 @@
noinst_PROGRAMS = BitEA RealEA ESEA noinst_PROGRAMS = BitEA RealEA ESEA
@ -15,9 +14,13 @@ noinst_HEADERS = binary_value.h \
extra_DIST = Makefile.simple extra_DIST = Makefile.simple
LDADD = -L$(top_builddir)/src -L$(top_builddir)/src/es \ AM_CXXFLAGS = -I$(top_srcdir)/src
-L$(top_builddir)/src/ga -L$(top_builddir)/src/utils
LIBS = -lga -les -leoutils -leo LIBEO = $(top_builddir)/src/libeo.a
LIBES = $(top_builddir)/src/es/libes.a
LIBGA = $(top_builddir)/src/ga/libga.a
LIBUTILS = $(top_builddir)/src/utils/libeoutils.a
INCLUDES = -I$(top_srcdir)/src DEPS = $(LIBEO) $(LIBUTILS) $(LIBES) $(LIBGA)
LIBS = $(LIBES) $(LIBGA) $(LIBEO) $(LIBUTILS)

View file

@ -17,6 +17,12 @@ noinst_HEADERS = eoOneMax.h \
extra_DIST = Makefile.simple extra_DIST = Makefile.simple
AM_CXXFLAGS = -I$(top_srcdir)/src AM_CXXFLAGS = -I$(top_srcdir)/src
LDADD = -L$(top_builddir)/src -L$(top_builddir)/src/ga -L$(top_builddir)/src/utils
LIBS = -lga -leoutils -leo
LIBEO = $(top_builddir)/src/libeo.a
LIBES = $(top_builddir)/src/es/libes.a
LIBGA = $(top_builddir)/src/ga/libga.a
LIBUTILS = $(top_builddir)/src/utils/libeoutils.a
DEPS = $(LIBEO) $(LIBUTILS) $(LIBES) $(LIBGA)
LIBS = $(LIBES) $(LIBGA) $(LIBEO) $(LIBUTILS)