remove multi-objective stuff, deprecated by ParadisEO-PEO

This commit is contained in:
Johann Dreo 2010-11-07 23:16:45 +01:00
commit 4cebad979d
11 changed files with 0 additions and 1350 deletions

View file

@ -15,7 +15,6 @@ SET (EO_SOURCES eoFunctorStore.cpp
eoPersistent.cpp
eoPrintable.cpp
eoCtrlCContinue.cpp
eoParetoFitness.cpp
eoScalarFitnessAssembled.cpp
eoSIGContinue.cpp)

View file

@ -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 EOT, class WorthT = double>
class eoNDPlusReplacement : public eoReplacement<EOT>
{
public:
eoNDPlusReplacement(eoPerf2Worth<EOT, WorthT>& _perf2worth) : perf2worth(_perf2worth) {}
struct WorthPair : public std::pair<WorthT, const EOT*>
{
bool operator<(const WorthPair& other) const { return other.first < this->first; }
};
void operator()(eoPop<EOT>& _parents, eoPop<EOT>& _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<EOT, WorthT>& 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 <class EOT>
eoAlgo<EOT> & do_make_algo_pareto(eoParser& _parser, eoState& _state, eoEvalFunc<EOT>& _eval, eoContinue<EOT>& _continue, eoGenOp<EOT>& _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<EOT, double> *p2w;
if ( (selStr == std::string("NSGA")) || (selStr == std::string("NSGA-I") ) )
p2w = new eoNDSorting_I<EOT>(nicheSize);
else if (selStr == std::string("NSGA-II"))
p2w = new eoNDSorting_II<EOT>();
else if (selStr == std::string("ParetoRanking"))
{
eoDominanceMap<EOT>& dominance = _state.storeFunctor(new eoDominanceMap<EOT>);
p2w = new eoParetoRanking<EOT>(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<eoParamParamType>& selectionParam = _parser.createParam(eoParamParamType("DetTour(2)"), "selection", "Selection: Roulette, DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value(); // std::pair<std::string,std::vector<std::string> >
eoSelectOne<EOT>* 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<EOT>(*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<EOT>(*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<EOT>(b);
// }
else if (ppSelect.first == std::string("Roulette")) // no argument (yet)
{
select = new eoRouletteWorthSelect<EOT>(*p2w);
}
else if (ppSelect.first == std::string("Random")) // no argument, no perf2Worth
{
select = new eoRandomSelect<EOT>;
}
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<eoHowMany>& offspringRateParam = _parser.createParam(eoHowMany(1.0), "nbOffspring", "Nb of offspring (percentage or absolute)", 'O', "Evolution Engine");
// the replacement
// actually limited to eoNDPlusReplacement
eoReplacement<EOT> & replace = _state.storeFunctor(
new eoNDPlusReplacement<EOT, double>(*p2w)
);
// the general breeder
eoGeneralBreeder<EOT> *breed =
new eoGeneralBreeder<EOT>(*select, _op, offspringRateParam.value());
_state.storeFunctor(breed);
// now the eoEasyEA
eoAlgo<EOT> *algo = new eoEasyEA<EOT>(_continue, _eval, *breed, replace);
_state.storeFunctor(algo);
// that's it!
return *algo;
}
#endif

View file

@ -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 <climits>
#include <cstdlib>
#include <sstream>
#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 <class EOT>
eoCheckPoint<EOT>& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state,
eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
{
// first, create a checkpoint from the eoContinue - and store in _state
eoCheckPoint<EOT> & checkpoint = _state.storeFunctor(new eoCheckPoint<EOT>(_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<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
// Create an incrementor (sub-class of eoUpdater).
eoIncrementor<unsigned> & increment =
_state.storeFunctor(new eoIncrementor<unsigned>(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<bool>& 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<eoParamParamType>& 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<std::string,std::vector<std::string> >
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<bool> bStat(nObj, false); // track of who's already there
std::vector<eoMOFitnessStat<EOT>* > theStats(nObj);
// first create the stats
for (unsigned i=0; i<nbPlot; i+=2)
{
unsigned obj1 = atoi(fPlot.second[i].c_str());
unsigned obj2 = atoi(fPlot.second[i+1].c_str());
eoMOFitnessStat<EOT>* fStat;
if (!bStat[obj1]) { // not already there: create it
std::ostringstream os;
os << "Obj. " << obj1 << std::ends;
fStat = new eoMOFitnessStat<EOT>(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<EOT>(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<EOT> * popStat;
if ( printPop ) // we do want pop dump
{
std::cout << "On cree printpop\n";
popStat = & _state.storeFunctor(new eoSortedPopStat<EOT>);
// 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<unsigned>& 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<unsigned>& 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

View file

@ -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 <eoCombinedContinue.h>
#include <eoGenContinue.h>
#include <eoEvalContinue.h>
#include <eoFitContinue.h>
#ifndef _MSC_VER
#include <eoCtrlCContinue.h> // CtrlC handling (using 2 global variables!)
#endif
// also need the parser and param includes
#include <utils/eoParser.h>
#include <utils/eoState.h>
/////////////////// helper function ////////////////
template <class Indi>
eoCombinedContinue<Indi> * make_combinedContinue(eoCombinedContinue<Indi> *_combined, eoContinue<Indi> *_cont)
{
if (_combined) // already exists
_combined->add(*_cont);
else
_combined = new eoCombinedContinue<Indi>(*_cont);
return _combined;
}
///////////// The make_continue function
template <class Indi>
eoContinue<Indi> & do_make_continue_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval)
{
//////////// Stopping criterion ///////////////////
// the combined continue - to be filled
eoCombinedContinue<Indi> *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<unsigned>& maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion");
if (maxGenParam.value()) // positive: -> define and store
{
eoGenContinue<Indi> *genCont = new eoGenContinue<Indi>(maxGenParam.value());
_state.storeFunctor(genCont);
// and "add" to combined
continuator = make_combinedContinue<Indi>(continuator, genCont);
}
#ifndef _MSC_VER
// the CtrlC interception (Linux only I'm afraid)
eoCtrlCContinue<Indi> *ctrlCCont;
eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
if (_parser.isItThere(ctrlCParam))
{
ctrlCCont = new eoCtrlCContinue<Indi>;
// store
_state.storeFunctor(ctrlCCont);
// add to combinedContinue
continuator = make_combinedContinue<Indi>(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

View file

@ -127,7 +127,6 @@
#include <eoSGATransform.h>
// Perf2Worth stuff - includes eoSelectFromWorth.h
#include <eoParetoRanking.h>
#include <eoNDSorting.h>

View file

@ -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 <eoFunctor.h>
#include <eoPop.h>
/**
eoDominanceMap, utility class to calculate and maintain a map (std::vector<std::vector<bool> >) 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 EoType>
class eoDominanceMap : public eoUF<const eoPop<EoType>&, void>, public std::vector<std::vector<bool> >
{
public:
/** Clears the map */
void clear() {
std::vector<std::vector<bool> >::clear();
fitness.clear();
}
/**
Update or create the dominance map
*/
void operator()(const eoPop<EoType>& _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<EoType>& _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<double> cuz that
makes subsequent manipulation that much easier
*/
std::vector<double> sum_dominators() const
{
std::vector<double> 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<double> cuz that
makes subsequent manipulation that much easier
*/
std::vector<double> sum_dominants() const
{
std::vector<double> 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<typename EoType::Fitness> fitness;
};
#endif

View file

@ -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 <math.h>
#include <vector>
#include <stdexcept>
#include <iostream>
#include <eoParetoFitness.h>
/**
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 FitnessTraits = eoParetoFitnessTraits>
class eoParetoOneConstraintFitness : public std::vector<double>
{
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<double>(FitnessTraits::nObjectives(),0.0) {}
// Ctr from a std::vector<double> (size nObjectives+1)
eoParetoOneConstraintFitness(std::vector<double> & _v) :
std::vector<double>(_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<double> and a value
eoParetoOneConstraintFitness(std::vector<double> & _v, double _c) :
std::vector<double>(_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<bool> & _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<FitnessTraits>& _other) const
bool dominates(const eoParetoOneConstraintFitness<FitnessTraits>& _other) const
{
bool dom = false;
double tol = FitnessTraits::tol();
const std::vector<double>& performance = *this;
const std::vector<double>& 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<FitnessTraits>& _other) const
{
double tol = FitnessTraits::tol();
const std::vector<double>& performance = *this;
const std::vector<double>& 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<FitnessTraits>& _other) const
{
return _other < *this;
}
bool operator<=(const eoParetoOneConstraintFitness<FitnessTraits>& _other) const
{
return operator==(_other) || operator<(_other);
}
bool operator>=(const eoParetoOneConstraintFitness<FitnessTraits>& _other) const
{
return _other <= *this;
}
bool operator==(const eoParetoOneConstraintFitness<FitnessTraits>& _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<FitnessTraits>& _other) const
{ return ! operator==(_other); }
};
template <class FitnessTraits>
std::ostream& operator<<(std::ostream& os, const eoParetoOneConstraintFitness<FitnessTraits>& fitness)
{
for (unsigned i = 0; i < fitness.size(); ++i)
{
os << fitness[i] << ' ';
}
os << fitness.ConstraintValue() << " " ;
return os;
}
template <class FitnessTraits>
std::istream& operator>>(std::istream& is, eoParetoOneConstraintFitness<FitnessTraits>& fitness)
{
fitness = eoParetoOneConstraintFitness<FitnessTraits>();
for (unsigned i = 0; i < fitness.size(); ++i)
{
is >> fitness[i];
}
double r;
is >> r;
fitness.ConstraintValue(r);
return is;
}
#endif

View file

@ -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<bool> eoVariableParetoTraits::bObj;

View file

@ -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 <math.h>
#include <vector>
#include <stdexcept>
#include <iostream>
#include <utils/eoLogger.h>
/**
* 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<bool> & _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<bool> 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 <a) does not neccessarily imply that (a==b)
The other way around does hold.
*/
template <class FitnessTraits = eoParetoFitnessTraits>
class eoParetoFitness : public std::vector<double>
{
public :
typedef FitnessTraits fitness_traits;
eoParetoFitness(void) : std::vector<double>(FitnessTraits::nObjectives(),0.0) {}
// Ctr from a std::vector<double>
eoParetoFitness(std::vector<double> & _v) : std::vector<double>(_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<bool> & _b) {FitnessTraits::setUp(_n, _b);}
static bool maximizing(unsigned _i) { return FitnessTraits::maximizing(_i);}
/// Partial order based on Pareto-dominance
//bool operator<(const eoParetoFitness<FitnessTraits>& _other) const
bool dominates(const eoParetoFitness<FitnessTraits>& _other) const
{
bool dom = false;
double tol = FitnessTraits::tol();
const std::vector<double>& performance = *this;
const std::vector<double>& 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<FitnessTraits>& _other) const
{
double tol = FitnessTraits::tol();
const std::vector<double>& performance = *this;
const std::vector<double>& 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<FitnessTraits>& _other) const
{
return _other < *this;
}
bool operator<=(const eoParetoFitness<FitnessTraits>& _other) const
{
return operator==(_other) || operator<(_other);
}
bool operator>=(const eoParetoFitness<FitnessTraits>& _other) const
{
return _other <= *this;
}
bool operator==(const eoParetoFitness<FitnessTraits>& _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<FitnessTraits>& _other) const
{ return ! operator==(_other); }
};
template <class FitnessTraits>
std::ostream& operator<<(std::ostream& os, const eoParetoFitness<FitnessTraits>& fitness)
{
for (unsigned i = 0; i < fitness.size(); ++i)
{
os << fitness[i] << ' ';
}
return os;
}
template <class FitnessTraits>
std::istream& operator>>(std::istream& is, eoParetoFitness<FitnessTraits>& fitness)
{
fitness = eoParetoFitness<FitnessTraits>();
for (unsigned i = 0; i < fitness.size(); ++i)
{
is >> fitness[i];
}
return is;
}
#endif

View file

@ -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 <eoPerf2Worth.h>
#include <eoDominanceMap.h>
/**
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 EOT>
class eoParetoRanking : public eoPerf2WorthCached<EOT, double>
{
public:
using eoPerf2WorthCached<EOT, double>::value;
eoParetoRanking(eoDominanceMap<EOT>& _dominanceMap)
: eoPerf2WorthCached<EOT, double>(), dominanceMap(_dominanceMap)
{}
void calculate_worths(const eoPop<EOT>& _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<EOT>& dominanceMap;
};
#endif

View file

@ -37,7 +37,6 @@ Contact: http://eodev.sourceforge.net
#include <eoFunctor.h>
#include <utils/eoParam.h>
#include <eoPop.h>
#include <eoParetoFitness.h>
#include <utils/eoMonitor.h>
#include <utils/eoCheckPoint.h>
@ -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 <class T>
void doit(const eoPop<EOT>& _pop, eoParetoFitness<T>)
{
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 <class T>
void doit(const eoPop<EOT>& _pop, T)
@ -280,25 +260,6 @@ private :
bool maxim;
};
// Specialization for eoParetoFitness
template <class T>
void doit(const eoPop<EOT>& _pop, eoParetoFitness<T>)
{
typedef typename EOT::Fitness::fitness_traits traits;
value().resize(traits::nObjectives());
// copy of pointers, what the heck
std::vector<const EOT*> tmp_pop = _pop;
for (unsigned o = 0; o < value().size(); ++o)
{
typename std::vector<const EOT*>::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 <class T>
void doit(const std::vector<const EOT*>& _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 <class T>
void doit(const eoPop<EOT>& _pop, eoParetoFitness<T>)
{
typedef typename EOT::Fitness::fitness_traits traits;
value().resize(traits::nObjectives());
for (unsigned o = 0; o < traits::nObjectives(); ++o)
{
typename eoPop<EOT>::const_iterator it = std::max_element(_pop.begin(), _pop.end(), CmpFitness(o, traits::maximizing(o)));
value()[o] = it->fitness()[o];
}
}
// default
template<class T>
void doit(const eoPop<EOT>& _pop, T)