Changes due to MSVC
This commit is contained in:
parent
8abb9242c2
commit
f41cd957c0
12 changed files with 114 additions and 37 deletions
|
|
@ -35,7 +35,11 @@
|
|||
* function class. That way, old style C or C++ functions can be adapted to EO
|
||||
* function classes.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& >
|
||||
#else
|
||||
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
|
||||
#endif
|
||||
struct eoEvalFuncPtr: public eoEvalFunc<EOT> {
|
||||
|
||||
/** Applies the function to the chromosome and sets the fitness of the
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
|
||||
void calculate_worths(const eoPop<EOT>& _pop)
|
||||
{
|
||||
unsigned i;
|
||||
value().resize(_pop.size());
|
||||
|
||||
typedef typename EOT::Fitness::fitness_traits traits;
|
||||
|
|
@ -66,7 +67,7 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
tmp_pop.resize(_pop.size());
|
||||
|
||||
// copy pop to dummy population (only need the fitnesses)
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
tmp_pop[i].fitness(_pop[i].fitness());
|
||||
tmp_pop[i].index = i;
|
||||
|
|
@ -76,7 +77,7 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
tmp_pop.sort();
|
||||
|
||||
//
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
value()[tmp_pop[i].index] = _pop.size() - i; // set rank
|
||||
}
|
||||
|
|
@ -87,10 +88,10 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
vector<vector<unsigned> > S(_pop.size()); // which individuals does guy i dominate
|
||||
vector<unsigned> n(_pop.size(), 0); // how many individuals dominate guy i
|
||||
|
||||
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
unsigned j;
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
for (unsigned j = 0; j < _pop.size(); ++j)
|
||||
for (j = 0; j < _pop.size(); ++j)
|
||||
{
|
||||
if (_pop[i].fitness().dominates(_pop[j].fitness()))
|
||||
{ // i dominates j
|
||||
|
|
@ -111,7 +112,7 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
current_front.reserve(_pop.size());
|
||||
|
||||
// get the first front out
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
if (n[i] == 0)
|
||||
{
|
||||
|
|
@ -138,16 +139,16 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
|
||||
double max_niche = *max_element(niche_count.begin(), niche_count.end());
|
||||
|
||||
for (unsigned i = 0; i < current_front.size(); ++i)
|
||||
for (i = 0; i < current_front.size(); ++i)
|
||||
{
|
||||
value()[current_front[i]] = front_index + niche_count[i] / (max_niche + 1.); // divide by max_niche + 1 to ensure that this front does not overlap with the next
|
||||
}
|
||||
|
||||
// Calculate which individuals are in the next front;
|
||||
|
||||
for (unsigned i = 0; i < current_front.size(); ++i)
|
||||
for (i = 0; i < current_front.size(); ++i)
|
||||
{
|
||||
for (unsigned j = 0; j < S[current_front[i]].size(); ++j)
|
||||
for (j = 0; j < S[current_front[i]].size(); ++j)
|
||||
{
|
||||
unsigned dominated_individual = S[current_front[i]][j];
|
||||
n[dominated_individual]--; // As we remove individual i -- being part of the current front -- it no longer dominates j
|
||||
|
|
@ -172,7 +173,7 @@ class eoNDSorting : public eoPerf2WorthCached<EOT, double>
|
|||
|
||||
unsigned nfirst = 0;
|
||||
|
||||
for (unsigned i = 0; i < value().size(); ++i)
|
||||
for (i = 0; i < value().size(); ++i)
|
||||
{
|
||||
value()[i] = max_fitness - value()[i];
|
||||
assert(n[i] == 0);
|
||||
|
|
@ -255,6 +256,7 @@ class eoNDSorting_II : public eoNDSorting<EOT>
|
|||
|
||||
vector<double> niche_penalty(const vector<unsigned>& _cf, const eoPop<EOT>& _pop)
|
||||
{
|
||||
unsigned i;
|
||||
vector<double> niche_count(_cf.size(), 0.);
|
||||
|
||||
unsigned nObjectives = _pop[_cf[0]].fitness().size();
|
||||
|
|
@ -263,7 +265,7 @@ class eoNDSorting_II : public eoNDSorting<EOT>
|
|||
{
|
||||
|
||||
vector<pair<double, unsigned> > performance(_cf.size());
|
||||
for (unsigned i =0; i < _cf.size(); ++i)
|
||||
for (i =0; i < _cf.size(); ++i)
|
||||
{
|
||||
performance[i].first = _pop[_cf[i]].fitness()[o];
|
||||
performance[i].second = i;
|
||||
|
|
@ -273,7 +275,7 @@ class eoNDSorting_II : public eoNDSorting<EOT>
|
|||
|
||||
vector<double> nc(niche_count.size(), 0.0);
|
||||
|
||||
for (unsigned i = 1; i < _cf.size()-1; ++i)
|
||||
for (i = 1; i < _cf.size()-1; ++i)
|
||||
{ // and yet another level of indirection
|
||||
nc[performance[i].second] = performance[i+1].first - performance[i-1].first;
|
||||
}
|
||||
|
|
@ -284,7 +286,7 @@ class eoNDSorting_II : public eoNDSorting<EOT>
|
|||
nc[performance[0].second] = max_dist + 1;
|
||||
nc[performance.back().second] = max_dist + 1;
|
||||
|
||||
for (unsigned i = 0; i < nc.size(); ++i)
|
||||
for (i = 0; i < nc.size(); ++i)
|
||||
{
|
||||
niche_count[i] += (max_dist + 1) - nc[i];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ class eoPerf2Worth : public eoUF<const eoPop<EOT>&, void>, public eoValueParam<v
|
|||
{ // start with a vector of indices
|
||||
vector<unsigned> indices(_pop.size());
|
||||
|
||||
for (unsigned i = 0; i < _pop.size();++i)
|
||||
unsigned i;
|
||||
for (i = 0; i < _pop.size();++i)
|
||||
{ // could use generate, but who cares
|
||||
indices[i] = i;
|
||||
}
|
||||
|
|
@ -59,7 +60,7 @@ class eoPerf2Worth : public eoUF<const eoPop<EOT>&, void>, public eoValueParam<v
|
|||
tmp_pop.resize(_pop.size());
|
||||
vector<WorthT> tmp_worths(value().size());
|
||||
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
tmp_pop[i] = _pop[indices[i]];
|
||||
tmp_worths[i] = value()[indices[i]];
|
||||
|
|
@ -111,10 +112,11 @@ class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
|||
*/
|
||||
void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
unsigned i;
|
||||
if (fitness_cache.size() == _pop.size())
|
||||
{
|
||||
bool in_sync = true;
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
if (fitness_cache[i] != _pop[i].fitness())
|
||||
{
|
||||
|
|
@ -131,7 +133,7 @@ class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
|||
else // just cache the fitness
|
||||
{
|
||||
fitness_cache.resize(_pop.size());
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
fitness_cache[i] = _pop[i].fitness();
|
||||
}
|
||||
|
|
@ -151,7 +153,8 @@ class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
|||
{ // start with a vector of indices
|
||||
vector<unsigned> indices(_pop.size());
|
||||
|
||||
for (unsigned i = 0; i < _pop.size();++i)
|
||||
unsigned i;
|
||||
for (i = 0; i < _pop.size();++i)
|
||||
{ // could use generate, but who cares
|
||||
indices[i] = i;
|
||||
}
|
||||
|
|
@ -161,9 +164,13 @@ class eoPerf2WorthCached : public eoPerf2Worth<EOT, WorthT>
|
|||
eoPop<EOT> tmp_pop;
|
||||
tmp_pop.resize(_pop.size());
|
||||
vector<WorthT> tmp_worths(value().size());
|
||||
vector<typename EOT::Fitness> tmp_cache(_pop.size());
|
||||
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
#ifdef _MSC_VER
|
||||
vector<EOT::Fitness> tmp_cache(_pop.size());
|
||||
#else
|
||||
vector<typename EOT::Fitness> tmp_cache(_pop.size());
|
||||
#endif
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
tmp_pop[i] = _pop[indices[i]];
|
||||
tmp_worths[i] = value()[indices[i]];
|
||||
|
|
@ -215,8 +222,9 @@ class eoNoPerf2Worth : public eoPerf2Worth<EOT, typename EOT::Fitness>
|
|||
// default behaviour, just copy fitnesses
|
||||
void operator()(const eoPop<EOT>& _pop)
|
||||
{
|
||||
unsigned i;
|
||||
value.resize(_pop.size());
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
for (i = 0; i < _pop.size(); ++i)
|
||||
value()[i]=_pop[i];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -57,29 +57,29 @@
|
|||
|
||||
/// The following function merely call the templatized do_* functions
|
||||
|
||||
eoEsChromInit<eoEsSimple<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple<double> _eo)
|
||||
eoRealInitBounded<eoEsSimple<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple<double> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
eoEsChromInit<eoEsSimple<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple<eoMinimizingFitness> _eo)
|
||||
eoRealInitBounded<eoEsSimple<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple<eoMinimizingFitness> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
eoEsChromInit<eoEsStdev<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev<double> _eo)
|
||||
eoRealInitBounded<eoEsStdev<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev<double> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
eoEsChromInit<eoEsStdev<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev<eoMinimizingFitness> _eo)
|
||||
eoRealInitBounded<eoEsStdev<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev<eoMinimizingFitness> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
||||
eoEsChromInit<eoEsFull<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull<double> _eo)
|
||||
eoRealInitBounded<eoEsFull<double> > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull<double> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
eoEsChromInit<eoEsFull<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull<eoMinimizingFitness> _eo)
|
||||
eoRealInitBounded<eoEsFull<eoMinimizingFitness> > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull<eoMinimizingFitness> _eo)
|
||||
{
|
||||
return do_make_genotype(_parser, _state, _eo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#ifndef _make_PBILdistrib_h
|
||||
#define _make_PBILdistrib_h
|
||||
|
||||
#include <sys/time.h> // for time(0) for random seeding
|
||||
#include <ctime> // for time(0) for random seeding
|
||||
#include <ga/eoPBILOrg.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <utils/eoParser.h>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#ifndef _make_PBILupdate_h
|
||||
#define _make_PBILupdate_h
|
||||
|
||||
#include <sys/time.h> // for time(0) for random seeding
|
||||
#include <ga/eoPBILOrg.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <utils/eoParser.h>
|
||||
|
|
|
|||
Reference in a new issue