update doc and sort files

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@211 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-04-12 08:26:52 +00:00
commit db21384417
17 changed files with 620 additions and 546 deletions

View file

@ -1,215 +1,90 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// make_checkpoint_pareto.h // make_checkpoint_moeo.h
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/* /*
This library is free software; you can redistribute it and/or This library...
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, Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
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 #ifndef MAKE_CHECKPOINT_MOEO_H_
#define _make_checkpoint_pareto_h #define MAKE_CHECKPOINT_MOEO_H_
#include <stdlib.h> #include <stdlib.h>
#include <sstream> #include <sstream>
#include <eoContinue.h>
#include <eoEvalFuncCounter.h>
#include <utils/checkpointing>
#include <utils/selectors.h>
#include <utils/eoParser.h>
#include <utils/eoState.h>
#include <moeoArchiveUpdater.h>
#include <moeoArchiveObjectiveVectorSavingUpdater.h>
#include <metric/moeoBinaryMetricSavingUpdater.h>
#include <metric/moeoContributionMetric.h>
#include <metric/moeoEntropyMetric.h>
#include "MOEO.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); bool testDirRes(std::string _dirName, bool _erase);
/////////////////// The checkpoint and other I/O //////////////
/** /**
* This functions allows to build an eoCheckPoint for multi-objective optimization from the parser (partly taken from make_checkpoint_pareto.h)
* @param _parser the parser
* @param _state to store allocated objects
* @param _eval the funtions evaluator
* @param _continue the stopping crietria
* @param _pop the population
* @param _archive the archive of non-dominated solutions
*/ */
template <class EOT> template < class MOEOT >
eoCheckPoint<EOT>& do_make_checkpoint_moeo(eoParser& _parser, eoState& _state, eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState & _state, eoEvalFuncCounter < MOEOT > & _eval, eoContinue < MOEOT > & _continue, eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _archive)
eoEvalFuncCounter<EOT>& _eval, eoContinue<EOT>& _continue)
{ {
// first, create a checkpoint from the eoContinue - and store in _state eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
eoCheckPoint<EOT> & checkpoint = _state.storeFunctor(new eoCheckPoint<EOT>(_continue)); /* the objective vector type */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/////// get number of obectives // get number of obectives
unsigned nObj = EOT::ObjectiveVector::nObjectives(); unsigned nObj = ObjectiveVector::nObjectives();
/////////////////// ///////////////////
// Counters // Counters
////////////////// //////////////////
// is nb Eval to be used as counter? // is nb Eval to be used as counter?
bool useEval = _parser.getORcreateParam(true, "useEval", bool useEval = _parser.getORcreateParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value();
"Use nb of eval. as counter (vs nb of gen.)", // Create anyway a generation-counter parameter
'\0', "Output").value();
// Create anyway a generation-counter parameter WARNING: not stored anywhere!!!
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen."); eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
// Create an incrementor (sub-class of eoUpdater). // Create an incrementor (sub-class of eoUpdater).
eoIncrementor<unsigned> & increment = eoIncrementor<unsigned> & increment = _state.storeFunctor( new eoIncrementor<unsigned>(generationCounter->value()) );
_state.storeFunctor(new eoIncrementor<unsigned>(generationCounter->value()) ); // Add it to the checkpoint
// Add it to the checkpoint,
checkpoint.add(increment); checkpoint.add(increment);
// dir for DISK output // dir for DISK output
std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value();
"Directory to store DISK outputs",
'\0', "Output - Disk").value();
// shoudl we empty it if exists // shoudl we empty it if exists
eoValueParam<bool>& eraseParam = _parser.getORcreateParam(true, "eraseDir", eoValueParam<bool>& eraseParam = _parser.getORcreateParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output");
"erase files in dirName if any",
'\0', "Output - Disk");
bool dirOK = false; // not tested yet 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 // Dump of the whole population
//----------------------------- //-----------------------------
/* bool printPop = _parser.getORcreateParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value();
bool printPop = _parser.getORcreateParam(false, "printPop", eoSortedPopStat<MOEOT> * popStat;
"Print sorted pop. every gen.",
'\0', "Output").value();
eoSortedPopStat<EOT> * popStat;
if ( printPop ) // we do want pop dump if ( printPop ) // we do want pop dump
{ {
std::cout << "On cree printpop\n"; popStat = & _state.storeFunctor(new eoSortedPopStat<MOEOT>);
popStat = & _state.storeFunctor(new eoSortedPopStat<EOT>);
// add it to the checkpoint
checkpoint.add(*popStat); 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 // State savers
////////////////////////////// //////////////////////////////
// feed the state to state savers // feed the state to state savers
// save state every N generation // 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" ); eoValueParam<unsigned>& saveFrequencyParam = _parser.createParam(unsigned(0), "saveFrequency", "Save every F generation (0 = only final state, absent = never)", '\0', "Persistence" );
if (_parser.isItThere(saveFrequencyParam)) if (_parser.isItThere(saveFrequencyParam))
{ {
// first make sure dirName is OK // first make sure dirName is OK
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX ); unsigned freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\generations"; std::string stmp = dirName + "\generations";
@ -220,17 +95,13 @@ eoCheckPoint<EOT>& do_make_checkpoint_moeo(eoParser& _parser, eoState& _state,
_state.storeFunctor(stateSaver1); _state.storeFunctor(stateSaver1);
checkpoint.add(*stateSaver1); checkpoint.add(*stateSaver1);
} }
// save state every T seconds // save state every T seconds
eoValueParam<unsigned>& saveTimeIntervalParam eoValueParam<unsigned>& saveTimeIntervalParam = _parser.getORcreateParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" );
= _parser.getORcreateParam(unsigned(0), "saveTimeInterval",
"Save every T seconds (0 or absent = never)", '\0',"Persistence" );
if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0)
{ {
// first make sure dirName is OK // first make sure dirName is OK
if (! dirOK ) if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC #ifdef _MSVC
std::string stmp = dirName + "\time"; std::string stmp = dirName + "\time";
#else #else
@ -241,9 +112,67 @@ eoCheckPoint<EOT>& do_make_checkpoint_moeo(eoParser& _parser, eoState& _state,
checkpoint.add(*stateSaver2); checkpoint.add(*stateSaver2);
} }
///////////////////
// Archive
//////////////////
// update the archive every generation
bool updateArch = _parser.getORcreateParam(true, "updateArch", "Update the archive at each gen.", '\0', "Evolution Engine").value();
if (updateArch)
{
moeoArchiveUpdater < MOEOT > * updater = new moeoArchiveUpdater < MOEOT > (_archive, _pop);
_state.storeFunctor(updater);
checkpoint.add(*updater);
}
// store the objective vectors contained in the archive every generation
bool storeArch = _parser.getORcreateParam(false, "storeArch", "Store the archive's objective vectors at each gen.", '\0', "Output").value();
if (storeArch)
{
if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC
std::string stmp = dirName + "\arch";
#else
std::string stmp = dirName + "/arch";
#endif
moeoArchiveObjectiveVectorSavingUpdater < MOEOT > * save_updater = new moeoArchiveObjectiveVectorSavingUpdater < MOEOT > (_archive, stmp);
_state.storeFunctor(save_updater);
checkpoint.add(*save_updater);
}
// store the contribution of the non-dominated solutions
bool cont = _parser.getORcreateParam(false, "contribution", "Store the contribution of the archive at each gen.", '\0', "Output").value();
if (cont)
{
if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC
std::string stmp = dirName + "\contribution";
#else
std::string stmp = dirName + "/contribution";
#endif
moeoContributionMetric < ObjectiveVector > * contribution = new moeoContributionMetric < ObjectiveVector >;
moeoBinaryMetricSavingUpdater < MOEOT > * contribution_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*contribution, _archive, stmp);
_state.storeFunctor(contribution_updater);
checkpoint.add(*contribution_updater);
}
// store the entropy of the non-dominated solutions
bool ent = _parser.getORcreateParam(false, "entropy", "Store the entropy of the archive at each gen.", '\0', "Output").value();
if (ent)
{
if (! dirOK )
dirOK = testDirRes(dirName, eraseParam.value()); // TRUE
#ifdef _MSVC
std::string stmp = dirName + "\entropy";
#else
std::string stmp = dirName + "/entropy";
#endif
moeoEntropyMetric < ObjectiveVector > * entropy = new moeoEntropyMetric < ObjectiveVector >;
moeoBinaryMetricSavingUpdater < MOEOT > * entropy_updater = new moeoBinaryMetricSavingUpdater < MOEOT > (*entropy, _archive, stmp);
_state.storeFunctor(entropy_updater);
checkpoint.add(*entropy_updater);
}
// and that's it for the (control and) output // and that's it for the (control and) output
return checkpoint; return checkpoint;
} }
#endif #endif /*MAKE_CHECKPOINT_MOEO_H_*/

View file

@ -1,142 +1,106 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// make_continue_pareto.h // make_continue_moeo.h
// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/* /*
This library is free software; you can redistribute it and/or This library...
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, Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
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 #ifndef MAKE_CONTINUE_MOEO_H_
#define _make_continue_pareto_h #define MAKE_CONTINUE_MOEO_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 <eoCombinedContinue.h>
#include <eoGenContinue.h> #include <eoGenContinue.h>
#include <eoEvalContinue.h> #include <eoEvalContinue.h>
#include <eoFitContinue.h> #include <eoFitContinue.h>
#include <eoTimeContinue.h> #include <eoTimeContinue.h>
#ifndef _MSC_VER #ifndef _MSC_VER
#include <eoCtrlCContinue.h> // CtrlC handling (using 2 global variables!) #include <eoCtrlCContinue.h>
#endif #endif
// also need the parser and param includes
#include <utils/eoParser.h> #include <utils/eoParser.h>
#include <utils/eoState.h> #include <utils/eoState.h>
/////////////////// helper function //////////////// /**
template <class Indi> * Helper function
eoCombinedContinue<Indi> * make_combinedContinue(eoCombinedContinue<Indi> *_combined, eoContinue<Indi> *_cont) * @param _combined the eoCombinedContinue object
* @param _cont the eoContinue to add
*/
template <class MOEOT>
eoCombinedContinue<MOEOT> * make_combinedContinue(eoCombinedContinue<MOEOT> *_combined, eoContinue<MOEOT> *_cont)
{ {
if (_combined) // already exists if (_combined) // already exists
_combined->add(*_cont); _combined->add(*_cont);
else else
_combined = new eoCombinedContinue<Indi>(*_cont); _combined = new eoCombinedContinue<MOEOT>(*_cont);
return _combined; return _combined;
} }
///////////// The make_continue function
template <class Indi> /**
eoContinue<Indi> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter<Indi> & _eval) * This functions allows to build a eoContinue for multi-objective optimization from the parser (partly taken from make_continue_pareto.h)
* @param _parser the parser
* @param _state to store allocated objects
* @param _eval the funtions evaluator
*/
template <class MOEOT>
eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eoEvalFuncCounter<MOEOT> & _eval)
{ {
//////////// Stopping criterion ///////////////////
// the combined continue - to be filled // the combined continue - to be filled
eoCombinedContinue<Indi> *continuator = NULL; eoCombinedContinue<MOEOT> *continuator = NULL;
// for each possible criterion, check if wanted, otherwise do nothing
// First the eoGenContinue - need a default value so you can run blind // First the eoGenContinue - need a default value so you can run blind
// but we also need to be able to avoid it <--> 0 // 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"); eoValueParam<unsigned>& maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion");
if (maxGenParam.value()) // positive: -> define and store if (maxGenParam.value()) // positive: -> define and store
{ {
eoGenContinue<Indi> *genCont = new eoGenContinue<Indi>(maxGenParam.value()); eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value());
_state.storeFunctor(genCont); _state.storeFunctor(genCont);
// and "add" to combined // and "add" to combined
continuator = make_combinedContinue<Indi>(continuator, genCont); continuator = make_combinedContinue<MOEOT>(continuator, genCont);
} }
// maxEval
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)0, "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
/**************************/ if (maxEvalParam.value())
eoValueParam<unsigned long>& maxEvalParam
= _parser.getORcreateParam((unsigned long)0, "maxEval",
"Maximum number of evaluations (0 = none)",
'E', "Stopping criterion");
if (maxEvalParam.value()) // positive: -> define and store
{ {
eoEvalContinue<Indi> *evalCont = new eoEvalContinue<Indi>(_eval, maxEvalParam.value()); eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
_state.storeFunctor(evalCont); _state.storeFunctor(evalCont);
// and "add" to combined // and "add" to combined
continuator = make_combinedContinue<Indi>(continuator, evalCont); continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
} }
/**************************/ // maxTime
eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)0, "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion");
/**************************/
eoValueParam<unsigned long>& maxTimeParam
= _parser.getORcreateParam((unsigned long)0, "maxTime",
"Maximum running time in seconds (0 = none)",
'T', "Stopping criterion");
if (maxTimeParam.value()) // positive: -> define and store if (maxTimeParam.value()) // positive: -> define and store
{ {
eoTimeContinue<Indi> *timeCont = new eoTimeContinue<Indi>(maxTimeParam.value()); eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value());
_state.storeFunctor(timeCont); _state.storeFunctor(timeCont);
// and "add" to combined // and "add" to combined
continuator = make_combinedContinue<Indi>(continuator, timeCont); continuator = make_combinedContinue<MOEOT>(continuator, timeCont);
} }
/**************************/ // CtrlC
#ifndef _MSC_VER #ifndef _MSC_VER
// the CtrlC interception (Linux only I'm afraid) // the CtrlC interception (Linux only I'm afraid)
eoCtrlCContinue<Indi> *ctrlCCont; eoCtrlCContinue<MOEOT> *ctrlCCont;
eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion"); eoValueParam<bool>& ctrlCParam = _parser.createParam(true, "CtrlC", "Terminate current generation upon Ctrl C",'C', "Stopping criterion");
if (_parser.isItThere(ctrlCParam)) if (_parser.isItThere(ctrlCParam))
{ {
ctrlCCont = new eoCtrlCContinue<Indi>; ctrlCCont = new eoCtrlCContinue<MOEOT>;
// store // store
_state.storeFunctor(ctrlCCont); _state.storeFunctor(ctrlCCont);
// add to combinedContinue // add to combinedContinue
continuator = make_combinedContinue<Indi>(continuator, ctrlCCont); continuator = make_combinedContinue<MOEOT>(continuator, ctrlCCont);
} }
#endif #endif
// now check that there is at least one! // now check that there is at least one!
if (!continuator) if (!continuator)
throw std::runtime_error("You MUST provide a stopping criterion"); throw std::runtime_error("You MUST provide a stopping criterion");
// OK, it's there: store in the eoState // OK, it's there: store in the eoState
_state.storeFunctor(continuator); _state.storeFunctor(continuator);
// and return // and return
return *continuator; return *continuator;
} }
#endif #endif /*MAKE_CONTINUE_MOEO_H_*/

