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

@ -1,9 +1,9 @@
/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
-----------------------------------------------------------------------------
eoSelectFromWorth.h
eoSelectFromWorth.h
(c) Maarten Keijzer, Marc Schoenauer, 2001
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
@ -33,9 +33,9 @@
#include <utils/selectors.h>
//-----------------------------------------------------------------------------
/** selects one element from a population (is an eoSelectOne)
but the selection is based on a std::vector of Worth that is different
from the fitnesses (e.g. EO fitness is what Koza terms "raw fitness",
/** selects one element from a population (is an eoSelectOne)
but the selection is based on a std::vector of Worth that is different
from the fitnesses (e.g. EO fitness is what Koza terms "raw fitness",
Worth is what the selection is based upon).
see class eoPerf2Worth: an eoStat that transforms fitnesses into Worthes
@ -51,40 +51,36 @@ template <class EOT, class WorthType = double>
class eoSelectFromWorth : public eoSelectOne<EOT>
{
public:
/* Default ctor from an eoPerf2Worth object
*/
eoSelectFromWorth(eoPerf2Worth<EOT, WorthType> & _perf2Worth) :
perf2Worth(_perf2Worth) {}
/* setup the worthes */
virtual void setup(const eoPop<EOT>& _pop)
{
perf2Worth(_pop);
/* Default ctor from an eoPerf2Worth object */
eoSelectFromWorth(eoPerf2Worth<EOT, WorthType>& _perf2Worth)
: perf2Worth(_perf2Worth)
{}
/* setup the worthes */
virtual void setup(const eoPop<EOT>& pop) {
perf2Worth(pop);
#ifndef NDEBUG
fitness.resize(_pop.size());
for (unsigned i = 0; i < _pop.size(); ++i)
{
fitness[i] = _pop[i].fitness();
}
fitness.resize(pop.size());
for (unsigned i = 0; i < pop.size(); ++i) {
fitness[i] = pop[i].fitness();
}
#endif
}
}
protected:
eoPerf2Worth<EOT, WorthType> & perf2Worth;
eoPerf2Worth<EOT, WorthType>& perf2Worth;
#ifndef NDEBUG
std::vector<typename EOT::Fitness> fitness;
void check_sync(unsigned index, const EOT& _eo)
{
if (fitness[index] != _eo.fitness())
{
throw std::runtime_error("eoSelectFromWorth: fitnesses are not in sync");
std::vector<typename EOT::Fitness> fitness;
void check_sync(unsigned index, const EOT& _eo) {
if (fitness[index] != _eo.fitness()) {
throw std::runtime_error("eoSelectFromWorth: fitnesses are not in sync");
}
}
}
#endif
};
@ -95,36 +91,34 @@ template <class EOT, class WorthT = double>
class eoDetTournamentWorthSelect : public eoSelectFromWorth<EOT, WorthT>
{
public:
typedef typename std::vector<WorthT>::iterator worthIterator;
/* Default ctor from an eoPerf2Worth object + tournament size
*/
eoDetTournamentWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth,
unsigned _tSize) :
eoSelectFromWorth<EOT, WorthT>(_perf2Worth), tSize(_tSize) {}
using eoSelectFromWorth<EOT, WorthT>::perf2Worth;
/* Perform deterministic tournament on worthes
by calling the appropriate fn
see selectors.h
*/
virtual const EOT& operator()(const eoPop<EOT>& _pop)
{
worthIterator it = deterministic_tournament(
perf2Worth.value().begin(),
perf2Worth.value().end(), tSize);
typedef typename std::vector<WorthT>::iterator worthIterator;
unsigned index = it - perf2Worth.value().begin();
/* Default ctor from an eoPerf2Worth object + tournament size */
eoDetTournamentWorthSelect(eoPerf2Worth<EOT, WorthT>& perf2Worth,
unsigned _tSize)
: eoSelectFromWorth<EOT, WorthT>(perf2Worth), tSize(_tSize) {}
/* Perform deterministic tournament on worthes by calling the
appropriate fn see selectors.h */
virtual const EOT& operator()(const eoPop<EOT>& pop) {
worthIterator it = deterministic_tournament(perf2Worth.value().begin(),
perf2Worth.value().end(),
tSize);
unsigned index = it - perf2Worth.value().begin();
#ifndef NDEBUG
// check whether the stuff is still in sync
check_sync(index, _pop[index]);
// check whether the stuff is still in sync
check_sync(index, pop[index]);
#endif
return pop[index];
}
return _pop[index];
}
private:
unsigned tSize;
unsigned tSize;
};
/** An instance of eoSelectPerf2Worth that does selection from the Worthes
@ -134,24 +128,25 @@ template <class EOT, class WorthT = double>
class eoStochTournamentWorthSelect : public eoSelectFromWorth<EOT, WorthT>
{
public:
typedef typename std::vector<WorthT>::iterator worthIterator;
/* Default ctor from an eoPerf2Worth object + tournament rate
*/
eoStochTournamentWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth,
double _tRate) :
eoSelectFromWorth<EOT, WorthT>(_perf2Worth), tRate(_tRate) {}
using eoSelectFromWorth<EOT, WorthT>::perf2Worth;
typedef typename std::vector<WorthT>::iterator worthIterator;
/* Default ctor from an eoPerf2Worth object + tournament rate */
eoStochTournamentWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth, double _tRate)
: eoSelectFromWorth<EOT, WorthT>(_perf2Worth), tRate(_tRate)
{}
/* Perform stochastic tournament on worthes
by calling the appropriate fn in selectors.h
*/
virtual const EOT& operator()(const eoPop<EOT>& _pop)
{
worthIterator it = stochastic_tournament(
perf2Worth.value().begin(),
perf2Worth.value().end(), tRate);
virtual const EOT& operator()(const eoPop<EOT>& _pop) {
worthIterator it = stochastic_tournament(perf2Worth.value().begin(),
perf2Worth.value().end(),
tRate);
unsigned index = it - perf2Worth.value().begin();
unsigned index = it - perf2Worth.value().begin();
#ifndef NDEBUG
// check whether the stuff is still in sync
@ -172,12 +167,16 @@ template <class EOT, class WorthT = double>
class eoRouletteWorthSelect : public eoSelectFromWorth<EOT, WorthT>
{
public:
typedef typename std::vector<WorthT>::iterator worthIterator;
/* Default ctor from an eoPerf2Worth object
*/
eoRouletteWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth) :
eoSelectFromWorth<EOT, WorthT>(_perf2Worth) {}
using eoSelectFromWorth<EOT, WorthT>::perf2Worth;
typedef typename std::vector<WorthT>::iterator worthIterator;
/* Default ctor from an eoPerf2Worth object */
eoRouletteWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth)
: eoSelectFromWorth<EOT, WorthT>(_perf2Worth)
{}
/* We have to override the default behavior to compute the total
* only once!
@ -195,18 +194,16 @@ public:
by calling the appropriate fn
see selectors.h
*/
virtual const EOT& operator()(const eoPop<EOT>& _pop)
{
// cout << "On affiche les worths\n";
// for (unsigned i=0;
// i<perf2Worth.value().size();
// i++)
// cout << perf2Worth.value().operator[](i) << "\n";
// cout << endl;
worthIterator it = roulette_wheel(
perf2Worth.value().begin(),
perf2Worth.value().end(),
total);
virtual const EOT& operator()(const eoPop<EOT>& _pop) {
// cout << "On affiche les worths\n";
// for (unsigned i=0;
// i<perf2Worth.value().size();
// i++)
// cout << perf2Worth.value().operator[](i) << "\n";
// cout << endl;
worthIterator it = roulette_wheel(perf2Worth.value().begin(),
perf2Worth.value().end(),
total);
unsigned index = it - perf2Worth.value().begin();
@ -216,7 +213,7 @@ public:
#endif
return _pop[index];
return _pop[it-perf2Worth.value().begin()];
return _pop[it - perf2Worth.value().begin()];
}
private: