* eoTimedMonitor.h (eoTimedMonitor::seconds): Make unsigned.

* eoRNG.cpp, eoRNG.h (K, M, N): Declare static and initialize in cpp.

* t-eoGenOp.cpp (init): Do not add std::ends to end of string, as this
results in escape-codes (^@) to be printed at runtime and is not
necessary anyway.

* test/t-eoSymreg.cpp (SymregNode::operator()): Initialize r1 and r2 to
avoid compiler warnings.
This commit is contained in:
kuepper 2006-12-02 10:18:57 +00:00
commit 7baf7cb799
6 changed files with 114 additions and 84 deletions

View file

@ -1,5 +1,7 @@
2006-12-02 Jochen Küpper <jochen@fhi-berlin.mpg.de> 2006-12-02 Jochen Küpper <jochen@fhi-berlin.mpg.de>
* eoTimedMonitor.h (eoTimedMonitor::seconds): Make unsigned.
* eoRNG.h: Cleanup docs and document /all/ members. * eoRNG.h: Cleanup docs and document /all/ members.
* eoRNG.cpp, eoRNG.h (K, M, N): Declare static and initialize in cpp. * eoRNG.cpp, eoRNG.h (K, M, N): Declare static and initialize in cpp.

View file

@ -6,13 +6,13 @@
#include <ctime> #include <ctime>
#include "eoRNG.h" #include "eoRNG.h"
namespace eo
{
// initialize static constants // initialize static constants
const uint32_t eoRng::K(0x9908B0DFU); const uint32_t eoRng::K(0x9908B0DFU);
const int eoRng::M(397); const int eoRng::M(397);
const int eoRng::N(624); const int eoRng::N(624);
namespace eo
{
// global random number generator object // global random number generator object
eoRng rng(static_cast<uint32_t>(time(0))); eoRng rng(static_cast<uint32_t>(time(0)));
} }

View file

@ -27,11 +27,11 @@
#ifndef _eoTimedMonitor_h #ifndef _eoTimedMonitor_h
#define _eoTimedMonitor_h #define _eoTimedMonitor_h
#include <ctime>
#include <string> #include <string>
#include <utils/eoMonitor.h> #include <utils/eoMonitor.h>
#include <eoObject.h> #include <eoObject.h>
#include <time.h>
/** /**
Holds a collection of monitors and only fires them when a time limit Holds a collection of monitors and only fires them when a time limit
@ -40,7 +40,13 @@
class eoTimedMonitor : public eoMonitor class eoTimedMonitor : public eoMonitor
{ {
public: public:
eoTimedMonitor(int seconds_) : last_tick(0), seconds(seconds_) {}
/** Constructor
No negative time can be specified, use 0 if you want it to fire "always".
@param seconds_ Specify time limit (s).
*/
eoTimedMonitor(unsigned seconds_) : last_tick(0), seconds(seconds_) {}
eoMonitor& operator()(void) { eoMonitor& operator()(void) {
bool monitor = false; bool monitor = false;
@ -67,9 +73,13 @@ public :
void add(eoMonitor& mon) { monitors.push_back(&mon); } void add(eoMonitor& mon) { monitors.push_back(&mon); }
virtual std::string className(void) const { return "eoTimedMonitor"; } virtual std::string className(void) const { return "eoTimedMonitor"; }
private: private:
clock_t last_tick; clock_t last_tick;
int seconds;
unsigned seconds;
std::vector<eoMonitor*> monitors; std::vector<eoMonitor*> monitors;
}; };

15
eo/test/ChangeLog Normal file
View file

@ -0,0 +1,15 @@
2006-12-02 Jochen Küpper <jochen@fhi-berlin.mpg.de>
* t-eoGenOp.cpp (init): Do not add std::ends to end of string, as this
results in escape-codes (^@) to be printed at runtime and is not
necessary anyway.
* test/t-eoSymreg.cpp (SymregNode::operator()): Initialize r1 and r2 to
avoid compiler warnings.
* Local Variables:
* coding: iso-8859-1
* mode: flyspell
* fill-column: 80
* End:

View file

