diff --git a/eo/src/utils/ChangeLog b/eo/src/utils/ChangeLog index 74ea2e1b..0f6b6cbd 100644 --- a/eo/src/utils/ChangeLog +++ b/eo/src/utils/ChangeLog @@ -1,5 +1,7 @@ 2006-12-02 Jochen Küpper + * eoTimedMonitor.h (eoTimedMonitor::seconds): Make unsigned. + * eoRNG.h: Cleanup docs and document /all/ members. * eoRNG.cpp, eoRNG.h (K, M, N): Declare static and initialize in cpp. diff --git a/eo/src/utils/eoRNG.cpp b/eo/src/utils/eoRNG.cpp index 1e49703e..79a53d30 100644 --- a/eo/src/utils/eoRNG.cpp +++ b/eo/src/utils/eoRNG.cpp @@ -6,13 +6,13 @@ #include #include "eoRNG.h" +// initialize static constants +const uint32_t eoRng::K(0x9908B0DFU); +const int eoRng::M(397); +const int eoRng::N(624); + namespace eo { - // initialize static constants - const uint32_t eoRng::K(0x9908B0DFU); - const int eoRng::M(397); - const int eoRng::N(624); - // global random number generator object eoRng rng(static_cast(time(0))); } diff --git a/eo/src/utils/eoTimedMonitor.h b/eo/src/utils/eoTimedMonitor.h index 4e44a2b6..c024083a 100644 --- a/eo/src/utils/eoTimedMonitor.h +++ b/eo/src/utils/eoTimedMonitor.h @@ -27,11 +27,11 @@ #ifndef _eoTimedMonitor_h #define _eoTimedMonitor_h +#include #include #include #include -#include /** Holds a collection of monitors and only fires them when a time limit @@ -39,8 +39,14 @@ */ class eoTimedMonitor : public eoMonitor { -public : - eoTimedMonitor(int seconds_) : last_tick(0), seconds(seconds_) {} +public: + + /** 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) { bool monitor = false; @@ -67,10 +73,14 @@ public : void add(eoMonitor& mon) { monitors.push_back(&mon); } virtual std::string className(void) const { return "eoTimedMonitor"; } -private : - clock_t last_tick; - int seconds; - std::vector monitors; + +private: + + clock_t last_tick; + + unsigned seconds; + + std::vector monitors; }; #endif diff --git a/eo/test/ChangeLog b/eo/test/ChangeLog new file mode 100644 index 00000000..02fb4a5e --- /dev/null +++ b/eo/test/ChangeLog @@ -0,0 +1,15 @@ +2006-12-02 Jochen Küpper + + * 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: diff --git a/eo/test/t-eoGenOp.cpp b/eo/test/t-eoGenOp.cpp index 45a790db..af8f5e69 100644 --- a/eo/test/t-eoGenOp.cpp +++ b/eo/test/t-eoGenOp.cpp @@ -35,16 +35,15 @@ struct Dummy : public EO { - typedef double Type; - Dummy(std::string _s="") : s(_s) {} + Dummy(std::string _s="") : s(_s) {} - void printOn(std::ostream & _os) const - { - EO::printOn(_os); - _os << " - " << s ; - } + void printOn(std::ostream & _os) const + { + EO::printOn(_os); + _os << " - " << s ; + } - std::string s; + std::string s; }; typedef Dummy EOT; @@ -180,18 +179,18 @@ void init(eoPop & _pop, unsigned _pSize) for (unsigned i=0; i<_pSize; i++) { std::ostringstream os; - os << i << std::ends; - _pop[i] = Dummy(os.str()); - _pop[i].fitness(i); + os << i; + _pop[i] = Dummy(os.str()); + _pop[i].fitness(i); } } // ok, now for the real work int the_main(int argc, char **argv) { - - eoParser parser(argc, argv); - eoValueParam parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P'); + eoParser parser(argc, argv); + eoValueParam parentSizeParam( + parser.createParam(unsigned(10), "parentSize", "Parent size",'P')); pSize = parentSizeParam.value(); // global variable eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); @@ -269,7 +268,7 @@ int the_main(int argc, char **argv) init(pop, pSize); // sort pop so seqPopulator is identical to SelectPopulator(SequentialSelect) 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 eoProportionalOp pSGAOp; diff --git a/eo/test/t-eoSymreg.cpp b/eo/test/t-eoSymreg.cpp index f83f3aaa..f9aebd06 100644 --- a/eo/test/t-eoSymreg.cpp +++ b/eo/test/t-eoSymreg.cpp @@ -16,44 +16,41 @@ public : enum Operator {X = 'x', Plus = '+', Min = '-', Mult = '*', PDiv = '/'}; - SymregNode(void) { init(); } - SymregNode(Operator _op) { op = _op; } - virtual ~SymregNode(void) {} + SymregNode() { init(); } + SymregNode(Operator _op) { op = _op; } + virtual ~SymregNode() {} // 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 randomize(void) {} - // evaluation function, single case, using first argument to give value of variable template void operator()(double& result, Children args, double var) const { - double r1, r2; - - if (arity() == 2) - { - args[0].apply(r1, var); - args[1].apply(r2, var); - } - - switch (op) - { - case Plus : result = r1 + r2; break; - case Min : result = r1 - r2; break; - case Mult : result = r1 * r2; break; - case PDiv : - { - if (r2 == 0.0) - result = 1.0; // protection a la Koza, realistic implementations should maybe throw an exception + double r1(0.), r2(0.); + if (arity() == 2) + { + args[0].apply(r1, var); + args[1].apply(r2, var); + } + switch (op) + { + case Plus : result = r1 + r2; break; + case Min : result = r1 - r2; break; + case Mult : result = r1 * r2; break; + case PDiv : { + if (r2 == 0.0) + // protection a la Koza, realistic implementations + // should maybe throw an exception + result = 1.0; else - result = r1 / r2; + result = r1 / r2; break; - } - - case X : result = var; break; - } - + } + case X : result = var; break; + } } /// 'Pretty' print to ostream function @@ -64,7 +61,7 @@ public : static const string rb = ")"; char opStr[4] = " "; opStr[1] = op; - + if (arity() == 0) { result = "x"; @@ -74,16 +71,16 @@ public : string r1; args[0].apply(r1); result = lb + r1; - result += opStr; + result += opStr; args[1].apply(r1); result += r1 + rb; } - Operator getOp(void) const { return op; } + Operator getOp() const { return op; } protected : - void init(void) { op = X; } + void init() { op = X; } private : @@ -98,9 +95,9 @@ static SymregNode init_sequence[5] = {SymregNode::X, SymregNode::Plus, SymregNod // 2 months later, it seems it does not accept this definition ... // but dies accept the lt_arity in eoParseTreeDepthInit // !!! -// #ifdef _MSC_VER +// #ifdef _MSC_VER // template <> -// bool lt_arity(const SymregNode &node1, const SymregNode &node2) +// bool lt_arity(const SymregNode &node1, const SymregNode &node2) // { // return (node1.arity() < node2.arity()); // } @@ -128,16 +125,16 @@ std::istream& operator>>(std::istream& is, SymregNode& eot) /** Implementation of a function evaluation object. */ double targetFunction(double x) -{ - return x * x * x * x - x * x * x + x * x * x - x * x + x - 10; +{ + return x * x * x * x - x * x * x + x * x * x - x * x + x - 10; } // parameters controlling the sampling of points const double xbegin = -10.0f; const double xend = 10.0f; -const double xstep = 1.3f; +const double xstep = 1.3f; -template struct RMS: public eoEvalFunc< eoParseTree > +template struct RMS: public eoEvalFunc< eoParseTree > { public : @@ -146,10 +143,10 @@ public : typedef eoParseTree argument_type; typedef double fitness_type; - RMS(void) : eoEvalFunc() + RMS() : eoEvalFunc() { int n = int( (xend - xbegin) / xstep); - + inputs.resize(n); target.resize(n); @@ -163,23 +160,23 @@ public : } ~RMS() {} - - void operator()( EoType & _eo ) + + void operator()( EoType & _eo ) { vector outputs; outputs.resize(inputs.size()); - + double fitness = 0.0; - + for (unsigned i = 0; i < inputs.size(); ++i) { _eo.apply(outputs[i], inputs[i]); fitness += (outputs[i] - target[i]) * (outputs[i] - target[i]); } - + fitness /= (double) target.size(); fitness = sqrt(fitness); - + if (fitness > 1e+20) fitness = 1e+20; @@ -206,12 +203,12 @@ void print_best(eoPop& pop) index = i; } } - + std::cout << "\t"; - + string str; pop[index].apply(str); - + std::cout << str.c_str(); std::cout << std::endl << "RMS Error = " << pop[index].fitness() << std::endl; } @@ -222,7 +219,7 @@ int main() typedef SymregNode GpNode; typedef eoParseTree EoType; - typedef eoPop Pop; + typedef eoPop Pop; const int MaxSize = 100; const int nGenerations = 10; // only a test, so few generations @@ -232,7 +229,7 @@ int main() // Depth Initializor, defaults to grow method. eoGpDepthInitializer initializer(10, init); - + // Root Mean Squared Error Measure RMS eval; @@ -243,18 +240,18 @@ int main() eoSubtreeXOver xover(MaxSize); eoBranchMutation mutation(initializer, MaxSize); - // The operators are encapsulated into an eoTRansform object, + // The operators are encapsulated into an eoTRansform object, // that performs sequentially crossover and mutation eoSGATransform transform(xover, 0.75, mutation, 0.25); // The robust tournament selection eoDetTournamentSelect selectOne(2); // tSize in [2,POPSIZE] // is now encapsulated in a eoSelectMany: 2 at a time -> SteadyState - eoSelectMany select(selectOne,2, eo_is_an_integer); - + eoSelectMany select(selectOne,2, eo_is_an_integer); + // and the Steady-State replacement eoSSGAWorseReplacement replace; - + // Terminators eoGenContinue term(nGenerations); @@ -289,7 +286,14 @@ int main() } print_best(pop); - } + +// Local Variables: +// coding: iso-8859-1 +// mode: C++ +// c-file-offsets: ((c . 0)) +// c-file-style: "Stroustrup" +// fill-column: 80 +// End: