diff --git a/eo/src/eoEvalFuncPtr.h b/eo/src/eoEvalFuncPtr.h index 8c28a721d..fd98e4e34 100644 --- a/eo/src/eoEvalFuncPtr.h +++ b/eo/src/eoEvalFuncPtr.h @@ -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 { /** Applies the function to the chromosome and sets the fitness of the diff --git a/eo/src/eoNDSorting.h b/eo/src/eoNDSorting.h index dea76083b..b2d49c934 100644 --- a/eo/src/eoNDSorting.h +++ b/eo/src/eoNDSorting.h @@ -55,6 +55,7 @@ class eoNDSorting : public eoPerf2WorthCached void calculate_worths(const eoPop& _pop) { + unsigned i; value().resize(_pop.size()); typedef typename EOT::Fitness::fitness_traits traits; @@ -66,7 +67,7 @@ class eoNDSorting : public eoPerf2WorthCached 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 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 vector > S(_pop.size()); // which individuals does guy i dominate vector 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 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 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 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 vector niche_penalty(const vector& _cf, const eoPop& _pop) { + unsigned i; vector niche_count(_cf.size(), 0.); unsigned nObjectives = _pop[_cf[0]].fitness().size(); @@ -263,7 +265,7 @@ class eoNDSorting_II : public eoNDSorting { vector > 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 vector 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 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]; } diff --git a/eo/src/eoPerf2Worth.h b/eo/src/eoPerf2Worth.h index 21ea551a4..f5bffc4a4 100644 --- a/eo/src/eoPerf2Worth.h +++ b/eo/src/eoPerf2Worth.h @@ -48,7 +48,8 @@ class eoPerf2Worth : public eoUF&, void>, public eoValueParam 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&, void>, public eoValueParam 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 */ void operator()(const eoPop& _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 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 { // start with a vector of indices vector 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 eoPop tmp_pop; tmp_pop.resize(_pop.size()); vector tmp_worths(value().size()); - vector tmp_cache(_pop.size()); - for (unsigned i = 0; i < _pop.size(); ++i) +#ifdef _MSC_VER + vector tmp_cache(_pop.size()); +#else + vector 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 // default behaviour, just copy fitnesses void operator()(const eoPop& _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]; } }; diff --git a/eo/src/es/make_genotype_es.cpp b/eo/src/es/make_genotype_es.cpp index a04215736..42006f610 100644 --- a/eo/src/es/make_genotype_es.cpp +++ b/eo/src/es/make_genotype_es.cpp @@ -57,29 +57,29 @@ /// The following function merely call the templatized do_* functions -eoEsChromInit > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple _eo) +eoRealInitBounded > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple _eo) { return do_make_genotype(_parser, _state, _eo); } -eoEsChromInit > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple _eo) +eoRealInitBounded > & make_genotype(eoParser& _parser, eoState& _state, eoEsSimple _eo) { return do_make_genotype(_parser, _state, _eo); } -eoEsChromInit > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev _eo) +eoRealInitBounded > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev _eo) { return do_make_genotype(_parser, _state, _eo); } -eoEsChromInit > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev _eo) +eoRealInitBounded > & make_genotype(eoParser& _parser, eoState& _state, eoEsStdev _eo) { return do_make_genotype(_parser, _state, _eo); } -eoEsChromInit > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull _eo) +eoRealInitBounded > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull _eo) { return do_make_genotype(_parser, _state, _eo); } -eoEsChromInit > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull _eo) +eoRealInitBounded > & make_genotype(eoParser& _parser, eoState& _state, eoEsFull _eo) { return do_make_genotype(_parser, _state, _eo); } diff --git a/eo/src/ga/make_PBILdistrib.h b/eo/src/ga/make_PBILdistrib.h index 2698cc349..3615aa33e 100644 --- a/eo/src/ga/make_PBILdistrib.h +++ b/eo/src/ga/make_PBILdistrib.h @@ -26,7 +26,7 @@ #ifndef _make_PBILdistrib_h #define _make_PBILdistrib_h -#include // for time(0) for random seeding +#include // for time(0) for random seeding #include #include #include diff --git a/eo/src/ga/make_PBILupdate.h b/eo/src/ga/make_PBILupdate.h index 7cf371b49..db9241ea6 100644 --- a/eo/src/ga/make_PBILupdate.h +++ b/eo/src/ga/make_PBILupdate.h @@ -26,7 +26,6 @@ #ifndef _make_PBILupdate_h #define _make_PBILupdate_h -#include // for time(0) for random seeding #include #include #include diff --git a/eo/test/t-eoESAll.cpp b/eo/test/t-eoESAll.cpp index cd6436e7e..1752faa80 100644 --- a/eo/test/t-eoESAll.cpp +++ b/eo/test/t-eoESAll.cpp @@ -9,7 +9,11 @@ #include #include #include -#include +#include + +#ifdef _MSC_VER + #include +#endif using namespace std; diff --git a/eo/test/t-eoGenOp.cpp b/eo/test/t-eoGenOp.cpp index d44251c01..dd13ba322 100644 --- a/eo/test/t-eoGenOp.cpp +++ b/eo/test/t-eoGenOp.cpp @@ -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 parentSizeParam = parser.createParam(10, "parentSize", "Parent size",'P'); + eoValueParam parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P'); pSize = parentSizeParam.value(); // global variable eoValueParam seedParam(time(0), "seed", "Random number seed", 'S'); diff --git a/eo/test/t-eoPBIL.cpp b/eo/test/t-eoPBIL.cpp index 8863bde0f..70efa6085 100644 --- a/eo/test/t-eoPBIL.cpp +++ b/eo/test/t-eoPBIL.cpp @@ -1,5 +1,30 @@ -#include +// -*- 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 #include #include #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& 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; diff --git a/eo/test/t-eoPareto.cpp b/eo/test/t-eoPareto.cpp index 33e3de73d..b79c2f0ac 100644 --- a/eo/test/t-eoPareto.cpp +++ b/eo/test/t-eoPareto.cpp @@ -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 ea(cp, eval, breeder, replace); diff --git a/eo/test/t-eoParetoFitness.cpp b/eo/test/t-eoParetoFitness.cpp index 18dbf2f31..402616703 100644 --- a/eo/test/t-eoParetoFitness.cpp +++ b/eo/test/t-eoParetoFitness.cpp @@ -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 #include "eoParetoFitness.h" +#include +using namespace std; + +/** test program for Pareto Fitness */ class MinimizingTraits : public eoParetoFitnessTraits { diff --git a/eo/test/t-eoSelect.cpp b/eo/test/t-eoSelect.cpp index 672b16ec6..05142eb69 100644 --- a/eo/test/t-eoSelect.cpp +++ b/eo/test/t-eoSelect.cpp @@ -105,7 +105,7 @@ void testSelectOne(eoSelectOne & _select, eoHowMany & _hm, string _name) int the_main(int argc, char **argv) { eoParser parser(argc, argv); - eoValueParam parentSizeParam = parser.createParam(10, "parentSize", "Parent size",'P'); + eoValueParam parentSizeParam = parser.createParam(unsigned(10), "parentSize", "Parent size",'P'); pSize = parentSizeParam.value(); // global variable // eoValueParam offsrpringRateParam = parser.createParam(1.0, "offsrpringRate", "Offsrpring rate",'O'); @@ -113,13 +113,13 @@ int the_main(int argc, char **argv) eoValueParam offsrpringRateParam = parser.createParam(eoHowMany(1.0), "offsrpringRate", "Offsrpring rate (% or absolute)",'O'); eoHowMany oRate = offsrpringRateParam.value(); -eoValueParam tournamentSizeParam = parser.createParam(2, "tournamentSize", "Deterministic tournament size",'T'); +eoValueParam tournamentSizeParam = parser.createParam(unsigned(2), "tournamentSize", "Deterministic tournament size",'T'); unsigned int tSize = tournamentSizeParam.value(); - eoValueParam tournamentRateParam = parser.createParam(0.75, "tournamentRate", "Stochastic tournament rate",'R'); + eoValueParam tournamentRateParam = parser.createParam(0.75, "tournamentRate", "Stochastic tournament rate",'R'); double tRate = tournamentRateParam.value(); - eoValueParam rankingPressureParam = parser.createParam(1.75, "rankingPressure", "Selective pressure for the ranking selection",'p'); + eoValueParam rankingPressureParam = parser.createParam(1.75, "rankingPressure", "Selective pressure for the ranking selection",'p'); double rankingPressure = rankingPressureParam.value(); if (parser.userNeedsHelp())