diff --git a/eo/src/eoDetTournamentInserter.h b/eo/src/eoDetTournamentInserter.h index c4777794..845a7b38 100644 --- a/eo/src/eoDetTournamentInserter.h +++ b/eo/src/eoDetTournamentInserter.h @@ -40,31 +40,32 @@ template class eoDetTournamentInserter : public eoSteadyStateInserter { - public : - - eoDetTournamentInserter(eoEvalFunc& _eval, unsigned _t_size) : t_size(_t_size), eoSteadyStateInserter(_eval) - { - if (t_size < 2) - { // warning, error? - t_size = 2; - } - } - - eoInserter& operator()(const EOT& _eot) - { - EOT& eo = inverse_deterministic_tournament(pop(), t_size); - eo = _eot; // overwrite loser of tournament - - eo.invalidate(); // This line should probably be removed when all genetic operators do this themselves - eval(eo); // Evaluate after insert - return *this; - } - - string className(void) const { return "eoDetTournamentInserter"; } - - private : - - unsigned t_size; +public : + + eoDetTournamentInserter(eoEvalFunc& _eval, unsigned _t_size): + eoSteadyStateInserter(_eval), + t_size(_t_size) + { + if (t_size < 2) + { // warning, error? + t_size = 2; + } + } + + eoInserter& operator()(const EOT& _eot) + { + EOT& eo = inverse_deterministic_tournament(pop(), t_size); + eo = _eot; // overwrite loser of tournament + + eo.invalidate(); // This line should probably be removed when all genetic operators do this themselves + eval(eo); // Evaluate after insert + return *this; + } + + string className(void) const { return "eoDetTournamentInserter"; } + +private : + unsigned t_size; }; #endif diff --git a/eo/src/eoGOpBreeder.h b/eo/src/eoGOpBreeder.h index 8e26f77e..e4803740 100644 --- a/eo/src/eoGOpBreeder.h +++ b/eo/src/eoGOpBreeder.h @@ -35,14 +35,14 @@ class eoGOpBreeder: public eoMonPopOp * @param pop The population to be transformed. */ void operator()(eoPop& _pop) - { - int size = _pop.size(); - + { + unsigned size = _pop.size(); + for (unsigned i = 0; i < size; i++) - { // and the one liner - opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop)); - } + { // and the one liner + opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop)); } + } /// The class name. string className() const { return "eoGOpBreeder"; } diff --git a/eo/src/eoGOpSelector.h b/eo/src/eoGOpSelector.h index 27e5ad60..002c90f5 100644 --- a/eo/src/eoGOpSelector.h +++ b/eo/src/eoGOpSelector.h @@ -56,9 +56,9 @@ public: } /* - Add any kind of operator to the operator mix, - @param _op operator, one of eoMonOp, eoBinOp, eoQuadraticOp or eoGeneralOp - @param _rate the rate at which it should be applied, it should be a probability + Add any kind of operator to the operator mix, + @param _op operator, one of eoMonOp, eoBinOp, eoQuadraticOp or eoGeneralOp + @param _rate the rate at which it should be applied, it should be a probability */ virtual ID addOp( eoOp& _op, float _rate ); @@ -66,12 +66,12 @@ public: /** Retrieve the operator using its integer handle @param _id The id number. Should be a valid id, or an exception - will be thrown + will be thrown @return a reference of the operator corresponding to that id. */ virtual eoOp& getOp( ID _id ) { - return *operator[](_id); + return *operator[](_id); } /// @@ -81,7 +81,7 @@ public: /// virtual eoOp* Op() { - return &selectOp(); + return &selectOp(); } /// Select an operator from the operators present here @@ -109,70 +109,70 @@ private : /* Implementation of longish functions defined above */ template -inline eoOpSelector::ID eoGOpSelector::addOp( eoOp& _op, float _arg ) +inline eoOpSelector::ID eoGOpSelector::addOp( eoOp& _op, + float _arg ) { - - eoGeneralOp* op; - - if (_op.getType() == eoOp::general) + eoGeneralOp* op; + + if (_op.getType() == eoOp::general) { - op = static_cast*>(&_op); + op = static_cast*>(&_op); } - else + else { - // if it's not a general op, it's a "old" op; create a wrapped op from it - // and keep it on a list to delete them afterwards - // will use auto_ptr when they're readily available + // if it's not a general op, it's a "old" op; create a wrapped op from it + // and keep it on a list to delete them afterwards + // will use auto_ptr when they're readily available + + switch(_op.getType()) + { + case eoOp::unary : + op= new eoWrappedMonOp(static_cast&>(_op)); + break; + case eoOp::binary : + op = new eoWrappedBinOp(static_cast&>(_op)); + break; + case eoOp::quadratic : + op = new eoWrappedQuadraticOp(static_cast&>(_op)); + break; + } + ownOpList.push_back( op ); + } + + // Now 'op' is a general operator, either because '_op' was one or + // because we wrapped it in an appropriate wrapper in the code above. - switch(_op.getType()) - { - case eoOp::unary : - op= new eoWrappedMonOp(static_cast&>(_op)); - break; - case eoOp::binary : - op = new eoWrappedBinOp(static_cast&>(_op)); - break; - case eoOp::quadratic : - op = new eoWrappedQuadraticOp(static_cast&>(_op)); - break; - } - ownOpList.push_back( op ); - } - - // Now 'op' is a general operator, either because '_op' was one or - // because we wrapped it in an appropriate wrapper in the code above. - - iterator result = find(begin(), end(), (eoGeneralOp*) 0); // search for nullpointer + iterator result = find(begin(), end(), (eoGeneralOp*) 0); // search for nullpointer - if (result == end()) - { - push_back(op); - rates.push_back(_arg); - return size(); - } - // else + if (result == end()) + { + push_back(op); + rates.push_back(_arg); + return size(); + } + // else - *result = op; - ID id = result - begin(); - rates[id] = _arg; - return id; + *result = op; + ID id = result - begin(); + rates[id] = _arg; + return id; } template inline void eoGOpSelector::deleteOp( ID _id ) { - eoGeneralOp* op = operator[](_id); + eoGeneralOp* op = operator[](_id); - operator[](_id) = 0; - rates[_id] = 0.0; + operator[](_id) = 0; + rates[_id] = 0.0; - // check oplist and clear it there too. + // check oplist and clear it there too. - list< eoGeneralOp* >::iterator it = find(ownOpList.begin(), ownOpList.end(), op); + list< eoGeneralOp* >::iterator it = find(ownOpList.begin(), ownOpList.end(), op); - if(it != ownOpList.end()) + if(it != ownOpList.end()) { - ownOpList.erase(it); + ownOpList.erase(it); } } diff --git a/eo/src/eoSequentialGOpSelector.h b/eo/src/eoSequentialGOpSelector.h index 95716153..e77bdec7 100644 --- a/eo/src/eoSequentialGOpSelector.h +++ b/eo/src/eoSequentialGOpSelector.h @@ -35,29 +35,29 @@ template class eoSequentialGOpSel : public eoGOpSelector { - public : - - virtual ~eoSequentialGOpSel(void) {} - - virtual eoGeneralOp& selectOp() - { - combined.clear(); - - for (int i = 0; i < size(); ++i) - { - if (operator[](i) == 0) - continue; - - if (rng.flip(getRates()[i])) - combined.addOp(operator[](i)); - } - - return combined; - } - - private : - - eoCombinedOp combined; +public : + + virtual ~eoSequentialGOpSel(void) {} + + virtual eoGeneralOp& selectOp() + { + combined.clear(); + + for (unsigned i = 0; i < size(); ++i) + { + if (operator[](i) == 0) + continue; + + if (rng.flip(getRates()[i])) + combined.addOp(operator[](i)); + } + + return combined; + } + +private : + + eoCombinedOp combined; }; #endif diff --git a/eo/src/eoSteadyStateInserter.h b/eo/src/eoSteadyStateInserter.h index 1732c345..83ae0d57 100644 --- a/eo/src/eoSteadyStateInserter.h +++ b/eo/src/eoSteadyStateInserter.h @@ -40,12 +40,13 @@ template class eoSteadyStateInserter : public eoPopInserter { - public : - eoSteadyStateInserter(eoEvalFunc& _eval) : eval(_eval) , eoPopInserter() {} - - protected : - - eoEvalFunc& eval; +public : + eoSteadyStateInserter(eoEvalFunc& _eval): + eoPopInserter(), + eval(_eval) {} + +protected : + eoEvalFunc& eval; }; diff --git a/eo/src/eoStochTournamentInserter.h b/eo/src/eoStochTournamentInserter.h index dbd161b9..a6855605 100644 --- a/eo/src/eoStochTournamentInserter.h +++ b/eo/src/eoStochTournamentInserter.h @@ -41,35 +41,36 @@ template class eoStochTournamentInserter : public eoSteadyStateInserter { - public : +public : + + eoStochTournamentInserter(eoEvalFunc& _eval, double _t_rate): + eoSteadyStateInserter(_eval), t_rate(_t_rate) + { + if (t_rate < 0.5) + { // warning, error? + t_rate = 0.55; + } - eoStochTournamentInserter(eoEvalFunc& _eval, double _t_rate) : t_rate(_t_rate), eoSteadyStateInserter(_eval) - { - if (t_rate < 0.5) - { // warning, error? - t_rate = 0.55; - } - - if (t_rate >= 1.0) - { - t_rate = 0.99; // 1.0 would mean deterministic tournament - } - } + if (t_rate >= 1.0) + { + t_rate = 0.99; // 1.0 would mean deterministic tournament + } + } - eoInserter& operator()(const EOT& _eot) - { - EOT& eo = inverse_stochastic_tournament(pop(), t_rate); - eo = _eot; // overwrite loser of tournament + eoInserter& operator()(const EOT& _eot) + { + EOT& eo = inverse_stochastic_tournament(pop(), t_rate); + eo = _eot; // overwrite loser of tournament - eo.invalidate(); - eval(eo); // Evaluate after insert - return *this; - } + eo.invalidate(); + eval(eo); // Evaluate after insert + return *this; + } - string className(void) const { return "eoStochTournamentInserter"; } + string className(void) const { return "eoStochTournamentInserter"; } - private : - double t_rate; +private : + double t_rate; }; #endif diff --git a/eo/test/t-eoCheckpointing.cpp b/eo/test/t-eoCheckpointing.cpp index 742c357a..61289047 100644 --- a/eo/test/t-eoCheckpointing.cpp +++ b/eo/test/t-eoCheckpointing.cpp @@ -47,7 +47,6 @@ int the_main(int argc, char **argv) eoParser parser(argc, argv); // Define Parameters - eoValueParam& chrom_size = parser.createParam(unsigned(2), "chrom-size", "Chromosome size"); eoValueParam rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit"); eoValueParam factor(0.99, "mutationFactor", "Decrease factor for mutation rate"); eoValueParam seed(time(0), "seed", "Random number seed"); @@ -183,4 +182,4 @@ int main(int argc, char **argv) } return 1; -} \ No newline at end of file +} diff --git a/eo/test/t-eoEasyEA.cpp b/eo/test/t-eoEasyEA.cpp index bf81e63d..7b0856b9 100644 --- a/eo/test/t-eoEasyEA.cpp +++ b/eo/test/t-eoEasyEA.cpp @@ -2,9 +2,10 @@ // t-eoEasyEA.cpp //----------------------------------------------------------------------------- +#ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) - +#endif // __GNUG__ #include diff --git a/eo/test/t-eoExternalEO.cpp b/eo/test/t-eoExternalEO.cpp index d750280e..debcb1c4 100644 --- a/eo/test/t-eoExternalEO.cpp +++ b/eo/test/t-eoExternalEO.cpp @@ -110,7 +110,7 @@ int main() eoExternalBinOp cross1(UserDefBinCrossover); eoExternalQuadraticOp cross2(UserDefQuadCrossover); - eoExternalEvalFunc eval(UserDefEvalFunc); + // eoExternalEvalFunc eval(UserDefEvalFunc); EoType eo1 = init(); EoType eo2 = init(); @@ -124,4 +124,4 @@ int main() cross2(eo1,eo2); return 1; -}; \ No newline at end of file +}; diff --git a/eo/test/t-eoGOpSel.cpp b/eo/test/t-eoGOpSel.cpp index 613303f9..bd4c82f1 100644 --- a/eo/test/t-eoGOpSel.cpp +++ b/eo/test/t-eoGOpSel.cpp @@ -25,8 +25,10 @@ //-----------------------------------------------------------------------------// +#ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) +#endif // __GNUG__ #include diff --git a/eo/test/t-eoStateAndParser.cpp b/eo/test/t-eoStateAndParser.cpp index e058db3a..fad70b24 100644 --- a/eo/test/t-eoStateAndParser.cpp +++ b/eo/test/t-eoStateAndParser.cpp @@ -41,7 +41,6 @@ int the_main(int argc, char **argv) eoParser parser(argc, argv); // Define Parameters - eoValueParam& chrom_size = parser.createParam(unsigned(2), "chrom-size", "Chromosome size"); eoValueParam rate(0.01, "mutationRatePerBit", "Initial value for mutation rate per bit"); eoValueParam factor(0.99, "mutationFactor", "Decrease factor for mutation rate"); eoValueParam seed(time(0), "seed", "Random number seed"); @@ -120,4 +119,4 @@ int main(int argc, char **argv) } return 1; -} \ No newline at end of file +} diff --git a/eo/test/t-eobreeder.cpp b/eo/test/t-eobreeder.cpp index 8b7fa2d7..58a2b1b4 100644 --- a/eo/test/t-eobreeder.cpp +++ b/eo/test/t-eobreeder.cpp @@ -24,8 +24,10 @@ */ //----------------------------------------------------------------------------- +#ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) +#endif // __GNUG__ #include // eoBin, eoPop, eoBreeder #include diff --git a/eo/test/t-selectOne.cpp b/eo/test/t-selectOne.cpp index 8304c503..1125201c 100644 --- a/eo/test/t-selectOne.cpp +++ b/eo/test/t-selectOne.cpp @@ -24,8 +24,10 @@ */ //----------------------------------------------------------------------------- +#ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) +#endif // __GNUG__ #include // eoBin, eoPop, eoBreeder #include