Moving function InitRamdom to eoParserUtils.h

This commit is contained in:
victor 1999-12-17 12:04:06 +00:00
commit 5a735c3915
4 changed files with 883 additions and 852 deletions

View file

@ -5,20 +5,22 @@
############################################################################### ###############################################################################
lib_LIBRARIES = libeo.a lib_LIBRARIES = libeo.a
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoParserUtils.cpp
libeoincdir = $(includedir)/eo libeoincdir = $(includedir)/eo
libeoinc_HEADERS = EO.h eo eo1d.h eo2d.h eo2dVector.h eoAged.h eoAlgo.h\ libeoinc_HEADERS = EO.h eo eo1d.h eo2d.h eo2dVector.h eoAged.h eoAlgo.h\
eoAtomBitFlip.h eoAtomCreep.h eoAtomMutation.h eoAtomMutator.h \ eoAtomBitFlip.h eoAtomCreep.h eoAtomMutation.h eoAtomMutator.h \
eoAtomRandom.h eoBin.h eoBitOp.h eoBitOpFactory.h eoBreeder.h\ eoAtomRandom.h eoBin.h eoBitOp.h eoBitOpFactory.h eoBreeder.h\
eoData.h eoDetTournament.h eoDup.h eoESChrom.h eoESFullChrom.h eoESFullMut.h eoEasyEA.h\ eoData.h eoDetTournament.h eoDup.h eoESChrom.h eoESFullChrom.h \
eoESFullMut.h eoEasyEA.h\
eoEvalFunc.h eoEvalFuncPtr.h eoFitTerm.h eoFitness.h\ eoEvalFunc.h eoEvalFuncPtr.h eoFitTerm.h eoFitness.h\
eoGenTerm.h eoGeneration.h eoID.h eoInclusion.h eoInsertion.h\ eoGenTerm.h eoGeneration.h eoID.h eoInclusion.h eoInsertion.h\
eoKill.h eoLottery.h eoMerge.h eoMultiBinOp.h eoMultiMonOp.h eoMutation.h eoNegExp.h\ eoKill.h eoLottery.h eoMerge.h eoMultiBinOp.h eoMultiMonOp.h \
eoMutation.h eoNegExp.h\
eoNonUniform.h eoNormal.h eoObject.h eoOp.h eoOpSelector.h\ eoNonUniform.h eoNormal.h eoObject.h eoOp.h eoOpSelector.h\
eoParser.h eoPersistent.h eoPop.h eoPopOps.h eoPrintable.h\ eoParser.h eoPersistent.h eoPop.h eoPopOps.h eoPrintable.h\
eoProblem.h eoProportionalOpSel.h eoRNG.h eoRnd.h eoString.h\ eoProblem.h eoProportionalOpSel.h eoRNG.h eoRnd.h eoString.h\
eoStochTournament.h eoTerm.h eoTranspose.h eoUniform.h \ eoStochTournament.h eoTerm.h eoTranspose.h eoUniform.h \
eoUniformSelect.h eoUniformXOver.h eoVector.h eoXOver2.h eoUniformSelect.h eoUniformXOver.h eoVector.h eoXOver2.h \
eoParserUtils.h

View file

