Moving function InitRamdom to eoParserUtils.h
This commit is contained in:
parent
d3642e4fde
commit
5a735c3915
4 changed files with 883 additions and 852 deletions
|
|
@ -5,20 +5,22 @@
|
|||
###############################################################################
|
||||
|
||||
lib_LIBRARIES = libeo.a
|
||||
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp
|
||||
libeo_a_SOURCES = eoPrintable.cpp eoPersistent.cpp eoParserUtils.cpp
|
||||
|
||||
libeoincdir = $(includedir)/eo
|
||||
libeoinc_HEADERS = EO.h eo eo1d.h eo2d.h eo2dVector.h eoAged.h eoAlgo.h\
|
||||
eoAtomBitFlip.h eoAtomCreep.h eoAtomMutation.h eoAtomMutator.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\
|
||||
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\
|
||||
eoParser.h eoPersistent.h eoPop.h eoPopOps.h eoPrintable.h\
|
||||
eoProblem.h eoProportionalOpSel.h eoRNG.h eoRnd.h eoString.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
|
||||
|
||||
|
|
|
|||
|
|
@ -45,20 +45,20 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/**
|
||||
* 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
|
||||
ion)+
|
||||
ion)+
|
||||
* to avoid conflicts with other classes.
|
||||
*/
|
||||
class UException: public exception {
|
||||
public:
|
||||
public:
|
||||
///
|
||||
UException( const string& _msg ): msg( _msg ) { };
|
||||
|
||||
///
|
||||
virtual const char* what() const { return msg.c_str(); };
|
||||
|
||||
private:
|
||||
private:
|
||||
string msg;
|
||||
};
|
||||
|
||||
|
|
@ -686,7 +686,7 @@ public:
|
|||
*/
|
||||
void printHelp() {
|
||||
vector<Param>::iterator p;
|
||||
// unsigned i;
|
||||
// unsigned i;
|
||||
|
||||
// print program name and description
|
||||
cout << this->programName <<": "<<programDescription<<endl<<endl;
|
||||
|
|
@ -696,16 +696,16 @@ public:
|
|||
// only short usage!
|
||||
cout << "Options of the form \"-ShortName value\" or \"--LongName value\"" << endl;
|
||||
|
||||
// for ( i=0,p=params.begin(); p!=params.end(); i++,p++ )
|
||||
// if( p->valType() != Param::TITLE ) {
|
||||
// if( p->valType() != Param::BOOL ){
|
||||
// cout << ( (!p->required())?"[":"");
|
||||
// cout <<p->shortName()<<" value"<<i;
|
||||
// cout << ( (!p->required())?"]":"")<<" ";
|
||||
// }else{
|
||||
// cout << "["<<p->shortName()<<"] ";
|
||||
// }
|
||||
// } // for p
|
||||
// for ( i=0,p=params.begin(); p!=params.end(); i++,p++ )
|
||||
// if( p->valType() != Param::TITLE ) {
|
||||
// if( p->valType() != Param::BOOL ){
|
||||
// cout << ( (!p->required())?"[":"");
|
||||
// cout <<p->shortName()<<" value"<<i;
|
||||
// cout << ( (!p->required())?"]":"")<<" ";
|
||||
// }else{
|
||||
// cout << "["<<p->shortName()<<"] ";
|
||||
// }
|
||||
// } // for p
|
||||
cout << "Where:"<<endl;
|
||||
|
||||
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
|
||||
|
|
|
|||
32
eo/src/eoParserUtils.cpp
Normal file
32
eo/src/eoParserUtils.cpp
Normal 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
24
eo/src/eoParserUtils.h
Normal 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
|
||||
Reference in a new issue