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>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,11 @@
|
|||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
#include <ctime>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoGenOp.h
|
||||
// eoGenOp.cpp
|
||||
// (c) Maarten Keijzer and Marc Schoenauer, 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -189,7 +189,7 @@ int the_main(int argc, char **argv)
|
|||
{
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
eoValueParam<unsigned int> parentSizeParam = parser.createParam<unsigned int>(10, "parentSize", "Parent size",'P');
|
||||
eoValueParam<unsigned int> parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P');
|
||||
pSize = parentSizeParam.value(); // global variable
|
||||
|
||||
eoValueParam<uint32> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,30 @@
|
|||
#include <iostream>
|
||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// t-eoPBIL.cpp
|
||||
// (c) Marc Schoenauer, 2001
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: Marc.Schoenauer@inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** test program for PBIL algorithm */
|
||||
|
||||
#include <iostream>
|
||||
#include <eo>
|
||||
#include <ga/make_ga.h>
|
||||
#include "binary_value.h"
|
||||
|
|
@ -66,6 +91,7 @@ int main(int argc, char* argv[])
|
|||
if (!ptDirNameParam) // not found
|
||||
throw runtime_error("Parameter resDir not found where it was supposed to be");
|
||||
|
||||
#if !defined(NO_GNUPLOT)
|
||||
// now create the snapshot monitor
|
||||
eoValueParam<bool>& plotDistribParam = parser.createParam(false, "plotDistrib", "Plot Distribution", '\0', "Output - Graphical");
|
||||
if (plotDistribParam.value())
|
||||
|
|
@ -78,6 +104,7 @@ int main(int argc, char* argv[])
|
|||
// and of course add it to the checkpoint
|
||||
checkpoint.add(*distribSnapshot);
|
||||
}
|
||||
#endif
|
||||
|
||||
// the algorithm: DEA
|
||||
// don't know where else to put the population size!
|
||||
|
|
@ -98,6 +125,7 @@ int main(int argc, char* argv[])
|
|||
distrib.printOn(cout);
|
||||
cout << endl;
|
||||
|
||||
#if !defined(NO_GNUPLOT)
|
||||
// wait - for graphical output
|
||||
if (plotDistribParam.value())
|
||||
{
|
||||
|
|
@ -105,6 +133,7 @@ int main(int argc, char* argv[])
|
|||
cin >> foo;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << e.what() << endl;
|
||||
|
|
|
|||
|
|
@ -195,6 +195,7 @@ void the_main(int argc, char* argv[])
|
|||
cp.add(fitness0);
|
||||
cp.add(fitness1);
|
||||
|
||||
#if !defined(NO_GNUPLOT)
|
||||
eoGnuplot1DSnapshot snapshot("pareto");
|
||||
snapshot.pointSize =3;
|
||||
|
||||
|
|
@ -202,6 +203,7 @@ void the_main(int argc, char* argv[])
|
|||
|
||||
snapshot.add(fitness0);
|
||||
snapshot.add(fitness1);
|
||||
#endif
|
||||
|
||||
// the algo
|
||||
eoEasyEA<eoDouble> ea(cp, eval, breeder, replace);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,33 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// t-eoParetoFitness.cpp
|
||||
// (c) Maarten Keijzer
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <iostream>
|
||||
#include "eoParetoFitness.h"
|
||||
#include <assert.h>
|
||||
using namespace std;
|
||||
|
||||
/** test program for Pareto Fitness */
|
||||
|
||||
class MinimizingTraits : public eoParetoFitnessTraits
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ void testSelectOne(eoSelectOne<EOT> & _select, eoHowMany & _hm, string _name)
|
|||
int the_main(int argc, char **argv)
|
||||
{
|
||||
eoParser parser(argc, argv);
|
||||
eoValueParam<unsigned int> parentSizeParam = parser.createParam<unsigned int>(10, "parentSize", "Parent size",'P');
|
||||
eoValueParam<unsigned> parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P');
|
||||
pSize = parentSizeParam.value(); // global variable
|
||||
|
||||
// eoValueParam<double> offsrpringRateParam = parser.createParam<double>(1.0, "offsrpringRate", "Offsrpring rate",'O');
|
||||
|
|
@ -113,13 +113,13 @@ int the_main(int argc, char **argv)
|
|||
eoValueParam<eoHowMany> offsrpringRateParam = parser.createParam(eoHowMany(1.0), "offsrpringRate", "Offsrpring rate (% or absolute)",'O');
|
||||
eoHowMany oRate = offsrpringRateParam.value();
|
||||
|
||||
eoValueParam<unsigned int> tournamentSizeParam = parser.createParam<unsigned int>(2, "tournamentSize", "Deterministic tournament size",'T');
|
||||
eoValueParam<unsigned> tournamentSizeParam = parser.createParam(unsigned(2), "tournamentSize", "Deterministic tournament size",'T');
|
||||
unsigned int tSize = tournamentSizeParam.value();
|
||||
|
||||
eoValueParam<double> tournamentRateParam = parser.createParam<double>(0.75, "tournamentRate", "Stochastic tournament rate",'R');
|
||||
eoValueParam<double> tournamentRateParam = parser.createParam(0.75, "tournamentRate", "Stochastic tournament rate",'R');
|
||||
double tRate = tournamentRateParam.value();
|
||||
|
||||
eoValueParam<double> rankingPressureParam = parser.createParam<double>(1.75, "rankingPressure", "Selective pressure for the ranking selection",'p');
|
||||
eoValueParam<double> rankingPressureParam = parser.createParam(1.75, "rankingPressure", "Selective pressure for the ranking selection",'p');
|
||||
double rankingPressure = rankingPressureParam.value();
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue