Small modifications here and there to be MSVC++ compatible
Mainly, time.h -> ctime
definition of loop index out of loops when multiply used
no typename in declaration using template typename
This commit is contained in:
parent
a5e3abd9f6
commit
d7c3d973c7
14 changed files with 56 additions and 27 deletions
|
|
@ -27,7 +27,7 @@
|
||||||
#ifndef _make_pop_h
|
#ifndef _make_pop_h
|
||||||
#define _make_pop_h
|
#define _make_pop_h
|
||||||
|
|
||||||
#include <sys/time.h> // for time(0) for random seeding
|
#include <ctime> // for time(0) for random seeding
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
#include <eoInit.h>
|
#include <eoInit.h>
|
||||||
#include <utils/eoRNG.h>
|
#include <utils/eoRNG.h>
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoDistribUpdater :
|
class eoDistribUpdater :
|
||||||
public eoBF<eoDistribution<EOT> &, eoPop<EOT> &, void>
|
public eoBF<eoDistribution<EOT> &, eoPop<EOT> &, void>
|
||||||
{};
|
{
|
||||||
|
public:
|
||||||
|
virtual void operator()(eoDistribution<EOT> &, eoPop<EOT> &)=0;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,11 @@
|
||||||
|
|
||||||
@see eoSelectMany, eoSelectRandom, eoDetTournament, eoStochTournament, eoProportional
|
@see eoSelectMany, eoSelectRandom, eoDetTournament, eoStochTournament, eoProportional
|
||||||
*/
|
*/
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
template<class EOT, class WorthT = EOT::Fitness>
|
||||||
|
#else
|
||||||
template<class EOT, class WorthT = typename EOT::Fitness>
|
template<class EOT, class WorthT = typename EOT::Fitness>
|
||||||
|
#endif
|
||||||
class eoSelectOne : public eoUF<const eoPop<EOT>&, const EOT&>
|
class eoSelectOne : public eoUF<const eoPop<EOT>&, const EOT&>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
|
||||||
|
|
@ -99,10 +99,10 @@ private :
|
||||||
// Adaptive mutation through a whole correlation matrix
|
// Adaptive mutation through a whole correlation matrix
|
||||||
void create_self_adapt(eoEsFull<FitT>& result)
|
void create_self_adapt(eoEsFull<FitT>& result)
|
||||||
{
|
{
|
||||||
unsigned theSize = eoRealInitBounded<EOT>::size();
|
unsigned i, theSize = eoRealInitBounded<EOT>::size();
|
||||||
|
|
||||||
result.stdevs.resize(theSize);
|
result.stdevs.resize(theSize);
|
||||||
for (unsigned i = 0; i < theSize; ++i)
|
for (i = 0; i < theSize; ++i)
|
||||||
{
|
{
|
||||||
// should we scale sigmas to the corresponding object variable range?
|
// should we scale sigmas to the corresponding object variable range?
|
||||||
result.stdevs[i] = sigma;
|
result.stdevs[i] = sigma;
|
||||||
|
|
@ -110,7 +110,7 @@ private :
|
||||||
|
|
||||||
// nb of rotation angles: N*(N-1)/2 (in general!)
|
// nb of rotation angles: N*(N-1)/2 (in general!)
|
||||||
result.correlations.resize(theSize*(theSize - 1) / 2);
|
result.correlations.resize(theSize*(theSize - 1) / 2);
|
||||||
for (unsigned i = 0; i < result.correlations.size(); ++i)
|
for (i = 0; i < result.correlations.size(); ++i)
|
||||||
{
|
{
|
||||||
// uniform in [-PI, PI)
|
// uniform in [-PI, PI)
|
||||||
result.correlations[i] = rng.uniform(2 * M_PI) - M_PI;
|
result.correlations[i] = rng.uniform(2 * M_PI) - M_PI;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoPBILDistrib.h
|
// eoPBILAdditive.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer, 2001
|
// (c) Marc Schoenauer, Maarten Keijzer, 2001
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,6 @@ public:
|
||||||
_eo.invalidate(); // DO NOT FORGET!!!
|
_eo.invalidate(); // DO NOT FORGET!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
/** update method - still PURE VIRTUAL */
|
|
||||||
// virtual void update(eoPop<EOT>&) = 0; // update from a population
|
|
||||||
|
|
||||||
/** Accessor to the genome size */
|
/** Accessor to the genome size */
|
||||||
unsigned Size() {return genomeSize;}
|
unsigned Size() {return genomeSize;}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoPBILDistrib.h
|
// eoPBILOrg.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer, 2001
|
// (c) Marc Schoenauer, Maarten Keijzer, 2001
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Distribution Class for PBIL algorithm
|
* Distribution Class for PBIL algorithm
|
||||||
* (Population-Based Incremental Learning, Baluja and Caruana 96)
|
* (Population-Based Incremental Learning, Baluja and Caruana 95)
|
||||||
*
|
*
|
||||||
* This class implements the update rule from the original paper:
|
* This class implements the update rule from the original paper:
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,22 @@ eoPBILDistrib<EOT> & do_make_PBILdistrib(eoParser & _parser, eoState& _state, E
|
||||||
if (seedParam.value() == 0)
|
if (seedParam.value() == 0)
|
||||||
seedParam.value() = time(0);
|
seedParam.value() = time(0);
|
||||||
|
|
||||||
// the representation dependent stuff
|
// chromosome size:
|
||||||
unsigned chromSize = _parser.createParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Algorithm").value();
|
unsigned theSize;
|
||||||
|
// but it might have been already read in the definition fo the performance
|
||||||
|
eoParam* ptParam = _parser.getParamWithLongName(string("chromSize"));
|
||||||
|
|
||||||
eoPBILDistrib<EOT> * ptDistrib = new eoPBILDistrib<EOT>(chromSize);
|
if (!ptParam) // not already defined: read it here
|
||||||
|
{
|
||||||
|
theSize = _parser.createParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value();
|
||||||
|
}
|
||||||
|
else // it was read before, get its value
|
||||||
|
{
|
||||||
|
eoValueParam<unsigned>* ptChromSize = dynamic_cast<eoValueParam<unsigned>*>(ptParam);
|
||||||
|
theSize = ptChromSize->value();
|
||||||
|
}
|
||||||
|
|
||||||
|
eoPBILDistrib<EOT> * ptDistrib = new eoPBILDistrib<EOT>(theSize);
|
||||||
_state.storeFunctor(ptDistrib);
|
_state.storeFunctor(ptDistrib);
|
||||||
|
|
||||||
// now the initialization: read a previously saved distribution, or random
|
// now the initialization: read a previously saved distribution, or random
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ eoInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
|
||||||
// for bitstring, only thing needed is the size
|
// for bitstring, only thing needed is the size
|
||||||
unsigned theSize;
|
unsigned theSize;
|
||||||
// but it might have been already read in the definition fo the performance
|
// but it might have been already read in the definition fo the performance
|
||||||
eoParam* ptParam = _parser.getParamWithLongName(string("ChromSize"));
|
eoParam* ptParam = _parser.getParamWithLongName(string("chromSize"));
|
||||||
|
|
||||||
if (!ptParam) // not already defined: read it here
|
if (!ptParam) // not already defined: read it here
|
||||||
{
|
{
|
||||||
theSize = _parser.createParam(unsigned(10), "ChromSize", "The length of the bitstrings", 'n',"Problem").value();
|
theSize = _parser.createParam(unsigned(10), "chromSize", "The length of the bitstrings", 'n',"Problem").value();
|
||||||
}
|
}
|
||||||
else // it was read before, get its value
|
else // it was read before, get its value
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -239,16 +239,16 @@ template <>
|
||||||
void eoValueParam<std::vector<std::vector<double> > >::setValue(std::string _value)
|
void eoValueParam<std::vector<std::vector<double> > >::setValue(std::string _value)
|
||||||
{
|
{
|
||||||
std::istrstream is(_value.c_str());
|
std::istrstream is(_value.c_str());
|
||||||
unsigned sz;
|
unsigned i,j,sz;
|
||||||
is >> sz;
|
is >> sz;
|
||||||
repValue.resize(sz);
|
repValue.resize(sz);
|
||||||
|
|
||||||
for (unsigned i = 0; i < repValue.size(); ++i)
|
for (i = 0; i < repValue.size(); ++i)
|
||||||
{
|
{
|
||||||
unsigned sz2;
|
unsigned sz2;
|
||||||
is >> sz2;
|
is >> sz2;
|
||||||
repValue[i].resize(sz2);
|
repValue[i].resize(sz2);
|
||||||
for (unsigned j = 0; j < sz2; ++j)
|
for (j = 0; j < sz2; ++j)
|
||||||
{
|
{
|
||||||
is >> repValue[i][j];
|
is >> repValue[i][j];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,12 @@ public :
|
||||||
Average fitness of a population, fitness can be a double, eoMinimizingFitness, eoMaximizingFitness or eoParetoFitness.
|
Average fitness of a population, fitness can be a double, eoMinimizingFitness, eoMaximizingFitness or eoParetoFitness.
|
||||||
In the case of pareto optimization it will calculate the average of each objective.
|
In the case of pareto optimization it will calculate the average of each objective.
|
||||||
*/
|
*/
|
||||||
template <class EOT>
|
|
||||||
class eoAverageStat : public eoStat<EOT, typename EOT::Fitness>
|
#ifdef _MSC_VER
|
||||||
|
template <class EOT> class eoAverageStat : public eoStat<EOT, EOT::Fitness>
|
||||||
|
#else
|
||||||
|
template <class EOT> class eoAverageStat : public eoStat<EOT, typename EOT::Fitness>
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
typedef typename EOT::Fitness fitness_type;
|
typedef typename EOT::Fitness fitness_type;
|
||||||
|
|
@ -99,7 +103,11 @@ public :
|
||||||
|
|
||||||
virtual void operator()(const eoPop<EOT>& _pop)
|
virtual void operator()(const eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
doit(_pop, EOT::Fitness()); // specializations for scalar and vector
|
||||||
|
#else
|
||||||
doit(_pop, typename EOT::Fitness()); // specializations for scalar and vector
|
doit(_pop, typename EOT::Fitness()); // specializations for scalar and vector
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
private :
|
private :
|
||||||
|
|
||||||
|
|
@ -248,17 +256,22 @@ public :
|
||||||
/**
|
/**
|
||||||
Best fitness in the population
|
Best fitness in the population
|
||||||
*/
|
*/
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
template <class EOT>
|
||||||
|
class eoBestFitnessStat : public eoStat<EOT, EOT::Fitness>
|
||||||
|
#else
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoBestFitnessStat : public eoStat<EOT, typename EOT::Fitness>
|
class eoBestFitnessStat : public eoStat<EOT, typename EOT::Fitness>
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
typedef typename EOT::Fitness Fitness;
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
|
||||||
eoBestFitnessStat(std::string _description = "Best ") : eoStat<EOT, typename EOT::Fitness>(typename EOT::Fitness(), _description) {}
|
eoBestFitnessStat(std::string _description = "Best ") : eoStat<EOT, Fitness>(Fitness(), _description) {}
|
||||||
|
|
||||||
void operator()(const eoPop<EOT>& _pop)
|
void operator()(const eoPop<EOT>& _pop)
|
||||||
{
|
{
|
||||||
doit(_pop, typename EOT::Fitness());
|
doit(_pop, Fitness());
|
||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
|
||||||
// initialize the population - and evaluate
|
// initialize the population - and evaluate
|
||||||
// yes, this is representation indepedent once you have an eoInit
|
// yes, this is representation indepedent once you have an eoInit
|
||||||
eoPop<EOT>& pop = make_pop(_parser, _state, init);
|
eoPop<EOT>& pop = make_pop(_parser, _state, init);
|
||||||
apply(eval, pop);
|
apply<EOT>(eval, pop);
|
||||||
|
|
||||||
// stopping criteria
|
// stopping criteria
|
||||||
eoContinue<EOT> & term = make_continue(_parser, _state, eval);
|
eoContinue<EOT> & term = make_continue(_parser, _state, eval);
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ int main(int argc, char* argv[])
|
||||||
//// GO
|
//// GO
|
||||||
///////
|
///////
|
||||||
// evaluate intial population AFTER help and status in case it takes time
|
// evaluate intial population AFTER help and status in case it takes time
|
||||||
apply(eval, pop);
|
apply<EOT>(eval, pop);
|
||||||
// print it out
|
// print it out
|
||||||
cout << "Initial Population\n";
|
cout << "Initial Population\n";
|
||||||
pop.sortedPrintOn(cout);
|
pop.sortedPrintOn(cout);
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ int main(int argc, char* argv[])
|
||||||
//// GO
|
//// GO
|
||||||
///////
|
///////
|
||||||
// evaluate intial population AFTER help and status in case it takes time
|
// evaluate intial population AFTER help and status in case it takes time
|
||||||
apply(eval, pop);
|
apply<EOT>(eval, pop);
|
||||||
// print it out
|
// print it out
|
||||||
cout << "Initial Population\n";
|
cout << "Initial Population\n";
|
||||||
pop.sortedPrintOn(cout);
|
pop.sortedPrintOn(cout);
|
||||||
|
|
|
||||||
Reference in a new issue