View file

@ -27,13 +27,23 @@
#include <moeoMoveIncrEval.h> #include <moeoMoveIncrEval.h>
/** /**
* ... * This functions allows to build a moeoLS from the parser
* @param _parser the parser
* @param _state to store allocated objects
* @param _eval the funtions evaluator
* @param _moveIncrEval the incremental evaluation
* @param _continue the stopping crietria
* @param _op the variation operators
* @param _opInit the initilization operator
* @param _moveInit the move initializer
* @param _nextMove the move incrementor
* @param _archive the archive of non-dominated solutions
*/ */
template < class MOEOT, class Move > template < class MOEOT, class Move >
moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo ( moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo (
eoParser & _parser, eoParser & _parser,
eoState & _state, eoState & _state,
moeoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval, moeoMoveIncrEval < Move > & _moveIncrEval,
eoContinue < MOEOT > & _continue, eoContinue < MOEOT > & _continue,
eoMonOp < MOEOT > & _op, eoMonOp < MOEOT > & _op,
@ -43,11 +53,8 @@ moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo (
moeoArchive < MOEOT > & _archive moeoArchive < MOEOT > & _archive
) )
{ {
/* the objective vector type */ /* the objective vector type */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/* the fitness assignment strategy */ /* the fitness assignment strategy */
string & fitnessParam = _parser.getORcreateParam(string("IndicatorBased"), "fitness", string & fitnessParam = _parser.getORcreateParam(string("IndicatorBased"), "fitness",
"Fitness assignment strategy parameter: IndicatorBased...", 'F', "Fitness assignment strategy parameter: IndicatorBased...", 'F',
@ -85,15 +92,8 @@ moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo (
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(fitnessAssignment); _state.storeFunctor(fitnessAssignment);
// number of iterations
unsigned n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization", 'n', "Evolution Engine").value();
unsigned n = _parser.getORcreateParam(1, "n", "Number of iterations for population Initialization",
'n', "Evolution Engine").value();
// LS // LS
string & lsParam = _parser.getORcreateParam(string("I-IBMOLS"), "ls", string & lsParam = _parser.getORcreateParam(string("I-IBMOLS"), "ls",
"Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L', "Local Search: IBMOLS, I-IBMOLS (Iterated-IBMOLS)...", 'L',
@ -113,10 +113,8 @@ moeoLS < MOEOT, eoPop<MOEOT> & > & do_make_ls_moeo (
throw std::runtime_error(stmp.c_str()); throw std::runtime_error(stmp.c_str());
} }
_state.storeFunctor(ls); _state.storeFunctor(ls);
// that's it !
return *ls; return *ls;
} }
#endif /*MAKE_LS_MOEO_H_*/ #endif /*MAKE_LS_MOEO_H_*/

View file

@ -16,26 +16,27 @@
#include <eo> #include <eo>
#include <MOEO.h> #include <MOEO.h>
#include <moeoArchiveFitnessSavingUpdater.h> #include <moeoArchiveObjectiveVectorSavingUpdater.h>
#include <moeoArchiveUpdater.h> #include <moeoArchiveUpdater.h>
#include <moeoArchive.h> #include <moeoArchive.h>
#include <moeoCombinedLS.h> #include <moeoCombinedLS.h>
#include <moeoComparator.h> #include <moeoComparator.h>
#include <moeoConvertPopToObjectiveVectors.h> #include <moeoConvertPopToObjectiveVectors.h>
#include <moeoCrowdingDiversityAssignment.h>
#include <moeoDetTournamentSelect.h> #include <moeoDetTournamentSelect.h>
#include <moeoDiversityAssignment.h> #include <moeoDiversityAssignment.h>
#include <moeoEA.h> #include <moeoEA.h>
#include <moeoEasyEA.h> #include <moeoEasyEA.h>
#include <moeoElitistReplacement.h> #include <moeoElitistReplacement.h>
#include <moeoEnvironmentalReplacement.h>
#include <moeoEvalFunc.h> #include <moeoEvalFunc.h>
//#include <moeoEvalFuncCounter.h>
#include <moeoFastNonDominatedSortingFitnessAssignment.h> #include <moeoFastNonDominatedSortingFitnessAssignment.h>
#include <moeoFitnessAssignment.h> #include <moeoFitnessAssignment.h>
#include <moeoGenerationalReplacement.h> #include <moeoGenerationalReplacement.h>
//#include <moeoHybridLS.h> #include <moeoHybridLS.h>
#include <moeoIndicatorBasedFitnessAssignment.h> #include <moeoIndicatorBasedFitnessAssignment.h>
//#include <moeoIndicatorBasedLS.h> #include <moeoIndicatorBasedLS.h>
//#include <moeoIteratedIBMOLS.h> #include <moeoIteratedIBMOLS.h>
#include <moeoLS.h> #include <moeoLS.h>
#include <moeoObjectiveVectorComparator.h> #include <moeoObjectiveVectorComparator.h>
#include <moeoObjectiveVector.h> #include <moeoObjectiveVector.h>

View file

@ -10,8 +10,8 @@
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#ifndef MOEOCROWDINGDISTANCEASSIGNMENT_H_ #ifndef MOEOCROWDINGDIVERSITYASSIGNMENT_H_
#define MOEOCROWDINGDISTANCEASSIGNMENT_H_ #define MOEOCROWDINGDIVERSITYASSIGNMENT_H_
#include <eoPop.h> #include <eoPop.h>
#include <moeoComparator.h> #include <moeoComparator.h>
@ -27,16 +27,21 @@ class moeoCrowdingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{ {
public: public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/** Infinity value */
double inf ()const /**
* Returns a big value (regarded as infinite)
*/
double inf() const
{ {
return std::numeric_limits<double>::max(); return std::numeric_limits<double>::max();
} }
/** /**
* ... * Computes diversity values for every solution contained in the population _pop
* @param _pop the population * @param _pop the population
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
@ -57,16 +62,23 @@ public:
} }
/**
* @warning NOT IMPLEMENTED, DO NOTHING !
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << endl;
}
private: private:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/** /**
* ... * Sets the distance values
* @param _pop the population * @param _pop the population
*/ */
void setDistances (eoPop < MOEOT > & _pop) void setDistances (eoPop < MOEOT > & _pop)
@ -88,6 +100,7 @@ private:
// min & max // min & max
min = _pop[0].objectiveVector()[obj]; min = _pop[0].objectiveVector()[obj];
max = _pop[_pop.size()-1].objectiveVector()[obj]; max = _pop[_pop.size()-1].objectiveVector()[obj];
// set the diversity value to infiny for min and max
_pop[0].diversity(inf()); _pop[0].diversity(inf());
_pop[_pop.size()-1].diversity(inf()); _pop[_pop.size()-1].diversity(inf());
for (unsigned i=1; i<_pop.size()-1; i++) for (unsigned i=1; i<_pop.size()-1; i++)

View file

@ -21,7 +21,32 @@
*/ */
template < class MOEOT > template < class MOEOT >
class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void > class moeoDiversityAssignment : public eoUF < eoPop < MOEOT > &, void >
{}; {
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
*/
virtual void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0;
/**
* Updates the diversity values of the whole population _pop by taking the deletion of the individual _moeo into account.
* @param _pop the population
* @param _moeo the individual
*/
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{
updateByDeleting(_pop, _moeo.objectiveVector());
}
};
/** /**
@ -32,6 +57,10 @@ class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{ {
public: public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/** /**
* Sets the diversity to '0' for every individuals of the population _pop if it is invalid * Sets the diversity to '0' for every individuals of the population _pop if it is invalid
* @param _pop the population * @param _pop the population
@ -48,6 +77,17 @@ public:
} }
} }
/**
* Updates the diversity values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
}; };
#endif /*MOEODIVERSITYASSIGNMENT_H_*/ #endif /*MOEODIVERSITYASSIGNMENT_H_*/

View file

@ -1,10 +1,18 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEA.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef _MOEOEASYEA_H #ifndef _MOEOEASYEA_H
#define _MOEOEASYEA_H #define _MOEOEASYEA_H
//-----------------------------------------------------------------------------
#include <apply.h> #include <apply.h>
#include <eoPopEvalFunc.h> #include <eoPopEvalFunc.h>
#include <eoContinue.h> #include <eoContinue.h>
@ -16,38 +24,40 @@
#include <moeoFitnessAssignment.h> #include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h> #include <moeoDiversityAssignment.h>
/**
* An easy class to design multi-objective evolutionary algorithms.
*/
template < class MOEOT > template < class MOEOT >
class moeoEasyEA: public moeoEA < MOEOT > class moeoEasyEA: public moeoEA < MOEOT >
{ {
public: public:
/** Ctor taking a breed and merge */ /**
moeoEasyEA( * Ctor.
eoContinue<MOEOT>& _continuator, * @param _continuator the stopping criteria
eoEvalFunc<MOEOT>& _eval, * @param _eval the evaluation functions
eoBreed<MOEOT>& _breed, * @param _breed the breeder
eoReplacement<MOEOT>& _replace, * @param _replace the replacment strategy
moeoFitnessAssignment<MOEOT>& _fitnessEval, * @param _fitnessEval the fitness evaluation scheme
moeoDiversityAssignment<MOEOT>& _diversityEval, * @param _diversityEval the diversity evaluation scheme
bool _evalFitAndDivBeforeSelection = false * @param _evalFitAndDivBeforeSelection put this parameter to 'true' if you want to re-evalue the fitness and the diversity of the population before the selection process
) : continuator(_continuator), */
eval (_eval), moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoReplacement < MOEOT > & _replace,
loopEval(_eval), moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
popEval(loopEval), :
breed(_breed), continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), breed(_breed), replace(_replace), fitnessEval(_fitnessEval),
replace(_replace), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
fitnessEval(_fitnessEval),
diversityEval(_diversityEval),
evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{} {}
/// Apply a few generation of evolution to the population.
virtual void operator()(eoPop<MOEOT>& _pop) /**
* Applies a few generation of evolution to the population _pop.
* @param _pop the population
*/
virtual void operator()(eoPop < MOEOT > & _pop)
{ {
eoPop<MOEOT> offspring, empty_pop; eoPop < MOEOT > offspring, empty_pop;
popEval(empty_pop, _pop); // A first eval of pop. popEval(empty_pop, _pop); // A first eval of pop.
fitnessEval(_pop);
diversityEval(_pop);
bool firstTime = true; bool firstTime = true;
do do
{ {
@ -55,58 +65,56 @@ public:
{ {
unsigned pSize = _pop.size(); unsigned pSize = _pop.size();
offspring.clear(); // new offspring offspring.clear(); // new offspring
// fitness and diversity assignment (if you want to or if it is the first generation)
/************************************/ if (evalFitAndDivBeforeSelection || firstTime)
if ( evalFitAndDivBeforeSelection && (! firstTime) )
{ {
firstTime = false;
fitnessEval(_pop); fitnessEval(_pop);
diversityEval(_pop); diversityEval(_pop);
} }
else
{
firstTime = false;
}
/************************************/
breed(_pop, offspring); breed(_pop, offspring);
popEval(_pop, offspring); // eval of parents + offspring if necessary popEval(_pop, offspring); // eval of parents + offspring if necessary
replace(_pop, offspring); // after replace, the new pop. is in _pop replace(_pop, offspring); // after replace, the new pop. is in _pop
if (pSize > _pop.size()) if (pSize > _pop.size())
{
throw std::runtime_error("Population shrinking!"); throw std::runtime_error("Population shrinking!");
}
else if (pSize < _pop.size()) else if (pSize < _pop.size())
{
throw std::runtime_error("Population growing!"); throw std::runtime_error("Population growing!");
} }
}
catch (std::exception& e) catch (std::exception& e)
{ {
std::string s = e.what(); std::string s = e.what();
s.append( " in moeoEasyEA"); s.append( " in moeoEasyEA");
throw std::runtime_error( s ); throw std::runtime_error( s );
} }
} while ( continuator( _pop ) ); } while (continuator(_pop));
} }
protected : protected:
eoContinue<MOEOT>& continuator; /** the stopping criteria */
eoEvalFunc <MOEOT> & eval ; eoContinue < MOEOT > & continuator;
eoPopLoopEval<MOEOT> loopEval; /** the evaluation functions */
eoPopEvalFunc<MOEOT>& popEval; eoEvalFunc < MOEOT > & eval;
eoBreed<MOEOT>& breed; /** to evaluate the whole population */
eoReplacement<MOEOT>& replace; eoPopLoopEval < MOEOT > loopEval;
/** to evaluate the whole population */
eoPopEvalFunc < MOEOT > & popEval;
/** the breeder */
eoBreed < MOEOT > & breed;
/** the replacment strategy */
eoReplacement < MOEOT > & replace;
/** the fitness assignment strategy */ /** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & fitnessEval; moeoFitnessAssignment < MOEOT > & fitnessEval;
/** the diversity assignment strategy */ /** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & diversityEval; moeoDiversityAssignment < MOEOT > & diversityEval;
/** */ /** if this parameter is set to 'true', the fitness and the diversity of the whole population will be re-evaluated before the selection process */
bool evalFitAndDivBeforeSelection; bool evalFitAndDivBeforeSelection;
}; };
//----------------------------------------------------------------------------- #endif /*MOEOEASYEA_H_*/
#endif

View file

@ -18,11 +18,11 @@
#include <moeoFitnessAssignment.h> #include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h> #include <moeoDiversityAssignment.h>
/////////////////////////////////////// ///////////////////////////////////////
#include <eoRemoveDoubles.h> //#include <eoRemoveDoubles.h>
/////////////////////////////////////// ///////////////////////////////////////
/** /**
* Elitist replacement strategy for multi-objective optimization. * Elitist replacement strategy that consists in keeping the N best individuals.
*/ */
template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT > template < class MOEOT > class moeoElitistReplacement:public moeoReplacement < MOEOT >
{ {
@ -94,17 +94,14 @@ public:
// merges offspring and parents into a global population // merges offspring and parents into a global population
_parents.reserve (_parents.size () + _offspring.size ()); _parents.reserve (_parents.size () + _offspring.size ());
copy (_offspring.begin (), _offspring.end (), back_inserter (_parents)); copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
//remove the doubles in the whole pop //remove the doubles in the whole pop
/****************************************************************************/ /****************************************************************************
eoRemoveDoubles < MOEOT > r; eoRemoveDoubles < MOEOT > r;
r(_parents); r(_parents);
/****************************************************************************/ ****************************************************************************/
// evaluates the fitness and the diversity of this global population // evaluates the fitness and the diversity of this global population
evalFitness (_parents); evalFitness (_parents);
evalDiversity (_parents); evalDiversity (_parents);
// sorts the whole population according to the comparator // sorts the whole population according to the comparator
Cmp cmp(comparator); Cmp cmp(comparator);
std::sort(_parents.begin(), _parents.end(), cmp); std::sort(_parents.begin(), _parents.end(), cmp);
@ -124,16 +121,38 @@ protected:
/** the comparator (used to compare 2 individuals) */ /** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator; moeoComparator < MOEOT > & comparator;
/**
* This class is used to compare solutions in order to sort the population.
*/
class Cmp class Cmp
{ {
public: public:
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator) {}
bool operator()(const MOEOT & a, const MOEOT & b) /**
* Ctor.
* @param _comparator the comparator
*/
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
{}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
* _moeo2 the first individual
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return comparator(a,b); return comparator(_moeo1,_moeo2);
} }
private: private:
/** the comparator */
moeoComparator < MOEOT > & comparator; moeoComparator < MOEOT > & comparator;
}; };
}; };

View file

@ -18,14 +18,18 @@
#include <moeoFitnessAssignment.h> #include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h> #include <moeoDiversityAssignment.h>
/** /**
* ??? * Environmental replacement strategy that consists in keeping the N best individuals by deleting individuals 1 by 1
* and by updating the fitness and diversity values after each deletion.
*/ */
template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT > template < class MOEOT > class moeoEnvironmentalReplacement:public moeoReplacement < MOEOT >
{ {
public: public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/** /**
* Full constructor. * Full constructor.
* @param _evalFitness the fitness assignment strategy * @param _evalFitness the fitness assignment strategy
@ -64,6 +68,7 @@ public:
evalDiversity = dummyDiversityAssignment; evalDiversity = dummyDiversityAssignment;
} }
/** /**
* Constructor without moeoDiversityAssignement nor moeoComparator. * Constructor without moeoDiversityAssignement nor moeoComparator.
* A moeoFitThenDivComparator and a dummy diversity are used as default. * A moeoFitThenDivComparator and a dummy diversity are used as default.
@ -95,13 +100,14 @@ public:
evalDiversity (_parents); evalDiversity (_parents);
// remove individuals 1 by 1 and update the fitness values // remove individuals 1 by 1 and update the fitness values
Cmp cmp(comparator); Cmp cmp(comparator);
MOEOT worst; ObjectiveVector worstObjVec;
while (_parents.size() > sz) while (_parents.size() > sz)
{ {
std::sort (_parents.begin(), _parents.end(), cmp); std::sort (_parents.begin(), _parents.end(), cmp);
worst = _parents[_parents.size()-1]; worstObjVec = _parents[_parents.size()-1].objectiveVector();
_parents.resize(_parents.size()-1); _parents.resize(_parents.size()-1);
evalFitness.updateByDeleting(_parents, worst); evalFitness.updateByDeleting(_parents, worstObjVec);
evalDiversity.updateByDeleting(_parents, worstObjVec);
} }
// clear the offspring population // clear the offspring population
_offspring.clear (); _offspring.clear ();
@ -117,16 +123,38 @@ protected:
/** the comparator (used to compare 2 individuals) */ /** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator; moeoComparator < MOEOT > & comparator;
/**
* This class is used to compare solutions in order to sort the population.
*/
class Cmp class Cmp
{ {
public: public:
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator) {}
bool operator()(const MOEOT & a, const MOEOT & b) /**
* Ctor.
* @param _comparator the comparator
*/
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
{}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
* _moeo2 the first individual
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{ {
return comparator(a,b); return comparator(_moeo1,_moeo2);
} }
private: private:
/** the comparator */
moeoComparator < MOEOT > & comparator; moeoComparator < MOEOT > & comparator;
}; };
}; };

View file

@ -30,14 +30,27 @@ class moeoFastNonDominatedSortingFitnessAssignment : public moeoParetoBasedFitne
{ {
public: public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/** /**
* Ctor * Default ctor
*/ */
moeoFastNonDominatedSortingFitnessAssignment() {} moeoFastNonDominatedSortingFitnessAssignment() : comparator(paretoComparator)
{}
/** /**
* Computes fitness values for every solution contained in the population _pop * Ctor where you can choose your own way to compare objective vectors
* @param _comparator the functor used to compare objective vectors
*/
moeoFastNonDominatedSortingFitnessAssignment(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator) : comparator(_comparator)
{}
/**
* Sets the fitness values for every solution contained in the population _pop
* @param _pop the population * @param _pop the population
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
@ -62,7 +75,7 @@ public:
else else
{ {
// problem with the number of objectives // problem with the number of objectives
throw std::runtime_error("Problem with the number of objectives in moeoFastNonDominatedSortingFitnessAssignment"); throw std::runtime_error("Problem with the number of objectives in moeoNonDominatedSortingFitnessAssignment");
} }
// a higher fitness is better, so the values need to be inverted // a higher fitness is better, so the values need to be inverted
double max = _pop[0].fitness(); double max = _pop[0].fitness();
@ -77,19 +90,27 @@ public:
} }
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) /**
* @warning NOT IMPLEMENTED, DO NOTHING !
* Updates the fitness values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
cout << "WARNING : not yet implemented in NDSortingFitAss" << endl; cout << "WARNING : updateByDeleting not implemented in moeoNonDominatedSortingFitnessAssignment" << endl;
} }
private: private:
/** the objective vector type of the solutions */ /** Functor to compare two objective vectors */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** Functor to compare two objective vectors according to Pareto dominance relation */ /** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > comparator; moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** Functor to compare two solutions on the first objective, then on the second, and so on */
moeoObjectiveComparator < MOEOT > objComparator;
/** /**
@ -98,14 +119,13 @@ private:
*/ */
void oneObjective (eoPop < MOEOT > & _pop) void oneObjective (eoPop < MOEOT > & _pop)
{ {
// TO DO ! // Functor to compare two solutions on the first objective, then on the second, and so on
/* moeoObjectiveComparator < MOEOT > objComparator;
std::sort(_pop.begin(), _pop.end(), objComparator); std::sort(_pop.begin(), _pop.end(), objComparator);
for (unsigned i=0; i<_pop.size(); i++) for (unsigned i=0; i<_pop.size(); i++)
{ {
_pop[i].fitness(i+1); _pop[i].fitness(i+1);
} }
*/
} }

View file

@ -23,7 +23,71 @@ template < class MOEOT >
class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void > class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void >
{ {
public: public:
virtual void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) = 0;
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Updates the fitness values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
*/
virtual void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) = 0;
/**
* Updates the fitness values of the whole population _pop by taking the deletion of the individual _moeo into account.
* @param _pop the population
* @param _moeo the individual
*/
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{
updateByDeleting(_pop, _moeo.objectiveVector());
}
};
/**
* moeoDummyFitnessAssignment is a moeoFitnessAssignment that gives the value '0' as the individual's fitness for a whole population if it is invalid.
*/
template < class MOEOT >
class moeoDummyFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{
public:
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Sets the fitness to '0' for every individuals of the population _pop if it is invalid
* @param _pop the population
*/
void operator () (eoPop < MOEOT > & _pop)
{
for (unsigned idx = 0; idx<_pop.size (); idx++)
{
if (_pop[idx].invalidFitness())
{
// set the diversity to 0
_pop[idx].fitness(0.0);
}
}
}
/**
* Updates the fitness values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
}; };

View file

@ -15,8 +15,8 @@
#include <eoContinue.h> #include <eoContinue.h>
#include <eoPop.h> #include <eoPop.h>
#include <eoUpdater.h>
#include <eoSelect.h> #include <eoSelect.h>
#include <utils/eoUpdater.h>
#include <moeoArchive.h> #include <moeoArchive.h>
#include <moeoLS.h> #include <moeoLS.h>
@ -36,15 +36,17 @@ public:
* @param _mols a multi-objective local search * @param _mols a multi-objective local search
* @param _arch the archive * @param _arch the archive
*/ */
eoHybridLS (eoContinue < MOEOT > & _term, eoSelect < MOEOT > & _select, moeoLS < MOEOT > & _mols, moeoArchive < MOEOT > & _arch) : term(_term), select(_select), mols(_mols), arch(_arch) moeoHybridLS (eoContinue < MOEOT > & _term, eoSelect < MOEOT > & _select, moeoLS < MOEOT, MOEOT > & _mols, moeoArchive < MOEOT > & _arch) :
term(_term), select(_select), mols(_mols), arch(_arch)
{} {}
/** /**
* Applies the multi-objective local search to selected individuals contained in the archive if the stopping criteria is not verified * Applies the multi-objective local search to selected individuals contained in the archive if the stopping criteria is not verified
*/ */
void operator () () void operator () ()
{ {
if (! cont (arch)) if (! term (arch))
{ {
// selection of solutions // selection of solutions
eoPop < MOEOT > selectedSolutions; eoPop < MOEOT > selectedSolutions;
@ -60,12 +62,12 @@ public:
private: private:
/** stopping criteria*/ /** stopping criteria */
eoContinue < MOEOT > & term; eoContinue < MOEOT > & term;
/** selector */ /** selector */
eoSelect < MOEOT > & select; eoSelect < MOEOT > & select;
/** multi-objective local search */ /** multi-objective local search */
moeoLS < MOEOT > & mols; moeoLS < MOEOT, MOEOT > & mols;
/** archive */ /** archive */
moeoArchive < MOEOT > & arch; moeoArchive < MOEOT > & arch;

View file

@ -20,26 +20,31 @@
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h> #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
/** /**
* Default is exponential * Fitness assignment sheme based an Indicator proposed in:
* E. Zitzler, S. Künzli, "Indicator-Based Selection in Multiobjective Search", Proc. 8th International Conference on Parallel Problem Solving from Nature (PPSN VIII), pp. 832-842, Birmingham, UK (2004).
* This strategy is, for instance, used in IBEA.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > class moeoIndicatorBasedFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT >
{ {
public: public:
/** The type of objective vector */ /** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/** /**
* Ctor * Ctor.
* @param ... * @param _metric the quality indicator
* @param _kappa the scaling factor
*/ */
moeoIndicatorBasedFitnessAssignment(moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * _metric, const double _kappa) : metric(_metric), kappa(_kappa) moeoIndicatorBasedFitnessAssignment(moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * _metric, const double _kappa) : metric(_metric), kappa(_kappa)
{} {}
/** /**
* * Sets the fitness values for every solution contained in the population _pop
* @param _pop the population
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
@ -52,25 +57,11 @@ public:
} }
///////////////////////////////////////////////////////////////////// /**
* Updates the fitness values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
// A SIMPLIFIER ! => utiliser la fonction d'en dessous ;-) * @param _objecVec the objective vector
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) */
{
vector < double > v;
v.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
{
v[i] = (*metric)(_moeo.objectiveVector(), _pop[i].objectiveVector());
}
for (unsigned i=0; i<_pop.size(); i++)
{
_pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) );
}
}
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
vector < double > v; vector < double > v;
@ -86,37 +77,12 @@ public:
} }
// IDEM ! /**
void updateByAdding(eoPop < MOEOT > & _pop, MOEOT & _moeo) * Updates the fitness values of the whole population _pop by taking the adding of the objective vector _objVec into account
{ * and returns the fitness value of _objVec.
vector < double > v; * @param _pop the population
// update every fitness values to take the new individual into account * @param _objecVec the objective vector
v.resize(_pop.size()); */
for (unsigned i=0; i<_pop.size(); i++)
{
v[i] = (*metric)(_moeo.objectiveVector(), _pop[i].objectiveVector());
}
for (unsigned i=0; i<_pop.size(); i++)
{
_pop[i].fitness( _pop[i].fitness() - exp(-v[i]/kappa) );
}
// compute the fitness of the new individual
v.clear();
v.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
{
v[i] = (*metric)(_pop[i].objectiveVector(), _moeo.objectiveVector());
}
double fitness = 0;
for (unsigned i=0; i<v.size(); i++)
{
fitness -= exp(-v[i]/kappa);
}
_moeo.fitness(fitness);
}
// update _pop et retourne la valeur de fitness de _objVec
double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec) double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{ {
vector < double > v; vector < double > v;
@ -146,12 +112,13 @@ public:
} }
/////////////////////////////////////////////////////////////////////
protected: protected:
/** the quality indicator */
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * metric; moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * metric;
/** the scaling factor */
double kappa; double kappa;
/** the computed indicator values */
std::vector < std::vector<double> > values; std::vector < std::vector<double> > values;
@ -176,9 +143,10 @@ protected:
} }
} }
/** /**
* Compute every indicator value : values[i] = I(_v[i], _o) !!!!!!!!!!! * Compute every indicator value in values (values[i] = I(_v[i], _o))
* @param ... * @param _pop the population
*/ */
void computeValues(const eoPop < MOEOT > & _pop) void computeValues(const eoPop < MOEOT > & _pop)
{ {
@ -197,6 +165,11 @@ protected:
} }
} }
/**
* Sets the fitness value of the whple population
* @param _pop the population
*/
void setFitnesses(eoPop < MOEOT > & _pop) void setFitnesses(eoPop < MOEOT > & _pop)
{ {
for (unsigned i=0; i<_pop.size(); i++) for (unsigned i=0; i<_pop.size(); i++)
@ -205,6 +178,11 @@ protected:
} }
} }
/**
* Returns the fitness value of the _idx th individual of the population
* @param _idx the index
*/
double computeFitness(const unsigned _idx) double computeFitness(const unsigned _idx)
{ {
double result = 0; double result = 0;
@ -217,6 +195,7 @@ protected:
} }
return result; return result;
} }
}; };
#endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/ #endif /*MOEOINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -14,13 +14,13 @@
#define MOEOINDICATORBASEDLS_H_ #define MOEOINDICATORBASEDLS_H_
#include <eoContinue.h> #include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoPop.h> #include <eoPop.h>
#include <moMove.h> #include <moMove.h>
#include <moMoveInit.h> #include <moMoveInit.h>
#include <moNextMove.h> #include <moNextMove.h>
#include <moeoMoveIncrEval.h> #include <moeoMoveIncrEval.h>
#include <moeoArchive.h> #include <moeoArchive.h>
#include <moeoEvalFunc.h>
#include <moeoLS.h> #include <moeoLS.h>
#include <moeoIndicatorBasedFitnessAssignment.h> #include <moeoIndicatorBasedFitnessAssignment.h>
@ -49,7 +49,7 @@ public:
moeoIndicatorBasedLS( moeoIndicatorBasedLS(
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
moeoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval, moeoMoveIncrEval < Move > & _moveIncrEval,
moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
eoContinue < MOEOT > & _continuator eoContinue < MOEOT > & _continuator

View file

@ -14,6 +14,7 @@
#define MOEOITERATEDIBMOLS_H_ #define MOEOITERATEDIBMOLS_H_
#include <eoContinue.h> #include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoOp.h> #include <eoOp.h>
#include <eoPop.h> #include <eoPop.h>
#include <utils/rnd_generators.h> #include <utils/rnd_generators.h>
@ -22,14 +23,13 @@
#include <moNextMove.h> #include <moNextMove.h>
#include <moeoMoveIncrEval.h> #include <moeoMoveIncrEval.h>
#include <moeoArchive.h> #include <moeoArchive.h>
#include <moeoEvalFunc.h>
#include <moeoLS.h> #include <moeoLS.h>
#include <moeoIndicatorBasedFitnessAssignment.h> #include <moeoIndicatorBasedFitnessAssignment.h>
#include <moeoIndicatorBasedLS.h> #include <moeoIndicatorBasedLS.h>
#include <rsCrossQuad.h> //#include <rsCrossQuad.h>
@ -61,7 +61,7 @@ public:
moeoIteratedIBMOLS( moeoIteratedIBMOLS(
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
moeoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval, moeoMoveIncrEval < Move > & _moveIncrEval,
moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment, moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
eoContinue < MOEOT > & _continuator, eoContinue < MOEOT > & _continuator,
@ -109,7 +109,7 @@ private:
/** the local search to iterate */ /** the local search to iterate */
moeoIndicatorBasedLS < MOEOT, Move > ibmols; moeoIndicatorBasedLS < MOEOT, Move > ibmols;
/** the full evaluation */ /** the full evaluation */
moeoEvalFunc < MOEOT > & eval; eoEvalFunc < MOEOT > & eval;
/** the monary operator */ /** the monary operator */
eoMonOp < MOEOT > & monOp; eoMonOp < MOEOT > & monOp;
/** the random monary operator (or random initializer) */ /** the random monary operator (or random initializer) */
@ -168,6 +168,7 @@ private:
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
// A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER // // A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER //
/*
void generateNewSolutions2(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch) void generateNewSolutions2(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
{ {
// here, we must have a QuadOp ! // here, we must have a QuadOp !
@ -207,6 +208,7 @@ private:
i++; i++;
} }
} }
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -18,7 +18,7 @@
/** /**
* Abstract class for local searches applied to multi-objective optimization. * Abstract class for local searches applied to multi-objective optimization.
* Starting from a Type, it produces a set of new non-dominated solutions. * Starting from a Type (i.e.: an individual, a pop, an archive...), it produces a set of new non-dominated solutions.
*/ */
template < class MOEOT, class Type > template < class MOEOT, class Type >
class moeoLS: public eoBF < Type, moeoArchive < MOEOT > &, void > class moeoLS: public eoBF < Type, moeoArchive < MOEOT > &, void >

View file

@ -19,7 +19,7 @@
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h> #include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
/** /**
* * Fitness assignment sheme based a Reference Point and a Quality Indicator.
*/ */
template < class MOEOT > template < class MOEOT >
class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
@ -31,21 +31,17 @@ public:
/** /**
* Ctor * Ctor
* @param ... * @param _refPoint the reference point
* @param _metric the quality indicator
*/ */
moeoReferencePointIndicatorBasedFitnessAssignment moeoReferencePointIndicatorBasedFitnessAssignment (const ObjectiveVector _refPoint, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * _metric) :
( refPoint(_refPoint), metric(_metric)
const ObjectiveVector _refPoint,
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * _metric
) :
refPoint(_refPoint),
metric(_metric)
{} {}
/** /**
* NE CALCULER LE FITNESS D'UNE SOL QUE SI INVALID() (ATTENTION BOUNDS !) * Sets the fitness values for every solution contained in the population _pop
* @param _pop the population
*/ */
void operator()(eoPop < MOEOT > & _pop) void operator()(eoPop < MOEOT > & _pop)
{ {
@ -55,6 +51,12 @@ public:
setFitnesses(_pop); setFitnesses(_pop);
} }
/**
* Updates the fitness values of the whole population _pop by taking the deletion of the objective vector _objVec into account.
* @param _pop the population
* @param _objecVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo) void updateByDeleting(eoPop < MOEOT > & _pop, MOEOT & _moeo)
{ {
// nothing to do ;-) // nothing to do ;-)
@ -62,8 +64,11 @@ public:
protected: protected:
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * metric;
/** the reference point */
ObjectiveVector refPoint; ObjectiveVector refPoint;
/** the quality indicator */
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * metric;
/** /**
@ -87,12 +92,14 @@ protected:
} }
} }
/**
* Sets the fitness of every individual contained in the population _pop
* @param _pop the population
*/
void setFitnesses(eoPop < MOEOT > & _pop) void setFitnesses(eoPop < MOEOT > & _pop)
{ {
for (unsigned i=0; i<_pop.size(); i++) for (unsigned i=0; i<_pop.size(); i++)
{ {
//_pop[i].fitness( (*metric)(refPoint, _pop[i].objectiveVector()) );
_pop[i].fitness(- (*metric)(_pop[i].objectiveVector(), refPoint) ); _pop[i].fitness(- (*metric)(_pop[i].objectiveVector(), refPoint) );
} }
} }