@ -45,20 +45,20 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** /**
* This class manages exceptions. It´s barely an extension of the standard except * This class manages exceptions. It´s barely an extension of the standard except
ion, ion,
* but it can be initialized with an STL string. Called UException (utils-except * but it can be initialized with an STL string. Called UException (utils-except
ion)+ ion)+
* to avoid conflicts with other classes. * to avoid conflicts with other classes.
*/ */
class UException: public exception { class UException: public exception {
public: public:
/// ///
UException( const string& _msg ): msg( _msg ) { }; UException( const string& _msg ): msg( _msg ) { };
/// ///
virtual const char* what() const { return msg.c_str(); }; virtual const char* what() const { return msg.c_str(); };
private: private:
string msg; string msg;
}; };
@ -686,7 +686,7 @@ public:
*/ */
void printHelp() { void printHelp() {
vector<Param>::iterator p; vector<Param>::iterator p;
// unsigned i; // unsigned i;
// print program name and description // print program name and description
cout << this->programName <<": "<<programDescription<<endl<<endl; cout << this->programName <<": "<<programDescription<<endl<<endl;
@ -696,16 +696,16 @@ public:
// only short usage! // only short usage!
cout << "Options of the form \"-ShortName value\" or \"--LongName value\"" << endl; cout << "Options of the form \"-ShortName value\" or \"--LongName value\"" << endl;
// for ( i=0,p=params.begin(); p!=params.end(); i++,p++ ) // for ( i=0,p=params.begin(); p!=params.end(); i++,p++ )
// if( p->valType() != Param::TITLE ) { // if( p->valType() != Param::TITLE ) {
// if( p->valType() != Param::BOOL ){ // if( p->valType() != Param::BOOL ){
// cout << ( (!p->required())?"[":""); // cout << ( (!p->required())?"[":"");
// cout <<p->shortName()<<" value"<<i; // cout <<p->shortName()<<" value"<<i;
// cout << ( (!p->required())?"]":"")<<" "; // cout << ( (!p->required())?"]":"")<<" ";
// }else{ // }else{
// cout << "["<<p->shortName()<<"] "; // cout << "["<<p->shortName()<<"] ";
// } // }
// } // for p // } // for p
cout << "Where:"<<endl; cout << "Where:"<<endl;
for ( p=params.begin(); p!=params.end(); p++ ) { for ( p=params.begin(); p!=params.end(); p++ ) {
@ -814,34 +814,7 @@ private:
}; };
/// Reproducible random seed
// Maybe there is a better place for this subroutine (a separate .cpp?)
#include <eoRNG.h>
//----------------------------------
void InitRandom( Parser & parser) {
//----------------------------------
unsigned long _seed;
try {
_seed = parser.getUnsignedLong("-S", "--seed", "0", "Seed for Random number generator" );
}
catch (UException & e)
{
cout << e.what() << endl;
parser.printHelp();
exit(1);
}
if (_seed == 0) { // use clock to get a "random" seed
_seed = (unsigned long)( time( 0 ) );
ostrstream s;
s << _seed;
parser.setParamValue("--seed", s.str()); // so it will be printed out in the status file, and canbe later re-used to re-run EXACTLY the same run
}
rng.reseed(_seed);
return;
}
#endif #endif

32
eo/src/eoParserUtils.cpp Normal file
View file

@ -0,0 +1,32 @@
// See eoParserUtils.h
#include <iostream.h>
#include <eoParserUtils.h>
/// Reproducible random seed
//----------------------------------
void InitRandom( Parser & parser) {
//----------------------------------
unsigned long _seed;
try {
_seed = parser.getUnsignedLong("-S", "--seed", "0",
"Seed for Random number generator" );
}
catch (UException & e)
{
cout << e.what() << endl;
parser.printHelp();
exit(1);
}
if (_seed == 0) { // use clock to get a "random" seed
_seed = (unsigned long)( time( 0 ) );
ostrstream s;
s << _seed;
parser.setParamValue("--seed", s.str()); // so it will be printed out in the status file, and canbe later re-used to re-run EXACTLY the same run
}
rng.reseed(_seed);
return;
}

24
eo/src/eoParserUtils.h Normal file
View file

@ -0,0 +1,24 @@
/*-------------------------------------------------------
File..........: eoParserUtils.h
Author........: Geneura Team, Marc Shoenauer
(this file: Victor Rivas, vrivas@ujaen.es)
Date..........: 17-Dec-1999
Description...: Some useful things that use eoParser.
Modifications.:
------------------- 1 -------------------
Author.......:
Date.........:
Description..:
*/
#ifndef EO_PARSER_UTILS
#define EO_PARSER_UTILS
#include <eoRNG.h>
#include <eoParser.h>
/// Reproducible random seed
//----------------------------------
void InitRandom( Parser & parser);
//----------------------------------
#endif