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:
parent
faaadf7599
commit
85a326c5e4
35 changed files with 1057 additions and 864 deletions
|
|
@ -464,4 +464,5 @@ namespace mlp {
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode:C++
|
// mode:C++
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
// End:
|
// End:
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
catch (exception& e)
|
catch (exception& e)
|
||||||
{
|
{
|
||||||
cerr << argv[0] << ": " << e.what() << endl;
|
cerr << argv[0] << ": " << e.what() << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
Marc.Schoenauer@polytechnique.fr
|
Marc.Schoenauer@polytechnique.fr
|
||||||
CVS Info: $Date: 2003-02-27 19:26:44 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/contrib/MGE/eoVirus.h,v 1.2 2003-02-27 19:26:44 okoenig Exp $ $Author: okoenig $
|
CVS Info: $Date: 2004-12-23 15:29:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/contrib/MGE/eoVirus.h,v 1.3 2004-12-23 15:29:07 kuepper Exp $ $Author: kuepper $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef eoVirus_h
|
#ifndef eoVirus_h
|
||||||
|
|
@ -43,9 +43,15 @@ CVS Info: $Date: 2003-02-27 19:26:44 $ $Header: /home/nojhan/dev/eodev/eodev_cvs
|
||||||
\ingroup bitstring
|
\ingroup bitstring
|
||||||
* based on STL's vector<bool> specialization.
|
* based on STL's vector<bool> specialization.
|
||||||
*/
|
*/
|
||||||
template <class FitT> class eoVirus: public eoBit<FitT>
|
template <class FitT>
|
||||||
|
class eoVirus: public eoBit<FitT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using eoBit<FitT>::begin;
|
||||||
|
using eoBit<FitT>::end;
|
||||||
|
using eoBit<FitT>::size;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Default) Constructor.
|
* (Default) Constructor.
|
||||||
|
|
@ -110,3 +116,9 @@ template <class FitT> class eoVirus: public eoBit<FitT>
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif //eoBit_h
|
#endif //eoBit_h
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: C++
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// End:
|
||||||
|
|
|
||||||
|
|
@ -46,16 +46,14 @@
|
||||||
template <class EoType>
|
template <class EoType>
|
||||||
class eoDominanceMap : public eoUF<const eoPop<EoType>&, void>, public std::vector<std::vector<bool> >
|
class eoDominanceMap : public eoUF<const eoPop<EoType>&, void>, public std::vector<std::vector<bool> >
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
/**
|
/** Clears the map */
|
||||||
Clears the map
|
void clear() {
|
||||||
*/
|
std::vector<std::vector<bool> >::clear();
|
||||||
void clear()
|
#warning Is this correct? Was: "fitnesses.clear()"
|
||||||
{
|
fitness.clear();
|
||||||
std::vector<std::vector<bool> >::clear();
|
}
|
||||||
fitnesses.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Update or create the dominance map
|
Update or create the dominance map
|
||||||
|
|
|
||||||
|
|
@ -43,47 +43,48 @@ template <class EOT>
|
||||||
class eoLinearFitScaling : public eoPerf2Worth<EOT> // false: do not cache fitness
|
class eoLinearFitScaling : public eoPerf2Worth<EOT> // false: do not cache fitness
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* Ctor:
|
|
||||||
@param _p selective pressure (in (1,2]
|
|
||||||
@param _e exponent (1 == linear)
|
|
||||||
*/
|
|
||||||
eoLinearFitScaling(double _p=2.0):
|
|
||||||
pressure(_p) {}
|
|
||||||
|
|
||||||
/* COmputes the ranked fitness: fitnesses range in [m,M]
|
using eoLinearFitScaling< EOT >::value;
|
||||||
with m=2-pressure/popSize and M=pressure/popSize.
|
|
||||||
in between, the progression depends on exponent (linear if 1).
|
|
||||||
*/
|
|
||||||
virtual void operator()(const eoPop<EOT>& _pop)
|
|
||||||
{
|
|
||||||
unsigned pSize =_pop.size();
|
|
||||||
// value() refers to the vector of worthes (we're in an eoParamvalue)
|
|
||||||
value().resize(pSize);
|
|
||||||
|
|
||||||
// best and worse fitnesses
|
/* Ctor:
|
||||||
double bestFitness = static_cast<double> (_pop.best_element().fitness());
|
@param _p selective pressure (in (1,2])
|
||||||
// double worstFitness = static_cast<double> (_pop.worse_element().fitness());
|
@param _e exponent (1 == linear)
|
||||||
|
*/
|
||||||
|
eoLinearFitScaling(double _p=2.0)
|
||||||
|
: pressure(_p) {}
|
||||||
|
|
||||||
// average fitness
|
/* COmputes the ranked fitness: fitnesses range in [m,M]
|
||||||
double sum=0.0;
|
with m=2-pressure/popSize and M=pressure/popSize.
|
||||||
unsigned i;
|
in between, the progression depends on exponent (linear if 1).
|
||||||
for (i=0; i<pSize; i++)
|
*/
|
||||||
sum += static_cast<double>(_pop[i].fitness());
|
virtual void operator()(const eoPop<EOT>& _pop) {
|
||||||
double averageFitness = sum/pSize;
|
unsigned pSize =_pop.size();
|
||||||
|
// value() refers to the vector of worthes (we're in an eoParamvalue)
|
||||||
|
value().resize(pSize);
|
||||||
|
|
||||||
// the coefficients for linear scaling
|
// best and worse fitnesses
|
||||||
double denom = pSize*(bestFitness - averageFitness);
|
double bestFitness = static_cast<double> (_pop.best_element().fitness());
|
||||||
double alpha = (pressure-1)/denom;
|
// double worstFitness = static_cast<double> (_pop.worse_element().fitness());
|
||||||
double beta = (bestFitness - pressure*averageFitness)/denom;
|
|
||||||
|
|
||||||
for (i=0; i<pSize; i++) // truncate to 0
|
// average fitness
|
||||||
{
|
double sum=0.0;
|
||||||
value()[i] = std::max(alpha*_pop[i].fitness()+beta, 0.0);
|
unsigned i;
|
||||||
}
|
for (i=0; i<pSize; i++)
|
||||||
|
sum += static_cast<double>(_pop[i].fitness());
|
||||||
|
double averageFitness = sum/pSize;
|
||||||
|
|
||||||
|
// the coefficients for linear scaling
|
||||||
|
double denom = pSize*(bestFitness - averageFitness);
|
||||||
|
double alpha = (pressure-1)/denom;
|
||||||
|
double beta = (bestFitness - pressure*averageFitness)/denom;
|
||||||
|
|
||||||
|
for (i=0; i<pSize; i++) { // truncate to 0
|
||||||
|
value()[i] = std::max(alpha*_pop[i].fitness()+beta, 0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
double pressure; // selective pressure
|
private:
|
||||||
|
double pressure; // selective pressure
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,13 @@
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
eoNDSorting() : nasty_declone_flag_that_only_is_implemented_for_two_objectives(false)
|
using eoNDSorting< EOT >::value;
|
||||||
{}
|
|
||||||
|
eoNDSorting()
|
||||||
|
: nasty_declone_flag_that_only_is_implemented_for_two_objectives(false)
|
||||||
|
{}
|
||||||
|
|
||||||
/** Pure virtual function that calculates the 'distance' for each element in the current front
|
/** Pure virtual function that calculates the 'distance' for each element in the current front
|
||||||
Implement to create your own nondominated sorting algorithm. The size of the returned std::vector
|
Implement to create your own nondominated sorting algorithm. The size of the returned std::vector
|
||||||
|
|
@ -409,21 +412,26 @@ public :
|
||||||
double nicheSize;
|
double nicheSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** @brief Fast Elitist Non-Dominant Sorting Genetic Algorithm
|
||||||
Adapted from Deb, Agrawal, Pratab and Meyarivan: A Fast Elitist Non-Dominant Sorting Genetic Algorithm for MultiObjective Optimization: NSGA-II
|
|
||||||
KanGAL Report No. 200001
|
|
||||||
|
|
||||||
Note that this class does not do the sorting per se, but the sorting of it worth_std::vector will give the right order
|
Adapted from Deb, Agrawal, Pratab and Meyarivan: A Fast Elitist
|
||||||
|
Non-Dominant Sorting Genetic Algorithm for MultiObjective
|
||||||
|
Optimization: NSGA-II KanGAL Report No. 200001
|
||||||
|
|
||||||
The crowding distance is calculated as the sum of the distances to the nearest neighbours. As we need to return the
|
Note that this class does not do the sorting per se, but the sorting
|
||||||
penalty value, we have to invert that and invert it again in the base class, but such is life, sigh
|
of it worth_std::vector will give the right order
|
||||||
|
|
||||||
|
The crowding distance is calculated as the sum of the distances to
|
||||||
|
the nearest neighbours. As we need to return the penalty value, we
|
||||||
|
have to invert that and invert it again in the base class, but such
|
||||||
|
is life, sigh
|
||||||
*/
|
*/
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoNDSorting_II : public eoNDSorting<EOT>
|
class eoNDSorting_II : public eoNDSorting<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef std::pair<double, unsigned> double_index_pair;
|
typedef std::pair<double, unsigned> double_index_pair;
|
||||||
|
|
||||||
class compare_nodes
|
class compare_nodes
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -87,55 +87,57 @@ class eoOpContainer : public eoGenOp<EOT>
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoSequentialOp : public eoOpContainer<EOT>
|
class eoSequentialOp : public eoOpContainer<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
typedef unsigned position_type;
|
|
||||||
|
using eoOpContainer< EOT >::ops;
|
||||||
|
using eoOpContainer< EOT >::rates;
|
||||||
|
|
||||||
|
typedef unsigned position_type;
|
||||||
|
|
||||||
|
|
||||||
void apply(eoPopulator<EOT>& _pop)
|
void apply(eoPopulator<EOT>& _pop) {
|
||||||
{
|
position_type pos = _pop.tellp();
|
||||||
position_type pos = _pop.tellp();
|
for (size_t i = 0; i < rates.size(); ++i) {
|
||||||
|
_pop.seekp(pos);
|
||||||
|
do {
|
||||||
|
if (eo::rng.flip(rates[i])) {
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// apply it to all the guys in the todo std::list
|
||||||
|
(*ops[i])(_pop);
|
||||||
|
// }
|
||||||
|
// check for out of individuals and do nothing with that...
|
||||||
|
// catch(eoPopulator<EOT>::OutOfIndividuals&)
|
||||||
|
// {
|
||||||
|
// std::cout << "Warning: not enough individuals to handle\n";
|
||||||
|
// return ;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < rates.size(); ++i)
|
if (!_pop.exhausted())
|
||||||
{
|
++_pop;
|
||||||
_pop.seekp(pos);
|
}
|
||||||
|
while (!_pop.exhausted());
|
||||||
do
|
|
||||||
{
|
|
||||||
if (eo::rng.flip(rates[i]))
|
|
||||||
{
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// apply it to all the guys in the todo std::list
|
|
||||||
(*ops[i])(_pop);
|
|
||||||
// }
|
|
||||||
// check for out of individuals and do nothing with that...
|
|
||||||
// catch(eoPopulator<EOT>::OutOfIndividuals&)
|
|
||||||
// {
|
|
||||||
// std::cout << "Warning: not enough individuals to handle\n";
|
|
||||||
// return ;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_pop.exhausted())
|
|
||||||
++_pop;
|
|
||||||
}
|
}
|
||||||
while (!_pop.exhausted());
|
}
|
||||||
}
|
virtual std::string className() const {return "SequentialOp";}
|
||||||
}
|
|
||||||
virtual std::string className() const {return "SequentialOp";}
|
|
||||||
|
|
||||||
private :
|
private:
|
||||||
|
|
||||||
std::vector<size_t> to_apply;
|
std::vector<size_t> to_apply;
|
||||||
std::vector<size_t> production;
|
std::vector<size_t> production;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** The proportional versions: easy! */
|
/** The proportional versions: easy! */
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoProportionalOp : public eoOpContainer<EOT>
|
class eoProportionalOp : public eoOpContainer<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoOpContainer< EOT >::ops;
|
||||||
|
using eoOpContainer< EOT >::rates;
|
||||||
|
|
||||||
void apply(eoPopulator<EOT>& _pop)
|
void apply(eoPopulator<EOT>& _pop)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,13 @@
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoParetoRanking : public eoPerf2WorthCached<EOT, double>
|
class eoParetoRanking : public eoPerf2WorthCached<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
eoParetoRanking(eoDominanceMap<EOT>& _dominanceMap) :
|
using eoParetoRanking< EOT>::value;
|
||||||
eoPerf2WorthCached<EOT, double>(), dominanceMap(_dominanceMap) {}
|
|
||||||
|
eoParetoRanking(eoDominanceMap<EOT>& _dominanceMap)
|
||||||
|
: eoPerf2WorthCached<EOT, double>(), dominanceMap(_dominanceMap)
|
||||||
|
{}
|
||||||
|
|
||||||
void calculate_worths(const eoPop<EOT>& _pop)
|
void calculate_worths(const eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,20 +35,24 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/** Base class to transform raw fitnesses into fitness for selection
|
/** @brief Base class to transform raw fitnesses into fitness for selection
|
||||||
|
|
||||||
@see eoSelectFromWorth
|
@see eoSelectFromWorth
|
||||||
*/
|
*/
|
||||||
template <class EOT, class WorthT = double>
|
template <class EOT, class WorthT = double>
|
||||||
class eoPerf2Worth : public eoUF<const eoPop<EOT>&, void>, public eoValueParam<std::vector<WorthT> >
|
class eoPerf2Worth : public eoUF<const eoPop<EOT>&, void>, public eoValueParam<std::vector<WorthT> >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
eoPerf2Worth(std::string _description = "Worths"):eoValueParam<std::vector<WorthT> >(std::vector<WorthT>(0),
|
|
||||||
_description) {}
|
|
||||||
|
|
||||||
/**
|
using eoPerf2Worth<EOT, WorthT>::value;
|
||||||
Sort population according to worth, will keep the worths and fitness_cache in sync with the population.
|
|
||||||
*/
|
/** @brief default constructor */
|
||||||
|
eoPerf2Worth(std::string _description = "Worths")
|
||||||
|
: eoValueParam<std::vector<WorthT> >(std::vector<WorthT>(0), _description)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/** Sort population according to worth, will keep the worths and
|
||||||
|
fitness_cache in sync with the population. */
|
||||||
virtual void sort_pop(eoPop<EOT>& _pop)
|
virtual void sort_pop(eoPop<EOT>& _pop)
|
||||||
{ // start with a std::vector of indices
|
{ // start with a std::vector of indices
|
||||||
std::vector<unsigned> indices(_pop.size());
|
std::vector<unsigned> indices(_pop.size());
|
||||||
|
|
@ -75,28 +79,28 @@ class eoPerf2Worth : public eoUF<const eoPop<EOT>&, void>, public eoValueParam<s
|
||||||
std::swap(value(), tmp_worths);
|
std::swap(value(), tmp_worths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** helper class used to sort indices into populations/worths
|
/** helper class used to sort indices into populations/worths */
|
||||||
*/
|
class compare_worth
|
||||||
class compare_worth
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
compare_worth(const std::vector<WorthT>& _worths) : worths(_worths) {}
|
|
||||||
|
|
||||||
bool operator()(unsigned a, unsigned b) const
|
|
||||||
{
|
{
|
||||||
return worths[b] < worths[a]; // sort in descending (!) order
|
public:
|
||||||
}
|
|
||||||
|
|
||||||
private :
|
compare_worth(const std::vector<WorthT>& _worths) : worths(_worths) {}
|
||||||
|
|
||||||
const std::vector<WorthT>& worths;
|
bool operator()(unsigned a, unsigned b) const {
|
||||||
};
|
return worths[b] < worths[a]; // sort in descending (!) order
|
||||||
|
}
|
||||||
|
|
||||||
virtual void resize(eoPop<EOT>& _pop, unsigned sz)
|
private:
|
||||||
{
|
|
||||||
_pop.resize(sz);
|
const std::vector<WorthT>& worths;
|
||||||
value().resize(sz);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
virtual void resize(eoPop<EOT>& _pop, unsigned sz) {
|
||||||
|
_pop.resize(sz);
|
||||||
|
value().resize(sz);
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -106,8 +110,11 @@ Perf2Worth with fitness cache
|
||||||
template <class EOT, class WorthT = typename EOT::Fitness>
|
template <class EOT, class WorthT = typename EOT::Fitness>
|
||||||
class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
eoPerf2WorthCached(std::string _description = "Worths") : eoPerf2Worth<EOT, WorthT>(_description) {}
|
|
||||||
|
using eoPerf2Worth<EOT, WorthT>::value;
|
||||||
|
|
||||||
|
eoPerf2WorthCached(std::string _description = "Worths") : eoPerf2Worth<EOT, WorthT>(_description) {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -164,7 +171,7 @@ class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
||||||
indices[i] = i;
|
indices[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(indices.begin(), indices.end(), eoPerf2Worth<EOT,WorthT>::compare_worth(value()));
|
std::sort(indices.begin(), indices.end(), compare_worth(value()));
|
||||||
|
|
||||||
eoPop<EOT> tmp_pop;
|
eoPop<EOT> tmp_pop;
|
||||||
tmp_pop.resize(_pop.size());
|
tmp_pop.resize(_pop.size());
|
||||||
|
|
@ -216,22 +223,25 @@ class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
||||||
std::vector <typename EOT::Fitness> fitness_cache;
|
std::vector <typename EOT::Fitness> fitness_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
A dummy perf2worth, just in case you need it
|
|
||||||
*/
|
/** A dummy perf2worth, just in case you need it */
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoNoPerf2Worth : public eoPerf2Worth<EOT, typename EOT::Fitness>
|
class eoNoPerf2Worth : public eoPerf2Worth<EOT, typename EOT::Fitness>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using eoValueParam< EOT >::value;
|
||||||
|
|
||||||
// default behaviour, just copy fitnesses
|
// default behaviour, just copy fitnesses
|
||||||
void operator()(const eoPop<EOT>& _pop)
|
void operator()(const eoPop<EOT>& _pop) {
|
||||||
{
|
unsigned i;
|
||||||
unsigned i;
|
value().resize(_pop.size());
|
||||||
value.resize(_pop.size());
|
for (i = 0; i < _pop.size(); ++i)
|
||||||
for (i = 0; i < _pop.size(); ++i)
|
value()[i]=_pop[i];
|
||||||
value()[i]=_pop[i];
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -120,15 +120,15 @@ public :
|
||||||
*/
|
*/
|
||||||
virtual const EOT& select() = 0;
|
virtual const EOT& select() = 0;
|
||||||
|
|
||||||
protected :
|
protected:
|
||||||
eoPop<EOT>& dest;
|
eoPop<EOT>& dest;
|
||||||
typename eoPop<EOT>::iterator current;
|
typename eoPop<EOT>::iterator current;
|
||||||
const eoPop<EOT>& src;
|
const eoPop<EOT>& src;
|
||||||
|
|
||||||
private :
|
private:
|
||||||
void get_next()
|
|
||||||
{
|
void get_next() {
|
||||||
if (current == dest.end())
|
if(current == dest.end())
|
||||||
{ // get new individual from derived class select()
|
{ // get new individual from derived class select()
|
||||||
dest.push_back(select());
|
dest.push_back(select());
|
||||||
current = dest.end();
|
current = dest.end();
|
||||||
|
|
@ -143,31 +143,34 @@ private :
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** SeqPopulator: an eoPopulator that sequentially goes through the population
|
/** SeqPopulator: an eoPopulator that sequentially goes through the
|
||||||
is supposed to be used after a batch select of a whole bunch or genitors
|
population is supposed to be used after a batch select of a whole
|
||||||
*/
|
bunch or genitors
|
||||||
|
*/
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoSeqPopulator : public eoPopulator<EOT>
|
class eoSeqPopulator : public eoPopulator<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
eoSeqPopulator(const eoPop<EOT>& _pop, eoPop<EOT>& _dest) :
|
eoSeqPopulator(const eoPop<EOT>& _pop, eoPop<EOT>& _dest) :
|
||||||
eoPopulator<EOT>(_pop, _dest), current(0) {}
|
eoPopulator<EOT>(_pop, _dest), current(0) {}
|
||||||
|
|
||||||
/** the select method simply returns next individual in the src pop */
|
/** the select method simply returns next individual in the src pop */
|
||||||
const EOT& select(void)
|
const EOT& select(void) {
|
||||||
{
|
if(current >= eoPopulator< EOT >::src.size()) {
|
||||||
if (current >= src.size())
|
throw OutOfIndividuals();
|
||||||
{
|
}
|
||||||
throw OutOfIndividuals();
|
|
||||||
}
|
|
||||||
|
|
||||||
const EOT& res = src[current++];
|
const EOT& res = eoPopulator< EOT >::src[current++];
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
|
||||||
unsigned current;
|
private:
|
||||||
|
|
||||||
|
struct OutOfIndividuals {};
|
||||||
|
|
||||||
|
unsigned current;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -178,20 +181,22 @@ template <class EOT>
|
||||||
class eoSelectivePopulator : public eoPopulator<EOT>
|
class eoSelectivePopulator : public eoPopulator<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
eoSelectivePopulator(const eoPop<EOT>& _pop, eoPop<EOT>& _dest, eoSelectOne<EOT>& _sel)
|
|
||||||
: eoPopulator<EOT>(_pop, _dest), sel(_sel)
|
using eoPopulator< EOT >::src;
|
||||||
{
|
|
||||||
sel.setup(_pop);
|
eoSelectivePopulator(const eoPop<EOT>& _pop, eoPop<EOT>& _dest, eoSelectOne<EOT>& _sel)
|
||||||
|
: eoPopulator<EOT>(_pop, _dest), sel(_sel)
|
||||||
|
{ sel.setup(_pop); };
|
||||||
|
|
||||||
|
/** the select method actually selects one guy from the src pop */
|
||||||
|
const EOT& select() {
|
||||||
|
return sel(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** the select method actually selects one guy from the src pop */
|
|
||||||
const EOT& select()
|
|
||||||
{
|
|
||||||
return sel(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
private :
|
private:
|
||||||
eoSelectOne<EOT>& sel;
|
|
||||||
|
eoSelectOne<EOT>& sel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,9 @@ template <class EOT>
|
||||||
class eoRanking : public eoPerf2Worth<EOT> // false: do not cache fitness
|
class eoRanking : public eoPerf2Worth<EOT> // false: do not cache fitness
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using eoRanking< EOT >::value;
|
||||||
|
|
||||||
/* Ctor:
|
/* Ctor:
|
||||||
@param _p selective pressure (in (1,2]
|
@param _p selective pressure (in (1,2]
|
||||||
@param _e exponent (1 == linear)
|
@param _e exponent (1 == linear)
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,12 @@ template <class ScalarType, class Compare, class FitnessTraits >
|
||||||
class eoScalarFitnessAssembled : public std::vector<ScalarType> {
|
class eoScalarFitnessAssembled : public std::vector<ScalarType> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using std::vector< ScalarType >::empty;
|
||||||
|
using std::vector< ScalarType >::front;
|
||||||
|
using std::vector< ScalarType >::size;
|
||||||
|
|
||||||
|
|
||||||
typedef typename std::vector<ScalarType> baseVector;
|
typedef typename std::vector<ScalarType> baseVector;
|
||||||
typedef typename baseVector::size_type size_type;
|
typedef typename baseVector::size_type size_type;
|
||||||
|
|
||||||
|
|
@ -130,12 +136,11 @@ public:
|
||||||
|
|
||||||
eoScalarFitnessAssembled& operator=( const ScalarType& v ) {
|
eoScalarFitnessAssembled& operator=( const ScalarType& v ) {
|
||||||
|
|
||||||
if ( empty() )
|
if( empty() )
|
||||||
push_back( v );
|
push_back( v );
|
||||||
else
|
else
|
||||||
front() = v;
|
front() = v;
|
||||||
|
return *this;
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Overload push_back()
|
//! Overload push_back()
|
||||||
|
|
|
||||||
|
|
@ -51,40 +51,36 @@ template <class EOT, class WorthType = double>
|
||||||
class eoSelectFromWorth : public eoSelectOne<EOT>
|
class eoSelectFromWorth : public eoSelectOne<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* Default ctor from an eoPerf2Worth object
|
|
||||||
*/
|
|
||||||
eoSelectFromWorth(eoPerf2Worth<EOT, WorthType> & _perf2Worth) :
|
|
||||||
perf2Worth(_perf2Worth) {}
|
|
||||||
|
|
||||||
/* setup the worthes */
|
/* Default ctor from an eoPerf2Worth object */
|
||||||
virtual void setup(const eoPop<EOT>& _pop)
|
eoSelectFromWorth(eoPerf2Worth<EOT, WorthType>& _perf2Worth)
|
||||||
{
|
: perf2Worth(_perf2Worth)
|
||||||
perf2Worth(_pop);
|
{}
|
||||||
|
|
||||||
|
/* setup the worthes */
|
||||||
|
virtual void setup(const eoPop<EOT>& pop) {
|
||||||
|
perf2Worth(pop);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
fitness.resize(_pop.size());
|
fitness.resize(pop.size());
|
||||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
for (unsigned i = 0; i < pop.size(); ++i) {
|
||||||
{
|
fitness[i] = pop[i].fitness();
|
||||||
fitness[i] = _pop[i].fitness();
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoPerf2Worth<EOT, WorthType> & perf2Worth;
|
|
||||||
|
eoPerf2Worth<EOT, WorthType>& perf2Worth;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
std::vector<typename EOT::Fitness> fitness;
|
std::vector<typename EOT::Fitness> fitness;
|
||||||
void check_sync(unsigned index, const EOT& _eo)
|
void check_sync(unsigned index, const EOT& _eo) {
|
||||||
{
|
if (fitness[index] != _eo.fitness()) {
|
||||||
if (fitness[index] != _eo.fitness())
|
throw std::runtime_error("eoSelectFromWorth: fitnesses are not in sync");
|
||||||
{
|
}
|
||||||
throw std::runtime_error("eoSelectFromWorth: fitnesses are not in sync");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -95,36 +91,34 @@ template <class EOT, class WorthT = double>
|
||||||
class eoDetTournamentWorthSelect : public eoSelectFromWorth<EOT, WorthT>
|
class eoDetTournamentWorthSelect : public eoSelectFromWorth<EOT, WorthT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename std::vector<WorthT>::iterator worthIterator;
|
|
||||||
|
|
||||||
/* Default ctor from an eoPerf2Worth object + tournament size
|
using eoSelectFromWorth<EOT, WorthT>::perf2Worth;
|
||||||
*/
|
|
||||||
eoDetTournamentWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth,
|
|
||||||
unsigned _tSize) :
|
|
||||||
eoSelectFromWorth<EOT, WorthT>(_perf2Worth), tSize(_tSize) {}
|
|
||||||
|
|
||||||
/* Perform deterministic tournament on worthes
|
typedef typename std::vector<WorthT>::iterator worthIterator;
|
||||||
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();
|
/* 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
|
#ifndef NDEBUG
|
||||||
// check whether the stuff is still in sync
|
// check whether the stuff is still in sync
|
||||||
check_sync(index, _pop[index]);
|
check_sync(index, pop[index]);
|
||||||
#endif
|
#endif
|
||||||
|
return pop[index];
|
||||||
|
}
|
||||||
|
|
||||||
return _pop[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned tSize;
|
|
||||||
|
unsigned tSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** An instance of eoSelectPerf2Worth that does selection from the Worthes
|
/** 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>
|
class eoStochTournamentWorthSelect : public eoSelectFromWorth<EOT, WorthT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename std::vector<WorthT>::iterator worthIterator;
|
|
||||||
|
|
||||||
/* Default ctor from an eoPerf2Worth object + tournament rate
|
using eoSelectFromWorth<EOT, WorthT>::perf2Worth;
|
||||||
*/
|
|
||||||
eoStochTournamentWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth,
|
typedef typename std::vector<WorthT>::iterator worthIterator;
|
||||||
double _tRate) :
|
|
||||||
eoSelectFromWorth<EOT, WorthT>(_perf2Worth), tRate(_tRate) {}
|
/* 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
|
/* Perform stochastic tournament on worthes
|
||||||
by calling the appropriate fn in selectors.h
|
by calling the appropriate fn in selectors.h
|
||||||
*/
|
*/
|
||||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
virtual const EOT& operator()(const eoPop<EOT>& _pop) {
|
||||||
{
|
worthIterator it = stochastic_tournament(perf2Worth.value().begin(),
|
||||||
worthIterator it = stochastic_tournament(
|
perf2Worth.value().end(),
|
||||||
perf2Worth.value().begin(),
|
tRate);
|
||||||
perf2Worth.value().end(), tRate);
|
|
||||||
|
|
||||||
unsigned index = it - perf2Worth.value().begin();
|
unsigned index = it - perf2Worth.value().begin();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// check whether the stuff is still in sync
|
// check whether the stuff is still in sync
|
||||||
|
|
@ -172,12 +167,16 @@ template <class EOT, class WorthT = double>
|
||||||
class eoRouletteWorthSelect : public eoSelectFromWorth<EOT, WorthT>
|
class eoRouletteWorthSelect : public eoSelectFromWorth<EOT, WorthT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename std::vector<WorthT>::iterator worthIterator;
|
|
||||||
|
|
||||||
/* Default ctor from an eoPerf2Worth object
|
using eoSelectFromWorth<EOT, WorthT>::perf2Worth;
|
||||||
*/
|
|
||||||
eoRouletteWorthSelect(eoPerf2Worth<EOT, WorthT> &_perf2Worth) :
|
typedef typename std::vector<WorthT>::iterator worthIterator;
|
||||||
eoSelectFromWorth<EOT, WorthT>(_perf2Worth) {}
|
|
||||||
|
|
||||||
|
/* 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
|
/* We have to override the default behavior to compute the total
|
||||||
* only once!
|
* only once!
|
||||||
|
|
@ -195,18 +194,16 @@ public:
|
||||||
by calling the appropriate fn
|
by calling the appropriate fn
|
||||||
see selectors.h
|
see selectors.h
|
||||||
*/
|
*/
|
||||||
virtual const EOT& operator()(const eoPop<EOT>& _pop)
|
virtual const EOT& operator()(const eoPop<EOT>& _pop) {
|
||||||
{
|
// cout << "On affiche les worths\n";
|
||||||
// cout << "On affiche les worths\n";
|
// for (unsigned i=0;
|
||||||
// for (unsigned i=0;
|
// i<perf2Worth.value().size();
|
||||||
// i<perf2Worth.value().size();
|
// i++)
|
||||||
// i++)
|
// cout << perf2Worth.value().operator[](i) << "\n";
|
||||||
// cout << perf2Worth.value().operator[](i) << "\n";
|
// cout << endl;
|
||||||
// cout << endl;
|
worthIterator it = roulette_wheel(perf2Worth.value().begin(),
|
||||||
worthIterator it = roulette_wheel(
|
perf2Worth.value().end(),
|
||||||
perf2Worth.value().begin(),
|
total);
|
||||||
perf2Worth.value().end(),
|
|
||||||
total);
|
|
||||||
|
|
||||||
unsigned index = it - perf2Worth.value().begin();
|
unsigned index = it - perf2Worth.value().begin();
|
||||||
|
|
||||||
|
|
@ -216,7 +213,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return _pop[index];
|
return _pop[index];
|
||||||
return _pop[it-perf2Worth.value().begin()];
|
return _pop[it - perf2Worth.value().begin()];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,11 @@
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoSharing : public eoPerf2Worth<EOT>
|
class eoSharing : public eoPerf2Worth<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using eoSharing< EOT >::value;
|
||||||
|
|
||||||
|
|
||||||
/* Ctor requires a distance - cannot have a default distance! */
|
/* Ctor requires a distance - cannot have a default distance! */
|
||||||
eoSharing(double _nicheSize, eoDistance<EOT> & _dist) : eoPerf2Worth<EOT>("Sharing"),
|
eoSharing(double _nicheSize, eoDistance<EOT> & _dist) : eoPerf2Worth<EOT>("Sharing"),
|
||||||
nicheSize(_nicheSize),
|
nicheSize(_nicheSize),
|
||||||
|
|
|
||||||
|
|
@ -64,22 +64,25 @@ protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** An instance (theonly one as of today, Dec. 20, 2000) of an
|
||||||
an instance (theonly one as of today, Dec. 20, 2000) of an eoSurviveAndDie,
|
eoSurviveAndDie, that does everything deterministically
|
||||||
that does everything deterministically
|
|
||||||
|
|
||||||
used in eoDeterministicSaDReplacement
|
Used in eoDeterministicSaDReplacement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoDeterministicSurviveAndDie : public eoSurviveAndDie<EOT>
|
class eoDeterministicSurviveAndDie : public eoSurviveAndDie<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
eoDeterministicSurviveAndDie(double _survive, double _die,
|
|
||||||
bool _interpret_as_rate = true):
|
using eoSurviveAndDie< EOT >::howmanyDie;
|
||||||
eoSurviveAndDie<EOT>(_survive, _die, _interpret_as_rate)
|
using eoSurviveAndDie< EOT >::howmanySurvive;
|
||||||
|
|
||||||
|
/** constructor */
|
||||||
|
eoDeterministicSurviveAndDie(double _survive, double _die, bool _interpret_as_rate = true)
|
||||||
|
: eoSurviveAndDie< EOT >(_survive, _die, _interpret_as_rate)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
void operator()(eoPop<EOT> & _pop, eoPop<EOT> & _luckyGuys)
|
void operator()(eoPop<EOT> & _pop, eoPop<EOT> & _luckyGuys)
|
||||||
{
|
{
|
||||||
unsigned pSize = _pop.size();
|
unsigned pSize = _pop.size();
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
Marc.Schoenauer@polytechnique.fr
|
Marc.Schoenauer@polytechnique.fr
|
||||||
mak@dhi.dk
|
mak@dhi.dk
|
||||||
|
|
||||||
CVS Info: $Date: 2003-03-18 16:57:17 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVector.h,v 1.15 2003-03-18 16:57:17 maartenkeijzer Exp $ $Author: maartenkeijzer $
|
CVS Info: $Date: 2004-12-23 15:29:06 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVector.h,v 1.16 2004-12-23 15:29:06 kuepper Exp $ $Author: kuepper $
|
||||||
|
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -45,14 +45,26 @@
|
||||||
template <class FitT, class GeneType>
|
template <class FitT, class GeneType>
|
||||||
class eoVector : public EO<FitT>, public std::vector<GeneType>
|
class eoVector : public EO<FitT>, public std::vector<GeneType>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using EO<FitT>::invalidate;
|
||||||
|
using std::vector<GeneType>::operator[];
|
||||||
|
using std::vector<GeneType>::begin;
|
||||||
|
using std::vector<GeneType>::end;
|
||||||
|
using std::vector<GeneType>::resize;
|
||||||
|
using std::vector<GeneType>::size;
|
||||||
|
|
||||||
typedef GeneType AtomType;
|
typedef GeneType AtomType;
|
||||||
typedef std::vector<GeneType> ContainerType;
|
typedef std::vector<GeneType> ContainerType;
|
||||||
|
|
||||||
|
/** default constructor
|
||||||
|
|
||||||
eoVector(unsigned size = 0, GeneType value = GeneType()) : EO<FitT>(), std::vector<GeneType>(size, value)
|
@param size Length of vector (default is 0)
|
||||||
{}
|
@param value Initial value of all elements (default is default value of type GeneType)
|
||||||
|
*/
|
||||||
|
eoVector(unsigned size = 0, GeneType value = GeneType())
|
||||||
|
: EO<FitT>(), std::vector<GeneType>(size, value)
|
||||||
|
{}
|
||||||
|
|
||||||
/// copy ctor abstracting from the FitT
|
/// copy ctor abstracting from the FitT
|
||||||
template <class OtherFitnessType>
|
template <class OtherFitnessType>
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,11 @@ rates and correlated mutations.
|
||||||
template <class Fit>
|
template <class Fit>
|
||||||
class eoEsFull : public eoVector<Fit, double>
|
class eoEsFull : public eoVector<Fit, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoEsFull< Fit >::size;
|
||||||
|
|
||||||
|
|
||||||
typedef double Type;
|
typedef double Type;
|
||||||
|
|
||||||
eoEsFull(void) : eoVector<Fit, double>() {}
|
eoEsFull(void) : eoVector<Fit, double>() {}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,9 @@ deviations.
|
||||||
template <class Fit>
|
template <class Fit>
|
||||||
class eoEsStdev : public eoVector<Fit, double>
|
class eoEsStdev : public eoVector<Fit, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoEsStdev< Fit >::size;
|
||||||
|
|
||||||
typedef double Type;
|
typedef double Type;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,10 @@ private:
|
||||||
* but this sometimes takes a long time!!!
|
* but this sometimes takes a long time!!!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<class EOT> class eoNormalMutation: public eoMonOp<EOT>
|
template<class EOT> class eoNormalMutation
|
||||||
|
: public eoMonOp<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* (Default) Constructor.
|
* (Default) Constructor.
|
||||||
* The bounds are initialized with the global object that says: no bounds.
|
* The bounds are initialized with the global object that says: no bounds.
|
||||||
|
|
@ -177,7 +178,10 @@ template<class EOT> class eoOneFifthMutation :
|
||||||
public eoNormalMutation<EOT>, public eoUpdatable
|
public eoNormalMutation<EOT>, public eoUpdatable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename EOT::Fitness Fitness;
|
|
||||||
|
using eoNormalMutation< EOT >::Sigma;
|
||||||
|
|
||||||
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Default) Constructor.
|
* (Default) Constructor.
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,11 @@
|
||||||
*/
|
*/
|
||||||
template <class FitT> class eoBit: public eoVector<FitT, bool>
|
template <class FitT> class eoBit: public eoVector<FitT, bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using eoVector< FitT, bool >::begin;
|
||||||
|
using eoVector< FitT, bool >::end;
|
||||||
|
using eoVector< FitT, bool >::size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Default) Constructor.
|
* (Default) Constructor.
|
||||||
|
|
@ -104,3 +108,9 @@ template <class FitT> class eoBit: public eoVector<FitT, bool>
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#endif //eoBit_h
|
#endif //eoBit_h
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: C++
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// End:
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,8 @@ public:
|
||||||
p[g] += lrw;
|
p[g] += lrw;
|
||||||
}
|
}
|
||||||
// stay in [0,1] (possibly strictly due to tolerance)
|
// stay in [0,1] (possibly strictly due to tolerance)
|
||||||
p[g] = min(maxBound, p[g]);
|
p[g] = std::min(maxBound, p[g]);
|
||||||
p[g] = max(minBound, p[g]);
|
p[g] = std::max(minBound, p[g]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,21 +57,25 @@ using namespace gp_parse_tree;
|
||||||
template <class FType, class Node>
|
template <class FType, class Node>
|
||||||
class eoParseTree : public EO<FType>, public parse_tree<Node>
|
class eoParseTree : public EO<FType>, public parse_tree<Node>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoParseTree<FType, Node >::back;
|
||||||
|
using eoParseTree<FType, Node >::ebegin;
|
||||||
|
using eoParseTree<FType, Node >::eend;
|
||||||
|
using eoParseTree<FType, Node >::size;
|
||||||
|
|
||||||
|
|
||||||
typedef typename parse_tree<Node>::subtree Subtree;
|
typedef typename parse_tree<Node>::subtree Subtree;
|
||||||
|
|
||||||
/* For Compatibility with the intel C++ compiler for Linux 5.x */
|
/* For Compatibility with the intel C++ compiler for Linux 5.x */
|
||||||
typedef Node reference;
|
typedef Node reference;
|
||||||
typedef const reference const_reference;
|
typedef const reference const_reference;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*/
|
*/
|
||||||
eoParseTree(void) {}
|
eoParseTree(void) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy Constructor
|
* Copy Constructor
|
||||||
* @param tree The tree to copy
|
* @param tree The tree to copy
|
||||||
|
|
|
||||||
|
|
@ -656,7 +656,7 @@ private :
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
base_iterator() {}
|
base_iterator() {}
|
||||||
base_iterator(subtree* n) { node = n; }
|
base_iterator(subtree* n) { node = n; }
|
||||||
|
|
||||||
base_iterator& operator=(const base_iterator& org)
|
base_iterator& operator=(const base_iterator& org)
|
||||||
|
|
@ -719,13 +719,16 @@ private :
|
||||||
|
|
||||||
class iterator : public base_iterator
|
class iterator : public base_iterator
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
typedef std::forward_iterator_tag iterator_category;
|
|
||||||
typedef subtree value_type;
|
using base_iterator::node;
|
||||||
typedef size_t distance_type;
|
|
||||||
typedef size_t difference_type;
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
typedef subtree* pointer;
|
typedef subtree value_type;
|
||||||
typedef subtree& reference;
|
typedef size_t distance_type;
|
||||||
|
typedef size_t difference_type;
|
||||||
|
typedef subtree* pointer;
|
||||||
|
typedef subtree& reference;
|
||||||
|
|
||||||
iterator() : base_iterator() {}
|
iterator() : base_iterator() {}
|
||||||
iterator(subtree* n): base_iterator(n) {}
|
iterator(subtree* n): base_iterator(n) {}
|
||||||
|
|
@ -736,15 +739,20 @@ private :
|
||||||
subtree* operator->(void) { return node; }
|
subtree* operator->(void) { return node; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class embedded_iterator : public base_iterator
|
class embedded_iterator : public base_iterator
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
typedef std::forward_iterator_tag iterator_category;
|
|
||||||
typedef T value_type;
|
using base_iterator::node;
|
||||||
typedef size_t distance_type;
|
|
||||||
typedef size_t difference_type;
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
typedef T* pointer;
|
typedef T value_type;
|
||||||
typedef T& reference;
|
typedef size_t distance_type;
|
||||||
|
typedef size_t difference_type;
|
||||||
|
typedef T* pointer;
|
||||||
|
typedef T& reference;
|
||||||
|
|
||||||
embedded_iterator() : base_iterator() {}
|
embedded_iterator() : base_iterator() {}
|
||||||
embedded_iterator(subtree* n): base_iterator(n) {}
|
embedded_iterator(subtree* n): base_iterator(n) {}
|
||||||
|
|
@ -757,7 +765,8 @@ private :
|
||||||
|
|
||||||
class base_const_iterator
|
class base_const_iterator
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
base_const_iterator() {}
|
base_const_iterator() {}
|
||||||
base_const_iterator(const subtree* n) { node = n; }
|
base_const_iterator(const subtree* n) { node = n; }
|
||||||
|
|
||||||
|
|
@ -808,13 +817,16 @@ private :
|
||||||
|
|
||||||
class const_iterator : public base_const_iterator
|
class const_iterator : public base_const_iterator
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
typedef std::forward_iterator_tag iterator_category;
|
|
||||||
typedef const subtree value_type;
|
using base_iterator::node;
|
||||||
typedef size_t distance_type;
|
|
||||||
typedef size_t difference_type;
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
typedef const subtree* pointer;
|
typedef const subtree value_type;
|
||||||
typedef const subtree& reference;
|
typedef size_t distance_type;
|
||||||
|
typedef size_t difference_type;
|
||||||
|
typedef const subtree* pointer;
|
||||||
|
typedef const subtree& reference;
|
||||||
|
|
||||||
const_iterator() : base_const_iterator() {}
|
const_iterator() : base_const_iterator() {}
|
||||||
const_iterator(const subtree* n): base_const_iterator(n) {}
|
const_iterator(const subtree* n): base_const_iterator(n) {}
|
||||||
|
|
@ -827,7 +839,10 @@ private :
|
||||||
|
|
||||||
class embedded_const_iterator : public base_const_iterator
|
class embedded_const_iterator : public base_const_iterator
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using base_const_iterator::node;
|
||||||
|
|
||||||
typedef std::forward_iterator_tag iterator_category;
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
typedef const T value_type;
|
typedef const T value_type;
|
||||||
typedef size_t distance_type;
|
typedef size_t distance_type;
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,18 @@ class eoExternalEO : public EO<Fit>, virtual public External
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
eoExternalEO(void) : EO<Fit>(), External() {}
|
eoExternalEO(void)
|
||||||
|
: EO<Fit>(), External()
|
||||||
|
{}
|
||||||
|
|
||||||
/**
|
/** Init externalEo with the struct itself and set fitness to zero */
|
||||||
Init externalEo with the struct itself and set fitness to zero
|
eoExternalEO(const External& ext)
|
||||||
*/
|
: EO<Fit>(), External(ext)
|
||||||
eoExternalEO(const External& ext) : EO<Fit>(), External(ext) {}
|
{}
|
||||||
eoExternalEO(std::istream& is) : EO<Fit>(), External(ext) { readFrom(is); }
|
|
||||||
|
eoExternalEO(std::istream& is, const External& ext)
|
||||||
|
: EO<Fit>(), External(ext)
|
||||||
|
{ readFrom(is); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read object, the external struct needs to have an operator>> defined
|
* Read object, the external struct needs to have an operator>> defined
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#define _eoString_H
|
#define _eoString_H
|
||||||
|
|
||||||
// STL libraries
|
// STL libraries
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
@ -42,9 +43,10 @@ class eoString: public EO<fitnessT>, public std::string
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef char Type;
|
typedef char Type;
|
||||||
typedef char AtomType;
|
typedef char AtomType;
|
||||||
typedef std::string ContainerType;
|
typedef std::string ContainerType;
|
||||||
|
|
||||||
|
|
||||||
/// Canonical part of the objects: several ctors, copy ctor, dtor and assignment operator
|
/// Canonical part of the objects: several ctors, copy ctor, dtor and assignment operator
|
||||||
//@{
|
//@{
|
||||||
|
|
@ -58,7 +60,7 @@ public:
|
||||||
EO<fitnessT>::printOn(os);
|
EO<fitnessT>::printOn(os);
|
||||||
os << ' ';
|
os << ' ';
|
||||||
|
|
||||||
os << size() << ' ' << substr() << endl;
|
os << size() << ' ' << substr() << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,19 @@ class eoAssembledFitnessAverageStat : public eoStat<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
using eoAssembledFitnessAverageStat< EOT >::value;
|
||||||
|
|
||||||
eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness")
|
typedef typename EOT::Fitness Fitness;
|
||||||
: eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
|
|
||||||
|
|
||||||
virtual void operator()(const eoPop<EOT>& _pop){
|
|
||||||
|
|
||||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
eoAssembledFitnessAverageStat(unsigned _whichTerm=0, std::string _description = "Average Fitness")
|
||||||
throw std::logic_error("Fitness term requested out of range");
|
: eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
virtual void operator()(const eoPop<EOT>& _pop) {
|
||||||
|
if( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||||
|
throw std::logic_error("Fitness term requested out of range");
|
||||||
|
|
||||||
double result =0.0;
|
double result =0.0;
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
|
|
@ -82,23 +86,27 @@ private:
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoAssembledFitnessBestStat : public eoStat<EOT, double>
|
class eoAssembledFitnessBestStat : public eoStat<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
typedef typename EOT::Fitness Fitness;
|
|
||||||
|
|
||||||
eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness")
|
using eoAssembledFitnessBestStat< EOT >::value;
|
||||||
: eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm) {}
|
|
||||||
|
|
||||||
virtual void operator()(const eoPop<EOT>& _pop){
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
if ( whichFitnessTerm >= _pop[0].fitness().size() )
|
eoAssembledFitnessBestStat(unsigned _whichTerm=0, std::string _description = "Best Fitness")
|
||||||
throw std::logic_error("Fitness term requested out of range");
|
: eoStat<EOT, double>(Fitness(), _description), whichFitnessTerm(_whichTerm)
|
||||||
|
{}
|
||||||
|
|
||||||
value() = _pop.best_element().fitness()[whichFitnessTerm];
|
virtual void operator()(const eoPop<EOT>& _pop) {
|
||||||
}
|
if( whichFitnessTerm >= _pop[0].fitness().size() )
|
||||||
|
throw std::logic_error("Fitness term requested out of range");
|
||||||
|
|
||||||
|
value() = _pop.best_element().fitness()[whichFitnessTerm];
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Store an index of the fitness term to be evaluated in eoScalarFitnessAssembled
|
|
||||||
unsigned whichFitnessTerm;
|
// Store an index of the fitness term to be evaluated in eoScalarFitnessAssembled
|
||||||
|
unsigned whichFitnessTerm;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,11 @@ so they can be snapshot by some eoGnuplotSnapshot ...
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoFDCStat : public eoStat<EOT, double>
|
class eoFDCStat : public eoStat<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
/** Ctor without the optimum
|
|
||||||
*/
|
using eoFDCStat < EOT>::value;
|
||||||
|
|
||||||
|
/** Ctor without the optimum */
|
||||||
eoFDCStat(eoDistance<EOT> & _dist, std::string _description = "FDC") :
|
eoFDCStat(eoDistance<EOT> & _dist, std::string _description = "FDC") :
|
||||||
eoStat<EOT,double>(0, _description), dist(_dist), boolOpt(false) {}
|
eoStat<EOT,double>(0, _description), dist(_dist), boolOpt(false) {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ template <class EOT, class FitT = typename EOT::Fitness>
|
||||||
class eoFitnessStat : public eoSortedStat<EOT, std::vector<FitT> >
|
class eoFitnessStat : public eoSortedStat<EOT, std::vector<FitT> >
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
|
using eoFitnessStat< EOT, FitT >::value;
|
||||||
|
|
||||||
eoFitnessStat(std::string _description = "AllFitnesses") :
|
eoFitnessStat(std::string _description = "AllFitnesses") :
|
||||||
eoSortedStat<EOT,std::vector<FitT> >(std::vector<FitT>(0), _description) {}
|
eoSortedStat<EOT,std::vector<FitT> >(std::vector<FitT>(0), _description) {}
|
||||||
|
|
||||||
|
|
@ -62,7 +65,10 @@ class eoMOFitnessStat : public eoSortedStat<EOT, std::vector<PartFitT> >
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoMOFitnessStat< EOT, PartFitT >::value;
|
||||||
|
|
||||||
/** Ctor: say what component you want
|
/** Ctor: say what component you want
|
||||||
*/
|
*/
|
||||||
eoMOFitnessStat(unsigned _objective, std::string _description = "MO-Fitness") :
|
eoMOFitnessStat(unsigned _objective, std::string _description = "MO-Fitness") :
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,10 @@ inside an eoFileMonitor, as the eoState construct will work much better there.
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoPopStat : public eoStat<EOT, std::string>
|
class eoPopStat : public eoStat<EOT, std::string>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoPopStat< EOT>::value;
|
||||||
|
|
||||||
/** default Ctor, void std::string by default, as it appears
|
/** default Ctor, void std::string by default, as it appears
|
||||||
on the description line once at beginning of evolution. and
|
on the description line once at beginning of evolution. and
|
||||||
is meaningless there. _howMany defaults to 0, that is, the whole
|
is meaningless there. _howMany defaults to 0, that is, the whole
|
||||||
|
|
@ -115,22 +118,27 @@ inside an eoFileMonitor, as the eoState construct will work much better there.
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoSortedPopStat : public eoSortedStat<EOT, std::string>
|
class eoSortedPopStat : public eoSortedStat<EOT, std::string>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
/** default Ctor, void std::string by default, as it appears
|
|
||||||
* on the description line once at beginning of evolution. and
|
|
||||||
* is meaningless there _howMany defaults to 0, that is, the whole
|
|
||||||
* population
|
|
||||||
*/
|
|
||||||
eoSortedPopStat(unsigned _howMany = 0, std::string _desc ="") :
|
|
||||||
eoSortedStat<EOT, std::string>("", _desc) , combien( _howMany) {}
|
|
||||||
|
|
||||||
/** Fills the value() of the eoParam with the dump of the population.
|
using eoSortedPopStat< EOT>::value;
|
||||||
Adds a \n before so it does not get mixed up with the rest of the stats
|
|
||||||
that are written by the monitor it is probably used from.
|
/** default Ctor, void std::string by default, as it appears on
|
||||||
*/
|
the description line once at beginning of evolution. and is
|
||||||
|
meaningless there _howMany defaults to 0, that is, the whole
|
||||||
|
population
|
||||||
|
*/
|
||||||
|
eoSortedPopStat(unsigned _howMany = 0, std::string _desc ="")
|
||||||
|
: eoSortedStat<EOT, std::string>("", _desc) , combien( _howMany)
|
||||||
|
{}
|
||||||
|
|
||||||
|
/** Fills the value() of the eoParam with the dump of the
|
||||||
|
population. Adds a \n before so it does not get mixed up with
|
||||||
|
the rest of the stats that are written by the monitor it is
|
||||||
|
probably used from.
|
||||||
|
*/
|
||||||
#ifdef HAVE_SSTREAM
|
#ifdef HAVE_SSTREAM
|
||||||
void operator()(const std::vector<const EOT*>& _pop)
|
void operator()(const std::vector<const EOT*>& _pop)
|
||||||
{
|
{
|
||||||
value() = ""; // empty
|
value() = ""; // empty
|
||||||
unsigned howMany=combien?combien:_pop.size();
|
unsigned howMany=combien?combien:_pop.size();
|
||||||
for (unsigned i = 0; i < howMany; ++i)
|
for (unsigned i = 0; i < howMany; ++i)
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,11 @@
|
||||||
template <class EOT, class FitT = typename EOT::Fitness>
|
template <class EOT, class FitT = typename EOT::Fitness>
|
||||||
class eoScalarFitnessStat : public eoSortedStat<EOT, std::vector<double> >
|
class eoScalarFitnessStat : public eoSortedStat<EOT, std::vector<double> >
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
eoScalarFitnessStat(std::string _description = "FitnessES",
|
|
||||||
|
using eoScalarFitnessStat< EOT, FitT >::value;
|
||||||
|
|
||||||
|
eoScalarFitnessStat(std::string _description = "FitnessES",
|
||||||
eoRealVectorBounds & _bounds = eoDummyVectorNoBounds) :
|
eoRealVectorBounds & _bounds = eoDummyVectorNoBounds) :
|
||||||
eoSortedStat<EOT, std::vector<double> >(std::vector<double>(0), _description) ,
|
eoSortedStat<EOT, std::vector<double> >(std::vector<double>(0), _description) ,
|
||||||
range(*_bounds[0])
|
range(*_bounds[0])
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,18 @@ public:
|
||||||
template <class EOT, class T>
|
template <class EOT, class T>
|
||||||
class eoStat : public eoValueParam<T>, public eoStatBase<EOT>
|
class eoStat : public eoValueParam<T>, public eoStatBase<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
eoStat(T _value, std::string _description) : eoValueParam<T>(_value, _description) {}
|
|
||||||
virtual std::string className(void) const { return "eoStat"; }
|
eoStat(T _value, std::string _description)
|
||||||
|
: eoValueParam<T>(_value, _description)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual std::string className(void) const
|
||||||
|
{ return "eoStat"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Base class for statistics calculated over a sorted snapshot of the population
|
Base class for statistics calculated over a sorted snapshot of the population
|
||||||
*/
|
*/
|
||||||
|
|
@ -102,6 +109,9 @@ template <class EOT> class eoAverageStat : public eoStat<EOT, typename EOT::Fitn
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
|
using eoAverageStat< EOT >::value;
|
||||||
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
eoAverageStat(std::string _description = "Average Fitness")
|
eoAverageStat(std::string _description = "Average Fitness")
|
||||||
|
|
@ -158,10 +168,16 @@ template <class EOT>
|
||||||
class eoSecondMomentStats : public eoStat<EOT, std::pair<double, double> >
|
class eoSecondMomentStats : public eoStat<EOT, std::pair<double, double> >
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
|
using eoSecondMomentStats< EOT >::value;
|
||||||
|
|
||||||
typedef typename EOT::Fitness fitness_type;
|
typedef typename EOT::Fitness fitness_type;
|
||||||
|
|
||||||
typedef std::pair<double, double> SquarePair;
|
typedef std::pair<double, double> SquarePair;
|
||||||
eoSecondMomentStats(std::string _description = "Average & Stdev") : eoStat<EOT, SquarePair>(std::make_pair(0.0,0.0), _description) {}
|
|
||||||
|
eoSecondMomentStats(std::string _description = "Average & Stdev")
|
||||||
|
: eoStat<EOT, SquarePair>(std::make_pair(0.0,0.0), _description)
|
||||||
|
{}
|
||||||
|
|
||||||
static SquarePair sumOfSquares(SquarePair _sq, const EOT& _eo)
|
static SquarePair sumOfSquares(SquarePair _sq, const EOT& _eo)
|
||||||
{
|
{
|
||||||
|
|
@ -196,6 +212,8 @@ class eoNthElementFitnessStat : public eoSortedStat<EOT, typename EOT::Fitness >
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
using eoNthElementFitnessStat< EOT >::value;
|
||||||
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
eoNthElementFitnessStat(unsigned _whichElement, std::string _description = "nth element fitness")
|
eoNthElementFitnessStat(unsigned _whichElement, std::string _description = "nth element fitness")
|
||||||
|
|
@ -298,17 +316,23 @@ template <class EOT>
|
||||||
class eoBestFitnessStat : public eoStat<EOT, typename EOT::Fitness>
|
class eoBestFitnessStat : public eoStat<EOT, typename EOT::Fitness>
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoBestFitnessStat< EOT >::value;
|
||||||
|
|
||||||
typedef typename EOT::Fitness Fitness;
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
eoBestFitnessStat(std::string _description = "Best ")
|
eoBestFitnessStat(std::string _description = "Best ")
|
||||||
: eoStat<EOT, Fitness>(Fitness(), _description) {}
|
: eoStat<EOT, Fitness>(Fitness(), _description)
|
||||||
|
{}
|
||||||
|
|
||||||
void operator()(const eoPop<EOT>& _pop){
|
void operator()(const eoPop<EOT>& _pop) {
|
||||||
doit(_pop, Fitness() ); // specializations for scalar and std::vector
|
doit(_pop, Fitness() ); // specializations for scalar and std::vector
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string className(void) const { return "eoBestFitnessStat"; }
|
virtual std::string className(void) const { return "eoBestFitnessStat"; }
|
||||||
|
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
struct CmpFitness
|
struct CmpFitness
|
||||||
|
|
@ -353,8 +377,13 @@ private :
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoDistanceStat : public eoStat<EOT, double>
|
class eoDistanceStat : public eoStat<EOT, double>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
eoDistanceStat(std::string _name = "distance") : eoStat<EOT, double>(0.0, _name) {}
|
|
||||||
|
using eoDistanceStat< EOT >::value;
|
||||||
|
|
||||||
|
eoDistanceStat(std::string _name = "distance")
|
||||||
|
: eoStat<EOT, double>(0.0, _name)
|
||||||
|
{}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
double distance(T a, T b)
|
double distance(T a, T b)
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,10 @@ private:
|
||||||
template <class T>
|
template <class T>
|
||||||
class eoIncrementorParam : public eoUpdater, public eoValueParam<T>
|
class eoIncrementorParam : public eoUpdater, public eoValueParam<T>
|
||||||
{
|
{
|
||||||
public :
|
public:
|
||||||
|
|
||||||
|
using eoIncrementorParam< T >::value;
|
||||||
|
|
||||||
/** Default Ctor : a name and optionally an increment*/
|
/** Default Ctor : a name and optionally an increment*/
|
||||||
eoIncrementorParam( std::string _name, T _stepsize = 1) :
|
eoIncrementorParam( std::string _name, T _stepsize = 1) :
|
||||||
eoValueParam<T>(T(0), _name), stepsize(_stepsize) {}
|
eoValueParam<T>(T(0), _name), stepsize(_stepsize) {}
|
||||||
|
|
@ -84,7 +87,7 @@ public :
|
||||||
/** Simply increments */
|
/** Simply increments */
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
value() += stepsize;
|
value() += stepsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string className(void) const { return "eoIncrementorParam"; }
|
virtual std::string className(void) const { return "eoIncrementorParam"; }
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,8 @@ double sum_fitness(const eoPop<EOT>& _pop)
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
|
double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
|
||||||
{
|
{
|
||||||
|
double rawTotal, scaledTotal;
|
||||||
|
|
||||||
typename eoPop<EOT>::const_iterator it = _pop.begin();
|
typename eoPop<EOT>::const_iterator it = _pop.begin();
|
||||||
|
|
||||||
_minmax.first = it->fitness();
|
_minmax.first = it->fitness();
|
||||||
|
|
@ -114,7 +116,7 @@ double sum_fitness(const eoPop<EOT>& _pop, std::pair<double, double>& _minmax)
|
||||||
double v = static_cast<double>(it->fitness());
|
double v = static_cast<double>(it->fitness());
|
||||||
|
|
||||||
_minmax.first = std::min(_minmax.first, v);
|
_minmax.first = std::min(_minmax.first, v);
|
||||||
_minmax.second = max(_minmax.second, v);
|
_minmax.second = std::max(_minmax.second, v);
|
||||||
|
|
||||||
rawTotal += v;
|
rawTotal += v;
|
||||||
}
|
}
|
||||||
|
|
@ -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
|
// unfortunately a second loop is neccessary to scale the fitness
|
||||||
for (it = _pop.begin(); it != _pop.end(); ++it)
|
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;
|
scaledTotal += v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return scaledTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class It>
|
template <class It>
|
||||||
|
|
|
||||||
|
|
@ -83,22 +83,26 @@ int main()
|
||||||
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace);
|
eoEasyEA<Chrom> ea(checkpoint, eval, breeder, replace);
|
||||||
|
|
||||||
// evolution
|
// evolution
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
ea(pop);
|
ea(pop);
|
||||||
}
|
} catch (std::exception& e) {
|
||||||
catch (std::exception& e)
|
std::cerr << "exception: " << e.what() << std::endl;;
|
||||||
{
|
|
||||||
std::cout << "exception: " << e.what() << std::endl;;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "pop" << std::endl;
|
std::cout << "pop" << std::endl;
|
||||||
for (i = 0; i < pop.size(); ++i)
|
for (i = 0; i < pop.size(); ++i)
|
||||||
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl;
|
||||||
|
|
||||||
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
std::cout << "\n --> Number of Evaluations = " << eval.getValue() << std::endl;
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: C++
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// End:
|
||||||
|
|
|
||||||
|
|
@ -79,17 +79,27 @@ class Init : public eoInit<eoDouble>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Trying out an elitist non-dominated sorted replacement scheme
|
/** @brief An elitist non-dominated sorted replacement scheme.
|
||||||
|
|
||||||
|
Trying out an elitist non-dominated sorted replacement scheme.
|
||||||
|
*/
|
||||||
template <class EOT, class WorthT = double>
|
template <class EOT, class WorthT = double>
|
||||||
class eoNDPlusReplacement : public eoReplacement<EOT>
|
class eoNDPlusReplacement : public eoReplacement<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
eoNDPlusReplacement(eoPerf2Worth<EOT, WorthT>& _perf2worth) : perf2worth(_perf2worth) {}
|
|
||||||
|
|
||||||
struct WorthPair : public pair<WorthT, const EOT*>
|
// using eoNDPlusReplacement< EOT, WorthT >::first;
|
||||||
{
|
|
||||||
bool operator<(const WorthPair& other) const { return other.first < first; }
|
eoNDPlusReplacement(eoPerf2Worth<EOT, WorthT>& _perf2worth)
|
||||||
};
|
: perf2worth(_perf2worth)
|
||||||
|
{}
|
||||||
|
|
||||||
|
struct WorthPair : public pair<WorthT, const EOT*>
|
||||||
|
{
|
||||||
|
bool operator<(const WorthPair& other) const
|
||||||
|
{ return other.first < this->first; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _offspring)
|
||||||
{
|
{
|
||||||
|
|
@ -106,7 +116,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
eoPerf2Worth<EOT, WorthT>& perf2worth;
|
eoPerf2Worth<EOT, WorthT>& perf2worth;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
|
|
@ -232,3 +242,9 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: C++
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// End:
|
||||||
|
|
|
||||||
Reference in a new issue