@ -35,7 +35,6 @@
struct Dummy : public EO<double> struct Dummy : public EO<double>
{ {
typedef double Type;
Dummy(std::string _s="") : s(_s) {} Dummy(std::string _s="") : s(_s) {}
void printOn(std::ostream & _os) const void printOn(std::ostream & _os) const
@ -180,7 +179,7 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
for (unsigned i=0; i<_pSize; i++) for (unsigned i=0; i<_pSize; i++)
{ {
std::ostringstream os; std::ostringstream os;
os << i << std::ends; os << i;
_pop[i] = Dummy(os.str()); _pop[i] = Dummy(os.str());
_pop[i].fitness(i); _pop[i].fitness(i);
} }
@ -189,9 +188,9 @@ void init(eoPop<Dummy> & _pop, unsigned _pSize)
// ok, now for the real work // ok, now for the real work
int the_main(int argc, char **argv) int the_main(int argc, char **argv)
{ {
eoParser parser(argc, argv); eoParser parser(argc, argv);
eoValueParam<unsigned int> parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P'); eoValueParam<unsigned int> parentSizeParam(
parser.createParam(unsigned(10), "parentSize", "Parent size",'P'));
pSize = parentSizeParam.value(); // global variable pSize = parentSizeParam.value(); // global variable
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S'); eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
@ -269,7 +268,7 @@ int the_main(int argc, char **argv)
init(pop, pSize); init(pop, pSize);
// sort pop so seqPopulator is identical to SelectPopulator(SequentialSelect) // sort pop so seqPopulator is identical to SelectPopulator(SequentialSelect)
pop.sort(); pop.sort();
std::cout << "Population initiale\n" << pop << std::endl; std::cout << "Population initiale" << std::endl << pop << std::endl;
// To simulate SGA: first a prop between quadOp and quadClone // To simulate SGA: first a prop between quadOp and quadClone
eoProportionalOp<EOT> pSGAOp; eoProportionalOp<EOT> pSGAOp;

View file

@ -16,44 +16,41 @@ public :
enum Operator {X = 'x', Plus = '+', Min = '-', Mult = '*', PDiv = '/'}; enum Operator {X = 'x', Plus = '+', Min = '-', Mult = '*', PDiv = '/'};
SymregNode(void) { init(); } SymregNode() { init(); }
SymregNode(Operator _op) { op = _op; } SymregNode(Operator _op) { op = _op; }
virtual ~SymregNode(void) {} virtual ~SymregNode() {}
// arity function, need this function! // arity function, need this function!
int arity(void) const { return op == X? 0 : 2; } int arity() const { return op == X? 0 : 2; }
void randomize(void) {} void randomize() {}
// evaluation function, single case, using first argument to give value of variable // evaluation function, single case, using first argument to give value of variable
template <class Children> template <class Children>
void operator()(double& result, Children args, double var) const void operator()(double& result, Children args, double var) const
{ {
double r1, r2; double r1(0.), r2(0.);
if (arity() == 2) if (arity() == 2)
{ {
args[0].apply(r1, var); args[0].apply(r1, var);
args[1].apply(r2, var); args[1].apply(r2, var);
} }
switch (op) switch (op)
{ {
case Plus : result = r1 + r2; break; case Plus : result = r1 + r2; break;
case Min : result = r1 - r2; break; case Min : result = r1 - r2; break;
case Mult : result = r1 * r2; break; case Mult : result = r1 * r2; break;
case PDiv : case PDiv : {
{
if (r2 == 0.0) if (r2 == 0.0)
result = 1.0; // protection a la Koza, realistic implementations should maybe throw an exception // protection a la Koza, realistic implementations
// should maybe throw an exception
result = 1.0;
else else
result = r1 / r2; result = r1 / r2;
break; break;
} }
case X : result = var; break; case X : result = var; break;
} }
} }
/// 'Pretty' print to ostream function /// 'Pretty' print to ostream function
@ -79,11 +76,11 @@ public :
result += r1 + rb; result += r1 + rb;
} }
Operator getOp(void) const { return op; } Operator getOp() const { return op; }
protected : protected :
void init(void) { op = X; } void init() { op = X; }
private : private :
@ -146,7 +143,7 @@ public :
typedef eoParseTree<FType, Node> argument_type; typedef eoParseTree<FType, Node> argument_type;
typedef double fitness_type; typedef double fitness_type;
RMS(void) : eoEvalFunc<EoType>() RMS() : eoEvalFunc<EoType>()
{ {
int n = int( (xend - xbegin) / xstep); int n = int( (xend - xbegin) / xstep);
@ -289,7 +286,14 @@ int main()
} }
print_best<EoType, FitnessType>(pop); print_best<EoType, FitnessType>(pop);
} }
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End: