From 795f63b7feae82efec3d68aeaa51912552586594 Mon Sep 17 00:00:00 2001 From: evomarc Date: Tue, 25 May 2004 08:03:30 +0000 Subject: [PATCH] Adding sharing - needed to modify quite a few files, like eoDistance.h make_algo_scalar.h and all related files, and the like --- eo/src/do/make_algo_scalar.h | 34 +++++++- eo/src/eoSelectFromWorth.h | 8 +- eo/src/eoSharing.h | 124 ++++++++++++++++------------ eo/src/eoSharingSelect.h | 54 ++++++++++++ eo/src/es/make_algo_scalar_es.cpp | 12 +-- eo/src/es/make_algo_scalar_real.cpp | 8 +- eo/src/es/make_es.h | 13 +-- eo/src/es/make_real.h | 5 +- eo/src/ga/make_algo_scalar_ga.cpp | 8 +- eo/src/ga/make_ga.h | 5 +- eo/src/utils/eoDistance.h | 43 +++++++++- eo/test/Makefile.am | 9 +- eo/tutorial/Lesson4/BitEA.cpp | 10 ++- eo/tutorial/Lesson4/binary_value.h | 4 +- 14 files changed, 244 insertions(+), 93 deletions(-) create mode 100644 eo/src/eoSharingSelect.h diff --git a/eo/src/do/make_algo_scalar.h b/eo/src/do/make_algo_scalar.h index 6500492e..975f9f6e 100644 --- a/eo/src/do/make_algo_scalar.h +++ b/eo/src/do/make_algo_scalar.h @@ -39,6 +39,7 @@ #include #include #include +#include // Breeders #include @@ -49,6 +50,9 @@ #include #include +// distance +#include + // Algorithm (only this one needed) #include @@ -70,11 +74,18 @@ * is actually templatized here */ + template -eoAlgo & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc& _eval, eoContinue& _continue, eoGenOp& _op) +eoAlgo & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc& _eval, eoContinue& _continue, eoGenOp& _op, eoDistance * _dist = NULL) { - // the selection - eoValueParam& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, Ranking(p,e), DetTour(T), StochTour(t) or Sequential(ordered/unordered)", 'S', "Evolution Engine"); + // the selection : help and comment depend on whether or not a distance is passed + std::string comment; + if (_dist == NULL) + comment = "Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e) or Sequential(ordered/unordered)"; + else + comment = "Selection: DetTour(T), StochTour(t), Roulette, Ranking(p,e), Sharing(sigma_share) or Sequential(ordered/unordered)"; + + eoValueParam& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", comment, 'S', "Evolution Engine"); eoParamParamType & ppSelect = selectionParam.value(); // std::pair > @@ -94,6 +105,23 @@ eoAlgo & do_make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc detSize = atoi(ppSelect.second[0].c_str()); select = new eoDetTournamentSelect(detSize); } + else if (ppSelect.first == std::string("Sharing")) + { + double nicheSize; + + if (!ppSelect.second.size()) // no parameter added + { + std::cerr << "WARNING, no parameter passed to Sharing, using 0.5" << std::endl; + nicheSize = 0.5; + // put back 2 in parameter for consistency (and status file) + ppSelect.second.push_back(std::string("0.5")); + } + else // parameter passed by user as DetTour(T) + nicheSize = atof(ppSelect.second[0].c_str()); + if (_dist == NULL) // no distance + throw std::runtime_error("You didn't specify a distance when calling make_algo_scalar and using sharing"); + select = new eoSharingSelect(nicheSize, *_dist); + } else if (ppSelect.first == std::string("StochTour")) { double p; diff --git a/eo/src/eoSelectFromWorth.h b/eo/src/eoSelectFromWorth.h index d2c993dc..fa596c13 100644 --- a/eo/src/eoSelectFromWorth.h +++ b/eo/src/eoSelectFromWorth.h @@ -26,7 +26,7 @@ #ifndef _eoSelectFromWorth_h #define _eoSelectFromWorth_h - +#include //----------------------------------------------------------------------------- #include #include @@ -197,6 +197,12 @@ public: */ virtual const EOT& operator()(const eoPop& _pop) { +// cout << "On affiche les worths\n"; +// for (unsigned i=0; +// i > -template -class eoSharing : public eoPerf2Worth -{ - public: - /** Ctor with only nicheSize: will use the default eoQuadDistance */ - eoSharing(double _nicheSize) : eoPerf2Worth("Sharing"), - nicheSize(_nicheSize), - dist(repDist) - {} - - eoSharing(double _nicheSize, Dist _dist) : eoPerf2Worth("Sharing"), - nicheSize(_nicheSize), - dist(_dist) - {} - - /** Computes shared fitnesses - */ - void operator()(const eoPop& _pop) - { - unsigned i, j, - pSize=_pop.size(); - if (pSize <= 1) - throw std::runtime_error("Apptempt to do sharing with population of size 1"); - value.resize(pSize); - std::vector sim(pSize); // to hold the similarities - std::vector distMatrix(pSize*(pSize-1)/2); // to hold the distances - - // compute the distances - distMatrix(0,0)=0; - for (i=1; i { public: // Ctor : sets size - dMatrix(unsigned _s) : std::vector(_s*(_s-1)), rSize(_s) {} + dMatrix(unsigned _s) : std::vector(_s*_s), rSize(_s) {} /** simple accessor */ double operator()(unsigned _i, unsigned _j) const @@ -121,11 +70,76 @@ class eoSharing : public eoPerf2Worth unsigned rSize; // row size (== number of columns!) }; + +// template > +template +class eoSharing : public eoPerf2Worth +{ + public: + /* Ctor requires a distance - cannot have a default distance! */ + eoSharing(double _nicheSize, eoDistance & _dist) : eoPerf2Worth("Sharing"), + nicheSize(_nicheSize), + dist(_dist) + {} + + /** Computes shared fitnesses + */ + void operator()(const eoPop& _pop) + { + unsigned i, j, + pSize=_pop.size(); + if (pSize <= 1) + throw std::runtime_error("Apptempt to do sharing with population of size 1"); + value().resize(pSize); + std::vector sim(pSize); // to hold the similarities + dMatrix distMatrix(pSize*(pSize-1)/2); // to hold the distances + + // compute the similarities (wrong name for distMatrix, I know) + distMatrix(0,0)=1; + for (i=1; inicheSize ? 0 : 1-(d/nicheSize) ); + } + } + +// cout << "Matrice des similarités\n"; +// for (i=0; i repDist; // default distance - eoDistance & dist; // allows to pass a specific distance + eoDistance & dist; // specific distance }; + + #endif diff --git a/eo/src/eoSharingSelect.h b/eo/src/eoSharingSelect.h new file mode 100644 index 00000000..7daf9fd1 --- /dev/null +++ b/eo/src/eoSharingSelect.h @@ -0,0 +1,54 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// eoSharingSelect.h +// (c) GeNeura Team, 1998, Maarten Keijzer 2000, 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@polytechnique.fr + mak@dhi.dk + */ +//----------------------------------------------------------------------------- + +#ifndef eoSharingSelect_h +#define eoSharingSelect_h + +//----------------------------------------------------------------------------- + +#include +#include + +/** eoRankingSelect: select an individual by roulette wheel on its rank + * is an eoRouletteWorthSelect, i.e. a selector using a std::vector of worthes + * rather than the raw fitness (see eoSelectFromWorth.h) + * uses an internal eoRanking object which is an eoPerf2Worth +*/ + +template +class eoSharingSelect: public eoRouletteWorthSelect +{ +public: + /** Ctor: + * @param _s the sigma_share + */ + eoSharingSelect(double _sigma, eoDistance & _dist): + eoRouletteWorthSelect(sharing), sharing(_sigma, _dist) {} + +private : + eoSharing sharing; // derived from eoPerf2Worth +}; + +#endif diff --git a/eo/src/es/make_algo_scalar_es.cpp b/eo/src/es/make_algo_scalar_es.cpp index 27624f3e..abc52682 100644 --- a/eo/src/es/make_algo_scalar_es.cpp +++ b/eo/src/es/make_algo_scalar_es.cpp @@ -51,34 +51,34 @@ // Algo /////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } ////////////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } /////////////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); } diff --git a/eo/src/es/make_algo_scalar_real.cpp b/eo/src/es/make_algo_scalar_real.cpp index 0a951c0f..91b5ccd1 100644 --- a/eo/src/es/make_algo_scalar_real.cpp +++ b/eo/src/es/make_algo_scalar_real.cpp @@ -49,13 +49,13 @@ // Algo /////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { - return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); + return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { - return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); + return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist); } diff --git a/eo/src/es/make_es.h b/eo/src/es/make_es.h index c2c7b379..3212f391 100644 --- a/eo/src/es/make_es.h +++ b/eo/src/es/make_es.h @@ -52,6 +52,7 @@ #include #include #include +#include #include // one Sigma per individual #include // one sigmal per object variable @@ -119,14 +120,14 @@ eoCheckPoint >& make_checkpoint(eoParser& _parser, // the algo -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); // run void run_ea(eoAlgo >& _ga, eoPop >& _pop); diff --git a/eo/src/es/make_real.h b/eo/src/es/make_real.h index 8c227f26..594934dd 100644 --- a/eo/src/es/make_real.h +++ b/eo/src/es/make_real.h @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -85,9 +86,9 @@ eoCheckPoint >& make_checkpoint(eoParser& _parser, e // the algo -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); // run void run_ea(eoAlgo >& _ga, eoPop >& _pop); diff --git a/eo/src/ga/make_algo_scalar_ga.cpp b/eo/src/ga/make_algo_scalar_ga.cpp index f2b6719c..aa9b2e05 100644 --- a/eo/src/ga/make_algo_scalar_ga.cpp +++ b/eo/src/ga/make_algo_scalar_ga.cpp @@ -52,13 +52,13 @@ // Algo /////// -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { - return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); + return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist); } -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op) +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _continue, eoGenOp >& _op, eoDistance >* _dist) { - return do_make_algo_scalar(_parser, _state, _eval, _continue, _op); + return do_make_algo_scalar(_parser, _state, _eval, _continue, _op, _dist); } diff --git a/eo/src/ga/make_ga.h b/eo/src/ga/make_ga.h index 4c63c22c..ee75b813 100644 --- a/eo/src/ga/make_ga.h +++ b/eo/src/ga/make_ga.h @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -77,9 +78,9 @@ eoCheckPoint >& make_checkpoint(eoParser& _parser, eo // the algo -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); -eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op); +eoAlgo >& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc >& _eval, eoContinue >& _ccontinue, eoGenOp >& _op, eoDistance >* _dist = NULL); // run void run_ea(eoAlgo >& _ga, eoPop >& _pop); diff --git a/eo/src/utils/eoDistance.h b/eo/src/utils/eoDistance.h index 2ffb8ccc..26ef0ea6 100644 --- a/eo/src/utils/eoDistance.h +++ b/eo/src/utils/eoDistance.h @@ -27,7 +27,6 @@ #define _eoDistance_H #include - /** This is a generic class for distance functors: takes 2 things ane returns a double @@ -36,27 +35,63 @@ template< class EOT > class eoDistance : public eoBF {}; + /** - This is a generic class for Euclidain distance computation: + This is a generic class for Euclidain distance (L2 norm) computation: assumes the 2 things are std::vectors of something that is double-castable */ - template< class EOT > class eoQuadDistance : public eoDistance { public: double operator()(const EOT & _v1, const EOT & _v2) { - double sum=0.0; + double sum=0.0; for (unsigned i=0; i<_v1.size(); i++) { double r = static_cast (_v1[i]) - static_cast (_v2[i]); sum += r*r; } + return sqrt(sum); + } +}; + +/** + This is a generic class for L1 distance computation: + assumes the 2 things are std::vectors of something + that is double-castable + For bitstrings, this is the Hamming distance +*/ +template< class EOT > +class eoHammingDistance : public eoDistance +{ +public: + double operator()(const EOT & _v1, const EOT & _v2) + { + double sum=0.0; + for (unsigned i=0; i<_v1.size(); i++) + { + double r = static_cast (_v1[i]) - static_cast (_v2[i]); + sum += fabs(r); + } return sum; } }; +/* this distance measures the difference in fitness + * I am not sure it can be of any use, though ... + * except for some testing + */ +template< class EOT > +class eoFitnessDistance : public eoDistance +{ +public: + double operator()(const EOT & _v1, const EOT & _v2) + { + double d = _v1.fitness() - _v2.fitness(); + return sqrt(d*d); + } +}; diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 5d30ccd0..43b61b81 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -17,7 +17,7 @@ CXXFLAGS = -g -Wall # PLEASE don't break the line (see create_batch.sh) -check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll t-eoPBIL t-eoFitnessAssembled t-eoFitnessAssembledEA t-eoRoulette +check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll t-eoPBIL t-eoFitnessAssembled t-eoFitnessAssembledEA t-eoRoulette t-eoSharing #The run_tests script can be used to check various arguments TESTS=$(check_PROGRAMS) run_tests @@ -198,3 +198,10 @@ t_eoRoulette_LDFLAGS = -lm t_eoRoulette_LDADD = $(LDADDS) ############################################################################### + +t_eoSharing_SOURCES = t-eoSharing.cpp +t_eoSharing_DEPENDENCIES = $(DEPS) +t_eoSharing_LDFLAGS = -lm +t_eoSharing_LDADD = $(LDADDS) + +############################################################################### diff --git a/eo/tutorial/Lesson4/BitEA.cpp b/eo/tutorial/Lesson4/BitEA.cpp index 96185656..fd6f1fbd 100644 --- a/eo/tutorial/Lesson4/BitEA.cpp +++ b/eo/tutorial/Lesson4/BitEA.cpp @@ -10,7 +10,7 @@ using namespace std; int main(int argc, char* argv[]) -{ +{ try { @@ -30,13 +30,17 @@ int main(int argc, char* argv[]) // EVAL // The evaluation fn - encapsulated into an eval counter for output - eoEvalFuncPtr mainEval( binary_value ); + eoEvalFuncPtr mainEval( binary_value ); eoEvalFuncCounter eval(mainEval); // REPRESENTATION // the genotype - through a genotype initializer eoInit& init = make_genotype(parser, state, EOT()); + // if you want to do sharing, you'll need a distance. + // here Hamming distance + eoHammingDistance dist; + // OPERATORS // Build the variation operator (any seq/prop construct) eoGenOp& op = make_op(parser, state, init); @@ -56,7 +60,7 @@ int main(int argc, char* argv[]) eoCheckPoint & checkpoint = make_checkpoint(parser, state, eval, term); // GENERATION // algorithm (need the operator!) - eoAlgo& ga = make_algo_scalar(parser, state, eval, checkpoint, op); + eoAlgo& ga = make_algo_scalar(parser, state, eval, checkpoint, op, &dist); ///// End of construction of the algorith ///////////////////////////////////////// diff --git a/eo/tutorial/Lesson4/binary_value.h b/eo/tutorial/Lesson4/binary_value.h index 0cd56007..188835fc 100644 --- a/eo/tutorial/Lesson4/binary_value.h +++ b/eo/tutorial/Lesson4/binary_value.h @@ -7,9 +7,9 @@ @param _chrom A binary chromosome */ -template float binary_value(const Chrom& _chrom) +template double binary_value(const Chrom& _chrom) { - float sum = 0; + double sum = 0; for (unsigned i = 0; i < _chrom.size(); i++) if (_chrom[i]) sum += _chrom[i];