Adjust code to perform to C++ standard according to gcc-3.4

interpretation... (Have not compiled/checked/changed paradisEO.)

That is, the current code compiles with gcc-3.4 and the checks
(besides t-MGE1bit) all pass.
This commit is contained in:
kuepper 2004-12-23 15:29:07 +00:00
commit 85a326c5e4
35 changed files with 1057 additions and 864 deletions

View file

@ -9,7 +9,7 @@
template <class EOT>
const EOT& select(const eoPop<EOT>& pop, params, eoRng& gen = rng);
template <class EOT>
EOT& select(eoPop<EOT>& pop, params, eoRng& gen = rng);
@ -17,7 +17,7 @@
and stochastic_tournament (at the moment).
(c) Maarten Keijzer (mak@dhi.dk) and GeNeura Team, 1999, 2000
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
@ -50,32 +50,32 @@ template <class EOT>
bool minimizing_fitness()
{
EOT eo1; // Assuming people don't do anything fancy in the default constructor!
EOT eo2;
EOT eo2;
/* Dear user, when the two line below do not compile you are most
/* Dear user, when the two line below do not compile you are most
likely not working with scalar fitness values. In that case we're sorry
but you cannot use lottery or roulette_wheel selection...
*/
#ifdef _MSC_VER
eo1.fitness( EOT::Fitness(0.0) );
eo2.fitness( EOT::Fitness(1.0) );
eo1.fitness( EOT::Fitness(0.0) );
eo2.fitness( EOT::Fitness(1.0) );
#else
eo1.fitness( typename EOT::Fitness(0.0) ); // tried to cast it to an EOT::Fitness, but for some reason GNU barfs on this
eo2.fitness( typename EOT::Fitness(1.0) );
eo1.fitness( typename EOT::Fitness(0.0) ); // tried to cast it to an EOT::Fitness, but for some reason GNU barfs on this
eo2.fitness( typename EOT::Fitness(1.0) );
#endif
return eo2 < eo1; // check whether we have a minimizing fitness
};
inline double scale_fitness(const std::pair<double, double>& _minmax, double _value)
inline double scale_fitness(const std::pair<double, double>& _minmax, double _value)
{
if (_minmax.first == _minmax.second)
{
return 0.0; // no differences in fitness, population converged!
}
// else
return (_value - _minmax.first) / (_minmax.second - _minmax.first);
}
@ -104,6 +104,8 @@ double sum_fitness(const eoPop<EOT>& _pop)
template <class EOT>
double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
{
double rawTotal, scaledTotal;
typename eoPop<EOT>::const_iterator it = _pop.begin();
_minmax.first = it->fitness();
@ -112,13 +114,13 @@ double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
for(; it != _pop.end(); ++it)
{
double v = static_cast<double>(it->fitness());
_minmax.first = std::min(_minmax.first, v);
_minmax.second = max(_minmax.second, v);
_minmax.second = std::max(_minmax.second, v);
rawTotal += v;
}
if (minimizing_fitness<EOT>())
{
std::swap(_minmax.first, _minmax.second);
@ -129,10 +131,12 @@ double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
// unfortunately a second loop is neccessary to scale the fitness
for (it = _pop.begin(); it != _pop.end(); ++it)
{
double v = scale_fitness(static_cast<double>(it->fitness()));
double v = scale_fitness(_minmax, static_cast<double>(it->fitness()));
scaledTotal += v;
}
return scaledTotal;
}
template <class It>
@ -143,14 +147,14 @@ It roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng)
if (roulette == 0.0) // covers the case where total==0.0
return _begin + _gen.random(_end - _begin); // uniform choice
It i = _begin;
while (roulette > 0.0)
{
roulette -= static_cast<double>(*(i++));
}
return --i;
}
@ -158,43 +162,43 @@ template <class EOT>
const EOT& roulette_wheel(const eoPop<EOT>& _pop, double total, eoRng& _gen = rng)
{
float roulette = _gen.uniform(total);
if (roulette == 0.0) // covers the case where total==0.0
return _pop[_gen.random(_pop.size())]; // uniform choice
typename eoPop<EOT>::const_iterator i = _pop.begin();
while (roulette > 0.0)
{
roulette -= static_cast<double>((i++)->fitness());
}
return *--i;
}
}
template <class EOT>
EOT& roulette_wheel(eoPop<EOT>& _pop, double total, eoRng& _gen = rng)
{
float roulette = _gen.uniform(total);
if (roulette == 0.0) // covers the case where total==0.0
return _pop[_gen.random(_pop.size())]; // uniform choice
typename eoPop<EOT>::iterator i = _pop.begin();
while (roulette > 0.0)
{
roulette -= static_cast<double>((i++)->fitness());
}
return *--i;
}
}
template <class It>
It deterministic_tournament(It _begin, It _end, unsigned _t_size, eoRng& _gen = rng)
{
It best = _begin + _gen.random(_end - _begin);
It best = _begin + _gen.random(_end - _begin);
for (unsigned i = 0; i < _t_size - 1; ++i)
{
It competitor = _begin + _gen.random(_end - _begin);
@ -223,8 +227,8 @@ EOT& deterministic_tournament(eoPop<EOT>& _pop, unsigned _t_size, eoRng& _gen =
template <class It>
It inverse_deterministic_tournament(It _begin, It _end, unsigned _t_size, eoRng& _gen = rng)
{
It worst = _begin + _gen.random(_end - _begin);
It worst = _begin + _gen.random(_end - _begin);
for (unsigned i = 1; i < _t_size; ++i)
{
It competitor = _begin + _gen.random(_end - _begin);
@ -257,27 +261,27 @@ EOT& inverse_deterministic_tournament(eoPop<EOT>& _pop, unsigned _t_size, eoRng&
}
template <class It>
It stochastic_tournament(It _begin, It _end, double _t_rate, eoRng& _gen = rng)
It stochastic_tournament(It _begin, It _end, double _t_rate, eoRng& _gen = rng)
{
It i1 = _begin + _gen.random(_end - _begin);
It i2 = _begin + _gen.random(_end - _begin);
bool return_better = _gen.flip(_t_rate);
if (*i1 < *i2)
if (*i1 < *i2)
{
if (return_better) return i2;
// else
return i1;
}
else
else
{
if (return_better) return i1;
// else
}
// else
return i2;
}
@ -294,27 +298,27 @@ EOT& stochastic_tournament(eoPop<EOT>& _pop, double _t_rate, eoRng& _gen = rng)
}
template <class It>
It inverse_stochastic_tournament(It _begin, It _end, double _t_rate, eoRng& _gen = rng)
It inverse_stochastic_tournament(It _begin, It _end, double _t_rate, eoRng& _gen = rng)
{
It i1 = _begin + _gen.random(_end - _begin);
It i2 = _begin + _gen.random(_end - _begin);
bool return_worse = _gen.flip(_t_rate);
if (*i1 < *i2)
if (*i1 < *i2)
{
if (return_worse) return i1;
// else
return i2;
}
else
else
{
if (return_worse) return i2;
// else
}
// else
return i1;
}