From 4cebad979d25d56863919816a98e4cb36ca72952 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Sun, 7 Nov 2010 23:16:45 +0100 Subject: [PATCH] remove multi-objective stuff, deprecated by ParadisEO-PEO --- eo/src/CMakeLists.txt | 1 - eo/src/do/make_algo_pareto.h | 203 ----------------------- eo/src/do/make_checkpoint_pareto.h | 248 ----------------------------- eo/src/do/make_continue_pareto.h | 108 ------------- eo/src/eo | 1 - eo/src/eoDominanceMap.h | 162 ------------------- eo/src/eoParetoConstraintFitness.h | 229 -------------------------- eo/src/eoParetoFitness.cpp | 38 ----- eo/src/eoParetoFitness.h | 235 --------------------------- eo/src/eoParetoRanking.h | 71 --------- eo/src/utils/eoStat.h | 54 ------- 11 files changed, 1350 deletions(-) delete mode 100644 eo/src/do/make_algo_pareto.h delete mode 100644 eo/src/do/make_checkpoint_pareto.h delete mode 100644 eo/src/do/make_continue_pareto.h delete mode 100644 eo/src/eoDominanceMap.h delete mode 100644 eo/src/eoParetoConstraintFitness.h delete mode 100644 eo/src/eoParetoFitness.cpp delete mode 100644 eo/src/eoParetoFitness.h delete mode 100644 eo/src/eoParetoRanking.h diff --git a/eo/src/CMakeLists.txt b/eo/src/CMakeLists.txt index 7a6d6f33..70e2c755 100644 --- a/eo/src/CMakeLists.txt +++ b/eo/src/CMakeLists.txt @@ -15,7 +15,6 @@ SET (EO_SOURCES eoFunctorStore.cpp eoPersistent.cpp eoPrintable.cpp eoCtrlCContinue.cpp - eoParetoFitness.cpp eoScalarFitnessAssembled.cpp eoSIGContinue.cpp) diff --git a/eo/src/do/make_algo_pareto.h b/eo/src/do/make_algo_pareto.h deleted file mode 100644 index 6231e4fe..00000000 --- a/eo/src/do/make_algo_pareto.h +++ /dev/null @@ -1,203 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// make_algo_pareto.h -// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2002 -/* - 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: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@inria.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _make_algo_pareto_h -#define _make_algo_pareto_h - -#include "utils/eoData.h" // for eo_is_a_rate -// everything tha's needed for the algorithms - SCALAR fitness - -// Selection -// the eoSelectOne's -#include "eoSelectFromWorth.h" -#include "eoNDSorting.h" - -// Breeders -#include "eoGeneralBreeder.h" - -// Replacement - at the moment limited to eoNDPlusReplacement, locally defined -#include "eoReplacement.h" - -template -class eoNDPlusReplacement : public eoReplacement -{ -public: - eoNDPlusReplacement(eoPerf2Worth& _perf2worth) : perf2worth(_perf2worth) {} - - struct WorthPair : public std::pair - { - bool operator<(const WorthPair& other) const { return other.first < this->first; } - }; - - void operator()(eoPop& _parents, eoPop& _offspring) - { - unsigned sz = _parents.size(); - _parents.reserve(_parents.size() + _offspring.size()); - copy(_offspring.begin(), _offspring.end(), back_inserter(_parents)); - - // calculate worths - perf2worth(_parents); - perf2worth.sort_pop(_parents); - perf2worth.resize(_parents, sz); - - _offspring.clear(); - } - -private : - eoPerf2Worth& perf2worth; -}; - - -// Algorithm (only this one needed) -#include "eoEasyEA.h" - - // also need the parser and param includes -#include "utils/eoParser.h" -#include "utils/eoState.h" - - -/* - * This function builds the algorithm (i.e. selection and replacement) - * from existing continue (or checkpoint) and operators - * - * It uses a parser (to get user parameters) and a state (to store the memory) - * the last argument is an individual, needed for 2 reasons - * it disambiguates the call after instanciations - * some operator might need some private information about the indis - * - * This is why the template is the complete EOT even though only the fitness - * is actually templatized here -*/ - -template -eoAlgo & do_make_algo_pareto(eoParser& _parser, eoState& _state, eoEvalFunc& _eval, eoContinue& _continue, eoGenOp& _op) -{ - // the selection - std::string & selStr = _parser.createParam(std::string("NSGA-II"), "selCrit", "Pareto Selection Criterion: NSGA, NSGA-II, ParetoRanking", 'S', "Evolution Engine").value(); - double nicheSize = _parser.createParam(1.0, "nicheSize", "Size of niche for NSGA-I", '\0', "Evolution Engine").value(); - eoPerf2Worth *p2w; - if ( (selStr == std::string("NSGA")) || (selStr == std::string("NSGA-I") ) ) - p2w = new eoNDSorting_I(nicheSize); - else if (selStr == std::string("NSGA-II")) - p2w = new eoNDSorting_II(); - else if (selStr == std::string("ParetoRanking")) - { - eoDominanceMap& dominance = _state.storeFunctor(new eoDominanceMap); - p2w = new eoParetoRanking(dominance); - } - - _state.storeFunctor(p2w); - - // now the selector (from p2w) - cut-and-pasted from make_algo_scalar! - // only all classes are now ...FromWorth ... - // only the ranking is not re-implemented (yet?) - eoValueParam& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine"); - - eoParamParamType & ppSelect = selectionParam.value(); // std::pair > - - eoSelectOne* select ; - if (ppSelect.first == std::string("DetTour")) - { - unsigned detSize; - - if (!ppSelect.second.size()) // no parameter added - { - std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl; - detSize = 2; - // put back 2 in parameter for consistency (and status file) - ppSelect.second.push_back(std::string("2")); - } - else // parameter passed by user as DetTour(T) - detSize = atoi(ppSelect.second[0].c_str()); - select = new eoDetTournamentWorthSelect(*p2w, detSize); - } - else if (ppSelect.first == std::string("StochTour")) - { - double p; - if (!ppSelect.second.size()) // no parameter added - { - std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl; - p = 1; - // put back p in parameter for consistency (and status file) - ppSelect.second.push_back(std::string("1")); - } - else // parameter passed by user as DetTour(T) - p = atof(ppSelect.second[0].c_str()); - - select = new eoStochTournamentWorthSelect(*p2w, p); - } -// else if (ppSelect.first == std::string("Sequential")) // one after the other -// { -// bool b; -// if (ppSelect.second.size() == 0) // no argument -> default = ordered -// { -// b=true; -// // put back in parameter for consistency (and status file) -// ppSelect.second.push_back(std::string("ordered")); -// } -// else -// b = !(ppSelect.second[0] == std::string("unordered")); -// select = new eoSequentialWorthSelect(b); -// } - else if (ppSelect.first == std::string("Roulette")) // no argument (yet) - { - select = new eoRouletteWorthSelect(*p2w); - } - else if (ppSelect.first == std::string("Random")) // no argument, no perf2Worth - { - select = new eoRandomSelect; - } - else - { - std::string stmp = std::string("Invalid selection: ") + ppSelect.first; - throw std::runtime_error(stmp.c_str()); - } - - _state.storeFunctor(select); - - - // the number of offspring - eoValueParam& offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "Evolution Engine"); - - // the replacement - // actually limited to eoNDPlusReplacement - eoReplacement & replace = _state.storeFunctor( - new eoNDPlusReplacement(*p2w) - ); - - // the general breeder - eoGeneralBreeder *breed = - new eoGeneralBreeder(*select, _op, offspringRateParam.value()); - _state.storeFunctor(breed); - - // now the eoEasyEA - eoAlgo *algo = new eoEasyEA(_continue, _eval, *breed, replace); - _state.storeFunctor(algo); - // that's it! - return *algo; -} - -#endif diff --git a/eo/src/do/make_checkpoint_pareto.h b/eo/src/do/make_checkpoint_pareto.h deleted file mode 100644 index 50b7253e..00000000 --- a/eo/src/do/make_checkpoint_pareto.h +++ /dev/null @@ -1,248 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// make_checkpoint_pareto.h -// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000 -/* - 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: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@inria.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _make_checkpoint_pareto_h -#define _make_checkpoint_pareto_h - -#include -#include -#include - -#include "EO.h" -#include "eoParetoFitness.h" -#include "eoEvalFuncCounter.h" -#include "utils/checkpointing" -#include "utils/selectors.h" - -// at the moment, in utils/make_help.cpp -// this should become some eoUtils.cpp with corresponding eoUtils.h -bool testDirRes(std::string _dirName, bool _erase); -/////////////////// The checkpoint and other I/O ////////////// - -/** Of course, Fitness needs to be an eoParetoFitness!!! - */ -template -eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, - eoEvalFuncCounter& _eval, eoContinue& _continue) -{ - // first, create a checkpoint from the eoContinue - and store in _state - eoCheckPoint & checkpoint = _state.storeFunctor(new eoCheckPoint(_continue)); - - /////// get number of obectives from Fitness - not very elegant - typedef typename EOT::Fitness Fit; - Fit fit; - unsigned nObj = fit.size(); - - /////////////////// - // Counters - ////////////////// - // is nb Eval to be used as counter? - bool useEval = _parser.getORcreateParam(true, "useEval", - "Use nb of eval. as counter (vs nb of gen.)", - '\0', "Output").value(); - - // Create anyway a generation-counter parameter WARNING: not stored anywhere!!! - eoValueParam *generationCounter = new eoValueParam(0, "Gen."); - // Create an incrementor (sub-class of eoUpdater). - eoIncrementor & increment = - _state.storeFunctor(new eoIncrementor(generationCounter->value()) ); - // Add it to the checkpoint, - checkpoint.add(increment); - - // dir for DISK output - std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", - "Directory to store DISK outputs", - '\0', "Output - Disk").value(); - // shoudl we empty it if exists - eoValueParam& eraseParam = _parser.getORcreateParam(true, "eraseDir", - "erase files in dirName if any", - '\0', "Output - Disk"); - bool dirOK = false; // not tested yet - - ///////////////////////////////////////// - // now some statistics on the population: - ///////////////////////////////////////// - /** - * existing stats for Pareto as of today, Jan. 31. 2002 - * - * eoSortedPopStat : whole population - type std::string (!!) - */ - - eoValueParam& fPlotParam - = _parser.getORcreateParam(eoParamParamType("1(0,1)"), "frontFileFrequency", - "File save frequency in objective spaces (std::pairs of comma-separated objectives " \ - "in 1 single parentheses std::pair)", - '\0', "Output - Disk"); - - bool boolGnuplot = _parser.getORcreateParam(false, "plotFront", - "Objective plots (requires corresponding files " \ - "- see frontFileFrequency", - '\0', "Output - Graphical").value(); - - eoParamParamType & fPlot = fPlotParam.value(); // std::pair > - unsigned frequency = atoi(fPlot.first.c_str()); - if (frequency) // something to plot - { - unsigned nbPlot = fPlot.second.size(); - if ( nbPlot % 2 ) // odd! - throw std::runtime_error("Odd number of front description in make_checkpoint_pareto"); - - // only create the necessary stats - std::vector bStat(nObj, false); // track of who's already there - std::vector* > theStats(nObj); - - // first create the stats - for (unsigned i=0; i* fStat; - if (!bStat[obj1]) { // not already there: create it - std::ostringstream os; - os << "Obj. " << obj1 << std::ends; - fStat = new eoMOFitnessStat(obj1, os.str().c_str()); - _state.storeFunctor(fStat); - bStat[obj1]=true; - theStats[obj1]=fStat; - checkpoint.add(*fStat); - } - if (!bStat[obj2]) { // not already there: create it - std::ostringstream os; - os << "Obj. " << obj2 << std::ends; - fStat = new eoMOFitnessStat(obj2, os.str().c_str()); - _state.storeFunctor(fStat); - bStat[obj2]=true; - theStats[obj2]=fStat; - checkpoint.add(*fStat); - } - - // then the fileSnapshots - std::ostringstream os; - os << "Front." << obj1 << "." << obj2 << "." << std::ends; - eoFileSnapshot& snapshot = _state.storeFunctor( - new eoFileSnapshot(dirName, frequency, os.str().c_str())); - checkpoint.add(snapshot); - - snapshot.add(*theStats[obj1]); - snapshot.add(*theStats[obj2]); - - // and create the gnuplotter from the fileSnapshot - if(boolGnuplot) - { - eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new - eoGnuplot1DSnapshot(snapshot)); - plotSnapshot.setPointSize(3); - checkpoint.add(plotSnapshot); - } - } - } - // Dump of the whole population - //----------------------------- - bool printPop = _parser.getORcreateParam(false, "printPop", - "Print sorted pop. every gen.", - '\0', "Output").value(); - eoSortedPopStat * popStat; - if ( printPop ) // we do want pop dump - { - std::cout << "On cree printpop\n"; - popStat = & _state.storeFunctor(new eoSortedPopStat); - // add it to the checkpoint - checkpoint.add(*popStat); - } - - /////////////// - // The monitors - /////////////// - // do we want an eoStdoutMonitor? - bool needStdoutMonitor = printPop ; // only this one at the moment - - // The Stdout monitor will print parameters to the screen ... - if ( needStdoutMonitor ) - { - eoStdoutMonitor & monitor = _state.storeFunctor(new eoStdoutMonitor(false)); - - // when called by the checkpoint (i.e. at every generation) - checkpoint.add(monitor); - - // the monitor will output a series of parameters: add them - monitor.add(*generationCounter); - if (useEval) // we want nb of evaluations - monitor.add(_eval); - if ( printPop) - monitor.add(*popStat); - } - - - ////////////////////////////////// - // State savers - ////////////////////////////// - - // feed the state to state savers - // save state every N generation - eoValueParam& saveFrequencyParam = _parser.createParam(unsigned(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" ); - - if (_parser.isItThere(saveFrequencyParam)) - { - // first make sure dirName is OK - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE - - unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); -#ifdef _MSVC - std::string stmp = dirName + "\generations"; -#else - std::string stmp = dirName + "/generations"; -#endif - eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); - _state.storeFunctor(stateSaver1); - checkpoint.add(*stateSaver1); - } - - // save state every T seconds - eoValueParam& saveTimeIntervalParam - = _parser.getORcreateParam(unsigned(0), "saveTimeInterval", - "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); - if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) - { - // first make sure dirName is OK - if (! dirOK ) - dirOK = testDirRes(dirName, eraseParam.value()); // TRUE - -#ifdef _MSVC - std::string stmp = dirName + "\time"; -#else - std::string stmp = dirName + "/time"; -#endif - eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); - _state.storeFunctor(stateSaver2); - checkpoint.add(*stateSaver2); - } - - // and that's it for the (control and) output - return checkpoint; -} - -#endif diff --git a/eo/src/do/make_continue_pareto.h b/eo/src/do/make_continue_pareto.h deleted file mode 100644 index 364f6057..00000000 --- a/eo/src/do/make_continue_pareto.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// make_continue_pareto.h -// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000 -/* - 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: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@inria.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef _make_continue_pareto_h -#define _make_continue_pareto_h - -/* -Contains the templatized version of parser-based choice of stopping criterion -for Pareto optimization (e.g. no "... without improvement" criterion -It can then be instantiated, and compiled on its own for a given EOType -(see e.g. in dir ga, ga.cpp) -*/ - -// Continuators - all include eoContinue.h -#include -#include -#include -#include -#ifndef _MSC_VER -#include // CtrlC handling (using 2 global variables!) -#endif - - // also need the parser and param includes -#include -#include - - -/////////////////// helper function //////////////// -template -eoCombinedContinue * make_combinedContinue(eoCombinedContinue *_combined, eoContinue *_cont) -{ - if (_combined) // already exists - _combined->add(*_cont); - else - _combined = new eoCombinedContinue(*_cont); - return _combined; -} - -///////////// The make_continue function -template -eoContinue & do_make_continue_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter & _eval) -{ - //////////// Stopping criterion /////////////////// - // the combined continue - to be filled - eoCombinedContinue *continuator = NULL; - - // for each possible criterion, check if wanted, otherwise do nothing - - // First the eoGenContinue - need a default value so you can run blind - // but we also need to be able to avoid it <--> 0 - eoValueParam& maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion"); - - if (maxGenParam.value()) // positive: -> define and store - { - eoGenContinue *genCont = new eoGenContinue(maxGenParam.value()); - _state.storeFunctor(genCont); - // and "add" to combined - continuator = make_combinedContinue(continuator, genCont); - } - -#ifndef _MSC_VER - // the CtrlC interception (Linux only I'm afraid) - eoCtrlCContinue *ctrlCCont; - eoValueParam& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion"); - if (_parser.isItThere(ctrlCParam)) - { - ctrlCCont = new eoCtrlCContinue; - // store - _state.storeFunctor(ctrlCCont); - // add to combinedContinue - continuator = make_combinedContinue(continuator, ctrlCCont); - } -#endif - - // now check that there is at least one! - if (!continuator) - throw std::runtime_error("You MUST provide a stopping criterion"); - // OK, it's there: store in the eoState - _state.storeFunctor(continuator); - - // and return - return *continuator; -} - -#endif diff --git a/eo/src/eo b/eo/src/eo index 61868d16..cf18f3ea 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -127,7 +127,6 @@ #include // Perf2Worth stuff - includes eoSelectFromWorth.h -#include #include diff --git a/eo/src/eoDominanceMap.h b/eo/src/eoDominanceMap.h deleted file mode 100644 index ead93196..00000000 --- a/eo/src/eoDominanceMap.h +++ /dev/null @@ -1,162 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoDominanceMap.h - (c) Maarten Keijzer, 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: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef eoDominanceMap_h -#define eoDominanceMap_h - -#include -#include - -/** - eoDominanceMap, utility class to calculate and maintain a map (std::vector >) of pareto dominance statistics. - - It is set up such that - - if map[i][j] == true - then i dominates j - - The dominance map can be used to perform pareto ranking (eoParetoRanking) or non dominated sorting. - For the latter, the remove() member function might come in handy. - - \todo make it an eoStat? -*/ -template -class eoDominanceMap : public eoUF&, void>, public std::vector > -{ -public: - - /** Clears the map */ - void clear() { - std::vector >::clear(); - fitness.clear(); - } - - /** - Update or create the dominance map - */ - void operator()(const eoPop& _pop) - { - setup(_pop); - return; - } - - /** - Removes the domination info for a given individual, thus nothing dominates it and it dominates nothing. - */ - void remove(unsigned i) - { - for (unsigned j = 0; j < size(); ++j) - { - operator[](i)[j] = false; // clear row - operator[](j)[i] = false; // clear col - } - } - - /** - Create domination matrix from scratch. Complexity O(N^2) - */ - void setup(const eoPop& _pop) - { - fitness.resize(_pop.size()); - resize(_pop.size()); - - for (unsigned i = 0; i < _pop.size(); ++i) - { - fitness[i] = _pop[i].fitness(); - operator[](i).resize(_pop.size(), false); - - for (unsigned j = 0; j < i; ++j) - { - if (_pop[i].fitness().dominates(_pop[j].fitness())) - { - operator[](i)[j] = true; - operator[](j)[i] = false; - } - else if (_pop[j].fitness().dominates(_pop[i].fitness())) - { - operator[](i)[j] = false; - operator[](j)[i] = true; - } - else - { - operator[](i)[j] = false; - operator[](j)[i] = false; - } - } - } - } - - /** - For all elements, returns the no. of elements that dominate the element - Thus: lower is better (and 0 is the front). - It returns a std::vector cuz that - makes subsequent manipulation that much easier - */ - std::vector sum_dominators() const - { - std::vector result(size(), 0.0); - - for (unsigned i = 0; i < size(); ++i) - { - for (unsigned j = 0; j < size(); ++j) - { - if (operator[](i)[j]) // i dominates j - result[j]++; - } - } - - return result; - } - - /** - For all elements, returns the number of elements that the element dominates - Thus: higher is better - It returns a std::vector cuz that - makes subsequent manipulation that much easier - */ - std::vector sum_dominants() const - { - std::vector result(size(), 0.0); - - for (unsigned i = 0; i < size(); ++i) - { - for (unsigned j = 0; j < size(); ++j) - { - if (operator[](i)[j]) // i dominates j - result[i]++; - } - } - - return result; - } - - private : - - - std::vector fitness; -}; - -#endif diff --git a/eo/src/eoParetoConstraintFitness.h b/eo/src/eoParetoConstraintFitness.h deleted file mode 100644 index c33417ad..00000000 --- a/eo/src/eoParetoConstraintFitness.h +++ /dev/null @@ -1,229 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoParetoConstraintFitness.h -// (c) Maarten Keijzer and 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: mkeijzer@cs.vu.nl - Marc.Schoenauer@inria.fr - */ -//----------------------------------------------------------------------------- - -#ifndef _eoParetoConstraintFitness_h -#define _eoParetoConstraintFitness_h - -#include -#include -#include -#include - -#include - -/** - eoParetoOneConstraintFitness class: - std::vector of doubles + constraint value - - Comparison (dominance) is done - on pareto dominance for 2 feasible individuals, - one feasible individual always wins over an infeasible - on constraint violations for 2 infeasible individuals - - The template argument FitnessTraits defaults to - eoParetoFitnessTraits, which can be replaces at will by any other - class that implements the static functions defined therein. - - Note that the domninance defines a partial order, so that - !dominates(a,b) && !domaintes(b,a) does not neccessarily imply that (a==b) - The other way around does hold. - - However, be careful that the comparison operators do define a total order - based on considering first objective, then in case of tie, second objective, etc - - NOTE: in a hurry, I did not want to make it derive from eoParetoFitness - (used cut-and-paste instead!) : I know it might be a good idea, but I'm - not sure I see why at the moment (any hint someone?) -*/ -template -class eoParetoOneConstraintFitness : public std::vector -{ -private: - // this class implements only 1 inequality constraint - // (must ponder a bit for generality without huge overload) - double constraintValue; // inequality cstr - must be negative - -public : - typedef FitnessTraits fitness_traits; - - eoParetoOneConstraintFitness(void) : std::vector(FitnessTraits::nObjectives(),0.0) {} - - // Ctr from a std::vector (size nObjectives+1) - eoParetoOneConstraintFitness(std::vector & _v) : - std::vector(_v) - { -#ifndef NDEBUG - if (_v.size() != fitness_traits::nObjectives()+1) - throw std::runtime_error("Size error in Ctor of eoParetoOneConstraintFitness from std::vector"); -#endif - constraintValue = _v[fitness_traits::nObjectives()]; - resize(fitness_traits::nObjectives()); - } - - // Ctr from a std::vector and a value - eoParetoOneConstraintFitness(std::vector & _v, double _c) : - std::vector(_v), constraintValue(_c) - { -#ifndef NDEBUG - if (_v.size() != fitness_traits::nObjectives()) - throw std::runtime_error("Size error in Ctor of eoParetoOneConstraintFitness from std::vector and value"); -#endif - } - - - /** access to the traits characteristics (so you don't have to write - * a lot of typedef's around - */ - static void setUp(unsigned _n, std::vector & _b) {FitnessTraits::setUp(_n, _b);} - static bool maximizing(unsigned _i) { return FitnessTraits::maximizing(_i);} - - bool feasible() const { return constraintValue<=0;} - double violation() const { return (feasible()?0.0:constraintValue);} - double ConstraintValue() const {return constraintValue;} - void ConstraintValue(double _c) {constraintValue=_c;} - - /// Partial order based on Pareto-dominance - //bool operator<(const eoParetoFitness& _other) const - bool dominates(const eoParetoOneConstraintFitness& _other) const - { - bool dom = false; - - double tol = FitnessTraits::tol(); - const std::vector& performance = *this; - const std::vector& otherperformance = _other; - - if (feasible() && _other.feasible()) - // here both are feasible: do the "standard" domination - for (unsigned i = 0; i < FitnessTraits::nObjectives(); ++i) - { - bool maxim = FitnessTraits::maximizing(i); - double aval = maxim? performance[i] : -performance[i]; - double bval = maxim? otherperformance[i] : -otherperformance[i]; - - if (fabs(aval - bval) > tol) - { - if (aval < bval) - { - return false; // cannot dominate - } - // else aval < bval - dom = true; // for the moment: goto next objective - } - //else they're equal in this objective, goto next - } - else - { // one at least is not feasible - if (feasible()) - return true; // feasible wins - else if (_other.feasible()) - return false; // feasible wins - return (violation()<_other.violation()); // smallest violation wins - } - - return dom; - } - - /// compare *not* on dominance, but on the first, then the second, etc - bool operator<(const eoParetoOneConstraintFitness& _other) const - { - double tol = FitnessTraits::tol(); - const std::vector& performance = *this; - const std::vector& otherperformance = _other; - for (unsigned i = 0; i < FitnessTraits::nObjectives(); ++i) - { - bool maxim = FitnessTraits::maximizing(i); - double aval = maxim? performance[i] : -performance[i]; - double bval = maxim? otherperformance[i] : -otherperformance[i]; - - if (fabs(aval-bval) > tol) - { - if (aval < bval) - return true; - - return false; - } - } - - return false; - } - - bool operator>(const eoParetoOneConstraintFitness& _other) const - { - return _other < *this; - } - - bool operator<=(const eoParetoOneConstraintFitness& _other) const - { - return operator==(_other) || operator<(_other); - } - - bool operator>=(const eoParetoOneConstraintFitness& _other) const - { - return _other <= *this; - } - - bool operator==(const eoParetoOneConstraintFitness& _other) const - { // check if they're all within tolerance - for (unsigned i = 0; i < size(); ++i) - { - if (fabs(operator[](i) - _other[i]) > FitnessTraits::tol()) - { - return false; - } - } - return true; - } - - bool operator!=(const eoParetoOneConstraintFitness& _other) const - { return ! operator==(_other); } - -}; - -template -std::ostream& operator<<(std::ostream& os, const eoParetoOneConstraintFitness& fitness) -{ - for (unsigned i = 0; i < fitness.size(); ++i) - { - os << fitness[i] << ' '; - } - os << fitness.ConstraintValue() << " " ; - return os; -} - -template -std::istream& operator>>(std::istream& is, eoParetoOneConstraintFitness& fitness) -{ - fitness = eoParetoOneConstraintFitness(); - for (unsigned i = 0; i < fitness.size(); ++i) - { - is >> fitness[i]; - } - double r; - is >> r; - fitness.ConstraintValue(r); - return is; -} - -#endif diff --git a/eo/src/eoParetoFitness.cpp b/eo/src/eoParetoFitness.cpp deleted file mode 100644 index 6de72db7..00000000 --- a/eo/src/eoParetoFitness.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoPareto.cpp -// (c) EEAAX,1996-GeNeura Team,1998-Maarten Keijzer,2000-Marc Schoenauer 2002 -/* - 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: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@inria.fr - mak@dhi.dk -*/ -//----------------------------------------------------------------------------- -#ifdef _MSC_VER -// to avoid long name warnings -#pragma warning(disable:4786) -#endif - -#include "eoParetoFitness.h" - - -// need to allocate the static variables of class eoVariableParetoTraits -unsigned eoVariableParetoTraits::nObj; -std::vector eoVariableParetoTraits::bObj; - - diff --git a/eo/src/eoParetoFitness.h b/eo/src/eoParetoFitness.h deleted file mode 100644 index 44594937..00000000 --- a/eo/src/eoParetoFitness.h +++ /dev/null @@ -1,235 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eoParetoFitness.h -// (c) Maarten Keijzer and 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: mak@dhi.dk - Marc.Schoenauer@inria.fr - */ -//----------------------------------------------------------------------------- - -#ifndef _eoParetoFitness_h -#define _eoParetoFitness_h - -#include -#include -#include -#include -#include - -/** - * eoFitnessTraits: a traits class to specify - * the number of objectives and which one are maximizing or not - * See test/t-eoParetoFitness for its use. - * - * If you define your own, make sure you make the functions static! -*/ -class eoParetoFitnessTraits -{ - public : - - static unsigned nObjectives() { return 2; } - static double tol() { return 1e-6; } - static bool maximizing(int which) { (void)which; return true; } // by default: all are maximizing -}; - -/** - * eoVariableParetoTraits : an eoParetoFitnessTraits whose characteristics - * can be set at run-time (nb objectives and min/max's) - * Why bother? For didactical purposes (and EASEA implementation :-) - */ -class eoVariableParetoTraits : public eoParetoFitnessTraits -{ -public : - /** setting the static stuff */ - static void setUp(unsigned _n, std::vector & _b) - { - // possible problems - if ( nObj && (nObj != _n) ) // was already set to a different value - { - eo::log << eo::warnings; - eo::log << "WARNING\n"; - eo::log << "WARNING : you are changing the number of objectives\n"; - eo::log << "WARNING : Make sure all existing objects are destroyed\n"; - eo::log << "WARNING\n"; - } - nObj=_n; - bObj=_b; - if (nObj != bObj.size()) - throw std::runtime_error("Number of objectives and min/max size don't match in VariableParetoTraits::setup"); - } - - /** the accessors */ - static unsigned nObjectives() - { -#ifndef NDEBUG - if (!nObj) - throw std::runtime_error("Number of objectives not assigned in VariableParetoTraits"); -#endif - return nObj; - } - static bool maximizing(unsigned _i) - { -#ifndef NDEBUG - if (_i >= bObj.size()) - throw std::runtime_error("Wrong index in VariableParetoTraits"); -#endif - return bObj[_i]; - } -private: - static unsigned nObj; - static std::vector bObj; -}; - -/** - eoParetoFitness class: std::vector of doubles with overloaded comparison operators. Comparison is done - on pareto dominance. The template argument FitnessTraits defaults to eoParetoFitnessTraits, which - can be replaces at will by any other class that implements the static functions defined therein. - - Note that the comparison defines a partial order, so that - !(a < b) && !(b -class eoParetoFitness : public std::vector -{ -public : - - typedef FitnessTraits fitness_traits; - - eoParetoFitness(void) : std::vector(FitnessTraits::nObjectives(),0.0) {} - - // Ctr from a std::vector - eoParetoFitness(std::vector & _v) : std::vector(_v) {} - - - /** access to the traits characteristics (so you don't have to write - * a lot of typedef's around - */ - static void setUp(unsigned _n, std::vector & _b) {FitnessTraits::setUp(_n, _b);} - static bool maximizing(unsigned _i) { return FitnessTraits::maximizing(_i);} - - /// Partial order based on Pareto-dominance - //bool operator<(const eoParetoFitness& _other) const - bool dominates(const eoParetoFitness& _other) const - { - bool dom = false; - - double tol = FitnessTraits::tol(); - const std::vector& performance = *this; - const std::vector& otherperformance = _other; - - for (unsigned i = 0; i < FitnessTraits::nObjectives(); ++i) - { - bool maxim = FitnessTraits::maximizing(i); - double aval = maxim? performance[i] : -performance[i]; - double bval = maxim? otherperformance[i] : -otherperformance[i]; - - if (fabs(aval - bval) > tol) - { - if (aval < bval) - { - return false; // cannot dominate - } - // else aval < bval - dom = true; // for the moment: goto next objective - } - //else they're equal in this objective, goto next - } - - return dom; - } - - /// compare *not* on dominance, but on the first, then the second, etc - bool operator<(const eoParetoFitness& _other) const - { - double tol = FitnessTraits::tol(); - const std::vector& performance = *this; - const std::vector& otherperformance = _other; - for (unsigned i = 0; i < FitnessTraits::nObjectives(); ++i) - { - bool maxim = FitnessTraits::maximizing(i); - double aval = maxim? performance[i] : -performance[i]; - double bval = maxim? otherperformance[i] : -otherperformance[i]; - - if (fabs(aval-bval) > tol) - { - if (aval < bval) - return true; - - return false; - } - } - - return false; - } - - bool operator>(const eoParetoFitness& _other) const - { - return _other < *this; - } - - bool operator<=(const eoParetoFitness& _other) const - { - return operator==(_other) || operator<(_other); - } - - bool operator>=(const eoParetoFitness& _other) const - { - return _other <= *this; - } - - bool operator==(const eoParetoFitness& _other) const - { // check if they're all within tolerance - for (unsigned i = 0; i < size(); ++i) - { - if (fabs(operator[](i) - _other[i]) > FitnessTraits::tol()) - { - return false; - } - } - return true; - } - - bool operator!=(const eoParetoFitness& _other) const - { return ! operator==(_other); } - -}; - -template -std::ostream& operator<<(std::ostream& os, const eoParetoFitness& fitness) -{ - for (unsigned i = 0; i < fitness.size(); ++i) - { - os << fitness[i] << ' '; - } - return os; -} - -template -std::istream& operator>>(std::istream& is, eoParetoFitness& fitness) -{ - fitness = eoParetoFitness(); - for (unsigned i = 0; i < fitness.size(); ++i) - { - is >> fitness[i]; - } - return is; -} - -#endif diff --git a/eo/src/eoParetoRanking.h b/eo/src/eoParetoRanking.h deleted file mode 100644 index cd54ff00..00000000 --- a/eo/src/eoParetoRanking.h +++ /dev/null @@ -1,71 +0,0 @@ -/** -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - - ----------------------------------------------------------------------------- - eoParetoRanking.h - (c) Maarten Keijzer, 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: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- - -#ifndef eoParetoRanking_h -#define eoParetoRanking_h - -#include -#include - -/** - Straightforward pareto ranking. Every individual gets a rank according to the number - of elements it dominates. Note that without niching, this technique will usually not - find the whole front of non-dominated solutions, but will quite likely converge - on a single spot on the front. -*/ -template -class eoParetoRanking : public eoPerf2WorthCached -{ -public: - - using eoPerf2WorthCached::value; - - eoParetoRanking(eoDominanceMap& _dominanceMap) - : eoPerf2WorthCached(), dominanceMap(_dominanceMap) - {} - - void calculate_worths(const eoPop& _pop) - { - dominanceMap(_pop); - value() = dominanceMap.sum_dominators(); // get rank: 0 means part of current front - - // calculate maximum - double maxim = *std::max_element(value().begin(), value().end()); - - // higher is better, so invert the value - for (unsigned i = 0; i < value().size(); ++i) - { - value()[i] = maxim - value()[i]; - } - - } - - private : - - eoDominanceMap& dominanceMap; -}; - -#endif diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index d00657d8..d27520b1 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -37,7 +37,6 @@ Contact: http://eodev.sourceforge.net #include #include #include -#include #include #include @@ -131,7 +130,6 @@ public : Average fitness of a population. Fitness can be: - double - eoMinimizingFitness or eoMaximizingFitness - - eoParetoFitness: The average of each objective is evaluated. ( For eoScalarFitnessAssembled user eoAssembledFitnessStat classes.) @@ -166,24 +164,6 @@ public : private : - // Specialization for pareto fitness - template - void doit(const eoPop& _pop, eoParetoFitness) - { - value().clear(); - value().resize(_pop[0].fitness().size(), 0.0); - - for (unsigned o = 0; o < value().size(); ++o) - { - for (unsigned i = 0; i < _pop.size(); ++i) - { - value()[o] += _pop[i].fitness()[o]; - } - - value()[o] /= _pop.size(); - } - } - // Default behavior template void doit(const eoPop& _pop, T) @@ -280,25 +260,6 @@ private : bool maxim; }; - // Specialization for eoParetoFitness - template - void doit(const eoPop& _pop, eoParetoFitness) - { - typedef typename EOT::Fitness::fitness_traits traits; - - value().resize(traits::nObjectives()); - - // copy of pointers, what the heck - std::vector tmp_pop = _pop; - - for (unsigned o = 0; o < value().size(); ++o) - { - typename std::vector::iterator nth = tmp_pop.begin() + whichElement; - std::nth_element(tmp_pop.begin(), nth, tmp_pop.end(), CmpFitness(o, traits::maximizing(o))); - value()[o] = (*nth)->fitness()[o]; - } - } - // for everything else template void doit(const std::vector& _pop, T) @@ -337,7 +298,6 @@ public : Best fitness of a population. Fitness can be: - double - eoMinimizingFitness or eoMaximizingFitness - - eoParetoFitness: ( For eoScalarFitnessAssembled look at eoAssembledFitnessStat ) */ @@ -385,20 +345,6 @@ private : bool maxim; }; - // Specialization for pareto fitness - template - void doit(const eoPop& _pop, eoParetoFitness) - { - typedef typename EOT::Fitness::fitness_traits traits; - value().resize(traits::nObjectives()); - - for (unsigned o = 0; o < traits::nObjectives(); ++o) - { - typename eoPop::const_iterator it = std::max_element(_pop.begin(), _pop.end(), CmpFitness(o, traits::maximizing(o))); - value()[o] = it->fitness()[o]; - } - } - // default template void doit(const eoPop& _pop, T)