merge ParadisEO-MOEO v-1.0

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@400 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-06-26 13:28:59 +00:00
commit 8b7d5260fb
724 changed files with 63305 additions and 2757 deletions

View file

@ -1 +1 @@
# Nothing to compile !
SUBDIRS = core

View file

@ -0,0 +1,21 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoAlgo.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOALGO_H_
#define MOEOALGO_H_
/**
* Abstract class for multi-objective algorithms.
*/
class moeoAlgo {};
#endif /*MOEOALGO_H_*/

View file

@ -13,8 +13,9 @@
#ifndef MOEOCOMBINEDLS_H_
#define MOEOCOMBINEDLS_H_
#include <moeoArchive.h>
#include <moeoLS.h>
#include <vector>
#include <algo/moeoLS.h>
#include <archive/moeoArchive.h>
/**
* This class allows to embed a set of local searches that are sequentially applied,
@ -51,7 +52,7 @@ public:
*/
void operator () (Type _type, moeoArchive < MOEOT > & _arch)
{
for (unsigned i=0; i<combinedLS.size(); i++)
for (unsigned int i=0; i<combinedLS.size(); i++)
combinedLS[i] -> operator()(_type, _arch);
}

View file

@ -14,12 +14,12 @@
#define MOEOEA_H_
#include <eoAlgo.h>
#include <algo/moeoAlgo.h>
/**
* Abstract class for multi-objective evolutionary algorithms.
*/
template < class MOEOT >
class moeoEA : public eoAlgo < MOEOT > {};
class moeoEA : public moeoAlgo, public eoAlgo < MOEOT > {};
#endif /*MOEOEA_H_*/

View file

@ -0,0 +1,218 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEasyEA.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
#define _MOEOEASYEA_H
#include <apply.h>
#include <eoBreed.h>
#include <eoContinue.h>
#include <eoMergeReduce.h>
#include <eoPopEvalFunc.h>
#include <eoSelect.h>
#include <eoTransform.h>
#include <algo/moeoEA.h>
#include <diversity/moeoDiversityAssignment.h>
#include <diversity/moeoDummyDiversityAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
#include <replacement/moeoReplacement.h>
/**
* An easy class to design multi-objective evolutionary algorithms.
*/
template < class MOEOT >
class moeoEasyEA: public moeoEA < MOEOT >
{
public:
/**
* Ctor taking a breed and merge.
* @param _continuator the stopping criteria
* @param _eval the evaluation functions
* @param _breed the breeder
* @param _replace the replacement strategy
* @param _fitnessEval the fitness evaluation scheme
* @param _diversityEval the diversity evaluation scheme
* @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
*/
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{}
/**
* Ctor taking a breed, a merge and a eoPopEval.
* @param _continuator the stopping criteria
* @param _popEval the evaluation functions for the whole population
* @param _breed the breeder
* @param _replace the replacement strategy
* @param _fitnessEval the fitness evaluation scheme
* @param _diversityEval the diversity evaluation scheme
* @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
*/
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoBreed < MOEOT > & _breed, moeoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval (dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{}
/**
* Ctor taking a breed, a merge and a reduce.
* @param _continuator the stopping criteria
* @param _eval the evaluation functions
* @param _breed the breeder
* @param _merge the merge scheme
* @param _reduce the reduce scheme
* @param _fitnessEval the fitness evaluation scheme
* @param _diversityEval the diversity evaluation scheme
* @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
*/
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(dummySelect, dummyTransform), breed(_breed), mergeReduce(_merge,_reduce), replace(mergeReduce),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{}
/**
* Ctor taking a select, a transform and a replacement.
* @param _continuator the stopping criteria
* @param _eval the evaluation functions
* @param _select the selection scheme
* @param _transform the tranformation scheme
* @param _replace the replacement strategy
* @param _fitnessEval the fitness evaluation scheme
* @param _diversityEval the diversity evaluation scheme
* @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
*/
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(dummyMerge, dummyReduce), replace(_replace),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{}
/**
* Ctor taking a select, a transform, a merge and a reduce.
* @param _continuator the stopping criteria
* @param _eval the evaluation functions
* @param _select the selection scheme
* @param _transform the tranformation scheme
* @param _merge the merge scheme
* @param _reduce the reduce scheme
* @param _fitnessEval the fitness evaluation scheme
* @param _diversityEval the diversity evaluation scheme
* @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
*/
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, eoMerge < MOEOT > & _merge, eoReduce< MOEOT > & _reduce,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval(_eval), loopEval(_eval), popEval(loopEval), selectTransform(_select, _transform), breed(selectTransform), mergeReduce(_merge,_reduce), replace(mergeReduce),
fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{}
/**
* 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;
popEval(empty_pop, _pop); // A first eval of pop.
bool firstTime = true;
do
{
try
{
unsigned int pSize = _pop.size();
offspring.clear(); // new offspring
// fitness and diversity assignment (if you want to or if it is the first generation)
if (evalFitAndDivBeforeSelection || firstTime)
{
firstTime = false;
fitnessEval(_pop);
diversityEval(_pop);
}
breed(_pop, offspring);
popEval(_pop, offspring); // eval of parents + offspring if necessary
replace(_pop, offspring); // after replace, the new pop. is in _pop
if (pSize > _pop.size())
{
throw std::runtime_error("Population shrinking!");
}
else if (pSize < _pop.size())
{
throw std::runtime_error("Population growing!");
}
}
catch (std::exception& e)
{
std::string s = e.what();
s.append( " in moeoEasyEA");
throw std::runtime_error( s );
}
} while (continuator(_pop));
}
protected:
/** the stopping criteria */
eoContinue < MOEOT > & continuator;
/** the evaluation functions */
eoEvalFunc < MOEOT > & eval;
/** to evaluate the whole population */
eoPopLoopEval < MOEOT > loopEval;
/** to evaluate the whole population */
eoPopEvalFunc < MOEOT > & popEval;
/** breed: a select followed by a transform */
eoSelectTransform < MOEOT > selectTransform;
/** the breeder */
eoBreed < MOEOT > & breed;
/** replacement: a merge followed by a reduce */
eoMergeReduce < MOEOT > mergeReduce;
/** the replacment strategy */
moeoReplacement < MOEOT > & replace;
/** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & fitnessEval;
/** the diversity assignment strategy */
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;
/** a dummy eval */
class eoDummyEval : public eoEvalFunc < MOEOT >
{ public: /** the dummy functor */
void operator()(MOEOT &) {}} dummyEval;
/** a dummy select */
class eoDummySelect : public eoSelect < MOEOT >
{ public: /** the dummy functor */
void operator()(const eoPop < MOEOT > &, eoPop < MOEOT > &) {} } dummySelect;
/** a dummy transform */
class eoDummyTransform : public eoTransform < MOEOT >
{ public: /** the dummy functor */
void operator()(eoPop < MOEOT > &) {} } dummyTransform;
/** a dummy merge */
eoNoElitism < MOEOT > dummyMerge;
/** a dummy reduce */
eoTruncate < MOEOT > dummyReduce;
};
#endif /*MOEOEASYEA_H_*/

View file

@ -17,8 +17,8 @@
#include <eoPop.h>
#include <eoSelect.h>
#include <utils/eoUpdater.h>
#include <moeoArchive.h>
#include <moeoLS.h>
#include <algo/moeoLS.h>
#include <archive/moeoArchive.h>
/**
* This class allows to apply a multi-objective local search to a number of selected individuals contained in the archive
@ -52,7 +52,7 @@ public:
eoPop < MOEOT > selectedSolutions;
select(arch, selectedSolutions);
// apply the local search to every selected solution
for (unsigned i=0; i<selectedSolutions.size(); i++)
for (unsigned int i=0; i<selectedSolutions.size(); i++)
{
mols(selectedSolutions[i], arch);
}

View file

@ -0,0 +1,168 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoIBEA.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOIBEA_H_
#define MOEOIBEA_H_
#include <eoBreed.h>
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoGenContinue.h>
#include <eoGeneralBreeder.h>
#include <eoGenOp.h>
#include <eoPopEvalFunc.h>
#include <eoSGAGenOp.h>
#include <algo/moeoEA.h>
#include <diversity/moeoDummyDiversityAssignment.h>
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
#include <replacement/moeoEnvironmentalReplacement.h>
#include <selection/moeoDetTournamentSelect.h>
/**
* IBEA (Indicator-Based Evolutionary Algorithm) as described 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 class builds the IBEA algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
*/
template < class MOEOT >
class moeoIBEA : public moeoEA < MOEOT >
{
public:
/** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Simple ctor with a eoGenOp.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
* @param _metric metric
* @param _kappa scaling factor kappa
*/
moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Simple ctor with a eoTransform.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
* @param _metric metric
* @param _kappa scaling factor kappa
*/
moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Ctor with a crossover, a mutation and their corresponding rates.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _crossover crossover
* @param _pCross crossover probability
* @param _mutation mutation
* @param _pMut mutation probability
* @param _metric metric
* @param _kappa scaling factor kappa
*/
moeoIBEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
fitnessAssignment(_metric, _kappa), replace (fitnessAssignment, dummyDiversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
genBreed (select, defaultSGAGenOp), breed (genBreed)
{}
/**
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
* @param _metric metric
* @param _kappa scaling factor kappa
*/
moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
continuator(_continuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
* @param _metric metric
* @param _kappa scaling factor kappa
*/
moeoIBEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric, const double _kappa=0.05) :
continuator(_continuator), popEval(_eval), select(2),
fitnessAssignment(_metric, _kappa), replace(fitnessAssignment, dummyDiversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified.
* @param _pop the population
*/
virtual void operator () (eoPop < MOEOT > &_pop)
{
eoPop < MOEOT > offspring, empty_pop;
popEval (empty_pop, _pop); // a first eval of _pop
// evaluate fitness and diversity
fitnessAssignment(_pop);
dummyDiversityAssignment(_pop);
do
{
// generate offspring, worths are recalculated if necessary
breed (_pop, offspring);
// eval of offspring
popEval (_pop, offspring);
// after replace, the new pop is in _pop. Worths are recalculated if necessary
replace (_pop, offspring);
} while (continuator (_pop));
}
protected:
/** a continuator based on the number of generations (used as default) */
eoGenContinue < MOEOT > defaultGenContinuator;
/** stopping criteria */
eoContinue < MOEOT > & continuator;
/** evaluation function used to evaluate the whole population */
eoPopLoopEval < MOEOT > popEval;
/** binary tournament selection */
moeoDetTournamentSelect < MOEOT > select;
/** fitness assignment used in IBEA */
moeoIndicatorBasedFitnessAssignment < MOEOT > fitnessAssignment;
/** dummy diversity assignment */
moeoDummyDiversityAssignment < MOEOT > dummyDiversityAssignment;
/** elitist replacement */
moeoEnvironmentalReplacement < MOEOT > replace;
/** an object for genetic operators (used as default) */
eoSGAGenOp < MOEOT > defaultSGAGenOp;
/** general breeder */
eoGeneralBreeder < MOEOT > genBreed;
/** breeder */
eoBreed < MOEOT > & breed;
};
#endif /*MOEOIBEA_H_*/

View file

@ -0,0 +1,280 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoIBMOLS.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOIBMOLS_H_
#define MOEOIBMOLS_H_
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoPop.h>
#include <moMove.h>
#include <moMoveInit.h>
#include <moNextMove.h>
#include <algo/moeoLS.h>
#include <archive/moeoArchive.h>
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
#include <move/moeoMoveIncrEval.h>
/**
* Indicator-Based Multi-Objective Local Search (IBMOLS) as described in
* Basseur M., Burke K. : "Indicator-Based Multi-Objective Local Search" (2007).
*/
template < class MOEOT, class Move >
class moeoIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
{
public:
/** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor.
* @param _moveInit the move initializer
* @param _nextMove the neighborhood explorer
* @param _eval the full evaluation
* @param _moveIncrEval the incremental evaluation
* @param _fitnessAssignment the fitness assignment strategy
* @param _continuator the stopping criteria
*/
moeoIBMOLS(
moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove,
eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval,
moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
eoContinue < MOEOT > & _continuator
) :
moveInit(_moveInit),
nextMove(_nextMove),
eval(_eval),
moveIncrEval(_moveIncrEval),
fitnessAssignment (_fitnessAssignment),
continuator (_continuator)
{}
/**
* Apply the local search until a local archive does not change or
* another stopping criteria is met and update the archive _arch with new non-dominated solutions.
* @param _pop the initial population
* @param _arch the (updated) archive
*/
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
{
// evaluation of the objective values
/*
for (unsigned int i=0; i<_pop.size(); i++)
{
eval(_pop[i]);
}
*/
// fitness assignment for the whole population
fitnessAssignment(_pop);
// creation of a local archive
moeoArchive < MOEOT > archive;
// creation of another local archive (for the stopping criteria)
moeoArchive < MOEOT > previousArchive;
// update the archive with the initial population
archive.update(_pop);
do
{
previousArchive.update(archive);
oneStep(_pop);
archive.update(_pop);
} while ( (! archive.equals(previousArchive)) && (continuator(_arch)) );
_arch.update(archive);
}
private:
/** the move initializer */
moMoveInit < Move > & moveInit;
/** the neighborhood explorer */
moNextMove < Move > & nextMove;
/** the full evaluation */
eoEvalFunc < MOEOT > & eval;
/** the incremental evaluation */
moeoMoveIncrEval < Move > & moveIncrEval;
/** the fitness assignment strategy */
moeoIndicatorBasedFitnessAssignment < MOEOT > & fitnessAssignment;
/** the stopping criteria */
eoContinue < MOEOT > & continuator;
/**
* Apply one step of the local search to the population _pop
* @param _pop the population
*/
void oneStep (eoPop < MOEOT > & _pop)
{
////////////////////////////////////////////
int ext_0_idx, ext_1_idx;
ObjectiveVector ext_0_objVec, ext_1_objVec;
///////////////////////////////////////////
// the move
Move move;
// the objective vector and the fitness of the current solution
ObjectiveVector x_objVec;
double x_fitness;
// the index, the objective vector and the fitness of the worst solution in the population (-1 implies that the worst is the newly created one)
int worst_idx;
ObjectiveVector worst_objVec;
double worst_fitness;
// the index current of the current solution to be explored
unsigned int i=0;
// initilization of the move for the first individual
moveInit(move, _pop[i]);
while (i<_pop.size() && continuator(_pop))
{
// x = one neigbour of pop[i]
// evaluate x in the objective space
x_objVec = moveIncrEval(move, _pop[i]);
// update every fitness values to take x into account and compute the fitness of x
x_fitness = fitnessAssignment.updateByAdding(_pop, x_objVec);
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// qui sont les extremes ? (=> min only !!!)
ext_0_idx = -1;
ext_0_objVec = x_objVec;
ext_1_idx = -1;
ext_1_objVec = x_objVec;
for (unsigned int k=0; k<_pop.size(); k++)
{
// ext_0
if (_pop[k].objectiveVector()[0] < ext_0_objVec[0])
{
ext_0_idx = k;
ext_0_objVec = _pop[k].objectiveVector();
}
else if ( (_pop[k].objectiveVector()[0] == ext_0_objVec[0]) && (_pop[k].objectiveVector()[1] < ext_0_objVec[1]) )
{
ext_0_idx = k;
ext_0_objVec = _pop[k].objectiveVector();
}
// ext_1
else if (_pop[k].objectiveVector()[1] < ext_1_objVec[1])
{
ext_1_idx = k;
ext_1_objVec = _pop[k].objectiveVector();
}
else if ( (_pop[k].objectiveVector()[1] == ext_1_objVec[1]) && (_pop[k].objectiveVector()[0] < ext_1_objVec[0]) )
{
ext_1_idx = k;
ext_1_objVec = _pop[k].objectiveVector();
}
}
// worst init
if (ext_0_idx == -1)
{
unsigned int ind = 0;
while (ind == ext_1_idx)
{
ind++;
}
worst_idx = ind;
worst_objVec = _pop[ind].objectiveVector();
worst_fitness = _pop[ind].fitness();
}
else if (ext_1_idx == -1)
{
unsigned int ind = 0;
while (ind == ext_0_idx)
{
ind++;
}
worst_idx = ind;
worst_objVec = _pop[ind].objectiveVector();
worst_fitness = _pop[ind].fitness();
}
else
{
worst_idx = -1;
worst_objVec = x_objVec;
worst_fitness = x_fitness;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// who is the worst ?
for (unsigned int j=0; j<_pop.size(); j++)
{
if ( (j!=ext_0_idx) && (j!=ext_1_idx) )
{
if (_pop[j].fitness() < worst_fitness)
{
worst_idx = j;
worst_objVec = _pop[j].objectiveVector();
worst_fitness = _pop[j].fitness();
}
}
}
// if the worst solution is the new one
if (worst_idx == -1)
{
// if all its neighbours have been explored,
// let's explore the neighborhoud of the next individual
if (! nextMove(move, _pop[i]))
{
i++;
if (i<_pop.size())
{
// initilization of the move for the next individual
moveInit(move, _pop[i]);
}
}
}
// if the worst solution is located before _pop[i]
else if (worst_idx <= i)
{
// the new solution takes place insteed of _pop[worst_idx]
_pop[worst_idx] = _pop[i];
move(_pop[worst_idx]);
_pop[worst_idx].objectiveVector(x_objVec);
_pop[worst_idx].fitness(x_fitness);
// let's explore the neighborhoud of the next individual
i++;
if (i<_pop.size())
{
// initilization of the move for the next individual
moveInit(move, _pop[i]);
}
}
// if the worst solution is located after _pop[i]
else if (worst_idx > i)
{
// the new solution takes place insteed of _pop[i+1] and _pop[worst_idx] is deleted
_pop[worst_idx] = _pop[i+1];
_pop[i+1] = _pop[i];
move(_pop[i+1]);
_pop[i+1].objectiveVector(x_objVec);
_pop[i+1].fitness(x_fitness);
// let's explore the neighborhoud of the individual _pop[i+2]
i += 2;
if (i<_pop.size())
{
// initilization of the move for the next individual
moveInit(move, _pop[i]);
}
}
// update fitness values
fitnessAssignment.updateByDeleting(_pop, worst_objVec);
}
}
};
#endif /*MOEOIBMOLS_H_*/

View file

@ -0,0 +1,215 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoIteratedIBMOLS.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOITERATEDIBMOLS_H_
#define MOEOITERATEDIBMOLS_H_
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoOp.h>
#include <eoPop.h>
#include <utils/rnd_generators.h>
#include <moMove.h>
#include <moMoveInit.h>
#include <moNextMove.h>
#include <algo/moeoIBMOLS.h>
#include <algo/moeoLS.h>
#include <archive/moeoArchive.h>
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
#include <move/moeoMoveIncrEval.h>
//#include <rsCrossQuad.h>
/**
* Iterated version of IBMOLS as described in
* Basseur M., Burke K. : "Indicator-Based Multi-Objective Local Search" (2007).
*/
template < class MOEOT, class Move >
class moeoIteratedIBMOLS : public moeoLS < MOEOT, eoPop < MOEOT > & >
{
public:
/** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor.
* @param _moveInit the move initializer
* @param _nextMove the neighborhood explorer
* @param _eval the full evaluation
* @param _moveIncrEval the incremental evaluation
* @param _fitnessAssignment the fitness assignment strategy
* @param _continuator the stopping criteria
* @param _monOp the monary operator
* @param _randomMonOp the random monary operator (or random initializer)
* @param _nNoiseIterations the number of iterations to apply the random noise
*/
moeoIteratedIBMOLS(
moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove,
eoEvalFunc < MOEOT > & _eval,
moeoMoveIncrEval < Move > & _moveIncrEval,
moeoIndicatorBasedFitnessAssignment < MOEOT > & _fitnessAssignment,
eoContinue < MOEOT > & _continuator,
eoMonOp < MOEOT > & _monOp,
eoMonOp < MOEOT > & _randomMonOp,
unsigned int _nNoiseIterations=1
) :
ibmols(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator),
eval(_eval),
continuator(_continuator),
monOp(_monOp),
randomMonOp(_randomMonOp),
nNoiseIterations(_nNoiseIterations)
{}
/**
* Apply the local search iteratively until the stopping criteria is met.
* @param _pop the initial population
* @param _arch the (updated) archive
*/
void operator() (eoPop < MOEOT > & _pop, moeoArchive < MOEOT > & _arch)
{
_arch.update(_pop);
ibmols(_pop, _arch);
while (continuator(_arch))
{
// generate new solutions from the archive
generateNewSolutions(_pop, _arch);
// apply the local search (the global archive is updated in the sub-function)
ibmols(_pop, _arch);
}
}
private:
/** the local search to iterate */
moeoIBMOLS < MOEOT, Move > ibmols;
/** the full evaluation */
eoEvalFunc < MOEOT > & eval;
/** the stopping criteria */
eoContinue < MOEOT > & continuator;
/** the monary operator */
eoMonOp < MOEOT > & monOp;
/** the random monary operator (or random initializer) */
eoMonOp < MOEOT > & randomMonOp;
/** the number of iterations to apply the random noise */
unsigned int nNoiseIterations;
/**
* Creates new population randomly initialized and/or initialized from the archive _arch.
* @param _pop the output population
* @param _arch the archive
*/
void generateNewSolutions(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
{
// shuffle vector for the random selection of individuals
vector<unsigned int> shuffle;
shuffle.resize(std::max(_pop.size(), _arch.size()));
// init shuffle
for (unsigned int i=0; i<shuffle.size(); i++)
{
shuffle[i] = i;
}
// randomize shuffle
UF_random_generator <unsigned int int> gen;
std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
// start the creation of new solutions
for (unsigned int i=0; i<_pop.size(); i++)
{
if (shuffle[i] < _arch.size())
// the given archive contains the individual i
{
// add it to the resulting pop
_pop[i] = _arch[shuffle[i]];
// then, apply the operator nIterationsNoise times
for (unsigned int j=0; j<nNoiseIterations; j++)
{
monOp(_pop[i]);
}
}
else
// a randomly generated solution needs to be added
{
// random initialization
randomMonOp(_pop[i]);
}
// evaluation of the new individual
_pop[i].invalidate();
eval(_pop[i]);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER //
/*
void generateNewSolutions2(eoPop < MOEOT > & _pop, const moeoArchive < MOEOT > & _arch)
{
// here, we must have a QuadOp !
//eoQuadOp < MOEOT > quadOp;
rsCrossQuad quadOp;
// shuffle vector for the random selection of individuals
vector<unsigned int> shuffle;
shuffle.resize(_arch.size());
// init shuffle
for (unsigned int i=0; i<shuffle.size(); i++)
{
shuffle[i] = i;
}
// randomize shuffle
UF_random_generator <unsigned int int> gen;
std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
// start the creation of new solutions
unsigned int i=0;
while ((i<_pop.size()-1) && (i<_arch.size()-1))
{
_pop[i] = _arch[shuffle[i]];
_pop[i+1] = _arch[shuffle[i+1]];
// then, apply the operator nIterationsNoise times
for (unsigned int j=0; j<nNoiseIterations; j++)
{
quadOp(_pop[i], _pop[i+1]);
}
eval(_pop[i]);
eval(_pop[i+1]);
i=i+2;
}
// do we have to add some random solutions ?
while (i<_pop.size())
{
randomMonOp(_pop[i]);
eval(_pop[i]);
i++;
}
}
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////
};
#endif /*MOEOITERATEDIBMOLS_H_*/

View file

@ -14,14 +14,14 @@
#define MOEOLS_H_
#include <eoFunctor.h>
#include <moeoArchive.h>
#include <algo/moeoAlgo.h>
#include <archive/moeoArchive.h>
/**
* Abstract class for local searches applied to multi-objective optimization.
* 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 >
class moeoLS: public eoBF < Type, moeoArchive < MOEOT > &, void >
{};
class moeoLS: public moeoAlgo, public eoBF < Type, moeoArchive < MOEOT > &, void > {};
#endif /*MOEOLS_H_*/

View file

@ -0,0 +1,158 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoNSGA.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEONSGA_H_
#define MOEONSGA_H_
#include <eoBreed.h>
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoGenContinue.h>
#include <eoGeneralBreeder.h>
#include <eoGenOp.h>
#include <eoPopEvalFunc.h>
#include <eoSGAGenOp.h>
#include <algo/moeoEA.h>
#include <diversity/moeoFrontByFrontSharingDiversityAssignment.h>
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
#include <replacement/moeoElitistReplacement.h>
#include <selection/moeoDetTournamentSelect.h>
/**
* NSGA (Non-dominated Sorting Genetic Algorithm) as described in:
* N. Srinivas, K. Deb, "Multiobjective Optimization Using Nondominated Sorting in Genetic Algorithms".
* Evolutionary Computation, Vol. 2(3), No 2, pp. 221-248 (1994).
* This class builds the NSGA algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
*/
template < class MOEOT >
class moeoNSGA: public moeoEA < MOEOT >
{
public:
/**
* Simple ctor with a eoGenOp.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
* @param _nicheSize niche size
*/
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Simple ctor with a eoTransform.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
* @param _nicheSize niche size
*/
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Ctor with a crossover, a mutation and their corresponding rates.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _crossover crossover
* @param _pCross crossover probability
* @param _mutation mutation
* @param _pMut mutation probability
* @param _nicheSize niche size
*/
moeoNSGA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, double _nicheSize = 0.5) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
diversityAssignment(_nicheSize), replace (fitnessAssignment, diversityAssignment),
defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed)
{}
/**
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
* @param _nicheSize niche size
*/
moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op, double _nicheSize = 0.5) :
continuator(_continuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
* @param _nicheSize niche size
*/
moeoNSGA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op, double _nicheSize = 0.5) :
continuator(_continuator), popEval(_eval), select(2),
diversityAssignment(_nicheSize), replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified.
* @param _pop the population
*/
virtual void operator () (eoPop < MOEOT > &_pop)
{
eoPop < MOEOT > offspring, empty_pop;
popEval (empty_pop, _pop); // a first eval of _pop
// evaluate fitness and diversity
fitnessAssignment(_pop);
diversityAssignment(_pop);
do
{
// generate offspring, worths are recalculated if necessary
breed (_pop, offspring);
// eval of offspring
popEval (_pop, offspring);
// after replace, the new pop is in _pop. Worths are recalculated if necessary
replace (_pop, offspring);
} while (continuator (_pop));
}
protected:
/** a continuator based on the number of generations (used as default) */
eoGenContinue < MOEOT > defaultGenContinuator;
/** stopping criteria */
eoContinue < MOEOT > & continuator;
/** evaluation function used to evaluate the whole population */
eoPopLoopEval < MOEOT > popEval;
/** binary tournament selection */
moeoDetTournamentSelect < MOEOT > select;
/** fitness assignment used in NSGA-II */
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
/** diversity assignment used in NSGA-II */
moeoFrontByFrontSharingDiversityAssignment < MOEOT > diversityAssignment;
/** elitist replacement */
moeoElitistReplacement < MOEOT > replace;
/** an object for genetic operators (used as default) */
eoSGAGenOp < MOEOT > defaultSGAGenOp;
/** general breeder */
eoGeneralBreeder < MOEOT > genBreed;
/** breeder */
eoBreed < MOEOT > & breed;
};
#endif /*MOEONSGAII_H_*/

View file

@ -0,0 +1,153 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoNSGAII.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEONSGAII_H_
#define MOEONSGAII_H_
#include <eoBreed.h>
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoGenContinue.h>
#include <eoGeneralBreeder.h>
#include <eoGenOp.h>
#include <eoPopEvalFunc.h>
#include <eoSGAGenOp.h>
#include <algo/moeoEA.h>
#include <diversity/moeoFrontByFrontCrowdingDistanceDiversityAssignment.h>
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
#include <replacement/moeoElitistReplacement.h>
#include <selection/moeoDetTournamentSelect.h>
/**
* NSGA-II (Non-dominated Sorting Genetic Algorithm II) as described in:
* Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan : "A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II".
* In IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197 (April 2002).
* This class builds the NSGA-II algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
*/
template < class MOEOT >
class moeoNSGAII: public moeoEA < MOEOT >
{
public:
/**
* Simple ctor with a eoGenOp.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Simple ctor with a eoTransform.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Ctor with a crossover, a mutation and their corresponding rates.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _crossover crossover
* @param _pCross crossover probability
* @param _mutation mutation
* @param _pMut mutation probability
*/
moeoNSGAII (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2),
replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
genBreed (select, defaultSGAGenOp), breed (genBreed)
{}
/**
* Ctor with a continuator (instead of _maxGen) and a eoGenOp.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
continuator(_continuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Ctor with a continuator (instead of _maxGen) and a eoTransform.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
continuator(_continuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), genBreed(select, _op), breed(genBreed)
{}
/**
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified.
* @param _pop the population
*/
virtual void operator () (eoPop < MOEOT > &_pop)
{
eoPop < MOEOT > offspring, empty_pop;
popEval (empty_pop, _pop); // a first eval of _pop
// evaluate fitness and diversity
fitnessAssignment(_pop);
diversityAssignment(_pop);
do
{
// generate offspring, worths are recalculated if necessary
breed (_pop, offspring);
// eval of offspring
popEval (_pop, offspring);
// after replace, the new pop is in _pop. Worths are recalculated if necessary
replace (_pop, offspring);
} while (continuator (_pop));
}
protected:
/** a continuator based on the number of generations (used as default) */
eoGenContinue < MOEOT > defaultGenContinuator;
/** stopping criteria */
eoContinue < MOEOT > & continuator;
/** evaluation function used to evaluate the whole population */
eoPopLoopEval < MOEOT > popEval;
/** binary tournament selection */
moeoDetTournamentSelect < MOEOT > select;
/** fitness assignment used in NSGA-II */
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
/** diversity assignment used in NSGA-II */
moeoFrontByFrontCrowdingDistanceDiversityAssignment < MOEOT > diversityAssignment;
/** elitist replacement */
moeoElitistReplacement < MOEOT > replace;
/** an object for genetic operators (used as default) */
eoSGAGenOp < MOEOT > defaultSGAGenOp;
/** general breeder */
eoGeneralBreeder < MOEOT > genBreed;
/** breeder */
eoBreed < MOEOT > & breed;
};
#endif /*MOEONSGAII_H_*/

View file

@ -14,7 +14,8 @@
#define MOEOARCHIVE_H_
#include <eoPop.h>
#include <moeoObjectiveVectorComparator.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
/**
* An archive is a secondary population that stores non-dominated solutions.
@ -24,10 +25,10 @@ class moeoArchive : public eoPop < MOEOT >
{
public:
using std::vector < MOEOT > :: size;
using std::vector < MOEOT > :: operator[];
using std::vector < MOEOT > :: back;
using std::vector < MOEOT > :: pop_back;
using eoPop < MOEOT > :: size;
using eoPop < MOEOT > :: operator[];
using eoPop < MOEOT > :: back;
using eoPop < MOEOT > :: pop_back;
/**
@ -58,9 +59,10 @@ public:
*/
bool dominates (const ObjectiveVector & _objectiveVector) const
{
for (unsigned i = 0; i<size(); i++)
for (unsigned int i = 0; i<size(); i++)
{
if ( comparator(operator[](i).fitness(), _objectiveVector) )
// if _objectiveVector is dominated by the ith individual of the archive...
if ( comparator(_objectiveVector, operator[](i).objectiveVector()) )
{
return true;
}
@ -75,7 +77,7 @@ public:
*/
bool contains (const ObjectiveVector & _objectiveVector) const
{
for (unsigned i = 0; i<size(); i++)
for (unsigned int i = 0; i<size(); i++)
{
if (operator[](i).objectiveVector() == _objectiveVector)
{
@ -93,10 +95,10 @@ public:
void update (const MOEOT & _moeo)
{
// first step: removing the dominated solutions from the archive
for (unsigned j=0; j<size();)
for (unsigned int j=0; j<size();)
{
// if _moeo dominates the jth solution contained in the archive
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
// if the jth solution contained in the archive is dominated by _moeo
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
{
operator[](j) = back();
pop_back();
@ -113,10 +115,10 @@ public:
}
// second step: is _moeo dominated?
bool dom = false;
for (unsigned j=0; j<size(); j++)
for (unsigned int j=0; j<size(); j++)
{
// if the jth solution contained in the archive dominates _moeo
if ( comparator(operator[](j).objectiveVector(), _moeo.objectiveVector()) )
// if _moeo is dominated by the jth solution contained in the archive
if ( comparator(_moeo.objectiveVector(), operator[](j).objectiveVector()) )
{
dom = true;
break;
@ -135,7 +137,7 @@ public:
*/
void update (const eoPop < MOEOT > & _pop)
{
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
update(_pop[i]);
}
@ -143,20 +145,19 @@ public:
/**
* Returns true if the current archive contains the same objective vectors
* than the given archive _arch
* Returns true if the current archive contains the same objective vectors than the given archive _arch
* @param _arch the given archive
*/
bool equals (const moeoArchive < MOEOT > & _arch)
{
for (unsigned i=0; i<size(); i++)
for (unsigned int i=0; i<size(); i++)
{
if (! _arch.contains(operator[](i).objectiveVector()))
{
return false;
}
}
for (unsigned i=0; i<_arch.size() ; i++)
for (unsigned int i=0; i<_arch.size() ; i++)
{
if (! contains(_arch[i].objectiveVector()))
{

View file

@ -0,0 +1,55 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoAggregativeComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOAGGREGATIVECOMPARATOR_H_
#define MOEOAGGREGATIVECOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to their fitness and diversity values, each according to its aggregative value.
*/
template < class MOEOT >
class moeoAggregativeComparator : public moeoComparator < MOEOT >
{
public:
/**
* Ctor.
* @param _weightFitness the weight for fitness
* @param _weightDiversity the weight for diversity
*/
moeoAggregativeComparator(double _weightFitness = 1.0, double _weightDiversity = 1.0) : weightFitness(_weightFitness), weightDiversity(_weightDiversity)
{}
/**
* Returns true if _moeo1 < _moeo2 according to the aggregation of their fitness and diversity values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return ( weightFitness * _moeo1.fitness() + weightDiversity * _moeo1.diversity() ) < ( weightFitness * _moeo2.fitness() + weightDiversity * _moeo2.diversity() );
}
private:
/** the weight for fitness */
double weightFitness;
/** the weight for diversity */
double weightDiversity;
};
#endif /*MOEOAGGREGATIVECOMPARATOR_H_*/

View file

@ -0,0 +1,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCOMPARATOR_H_
#define MOEOCOMPARATOR_H_
#include <eoFunctor.h>
/**
* Functor allowing to compare two solutions.
*/
template < class MOEOT >
class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool > {};
#endif /*MOEOCOMPARATOR_H_*/

View file

@ -0,0 +1,45 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDiversityThenFitnessComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODIVERSITYTHENFITNESSCOMPARATOR_H_
#define MOEODIVERSITYTHENFITNESSCOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to their diversity values, then according to their fitness values.
*/
template < class MOEOT >
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 < _moeo2 according to their diversity values, then according to their fitness values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.diversity() == _moeo2.diversity())
{
return _moeo1.fitness() < _moeo2.fitness();
}
else
{
return _moeo1.diversity() < _moeo2.diversity();
}
}
};
#endif /*MOEODIVERSITYTHENFITNESSCOMPARATOR_H_*/

View file

@ -0,0 +1,45 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoFitnessThenDiversityComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_
#define MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to their fitness values, then according to their diversity values.
*/
template < class MOEOT >
class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 < _moeo2 according to their fitness values, then according to their diversity values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.fitness() == _moeo2.fitness())
{
return _moeo1.diversity() < _moeo2.diversity();
}
else
{
return _moeo1.fitness() < _moeo2.fitness();
}
}
};
#endif /*MOEOFITNESSTHENDIVERSITYCOMPARATOR_H_*/

View file

@ -0,0 +1,102 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoGDominanceObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* This functor class allows to compare 2 objective vectors according to g-dominance.
* The concept of g-dominance as been introduced in:
* J. Molina, L. V. Santana, A. G. Hernandez-Diaz, C. A. Coello Coello, R. Caballero,
* "g-dominance: Reference point based dominance" (2007)
*/
template < class ObjectiveVector >
class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Ctor.
* @param _ref the reference point
*/
moeoGDominanceObjectiveVectorComparator(ObjectiveVector & _ref) : ref(_ref)
{}
/**
* Returns true if _objectiveVector1 is g-dominated by _objectiveVector2.
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
unsigned int flag1 = flag(_objectiveVector1);
unsigned int flag2 = flag(_objectiveVector2);
if (flag2==0)
{
// cannot dominate
return false;
}
else if ( (flag2==1) && (flag1==0) )
{
// is dominated
return true;
}
else // (flag1==1) && (flag2==1)
{
// both are on the good region, so let's use the classical Pareto dominance
return paretoComparator(_objectiveVector1, _objectiveVector2);
}
}
private:
/** the reference point */
ObjectiveVector & ref;
/** Pareto comparator */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
* Returns the flag of _objectiveVector according to the reference point
* @param _objectiveVector the first objective vector
*/
unsigned int flag(const ObjectiveVector & _objectiveVector)
{
unsigned int result=1;
for (unsigned int i=0; i<ref.nObjectives(); i++)
{
if (_objectiveVector[i] > ref[i])
{
result=0;
}
}
if (result==0)
{
result=1;
for (unsigned int i=0; i<ref.nObjectives(); i++)
{
if (_objectiveVector[i] < ref[i])
{
result=0;
}
}
}
return result;
}
};
#endif /*MOEOGDOMINANCEOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,52 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* Functor allowing to compare two objective vectors according to their first objective value, then their second, and so on.
*/
template < class ObjectiveVector >
class moeoObjectiveObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Returns true if _objectiveVector1 < _objectiveVector2 on the first objective, then on the second, and so on
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{
if (_objectiveVector1[i] < _objectiveVector2[i])
{
return true;
}
else
{
return false;
}
}
}
return false;
}
};
#endif /*MOEOOBJECTIVEOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,26 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOOBJECTIVEVECTORCOMPARATOR_H_
#include <math.h>
#include <eoFunctor.h>
/**
* Abstract class allowing to compare 2 objective vectors.
* The template argument ObjectiveVector have to be a moeoObjectiveVector.
*/
template < class ObjectiveVector >
class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, const bool > {};
#endif /*MOEOOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,57 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoOneObjectiveComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOONEOBJECTIVECOMPARATOR_H_
#define MOEOONEOBJECTIVECOMPARATOR_H_
#include <comparator/moeoComparator.h>
/**
* Functor allowing to compare two solutions according to one objective.
*/
template < class MOEOT >
class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Ctor.
* @param _obj the index of objective
*/
moeoOneObjectiveComparator(unsigned int _obj) : obj(_obj)
{
if (obj > MOEOT::ObjectiveVector::nObjectives())
{
throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator");
}
}
/**
* Returns true if _moeo1 < _moeo2 on the obj objective
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return _moeo1.objectiveVector()[obj] < _moeo2.objectiveVector()[obj];
}
private:
/** the index of objective */
unsigned int obj;
};
#endif /*MOEOONEOBJECTIVECOMPARATOR_H_*/

View file

@ -0,0 +1,70 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoParetoObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_
#include <comparator/moeoObjectiveVectorComparator.h>
/**
* This functor class allows to compare 2 objective vectors according to Pareto dominance.
*/
template < class ObjectiveVector >
class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Returns true if _objectiveVector1 is dominated by _objectiveVector2
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
const bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
bool dom = false;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{
// first, we have to check if the 2 objective values are not equal for the ith objective
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{
// if the ith objective have to be minimized...
if (ObjectiveVector::minimizing(i))
{
if (_objectiveVector1[i] > _objectiveVector2[i])
{
dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i]
}
else
{
return false; //_objectiveVector2 cannot dominate _objectiveVector1
}
}
// if the ith objective have to be maximized...
else if (ObjectiveVector::maximizing(i))
{
if (_objectiveVector1[i] > _objectiveVector2[i])
{
dom = true; //_objectiveVector1[i] is not better than _objectiveVector2[i]
}
else
{
return false; //_objectiveVector2 cannot dominate _objectiveVector1
}
}
}
}
return dom;
}
};
#endif /*MOEOPARETOOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -24,6 +24,9 @@
* The template argument MOEOFitness is an object reflecting the quality of the solution in term of convergence (the fitness of a solution is always to be maximized).
* The template argument MOEODiversity is an object reflecting the quality of the solution in term of diversity (the diversity of a solution is always to be maximized).
* All template arguments must have a void and a copy constructor.
* Using some specific representations, you will have to define a copy constructor if the default one is not what you want.
* In the same cases, you will also have to define the affectation operator (operator=).
* Then, you will explicitly have to call the parent copy constructor and the parent affectation operator at the beginning of the corresponding implementation.
* Besides, note that, contrary to the mono-objective case (and to EO) where the fitness value of a solution is confused with its objective value,
* the fitness value differs of the objectives values in the multi-objective case.
*/
@ -69,7 +72,7 @@ public:
{
if ( invalidObjectiveVector() )
{
throw std::runtime_error("invalid objective vector");
throw std::runtime_error("invalid objective vector in MOEO");
}
return objectiveVectorValue;
}
@ -111,7 +114,7 @@ public:
{
if ( invalidFitness() )
{
throw std::runtime_error("invalid fitness (MOEO)");
throw std::runtime_error("invalid fitness in MOEO");
}
return fitnessValue;
}
@ -153,7 +156,7 @@ public:
{
if ( invalidDiversity() )
{
throw std::runtime_error("invalid diversity");
throw std::runtime_error("invalid diversity in MOEO");
}
return diversityValue;
}

View file

@ -0,0 +1,9 @@
lib_LIBRARIES = libmoeo.a
libmoeo_a_SOURCES = moeoObjectiveVectorTraits.cpp
pkginclude_HEADERS = moeoObjectiveVectorTraits.h
INCLUDES = -I$(EO_DIR)/src/ -I$(top_srcdir)/src/
AM_CXXFLAGS = -Wall -ansi -pedantic

View file

@ -0,0 +1,74 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoBitVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOBITVECTOR_H_
#define MOEOBITVECTOR_H_
#include <core/moeoVector.h>
/**
* This class is an implementationeo of a simple bit-valued moeoVector.
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >
{
public:
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: resize;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: size;
/**
* Ctor
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type GeneType)
*/
moeoBitVector(unsigned int _size = 0, bool _value = false) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >(_size, _value)
{}
/**
* Writing object
* @param _os output stream
*/
virtual void printOn(std::ostream & _os) const
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
_os << ' ';
_os << size() << ' ';
std::copy(begin(), end(), std::ostream_iterator<bool>(_os));
}
/**
* Reading object
* @param _is input stream
*/
virtual void readFrom(std::istream & _is)
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
unsigned int s;
_is >> s;
std::string bits;
_is >> bits;
if (_is)
{
resize(bits.size());
std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1'));
}
}
};
#endif /*MOEOBITVECTOR_H_*/

View file

@ -0,0 +1,91 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEVECTOR_H_
#define MOEOOBJECTIVEVECTOR_H_
#include <vector>
/**
* Abstract class allowing to represent a solution in the objective space (phenotypic representation).
* The template argument ObjectiveVectorTraits defaults to moeoObjectiveVectorTraits,
* but it can be replaced at will by any other class that implements the static functions defined therein.
* Some static funtions to access to the traits characteristics are re-defined in order not to write a lot of typedef's.
*/
template < class ObjectiveVectorTraits, class ObjectiveVectorType >
class moeoObjectiveVector : public std::vector < ObjectiveVectorType >
{
public:
/** The traits of objective vectors */
typedef ObjectiveVectorTraits Traits;
/** The type of an objective value */
typedef ObjectiveVectorType Type;
/**
* Ctor
*/
moeoObjectiveVector(Type _value = Type()) : std::vector < Type > (ObjectiveVectorTraits::nObjectives(), _value)
{}
/**
* Ctor from a vector of Type
* @param _v the std::vector < Type >
*/
moeoObjectiveVector(std::vector < Type > & _v) : std::vector < Type > (_v)
{}
/**
* Parameters setting (for the objective vector of any solution)
* @param _nObjectives the number of objectives
* @param _bObjectives the min/max vector (true = min / false = max)
*/
static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives)
{
ObjectiveVectorTraits::setup(_nObjectives, _bObjectives);
}
/**
* Returns the number of objectives
*/
static unsigned int nObjectives()
{
return ObjectiveVectorTraits::nObjectives();
}
/**
* Returns true if the _ith objective have to be minimized
* @param _i the index
*/
static bool minimizing(unsigned int _i)
{
return ObjectiveVectorTraits::minimizing(_i);
}
/**
* Returns true if the _ith objective have to be maximized
* @param _i the index
*/
static bool maximizing(unsigned int _i)
{
return ObjectiveVectorTraits::maximizing(_i);
}
};
#endif /*MOEOOBJECTIVEVECTOR_H_*/

View file

@ -1,7 +1,7 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVector.h
// moeoObjectiveVectorDouble.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
@ -10,92 +10,40 @@
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEVECTOR_H_
#define MOEOOBJECTIVEVECTOR_H_
#ifndef MOEOOBJECTIVEVECTORDOUBLE_H_
#define MOEOOBJECTIVEVECTORDOUBLE_H_
#include <iostream>
#include <math.h>
#include <vector>
#include <moeoObjectiveVectorComparator.h>
/**
* Abstract class allowing to represent a solution in the objective space (phenotypic representation).
* The template argument ObjectiveVectorTraits defaults to moeoObjectiveVectorTraits,
* but it can be replaced at will by any other class that implements the static functions defined therein.
* Some static funtions to access to the traits characteristics are re-defined in order not to write a lot of typedef's.
*/
template < class ObjectiveVectorTraits >
class moeoObjectiveVector
{
public:
/** The traits of objective vectors */
typedef ObjectiveVectorTraits Traits;
/**
* Parameters setting (for the objective vector of any solution)
* @param _nObjectives the number of objectives
* @param _bObjectives the min/max vector (true = min / false = max)
*/
static void setup(unsigned _nObjectives, std::vector < bool > & _bObjectives)
{
ObjectiveVectorTraits::setup(_nObjectives, _bObjectives);
}
/**
* Returns the number of objectives
*/
static unsigned nObjectives()
{
return ObjectiveVectorTraits::nObjectives();
}
/**
* Returns true if the _ith objective have to be minimized
* @param _i the index
*/
static bool minimizing(unsigned _i) {
return ObjectiveVectorTraits::minimizing(_i);
}
/**
* Returns true if the _ith objective have to be maximized
* @param _i the index
*/
static bool maximizing(unsigned _i) {
return ObjectiveVectorTraits::maximizing(_i);
}
};
#include <comparator/moeoObjectiveObjectiveVectorComparator.h>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <core/moeoObjectiveVector.h>
/**
* This class allows to represent a solution in the objective space (phenotypic representation) by a std::vector of doubles,
* i.e. that an objective value is represented using a double, and this for any objective.
*/
template < class ObjectiveVectorTraits >
class moeoObjectiveVectorDouble : public moeoObjectiveVector < ObjectiveVectorTraits >, public std::vector < double >
class moeoObjectiveVectorDouble : public moeoObjectiveVector < ObjectiveVectorTraits, double >
{
public:
using std::vector< double >::size;
using std::vector< double >::operator[];
using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
/**
* Ctor
*/
moeoObjectiveVectorDouble() : std::vector < double > (ObjectiveVectorTraits::nObjectives(), 0.0) {}
moeoObjectiveVectorDouble(double _value = 0.0) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_value)
{}
/**
* Ctor from a vector of doubles
* @param _v the std::vector < double >
*/
moeoObjectiveVectorDouble(std::vector <double> & _v) : std::vector < double > (_v) {}
moeoObjectiveVectorDouble(std::vector < double > & _v) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_v)
{}
/**
@ -106,7 +54,7 @@ public:
bool dominates(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
moeoParetoObjectiveVectorComparator < moeoObjectiveVectorDouble<ObjectiveVectorTraits> > comparator;
return comparator(*this, _other);
return comparator(_other, *this);
}
@ -116,7 +64,7 @@ public:
*/
bool operator==(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
for (unsigned i=0; i < size(); i++)
for (unsigned int i=0; i < size(); i++)
{
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
{
@ -144,21 +92,8 @@ public:
*/
bool operator<(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
for (unsigned i=0; i < size(); i++)
{
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
{
if (operator[](i) < _other[i])
{
return true;
}
else
{
return false;
}
}
}
return false;
moeoObjectiveObjectiveVectorComparator < moeoObjectiveVectorDouble < ObjectiveVectorTraits > > cmp;
return cmp(*this, _other);
}
@ -205,7 +140,7 @@ public:
template < class ObjectiveVectorTraits >
std::ostream & operator<<(std::ostream & _os, const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
{
for (unsigned i=0; i<_objectiveVector.size(); i++)
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_os << _objectiveVector[i] << '\t';
}
@ -221,11 +156,11 @@ template < class ObjectiveVectorTraits >
std::istream & operator>>(std::istream & _is, moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
{
_objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
for (unsigned i=0; i<_objectiveVector.size(); i++)
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_is >> _objectiveVector[i];
}
return _is;
}
#endif /*MOEOOBJECTIVEVECTOR_H_*/
#endif /*MOEOOBJECTIVEVECTORDOUBLE_H_*/

View file

@ -0,0 +1,17 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorTraits.cpp
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#include <core/moeoObjectiveVectorTraits.h>
// The static variables of the moeoObjectiveVectorTraits class need to be allocated
unsigned int moeoObjectiveVectorTraits::nObj;
std::vector < bool > moeoObjectiveVectorTraits::bObj;

View file

@ -13,9 +13,9 @@
#ifndef MOEOOBJECTIVEVECTORTRAITS_H_
#define MOEOOBJECTIVEVECTORTRAITS_H_
#include <vector>
#include <iostream>
#include <stdexcept>
#include <vector>
/**
* A traits class for moeoObjectiveVector to specify the number of objectives and which ones have to be minimized or maximized.
@ -29,7 +29,7 @@ public:
* @param _nObjectives the number of objectives
* @param _bObjectives the min/max vector (true = min / false = max)
*/
static void setup(unsigned _nObjectives, std::vector < bool > & _bObjectives)
static void setup(unsigned int _nObjectives, std::vector < bool > & _bObjectives)
{
// in case the number of objectives was already set to a different value
if ( nObj && (nObj != _nObjectives) ) {
@ -47,10 +47,11 @@ public:
throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
}
/**
* Returns the number of objectives
*/
static unsigned nObjectives()
static unsigned int nObjectives()
{
// in case the number of objectives would not be assigned yet
if (! nObj)
@ -58,11 +59,12 @@ public:
return nObj;
}
/**
* Returns true if the _ith objective have to be minimized
* @param _i the index
*/
static bool minimizing(unsigned _i)
static bool minimizing(unsigned int _i)
{
// in case there would be a wrong index
if (_i >= bObj.size())
@ -70,14 +72,16 @@ public:
return bObj[_i];
}
/**
* Returns true if the _ith objective have to be maximized
* @param _i the index
*/
static bool maximizing(unsigned _i) {
static bool maximizing(unsigned int _i) {
return (! minimizing(_i));
}
/**
* Returns the tolerance value (to compare solutions)
*/
@ -90,16 +94,10 @@ public:
private:
/** The number of objectives */
static unsigned nObj;
static unsigned int nObj;
/** The min/max vector */
static std::vector < bool > bObj;
};
#endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/
// The static variables of the moeoObjectiveVectorTraits class need to be allocated
// (maybe it would have been better to put this on a moeoObjectiveVectorTraits.cpp file)
unsigned moeoObjectiveVectorTraits::nObj;
std::vector < bool > moeoObjectiveVectorTraits::bObj;

View file

@ -0,0 +1,36 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoRealVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOREALVECTOR_H_
#define MOEOREALVECTOR_H_
#include <core/moeoVector.h>
/**
* This class is an implementation of a simple double-valued moeoVector.
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >
{
public:
/**
* Ctor
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type GeneType)
*/
moeoRealVector(unsigned int _size = 0, double _value = 0.0) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >(_size, _value)
{}
};
#endif /*MOEOREALVECTOR_H_*/

View file

@ -13,9 +13,9 @@
#ifndef MOEOVECTOR_H_
#define MOEOVECTOR_H_
#include <vector>
#include <iterator>
#include <MOEO.h>
#include <vector>
#include <core/MOEO.h>
/**
* Base class for fixed length chromosomes, just derives from MOEO and std::vector and redirects the smaller than operator to MOEO (objective vector based comparison).
@ -44,11 +44,11 @@ public:
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type GeneType)
*/
moeoVector(unsigned _size = 0, GeneType _value = GeneType()) :
moeoVector(unsigned int _size = 0, GeneType _value = GeneType()) :
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >(), std::vector<GeneType>(_size, _value)
{}
/**
* We can't have a Ctor from a std::vector as it would create ambiguity with the copy Ctor.
* @param _v a vector of GeneType
@ -62,6 +62,10 @@ public:
std::cout << "Warning: Changing size in moeoVector assignation"<<std::endl;
resize(_v.size());
}
else
{
throw std::runtime_error("Size not initialized in moeoVector");
}
}
std::copy(_v.begin(), _v.end(), begin());
invalidate();
@ -79,9 +83,9 @@ public:
/**
* Writing object
* @param _os output stream
*/
* Writing object
* @param _os output stream
*/
virtual void printOn(std::ostream & _os) const
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
@ -92,16 +96,16 @@ public:
/**
* Reading object
* @param _is input stream
*/
* Reading object
* @param _is input stream
*/
virtual void readFrom(std::istream & _is)
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
unsigned sz;
unsigned int sz;
_is >> sz;
resize(sz);
unsigned i;
unsigned int i;
for (i = 0; i < sz; ++i)
{
AtomType atom;
@ -136,81 +140,4 @@ bool operator>(const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity
return _moeo1.operator>(_moeo2);
}
/**
* This class is an implementationeo of a simple double-valued moeoVector.
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >
{
public:
/**
* Ctor
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type GeneType)
*/
moeoRealVector(unsigned _size = 0, double _value = 0.0) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >(_size, _value)
{}
};
/**
* This class is an implementationeo of a simple bit-valued moeoVector.
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >
{
public:
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: resize;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: size;
/**
* Ctor
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type GeneType)
*/
moeoBitVector(unsigned _size = 0, bool _value = false) : moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >(_size, _value)
{}
/**
* Writing object
* @param _os output stream
*/
virtual void printOn(std::ostream & _os) const
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::printOn(_os);
_os << ' ';
_os << size() << ' ';
std::copy(begin(), end(), std::ostream_iterator<bool>(_os));
}
/**
* Reading object
* @param _is input stream
*/
virtual void readFrom(std::istream & _is)
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
unsigned s;
_is >> s;
std::string bits;
_is >> bits;
if (_is)
{
resize(bits.size());
std::transform(bits.begin(), bits.end(), begin(), std::bind2nd(std::equal_to<char>(), '1'));
}
}
};
#endif /*MOEOVECTOR_H_*/

View file

@ -0,0 +1,54 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDistance.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODISTANCE_H_
#define MOEODISTANCE_H_
#include <eoFunctor.h>
/**
* The base class for distance computation.
*/
template < class MOEOT , class Type >
class moeoDistance : public eoBF < const MOEOT &, const MOEOT &, const Type >
{
public:
/**
* Nothing to do
* @param _pop the population
*/
virtual void setup(const eoPop < MOEOT > & _pop)
{}
/**
* Nothing to do
* @param _min lower bound
* @param _max upper bound
* @param _obj the objective index
*/
virtual void setup(double _min, double _max, unsigned int _obj)
{}
/**
* Nothing to do
* @param _realInterval the eoRealInterval object
* @param _obj the objective index
*/
virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
{}
};
#endif /*MOEODISTANCE_H_*/

View file

@ -0,0 +1,76 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDistanceMatrix.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODISTANCEMATRIX_H_
#define MOEODISTANCEMATRIX_H_
#include <vector>
#include <eoFunctor.h>
#include <distance/moeoDistance.h>
/**
* A matrix to compute distances between every pair of individuals contained in a population.
*/
template < class MOEOT , class Type >
class moeoDistanceMatrix : public eoUF < const eoPop < MOEOT > &, void > , public std::vector< std::vector < Type > >
{
public:
using std::vector< std::vector < Type > > :: size;
using std::vector< std::vector < Type > > :: operator[];
/**
* Ctor
* @param _size size for every dimension of the matrix
* @param _distance the distance to use
*/
moeoDistanceMatrix (unsigned int _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance)
{
this->resize(_size);
for (unsigned int i=0; i<_size; i++)
{
this->operator[](i).resize(_size);
}
}
/**
* Sets the distance between every pair of individuals contained in the population _pop
* @param _pop the population
*/
void operator()(const eoPop < MOEOT > & _pop)
{
// 1 - setup the bounds (if necessary)
distance.setup(_pop);
// 2 - compute distances
this->operator[](0).operator[](0) = Type();
for (unsigned int i=0; i<size(); i++)
{
this->operator[](i).operator[](i) = Type();
for (unsigned int j=0; j<i; j++)
{
this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]);
this->operator[](j).operator[](i) = this->operator[](i).operator[](j);
}
}
}
private:
/** the distance to use */
moeoDistance < MOEOT , Type > & distance;
};
#endif /*MOEODISTANCEMATRIX_H_*/

View file

@ -0,0 +1,58 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEuclideanDistance.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOEUCLIDEANDISTANCE_H_
#define MOEOEUCLIDEANDISTANCE_H_
#include <math.h>
#include <distance/moeoNormalizedDistance.h>
/**
* A class allowing to compute an euclidian distance between two solutions in the objective space with normalized objective values (i.e. between 0 and 1).
* A distance value then lies between 0 and sqrt(nObjectives).
*/
template < class MOEOT >
class moeoEuclideanDistance : public moeoNormalizedDistance < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Returns the euclidian distance between _moeo1 and _moeo2 in the objective space
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
double result = 0.0;
double tmp1, tmp2;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
result += (tmp1-tmp2) * (tmp1-tmp2);
}
return sqrt(result);
}
private:
/** the bounds for every objective */
using moeoNormalizedDistance < MOEOT > :: bounds;
};
#endif /*MOEOEUCLIDEANDISTANCE_H_*/

View file

@ -0,0 +1,58 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoManhattanDistance.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOMANHATTANDISTANCE_H_
#define MOEOMANHATTANDISTANCE_H_
#include <math.h>
#include <distance/moeoNormalizedDistance.h>
/**
* A class allowing to compute the Manhattan distance between two solutions in the objective space normalized objective values (i.e. between 0 and 1).
* A distance value then lies between 0 and nObjectives.
*/
template < class MOEOT >
class moeoManhattanDistance : public moeoNormalizedDistance < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Returns the Manhattan distance between _moeo1 and _moeo2 in the objective space
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const double operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
double result = 0.0;
double tmp1, tmp2;
for (unsigned int i=0; i<ObjectiveVector::nObjectives(); i++)
{
tmp1 = (_moeo1.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
tmp2 = (_moeo2.objectiveVector()[i] - bounds[i].minimum()) / bounds[i].range();
result += fabs(tmp1-tmp2);
}
return result;
}
private:
/** the bounds for every objective */
using moeoNormalizedDistance < MOEOT > :: bounds;
};
#endif /*MOEOMANHATTANDISTANCE_H_*/

View file

@ -0,0 +1,112 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoNormalizedDistance.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEONORMALIZEDDISTANCE_H_
#define MOEONORMALIZEDDISTANCE_H_
#include <vector>
#include <utils/eoRealBounds.h>
#include <distance/moeoDistance.h>
/**
* The base class for double distance computation with normalized objective values (i.e. between 0 and 1).
*/
template < class MOEOT , class Type = double >
class moeoNormalizedDistance : public moeoDistance < MOEOT , Type >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Default ctr
*/
moeoNormalizedDistance()
{
bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
bounds[i] = eoRealInterval(0,1);
}
}
/**
* Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound)
*/
static double tiny()
{
return 1e-6;
}
/**
* Sets the lower and the upper bounds for every objective using extremes values for solutions contained in the population _pop
* @param _pop the population
*/
virtual void setup(const eoPop < MOEOT > & _pop)
{
double min, max;
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
min = _pop[0].objectiveVector()[i];
max = _pop[0].objectiveVector()[i];
for (unsigned int j=1; j<_pop.size(); j++)
{
min = std::min(min, _pop[j].objectiveVector()[i]);
max = std::max(max, _pop[j].objectiveVector()[i]);
}
// setting of the bounds for the objective i
setup(min, max, i);
}
}
/**
* Sets the lower bound (_min) and the upper bound (_max) for the objective _obj
* @param _min lower bound
* @param _max upper bound
* @param _obj the objective index
*/
virtual void setup(double _min, double _max, unsigned int _obj)
{
if (_min == _max)
{
_min -= tiny();
_max += tiny();
}
bounds[_obj] = eoRealInterval(_min, _max);
}
/**
* Sets the lower bound and the upper bound for the objective _obj using a eoRealInterval object
* @param _realInterval the eoRealInterval object
* @param _obj the objective index
*/
virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
{
bounds[_obj] = _realInterval;
}
protected:
/** the bounds for every objective (bounds[i] = bounds for the objective i) */
std::vector < eoRealInterval > bounds;
};
#endif /*MOEONORMALIZEDDISTANCE_H_*/

View file

@ -14,13 +14,12 @@
#define MOEOCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
#include <eoPop.h>
#include <moeoComparator.h>
#include <moeoDiversityAssignment.h>
#include <comparator/moeoOneObjectiveComparator.h>
#include <diversity/moeoDiversityAssignment.h>
/**
* Diversity assignment sheme based on crowding distance proposed in:
* K. Deb, A. Pratap, S. Agarwal, T. Meyarivan, "A Fast and Elitist Multi-Objective Genetic Algorithm: NSGA-II", IEEE Transactions on Evolutionary Computation, vol. 6, no. 2 (2002).
* This strategy is, for instance, used in NSGA-II.
*/
template < class MOEOT >
class moeoCrowdingDistanceDiversityAssignment : public moeoDiversityAssignment < MOEOT >
@ -40,6 +39,15 @@ public:
}
/**
* Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound)
*/
double tiny() const
{
return 1e-6;
}
/**
* Computes diversity values for every solution contained in the population _pop
* @param _pop the population
@ -48,7 +56,7 @@ public:
{
if (_pop.size() <= 2)
{
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].diversity(inf());
}
@ -69,39 +77,39 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << endl;
std::cout << "WARNING : updateByDeleting not implemented in moeoCrowdingDiversityAssignment" << std::endl;
}
private:
protected:
/**
* Sets the distance values
* @param _pop the population
*/
void setDistances (eoPop < MOEOT > & _pop)
virtual void setDistances (eoPop < MOEOT > & _pop)
{
double min, max, distance;
unsigned nObjectives = MOEOT::ObjectiveVector::nObjectives();
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].diversity(0);
}
// for each objective
for (unsigned obj=0; obj<nObjectives; obj++)
for (unsigned int obj=0; obj<nObjectives; obj++)
{
// comparator
moeoOneObjectiveComparator < MOEOT > comp(obj);
moeoOneObjectiveComparator < MOEOT > objComp(obj);
// sort
std::sort(_pop.begin(), _pop.end(), comp);
std::sort(_pop.begin(), _pop.end(), objComp);
// min & max
min = _pop[0].objectiveVector()[obj];
max = _pop[_pop.size()-1].objectiveVector()[obj];
// set the diversity value to infiny for min and max
_pop[0].diversity(inf());
_pop[_pop.size()-1].diversity(inf());
for (unsigned i=1; i<_pop.size()-1; i++)
for (unsigned int i=1; i<_pop.size()-1; i++)
{
distance = (_pop[i+1].objectiveVector()[obj] - _pop[i-1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance);

View file

@ -48,46 +48,4 @@ public:
};
/**
* moeoDummyDiversityAssignment is a moeoDiversityAssignment that gives the value '0' as the individual's diversity for a whole population if it is invalid.
*/
template < class MOEOT >
class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
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
* @param _pop the population
*/
void operator () (eoPop < MOEOT > & _pop)
{
for (unsigned idx = 0; idx<_pop.size (); idx++)
{
if (_pop[idx].invalidDiversity())
{
// set the diversity to 0
_pop[idx].diversity(0.0);
}
}
}
/**
* 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 _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
};
#endif /*MOEODIVERSITYASSIGNMENT_H_*/

View file

@ -0,0 +1,59 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDummyDiversityAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODUMMYDIVERSITYASSIGNMENT_H_
#define MOEODUMMYDIVERSITYASSIGNMENT_H_
#include<diversity/moeoDiversityAssignment.h>
/**
* moeoDummyDiversityAssignment is a moeoDiversityAssignment that gives the value '0' as the individual's diversity for a whole population if it is invalid.
*/
template < class MOEOT >
class moeoDummyDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
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
* @param _pop the population
*/
void operator () (eoPop < MOEOT > & _pop)
{
for (unsigned int idx = 0; idx<_pop.size (); idx++)
{
if (_pop[idx].invalidDiversity())
{
// set the diversity to 0
_pop[idx].diversity(0.0);
}
}
}
/**
* 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 _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
};
#endif /*MOEODUMMYDIVERSITYASSIGNMENT_H_*/

View file

@ -0,0 +1,133 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoFrontByFrontCrowdingDistanceDiversityAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOFRONTBYFRONTCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
#define MOEOFRONTBYFRONTCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_
#include <diversity/moeoCrowdingDistanceDiversityAssignment.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
/**
* Diversity assignment sheme based on crowding distance proposed in:
* K. Deb, A. Pratap, S. Agarwal, T. Meyarivan, "A Fast and Elitist Multi-Objective Genetic Algorithm: NSGA-II", IEEE Transactions on Evolutionary Computation, vol. 6, no. 2 (2002).
* Tis strategy assigns diversity values FRONT BY FRONT. It is, for instance, used in NSGA-II.
*/
template < class MOEOT >
class moeoFrontByFrontCrowdingDistanceDiversityAssignment : public moeoCrowdingDistanceDiversityAssignment < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* @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 _objVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoFrontByFrontCrowdingDistanceDiversityAssignment" << std::endl;
}
private:
using moeoCrowdingDistanceDiversityAssignment < MOEOT >::inf;
using moeoCrowdingDistanceDiversityAssignment < MOEOT >::tiny;
/**
* Sets the distance values
* @param _pop the population
*/
void setDistances (eoPop < MOEOT > & _pop)
{
unsigned int a,b;
double min, max, distance;
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
// set diversity to 0 for every individual
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].diversity(0.0);
}
// sort the whole pop according to fitness values
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
std::sort(_pop.begin(), _pop.end(), fitnessComparator);
// compute the crowding distance values for every individual "front" by "front" (front : from a to b)
a = 0; // the front starts at a
while (a < _pop.size())
{
b = lastIndex(_pop,a); // the front ends at b
// if there is less than 2 individuals in the front...
if ((b-a) < 2)
{
for (unsigned int i=a; i<=b; i++)
{
_pop[i].diversity(inf());
}
}
// else...
else
{
// for each objective
for (unsigned int obj=0; obj<nObjectives; obj++)
{
// sort in the descending order using the values of the objective 'obj'
moeoOneObjectiveComparator < MOEOT > objComp(obj);
std::sort(_pop.begin()+a, _pop.begin()+b+1, objComp);
// min & max
min = _pop[b].objectiveVector()[obj];
max = _pop[a].objectiveVector()[obj];
// avoid extreme case
if (min == max)
{
min -= tiny();
max += tiny();
}
// set the diversity value to infiny for min and max
_pop[a].diversity(inf());
_pop[b].diversity(inf());
// set the diversity values for the other individuals
for (unsigned int i=a+1; i<b; i++)
{
distance = (_pop[i-1].objectiveVector()[obj] - _pop[i+1].objectiveVector()[obj]) / (max-min);
_pop[i].diversity(_pop[i].diversity() + distance);
}
}
}
// go to the next front
a = b+1;
}
}
/**
* Returns the index of the last individual having the same fitness value than _pop[_start]
* @param _pop the population
* @param _start the index to start from
*/
unsigned int lastIndex (eoPop < MOEOT > & _pop, unsigned int _start)
{
unsigned int i=_start;
while ( (i<_pop.size()-1) && (_pop[i].fitness()==_pop[i+1].fitness()) )
{
i++;
}
return i;
}
};
#endif /*MOEOFRONTBYFRONTCROWDINGDISTANCEDIVERSITYASSIGNMENT_H_*/

View file

@ -0,0 +1,106 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoFrontByFrontSharingDiversityAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_
#define MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_
#include <diversity/moeoSharingDiversityAssignment.h>
/**
* Sharing assignment scheme on the way it is used in NSGA.
*/
template < class MOEOT >
class moeoFrontByFrontSharingDiversityAssignment : public moeoSharingDiversityAssignment < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor
* @param _distance the distance used to compute the neighborhood of solutions (can be related to the decision space or the objective space)
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
* @param _alpha parameter used to regulate the shape of the sharing function
*/
moeoFrontByFrontSharingDiversityAssignment(moeoDistance<MOEOT,double> & _distance, double _nicheSize = 0.5, double _alpha = 2.0) : moeoSharingDiversityAssignment < MOEOT >(_distance, _nicheSize, _alpha)
{}
/**
* Ctor with an euclidean distance (with normalized objective values) in the objective space is used as default
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
* @param _alpha parameter used to regulate the shape of the sharing function
*/
moeoFrontByFrontSharingDiversityAssignment(double _nicheSize = 0.5, double _alpha = 2.0) : moeoSharingDiversityAssignment < MOEOT >(_nicheSize, _alpha)
{}
/**
* @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 _objVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
}
private:
using moeoSharingDiversityAssignment < MOEOT >::distance;
using moeoSharingDiversityAssignment < MOEOT >::nicheSize;
using moeoSharingDiversityAssignment < MOEOT >::sh;
using moeoSharingDiversityAssignment < MOEOT >::operator();
/**
* Sets similarities FRONT BY FRONT for every solution contained in the population _pop
* @param _pop the population
*/
void setSimilarities(eoPop < MOEOT > & _pop)
{
// compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop);
// sets the distance to bigger than the niche size for every couple of solutions that do not belong to the same front
for (unsigned int i=0; i<_pop.size(); i++)
{
for (unsigned int j=0; j<i; j++)
{
if (_pop[i].fitness() != _pop[j].fitness())
{
dMatrix[i][j] = nicheSize;
dMatrix[j][i] = nicheSize;
}
}
}
// compute similarities
double sum;
for (unsigned int i=0; i<_pop.size(); i++)
{
sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++)
{
sum += sh(dMatrix[i][j]);
}
_pop[i].diversity(sum);
}
}
};
#endif /*MOEOFRONTBYFRONTSHARINGDIVERSITYASSIGNMENT_H_*/

View file

@ -0,0 +1,142 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoSharingDiversityAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOSHARINGDIVERSITYASSIGNMENT_H_
#define MOEOSHARINGDIVERSITYASSIGNMENT_H_
#include <eoPop.h>
#include <comparator/moeoDiversityThenFitnessComparator.h>
#include <distance/moeoDistance.h>
#include <distance/moeoDistanceMatrix.h>
#include <distance/moeoEuclideanDistance.h>
#include <diversity/moeoDiversityAssignment.h>
/**
* Sharing assignment scheme originally porposed by:
* D. E. Goldberg, "Genetic Algorithms in Search, Optimization and Machine Learning", Addision-Wesley, MA, USA (1989).
*/
template < class MOEOT >
class moeoSharingDiversityAssignment : public moeoDiversityAssignment < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor
* @param _distance the distance used to compute the neighborhood of solutions (can be related to the decision space or the objective space)
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
* @param _alpha parameter used to regulate the shape of the sharing function
*/
moeoSharingDiversityAssignment(moeoDistance<MOEOT,double> & _distance, double _nicheSize = 0.5, double _alpha = 1.0) : distance(_distance), nicheSize(_nicheSize), alpha(_alpha)
{}
/**
* Ctor with an euclidean distance (with normalized objective values) in the objective space is used as default
* @param _nicheSize neighborhood size in terms of radius distance (closely related to the way the distances are computed)
* @param _alpha parameter used to regulate the shape of the sharing function
*/
moeoSharingDiversityAssignment(double _nicheSize = 0.5, double _alpha = 1.0) : distance(defaultDistance), nicheSize(_nicheSize), alpha(_alpha)
{}
/**
* Sets diversity values for every solution contained in the population _pop
* @param _pop the population
*/
void operator()(eoPop < MOEOT > & _pop)
{
// 1 - set simuilarities
setSimilarities(_pop);
// 2 - a higher diversity is better, so the values need to be inverted
moeoDiversityThenFitnessComparator < MOEOT > divComparator;
double max = std::max_element(_pop.begin(), _pop.end(), divComparator)->diversity();
for (unsigned int i=0 ; i<_pop.size() ; i++)
{
_pop[i].diversity(max - _pop[i].diversity());
}
}
/**
* @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 _objVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
std::cout << "WARNING : updateByDeleting not implemented in moeoSharingDiversityAssignment" << std::endl;
}
protected:
/** the distance used to compute the neighborhood of solutions */
moeoDistance < MOEOT , double > & distance;
/** euclidean distancein the objective space (can be used as default) */
moeoEuclideanDistance < MOEOT > defaultDistance;
/** neighborhood size in terms of radius distance */
double nicheSize;
/** parameter used to regulate the shape of the sharing function */
double alpha;
/**
* Sets similarities for every solution contained in the population _pop
* @param _pop the population
*/
virtual void setSimilarities(eoPop < MOEOT > & _pop)
{
// compute distances between every individuals
moeoDistanceMatrix < MOEOT , double > dMatrix (_pop.size(), distance);
dMatrix(_pop);
// compute similarities
double sum;
for (unsigned int i=0; i<_pop.size(); i++)
{
sum = 0.0;
for (unsigned int j=0; j<_pop.size(); j++)
{
sum += sh(dMatrix[i][j]);
}
_pop[i].diversity(sum);
}
}
/**
* Sharing function
* @param _dist the distance value
*/
double sh(double _dist)
{
double result;
if (_dist < nicheSize)
{
result = 1.0 - pow(_dist / nicheSize, alpha);
}
else
{
result = 0.0;
}
return result;
}
};
#endif /*MOEOSHARINGDIVERSITYASSIGNMENT_H_*/

View file

@ -21,11 +21,11 @@
#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 <utils/moeoArchiveUpdater.h>
#include <utils/moeoArchiveObjectiveVectorSavingUpdater.h>
#include <utils/moeoBinaryMetricSavingUpdater.h>
bool testDirRes(std::string _dirName, bool _erase);
@ -44,16 +44,16 @@ eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState &
eoCheckPoint < MOEOT > & checkpoint = _state.storeFunctor(new eoCheckPoint < MOEOT > (_continue));
/* the objective vector type */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
///////////////////
// 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
eoValueParam<unsigned> *generationCounter = new eoValueParam<unsigned>(0, "Gen.");
eoValueParam<unsigned int> *generationCounter = new eoValueParam<unsigned int>(0, "Gen.");
// Create an incrementor (sub-class of eoUpdater).
eoIncrementor<unsigned> & increment = _state.storeFunctor( new eoIncrementor<unsigned>(generationCounter->value()) );
eoIncrementor<unsigned int> & increment = _state.storeFunctor( new eoIncrementor<unsigned int>(generationCounter->value()) );
// Add it to the checkpoint
checkpoint.add(increment);
// dir for DISK output
@ -77,13 +77,13 @@ eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState &
//////////////////////////////
// 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" );
eoValueParam<unsigned int>& saveFrequencyParam = _parser.createParam((unsigned int)(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 );
unsigned int freq = (saveFrequencyParam.value()>0 ? saveFrequencyParam.value() : UINT_MAX );
#ifdef _MSVC
std::string stmp = dirName + "\generations";
#else
@ -94,7 +94,7 @@ eoCheckPoint < MOEOT > & do_make_checkpoint_moeo (eoParser & _parser, eoState &
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" );
eoValueParam<unsigned int>& saveTimeIntervalParam = _parser.getORcreateParam((unsigned int)(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

View file

@ -54,7 +54,7 @@ eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo
eoCombinedContinue<MOEOT> *continuator = NULL;
// 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 (0 = none)",'G',"Stopping criterion");
eoValueParam<unsigned int>& maxGenParam = _parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations (0 = none)",'G',"Stopping criterion");
if (maxGenParam.value()) // positive: -> define and store
{
eoGenContinue<MOEOT> *genCont = new eoGenContinue<MOEOT>(maxGenParam.value());
@ -63,7 +63,7 @@ eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo
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");
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
if (maxEvalParam.value())
{
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
@ -72,7 +72,7 @@ eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo
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
{
eoTimeContinue<MOEOT> *timeCont = new eoTimeContinue<MOEOT>(maxTimeParam.value());

View file

@ -20,6 +20,7 @@
#include <eoGenOp.h>
#include <utils/eoParser.h>
#include <utils/eoState.h>
<<<<<<< .courant
#include <moeoArchive.h>
#include <moeoComparator.h>
#include <moeoCrowdingDistanceDiversityAssignment.h>
@ -37,7 +38,37 @@
#include <moeoReplacement.h>
#include <moeoSelectOne.h>
#include <moeoStochTournamentSelect.h>
=======
#include <algo/moeoEA.h>
#include <algo/moeoEasyEA.h>
#include <archive/moeoArchive.h>
#include <comparator/moeoAggregativeComparator.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoDiversityThenFitnessComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <diversity/moeoDiversityAssignment.h>
#include <diversity/moeoDummyDiversityAssignment.h>
#include <diversity/moeoFrontByFrontCrowdingDistanceDiversityAssignment.h>
#include <diversity/moeoFrontByFrontSharingDiversityAssignment.h>
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
#include <fitness/moeoDummyFitnessAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
#include <metric/moeoAdditiveEpsilonBinaryMetric.h>
#include <metric/moeoHypervolumeBinaryMetric.h>
>>>>>>> .fusion-droit.r399
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
#include <replacement/moeoElitistReplacement.h>
#include <replacement/moeoEnvironmentalReplacement.h>
#include <replacement/moeoGenerationalReplacement.h>
#include <replacement/moeoReplacement.h>
#include <selection/moeoDetTournamentSelect.h>
#include <selection/moeoRandomSelect.h>
#include <selection/moeoStochTournamentSelect.h>
#include <selection/moeoSelectOne.h>
#include <selection/moeoSelectors.h>
/**
* This functions allows to build a moeoEA from the parser
@ -57,10 +88,10 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF
/* the fitness assignment strategy */
string & fitnessParam = _parser.createParam(string("FastNonDominatedSorting"), "fitness",
std::string & fitnessParam = _parser.createParam(std::string("FastNonDominatedSorting"), "fitness",
"Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased", 'F',
"Evolution Engine").value();
string & indicatorParam = _parser.createParam(string("Epsilon"), "indicator",
std::string & indicatorParam = _parser.createParam(std::string("Epsilon"), "indicator",
"Binary indicator for IndicatorBased: Epsilon, Hypervolume", 'i',
"Evolution Engine").value();
double rho = _parser.createParam(1.1, "rho", "reference point for the hypervolume indicator", 'r',
@ -68,76 +99,96 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF
double kappa = _parser.createParam(0.05, "kappa", "Scaling factor kappa for IndicatorBased", 'k',
"Evolution Engine").value();
moeoFitnessAssignment < MOEOT > * fitnessAssignment;
if (fitnessParam == string("Dummy"))
if (fitnessParam == std::string("Dummy"))
{
fitnessAssignment = new moeoDummyFitnessAssignment < MOEOT> ();
}
else if (fitnessParam == string("FastNonDominatedSorting"))
else if (fitnessParam == std::string("FastNonDominatedSorting"))
{
fitnessAssignment = new moeoFastNonDominatedSortingFitnessAssignment < MOEOT> ();
}
else if (fitnessParam == string("IndicatorBased"))
else if (fitnessParam == std::string("IndicatorBased"))
{
// metric
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > *metric;
if (indicatorParam == string("Epsilon"))
if (indicatorParam == std::string("Epsilon"))
{
metric = new moeoAdditiveEpsilonBinaryMetric < ObjectiveVector >;
}
else if (indicatorParam == string("Hypervolume"))
else if (indicatorParam == std::string("Hypervolume"))
{
metric = new moeoHypervolumeBinaryMetric < ObjectiveVector > (rho);
}
else
{
string stmp = string("Invalid binary quality indicator: ") + indicatorParam;
std::string stmp = std::string("Invalid binary quality indicator: ") + indicatorParam;
throw std::runtime_error(stmp.c_str());
}
fitnessAssignment = new moeoIndicatorBasedFitnessAssignment < MOEOT> (metric, kappa);
fitnessAssignment = new moeoIndicatorBasedFitnessAssignment < MOEOT > (*metric, kappa);
}
else
{
string stmp = string("Invalid fitness assignment strategy: ") + fitnessParam;
std::string stmp = std::string("Invalid fitness assignment strategy: ") + fitnessParam;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(fitnessAssignment);
/* the diversity assignment strategy */
string & diversityParam = _parser.createParam(string("Dummy"), "diversity",
"Diversity assignment scheme: Dummy or CrowdingDistance", 'D', "Evolution Engine").value();
eoValueParam<eoParamParamType> & diversityParam = _parser.createParam(eoParamParamType("Dummy"), "diversity",
"Diversity assignment scheme: Dummy, Sharing(nicheSize) or Crowding", 'D', "Evolution Engine");
eoParamParamType & diversityParamValue = diversityParam.value();
moeoDiversityAssignment < MOEOT > * diversityAssignment;
if (diversityParam == string("CrowdingDistance"))
{
diversityAssignment = new moeoCrowdingDistanceDiversityAssignment < MOEOT> ();
}
else if (diversityParam == string("Dummy"))
if (diversityParamValue.first == std::string("Dummy"))
{
diversityAssignment = new moeoDummyDiversityAssignment < MOEOT> ();
}
else if (diversityParamValue.first == std::string("Sharing"))
{
double nicheSize;
if (!diversityParamValue.second.size()) // no parameter added
{
std::cerr << "WARNING, no niche size given for Sharing, using 0.5" << std::endl;
nicheSize = 0.5;
diversityParamValue.second.push_back(std::string("0.5"));
}
else
{
nicheSize = atoi(diversityParamValue.second[0].c_str());
}
diversityAssignment = new moeoFrontByFrontSharingDiversityAssignment < MOEOT> (nicheSize);
}
else if (diversityParamValue.first == std::string("Crowding"))
{
diversityAssignment = new moeoFrontByFrontCrowdingDistanceDiversityAssignment < MOEOT> ();
}
else
{
string stmp = string("Invalid diversity assignment strategy: ") + diversityParam;
std::string stmp = std::string("Invalid diversity assignment strategy: ") + diversityParamValue.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(diversityAssignment);
/* the comparator strategy */
string & comparatorParam = _parser.createParam(string("FitnessThenDiversity"), "comparator",
"Comparator scheme: FitnessThenDiversity or DiversityThenFitness", 'C', "Evolution Engine").value();
std::string & comparatorParam = _parser.createParam(std::string("FitnessThenDiversity"), "comparator",
"Comparator scheme: FitnessThenDiversity, DiversityThenFitness or Aggregative", 'C', "Evolution Engine").value();
moeoComparator < MOEOT > * comparator;
if (comparatorParam == string("FitnessThenDiversity"))
if (comparatorParam == std::string("FitnessThenDiversity"))
{
comparator = new moeoFitnessThenDiversityComparator < MOEOT> ();
}
else if (comparatorParam == string("DiversityThenFitness"))
else if (comparatorParam == std::string("DiversityThenFitness"))
{
comparator = new moeoDiversityThenFitnessComparator < MOEOT> ();
}
else if (comparatorParam == std::string("Aggregative"))
{
comparator = new moeoAggregativeComparator < MOEOT> ();
}
else
{
string stmp = string("Invalid comparator strategy: ") + comparatorParam;
std::string stmp = std::string("Invalid comparator strategy: ") + comparatorParam;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(comparator);
@ -148,15 +199,15 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF
"Selection scheme: DetTour(T), StochTour(t) or Random", 'S', "Evolution Engine");
eoParamParamType & ppSelect = selectionParam.value();
moeoSelectOne < MOEOT > * select;
if (ppSelect.first == string("DetTour"))
if (ppSelect.first == std::string("DetTour"))
{
unsigned tSize;
unsigned int tSize;
if (!ppSelect.second.size()) // no parameter added
{
cerr << "WARNING, no parameter passed to DetTour, using 2" << endl;
std::cerr << "WARNING, no parameter passed to DetTour, using 2" << std::endl;
tSize = 2;
// put back 2 in parameter for consistency (and status file)
ppSelect.second.push_back(string("2"));
ppSelect.second.push_back(std::string("2"));
}
else // parameter passed by user as DetTour(T)
{
@ -164,15 +215,15 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF
}
select = new moeoDetTournamentSelect < MOEOT > (*comparator, tSize);
}
else if (ppSelect.first == string("StochTour"))
else if (ppSelect.first == std::string("StochTour"))
{
double tRate;
if (!ppSelect.second.size()) // no parameter added
{
cerr << "WARNING, no parameter passed to StochTour, using 1" << endl;
std::cerr << "WARNING, no parameter passed to StochTour, using 1" << std::endl;
tRate = 1;
// put back 1 in parameter for consistency (and status file)
ppSelect.second.push_back(string("1"));
ppSelect.second.push_back(std::string("1"));
}
else // parameter passed by user as StochTour(T)
{
@ -180,42 +231,44 @@ moeoEA < MOEOT > & do_make_ea_moeo(eoParser & _parser, eoState & _state, eoEvalF
}
select = new moeoStochTournamentSelect < MOEOT > (*comparator, tRate);
}
/*
else if (ppSelect.first == string("Roulette"))
{
// TO DO !
// ...
}
else if (ppSelect.first == string("Random"))
*/
else if (ppSelect.first == std::string("Random"))
{
select = new moeoRandomSelect <MOEOT > ();
}
else
{
string stmp = string("Invalid selection strategy: ") + ppSelect.first;
std::string stmp = std::string("Invalid selection strategy: ") + ppSelect.first;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(select);
/* the replacement strategy */
string & replacementParam = _parser.createParam(string("Elitist"), "replacement",
std::string & replacementParam = _parser.createParam(std::string("Elitist"), "replacement",
"Replacement scheme: Elitist, Environmental or Generational", 'R', "Evolution Engine").value();
moeoReplacement < MOEOT > * replace;
if (replacementParam == string("Elitist"))
if (replacementParam == std::string("Elitist"))
{
replace = new moeoElitistReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
}
else if (replacementParam == string("Environmental"))
else if (replacementParam == std::string("Environmental"))
{
replace = new moeoEnvironmentalReplacement < MOEOT> (*fitnessAssignment, *diversityAssignment, *comparator);
}
else if (replacementParam == string("Generational"))
else if (replacementParam == std::string("Generational"))
{
replace = new moeoGenerationalReplacement < MOEOT> ();
}
else
{
string stmp = string("Invalid replacement strategy: ") + replacementParam;
std::string stmp = std::string("Invalid replacement strategy: ") + replacementParam;
throw std::runtime_error(stmp.c_str());
}
_state.storeFunctor(replace);

View file

@ -0,0 +1,145 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoAchievementFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOACHIEVEMENTFITNESSASSIGNMENT_H_
#define MOEOACHIEVEMENTFITNESSASSIGNMENT_H_
#include <vector>
#include <eoPop.h>
#include <fitness/moeoScalarFitnessAssignment.h>
/**
* Fitness assignment sheme based on the achievement scalarizing function propozed by Wiersbicki (1980).
*/
template < class MOEOT >
class moeoAchievementFitnessAssignment : public moeoScalarFitnessAssignment < MOEOT >
{
public:
/** the objective vector type of the solutions */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Default ctor
* @param _reference reference point vector
* @param _lambdas weighted coefficients vector
* @param _spn arbitrary small positive number (0 < _spn << 1)
*/
moeoAchievementFitnessAssignment(ObjectiveVector & _reference, std::vector < double > & _lambdas, double _spn=0.0001) : reference(_reference), lambdas(_lambdas), spn(_spn)
{
// consistency check
if ((spn < 0.0) || (spn > 1.0))
{
std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
spn = 0.0001;
}
}
/**
* Ctor with default values for lambdas (1/nObjectives)
* @param _reference reference point vector
* @param _spn arbitrary small positive number (0 < _spn << 1)
*/
moeoAchievementFitnessAssignment(ObjectiveVector & _reference, double _spn=0.0001) : reference(_reference), spn(_spn)
{
// compute the default values for lambdas
lambdas = std::vector < double > (ObjectiveVector::nObjectives());
for (unsigned int i=0 ; i<lambdas.size(); i++)
{
lambdas[i] = 1.0 / ObjectiveVector::nObjectives();
}
// consistency check
if ((spn < 0.0) || (spn > 1.0))
{
std::cout << "Warning, the arbitrary small positive number should be > 0 and <<1, adjusted to 0.0001\n";
spn = 0.0001;
}
}
/**
* Sets the fitness values for every solution contained in the population _pop
* @param _pop the population
*/
virtual void operator()(eoPop < MOEOT > & _pop)
{
for (unsigned int i=0; i<_pop.size() ; i++)
{
compute(_pop[i]);
}
}
/**
* Updates the fitness values of the whole population _pop by taking the deletion of the objective vector _objVec into account (nothing to do).
* @param _pop the population
* @param _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do ;-)
}
/**
* Sets the reference point
* @param _reference the new reference point
*/
void setReference(const ObjectiveVector & _reference)
{
reference = _reference;
}
private:
/** the reference point */
ObjectiveVector reference;
/** the weighted coefficients vector */
std::vector < double > lambdas;
/** an arbitrary small positive number (0 < _spn << 1) */
double spn;
/**
* Returns a big value (regarded as infinite)
*/
double inf() const
{
return std::numeric_limits<double>::max();
}
/**
* Computes the fitness value for a solution
* @param _moeo the solution
*/
void compute(MOEOT & _moeo)
{
unsigned int nobj = MOEOT::ObjectiveVector::nObjectives();
double temp;
double min = inf();
double sum = 0;
for (unsigned int obj=0; obj<nobj; obj++)
{
temp = lambdas[obj] * (reference[obj] - _moeo.objectiveVector()[obj]);
min = std::min(min, temp);
sum += temp;
}
_moeo.fitness(min + spn*sum);
}
};
#endif /*MOEOACHIEVEMENTFITNESSASSIGNMENT_H_*/

View file

@ -0,0 +1,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoCriterionBasedFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_
#define MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_
#include <fitness/moeoFitnessAssignment.h>
/**
* moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies.
*/
template < class MOEOT >
class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
#endif /*MOEOCRITERIONBASEDFITNESSASSIGNMENT_H_*/

View file

@ -0,0 +1,59 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoDummyFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEODUMMYFITNESSASSIGNMENT_H_
#define MOEODUMMYFITNESSASSIGNMENT_H_
#include <fitness/moeoFitnessAssignment.h>
/**
* 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 int 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 _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
};
#endif /*MOEODUMMYFITNESSASSIGNMENT_H_*/

View file

@ -13,10 +13,13 @@
#ifndef MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_
#define MOEOFASTNONDOMINATEDSORTINGFITNESSASSIGNMENT_H_
#include <vector>
#include <eoPop.h>
#include <moeoComparator.h>
#include <moeoFitnessAssignment.h>
#include <moeoObjectiveVectorComparator.h>
#include <comparator/moeoObjectiveObjectiveVectorComparator.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <fitness/moeoParetoBasedFitnessAssignment.h>
/**
* Fitness assignment sheme based on Pareto-dominance count proposed in:
@ -56,7 +59,7 @@ public:
void operator()(eoPop < MOEOT > & _pop)
{
// number of objectives for the problem under consideration
unsigned nObjectives = MOEOT::ObjectiveVector::nObjectives();
unsigned int nObjectives = MOEOT::ObjectiveVector::nObjectives();
if (nObjectives == 1)
{
// one objective
@ -79,11 +82,11 @@ public:
}
// a higher fitness is better, so the values need to be inverted
double max = _pop[0].fitness();
for (unsigned i=1 ; i<_pop.size() ; i++)
for (unsigned int i=1 ; i<_pop.size() ; i++)
{
max = std::max(max, _pop[i].fitness());
}
for (unsigned i=0 ; i<_pop.size() ; i++)
for (unsigned int i=0 ; i<_pop.size() ; i++)
{
_pop[i].fitness(max - _pop[i].fitness());
}
@ -91,15 +94,20 @@ public:
/**
* @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 _objVec the objective vector
* @warning NOT IMPLEMENTED, DO NOTHING !
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
cout << "WARNING : updateByDeleting not implemented in moeoNonDominatedSortingFitnessAssignment" << endl;
for (unsigned int i=0; i<_pop.size(); i++)
{
// if _pop[i] is dominated by _objVec
if ( comparator(_pop[i].objectiveVector(), _objVec) )
{
_pop[i].fitness(_pop[i].fitness()+1);
}
}
}
@ -109,8 +117,23 @@ private:
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** Functor allowing to compare two solutions according to their first objective value, then their second, and so on. */
class ObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 < _moeo2 on the first objective, then on the second, and so on
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return cmp(_moeo1.objectiveVector(), _moeo2.objectiveVector());
}
private:
/** the corresponding comparator for objective vectors */
moeoObjectiveObjectiveVectorComparator < ObjectiveVector > cmp;
} objComparator;
/**
@ -119,12 +142,18 @@ private:
*/
void oneObjective (eoPop < MOEOT > & _pop)
{
// Functor to compare two solutions on the first objective, then on the second, and so on
moeoObjectiveComparator < MOEOT > objComparator;
// sorts the population in the ascending order
std::sort(_pop.begin(), _pop.end(), objComparator);
for (unsigned i=0; i<_pop.size(); i++)
// assign fitness values
unsigned int rank = 1;
_pop[_pop.size()-1].fitness(rank);
for (unsigned int i=_pop.size()-2; i>=0; i--)
{
_pop[i].fitness(i+1);
if (_pop[i].objectiveVector() != _pop[i+1].objectiveVector())
{
rank++;
}
_pop[i].fitness(rank);
}
}
@ -146,25 +175,25 @@ private:
void mObjectives (eoPop < MOEOT > & _pop)
{
// S[i] = indexes of the individuals dominated by _pop[i]
std::vector < std::vector<unsigned> > S(_pop.size());
std::vector < std::vector<unsigned int> > S(_pop.size());
// n[i] = number of individuals that dominate the individual _pop[i]
std::vector < unsigned > n(_pop.size(), 0);
std::vector < unsigned int > n(_pop.size(), 0);
// fronts: F[i] = indexes of the individuals contained in the ith front
std::vector < std::vector<unsigned> > F(_pop.size()+1);
std::vector < std::vector<unsigned int> > F(_pop.size()+2);
// used to store the number of the first front
F[1].reserve(_pop.size());
for (unsigned p=0; p<_pop.size(); p++)
for (unsigned int p=0; p<_pop.size(); p++)
{
for (unsigned q=0; q<_pop.size(); q++)
for (unsigned int q=0; q<_pop.size(); q++)
{
// if p dominates q
if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) )
// if q is dominated by p
if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) )
{
// add q to the set of solutions dominated by p
S[p].push_back(q);
}
// if q dominates p
else if ( comparator(_pop[q].objectiveVector(), _pop[p].objectiveVector()) )
// if p is dominated by q
else if ( comparator(_pop[p].objectiveVector(), _pop[q].objectiveVector()) )
{
// increment the domination counter of p
n[p]++;
@ -179,16 +208,16 @@ private:
}
}
// front counter
unsigned counter=1;
unsigned p,q;
unsigned int counter=1;
unsigned int p,q;
while (! F[counter].empty())
{
// used to store the number of the next front
F[counter+1].reserve(_pop.size());
for (unsigned i=0; i<F[counter].size(); i++)
for (unsigned int i=0; i<F[counter].size(); i++)
{
p = F[counter][i];
for (unsigned j=0; j<S[p].size(); j++)
for (unsigned int j=0; j<S[p].size(); j++)
{
q = S[p][j];
n[q]--;

View file

@ -0,0 +1,51 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOFITNESSASSIGNMENT_H_
#define MOEOFITNESSASSIGNMENT_H_
#include <eoFunctor.h>
#include <eoPop.h>
/**
* Functor that sets the fitness values of a whole population.
*/
template < class MOEOT >
class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void >
{
public:
/** 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 _objVec 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());
}
};
#endif /*MOEOFITNESSASSIGNMENT_H_*/

View file

@ -14,10 +14,11 @@
#define MOEOINDICATORBASEDFITNESSASSIGNMENT_H_
#include <math.h>
#include <vector>
#include <eoPop.h>
#include <moeoConvertPopToObjectiveVectors.h>
#include <moeoFitnessAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
#include <utils/moeoConvertPopToObjectiveVectors.h>
/**
* Fitness assignment sheme based an Indicator proposed in:
@ -25,7 +26,7 @@
* This strategy is, for instance, used in IBEA.
*/
template < class MOEOT >
class moeoIndicatorBasedFitnessAssignment : public moeoParetoBasedFitnessAssignment < MOEOT >
class moeoIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{
public:
@ -38,7 +39,7 @@ public:
* @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 = 0.05) : metric(_metric), kappa(_kappa)
{}
@ -64,13 +65,13 @@ public:
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
vector < double > v;
std::vector < double > v;
v.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
v[i] = (*metric)(_objVec, _pop[i].objectiveVector());
v[i] = metric(_objVec, _pop[i].objectiveVector());
}
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].fitness( _pop[i].fitness() + exp(-v[i]/kappa) );
}
@ -85,26 +86,26 @@ public:
*/
double updateByAdding(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
vector < double > v;
std::vector < double > v;
// update every fitness values to take the new individual into account
v.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
v[i] = (*metric)(_objVec, _pop[i].objectiveVector());
v[i] = metric(_objVec, _pop[i].objectiveVector());
}
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int 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++)
for (unsigned int i=0; i<_pop.size(); i++)
{
v[i] = (*metric)(_pop[i].objectiveVector(), _objVec);
v[i] = metric(_pop[i].objectiveVector(), _objVec);
}
double result = 0;
for (unsigned i=0; i<v.size(); i++)
for (unsigned int i=0; i<v.size(); i++)
{
result -= exp(-v[i]/kappa);
}
@ -115,7 +116,7 @@ public:
protected:
/** the quality indicator */
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > * metric;
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & metric;
/** the scaling factor */
double kappa;
/** the computed indicator values */
@ -129,17 +130,17 @@ protected:
void setup(const eoPop < MOEOT > & _pop)
{
double min, max;
for (unsigned i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
min = _pop[0].objectiveVector()[i];
max = _pop[0].objectiveVector()[i];
for (unsigned j=1; j<_pop.size(); j++)
for (unsigned int j=1; j<_pop.size(); j++)
{
min = std::min(min, _pop[j].objectiveVector()[i]);
max = std::max(max, _pop[j].objectiveVector()[i]);
}
// setting of the bounds for the objective i
(*metric).setup(min, max, i);
metric.setup(min, max, i);
}
}
@ -152,14 +153,14 @@ protected:
{
values.clear();
values.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
values[i].resize(_pop.size());
for (unsigned j=0; j<_pop.size(); j++)
for (unsigned int j=0; j<_pop.size(); j++)
{
if (i != j)
{
values[i][j] = (*metric)(_pop[i].objectiveVector(), _pop[j].objectiveVector());
values[i][j] = metric(_pop[i].objectiveVector(), _pop[j].objectiveVector());
}
}
}
@ -172,7 +173,7 @@ protected:
*/
void setFitnesses(eoPop < MOEOT > & _pop)
{
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].fitness(computeFitness(i));
}
@ -183,10 +184,10 @@ 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 int _idx)
{
double result = 0;
for (unsigned i=0; i<values.size(); i++)
for (unsigned int i=0; i<values.size(); i++)
{
if (i != _idx)
{

View file

@ -0,0 +1,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoParetoBasedFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOPARETOBASEDFITNESSASSIGNMENT_H_
#define MOEOPARETOBASEDFITNESSASSIGNMENT_H_
#include <fitness/moeoFitnessAssignment.h>
/**
* moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies.
*/
template < class MOEOT >
class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
#endif /*MOEOPARETOBASEDFITNESSASSIGNMENT_H_*/

View file

@ -0,0 +1,109 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoReferencePointIndicatorBasedFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOREFERENCEPOINTINDICATORBASEDFITNESSASSIGNMENT_H_
#define MOEOREFERENCEPOINTINDICATORBASEDFITNESSASSIGNMENT_H_
#include <math.h>
#include <eoPop.h>
#include <fitness/moeoFitnessAssignment.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
/**
* Fitness assignment sheme based a Reference Point and a Quality Indicator.
*/
template < class MOEOT >
class moeoReferencePointIndicatorBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{
public:
/** The type of objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor
* @param _refPoint the reference point
* @param _metric the quality indicator
*/
moeoReferencePointIndicatorBasedFitnessAssignment (ObjectiveVector & _refPoint, moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & _metric) :
refPoint(_refPoint), metric(_metric)
{}
/**
* Sets the fitness values for every solution contained in the population _pop
* @param _pop the population
*/
void operator()(eoPop < MOEOT > & _pop)
{
// 1 - setting of the bounds
setup(_pop);
// 2 - setting fitnesses
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 _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do ;-)
}
protected:
/** the reference point */
ObjectiveVector & refPoint;
/** the quality indicator */
moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > & metric;
/**
* Sets the bounds for every objective using the min and the max value for every objective vector of _pop (and the reference point)
* @param _pop the population
*/
void setup(const eoPop < MOEOT > & _pop)
{
double min, max;
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
min = refPoint[i];
max = refPoint[i];
for (unsigned int j=0; j<_pop.size(); j++)
{
min = std::min(min, _pop[j].objectiveVector()[i]);
max = std::max(max, _pop[j].objectiveVector()[i]);
}
// setting of the bounds for the objective i
metric.setup(min, max, i);
}
}
/**
* Sets the fitness of every individual contained in the population _pop
* @param _pop the population
*/
void setFitnesses(eoPop < MOEOT > & _pop)
{
for (unsigned int i=0; i<_pop.size(); i++)
{
_pop[i].fitness(- metric(_pop[i].objectiveVector(), refPoint) );
}
}
};
#endif /*MOEOREFERENCEPOINTINDICATORBASEDFITNESSASSIGNMENT_H_*/

View file

@ -0,0 +1,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoScalarFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOSCALARFITNESSASSIGNMENT_H_
#define MOEOSCALARFITNESSASSIGNMENT_H_
#include <fitness/moeoFitnessAssignment.h>
/**
* moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies.
*/
template < class MOEOT >
class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT > {};
#endif /*MOEOSCALARFITNESSASSIGNMENT_H_*/

View file

@ -0,0 +1,84 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoAdditiveEpsilonBinaryMetric.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOADDITIVEEPSILONBINARYMETRIC_H_
#define MOEOADDITIVEEPSILONBINARYMETRIC_H_
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
/**
* Additive epsilon binary metric allowing to compare two objective vectors as proposed in
* Zitzler E., Thiele L., Laumanns M., Fonseca C. M., Grunert da Fonseca V.:
* Performance Assessment of Multiobjective Optimizers: An Analysis and Review. IEEE Transactions on Evolutionary Computation 7(2), pp.117132 (2003).
*/
template < class ObjectiveVector >
class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
{
public:
/**
* Returns the minimal distance by which the objective vector _o1 must be translated in all objectives
* so that it weakly dominates the objective vector _o2
* @warning don't forget to set the bounds for every objective before the call of this function
* @param _o1 the first objective vector
* @param _o2 the second objective vector
*/
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{
// computation of the epsilon value for the first objective
double result = epsilon(_o1, _o2, 0);
// computation of the epsilon value for the other objectives
double tmp;
for (unsigned int i=1; i<ObjectiveVector::Traits::nObjectives(); i++)
{
tmp = epsilon(_o1, _o2, i);
result = std::max(result, tmp);
}
// returns the maximum epsilon value
return result;
}
private:
/** the bounds for every objective */
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
/**
* Returns the epsilon value by which the objective vector _o1 must be translated in the objective _obj
* so that it dominates the objective vector _o2
* @param _o1 the first objective vector
* @param _o2 the second objective vector
* @param _obj the index of the objective
*/
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj)
{
double result;
// if the objective _obj have to be minimized
if (ObjectiveVector::Traits::minimizing(_obj))
{
// _o1[_obj] - _o2[_obj]
result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
}
// if the objective _obj have to be maximized
else
{
// _o2[_obj] - _o1[_obj]
result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
}
return result;
}
};
#endif /*MOEOADDITIVEEPSILONBINARYMETRIC_H_*/

View file

@ -13,6 +13,7 @@
#ifndef MOEOCONTRIBUTIONMETRIC_H_
#define MOEOCONTRIBUTIONMETRIC_H_
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <metric/moeoMetric.h>
/**
@ -30,26 +31,30 @@ public:
* @param _set2 the second Pareto set
*/
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned c = card_C(_set1, _set2);
unsigned w1 = card_W(_set1, _set2);
unsigned n1 = card_N(_set1, _set2);
unsigned w2 = card_W(_set2, _set1);
unsigned n2 = card_N(_set2, _set1);
unsigned int c = card_C(_set1, _set2);
unsigned int w1 = card_W(_set1, _set2);
unsigned int n1 = card_N(_set1, _set2);
unsigned int w2 = card_W(_set2, _set1);
unsigned int n2 = card_N(_set2, _set1);
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
}
private:
/** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
* Returns the number of solutions both in '_set1' and '_set2'
* @param _set1 the first Pareto set
* @param _set2 the second Pareto set
*/
unsigned card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned c=0;
for (unsigned i=0; i<_set1.size(); i++)
for (unsigned j=0; j<_set2.size(); j++)
unsigned int card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned int c=0;
for (unsigned int i=0; i<_set1.size(); i++)
for (unsigned int j=0; j<_set2.size(); j++)
if (_set1[i] == _set2[j]) {
c++;
break;
@ -57,33 +62,37 @@ private:
return c;
}
/**
* Returns the number of solutions in '_set1' dominating at least one solution of '_set2'
* @param _set1 the first Pareto set
* @param _set2 the second Pareto set
*/
unsigned card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned w=0;
for (unsigned i=0; i<_set1.size(); i++)
for (unsigned j=0; j<_set2.size(); j++)
if (_set1[i].dominates(_set2[j])) {
unsigned int card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned int w=0;
for (unsigned int i=0; i<_set1.size(); i++)
for (unsigned int j=0; j<_set2.size(); j++)
if (paretoComparator(_set2[j], _set1[i]))
{
w++;
break;
}
return w;
}
/**
* Returns the number of solutions in '_set1' having no relation of dominance with those from '_set2'
* @param _set1 the first Pareto set
* @param _set2 the second Pareto set
*/
unsigned card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned n=0;
for (unsigned i=0; i<_set1.size(); i++) {
unsigned int card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
unsigned int n=0;
for (unsigned int i=0; i<_set1.size(); i++) {
bool domin_rel = false;
for (unsigned j=0; j<_set2.size(); j++)
if (_set1[i].dominates(_set2[j]) || _set2[j].dominates(_set1 [i])) {
for (unsigned int j=0; j<_set2.size(); j++)
if ( (paretoComparator(_set2[j], _set1[i])) || (paretoComparator(_set1[i], _set2[j])) )
{
domin_rel = true;
break;
}

View file

@ -13,6 +13,8 @@
#ifndef MOEOENTROPYMETRIC_H_
#define MOEOENTROPYMETRIC_H_
#include <vector>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <metric/moeoMetric.h>
/**
@ -48,13 +50,13 @@ public:
std::vector< ObjectiveVector > union_set1_star; // rotf again ...
computeUnion (set1, star, union_set1_star);
unsigned C = union_set1_star.size();
unsigned int C = union_set1_star.size();
float omega=0;
float entropy=0;
for (unsigned i=0 ; i<C ; i++) {
unsigned N_i = howManyInNicheOf (union_set1_star, union_set1_star[i], star.size());
unsigned n_i = howManyInNicheOf (set1, union_set1_star[i], star.size());
for (unsigned int i=0 ; i<C ; i++) {
unsigned int N_i = howManyInNicheOf (union_set1_star, union_set1_star[i], star.size());
unsigned int n_i = howManyInNicheOf (set1, union_set1_star[i], star.size());
if (n_i > 0) {
omega += 1.0 / N_i;
entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0));
@ -72,6 +74,8 @@ private:
std::vector<double> vect_min_val;
/** vector of max values */
std::vector<double> vect_max_val;
/** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
@ -79,10 +83,11 @@ private:
* @param _f a Pareto set
*/
void removeDominated(std::vector < ObjectiveVector > & _f) {
for (unsigned i=0 ; i<_f.size(); i++) {
for (unsigned int i=0 ; i<_f.size(); i++) {
bool dom = false;
for (unsigned j=0; j<_f.size(); j++)
if (i != j && _f[j].dominates(_f[i])) {
for (unsigned int j=0; j<_f.size(); j++)
if (i != j && paretoComparator(_f[i],_f[j]))
{
dom = true;
break;
}
@ -103,9 +108,9 @@ private:
vect_min_val.clear();
vect_max_val.clear();
for (unsigned char i=0 ; i<ObjectiveVector::nObjectives(); i++) {
for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); i++) {
float min_val = _f.front()[i], max_val = min_val;
for (unsigned j=1 ; j<_f.size(); j++) {
for (unsigned int j=1 ; j<_f.size(); j++) {
if (_f[j][i] < min_val)
min_val = _f[j][i];
if (_f[j][i]>max_val)
@ -122,8 +127,8 @@ private:
* @param _f a Pareto set
*/
void normalize (std::vector< ObjectiveVector > & _f) {
for (unsigned i=0 ; i<ObjectiveVector::nObjectives(); i++)
for (unsigned j=0; j<_f.size(); j++)
for (unsigned int i=0 ; i<ObjectiveVector::nObjectives(); i++)
for (unsigned int j=0; j<_f.size(); j++)
_f[j][i] = (_f[j][i] - vect_min_val[i]) / (vect_max_val[i] - vect_min_val[i]);
}
@ -136,9 +141,9 @@ private:
*/
void computeUnion(const std::vector< ObjectiveVector > & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f) {
_f = _f1 ;
for (unsigned i=0; i<_f2.size(); i++) {
for (unsigned int i=0; i<_f2.size(); i++) {
bool b = false;
for (unsigned j=0; j<_f1.size(); j ++)
for (unsigned int j=0; j<_f1.size(); j ++)
if (_f1[j] == _f2[i]) {
b = true;
break;
@ -152,9 +157,9 @@ private:
/**
* How many in niche
*/
unsigned howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned _size) {
unsigned n=0;
for (unsigned i=0 ; i<_f.size(); i++) {
unsigned int howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned int _size) {
unsigned int n=0;
for (unsigned int i=0 ; i<_f.size(); i++) {
if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size))
n++;
}
@ -165,9 +170,9 @@ private:
/**
* Euclidian distance
*/
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned _deg = 2) {
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned int _deg = 2) {
double dist=0;
for (unsigned i=0; i<_set1.size(); i++)
for (unsigned int i=0; i<_set1.size(); i++)
dist += pow(fabs(_set1[i] - _to[i]), (int)_deg);
return pow(dist, 1.0 / _deg);
}

View file

@ -0,0 +1,141 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoHypervolumeBinaryMetric.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOHYPERVOLUMEBINARYMETRIC_H_
#define MOEOHYPERVOLUMEBINARYMETRIC_H_
#include <stdexcept>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
/**
* Hypervolume binary metric allowing to compare two objective vectors as proposed in
* Zitzler E., Künzli S.: Indicator-Based Selection in Multiobjective Search. In Parallel Problem Solving from Nature (PPSN VIII).
* Lecture Notes in Computer Science 3242, Springer, Birmingham, UK pp.832842 (2004).
* This indicator is based on the hypervolume concept introduced in
* Zitzler, E., Thiele, L.: Multiobjective Optimization Using Evolutionary Algorithms - A Comparative Case Study.
* Parallel Problem Solving from Nature (PPSN-V), pp.292-301 (1998).
*/
template < class ObjectiveVector >
class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
{
public:
/**
* Ctor
* @param _rho value used to compute the reference point from the worst values for each objective (default : 1.1)
*/
moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho)
{
// not-a-maximization problem check
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
if (ObjectiveVector::Traits::maximizing(i))
{
throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric");
}
}
// consistency check
if (rho < 1)
{
std::cout << "Warning, value used to compute the reference point rho for the hypervolume calculation must not be smaller than 1" << std::endl;
std::cout << "Adjusted to 1" << std::endl;
rho = 1;
}
}
/**
* Returns the volume of the space that is dominated by _o2 but not by _o1 with respect to a reference point computed using rho.
* @warning don't forget to set the bounds for every objective before the call of this function
* @param _o1 the first objective vector
* @param _o2 the second objective vector
*/
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{
double result;
// if _o2 is dominated by _o1
if ( paretoComparator(_o2,_o1) )
{
result = - hypervolume(_o1, _o2, ObjectiveVector::Traits::nObjectives()-1);
}
else
{
result = hypervolume(_o2, _o1, ObjectiveVector::Traits::nObjectives()-1);
}
return result;
}
private:
/** value used to compute the reference point from the worst values for each objective */
double rho;
/** the bounds for every objective */
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
/** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
* Returns the volume of the space that is dominated by _o2 but not by _o1 with respect to a reference point computed using rho for the objective _obj.
* @param _o1 the first objective vector
* @param _o2 the second objective vector
* @param _obj the objective index
* @param _flag used for iteration, if _flag=true _o2 is not talen into account (default : false)
*/
double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned int _obj, const bool _flag = false)
{
double result;
double range = rho * bounds[_obj].range();
double max = bounds[_obj].minimum() + range;
// value of _1 for the objective _obj
double v1 = _o1[_obj];
// value of _2 for the objective _obj (if _flag=true, v2=max)
double v2;
if (_flag)
{
v2 = max;
}
else
{
v2 = _o2[_obj];
}
// computation of the volume
if (_obj == 0)
{
if (v1 < v2)
{
result = (v2 - v1) / range;
}
else
{
result = 0;
}
}
else
{
if (v1 < v2)
{
result = ( hypervolume(_o1, _o2, _obj-1, true) * (v2 - v1) / range ) + ( hypervolume(_o1, _o2, _obj-1) * (max - v2) / range );
}
else
{
result = hypervolume(_o1, _o2, _obj-1) * (max - v2) / range;
}
}
return result;
}
};
#endif /*MOEOHYPERVOLUMEBINARYMETRIC_H_*/

View file

@ -13,61 +13,55 @@
#ifndef MOEOMETRIC_H_
#define MOEOMETRIC_H_
#include <vector>
#include <eoFunctor.h>
/**
* Base class for performance metrics (also known as quality indicators).
*/
class moeoMetric : public eoFunctorBase
{};
class moeoMetric : public eoFunctorBase {};
/**
* Base class for unary metrics.
*/
template < class A, class R >
class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric
{};
class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric {};
/**
* Base class for binary metrics.
*/
template < class A1, class A2, class R >
class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric
{};
class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric {};
/**
* Base class for unary metrics dedicated to the performance evaluation of a single solution's objective vector.
*/
template < class ObjectiveVector, class R >
class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R >
{};
class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R > {};
/**
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of objective vectors)
*/
template < class ObjectiveVector, class R >
class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R >
{};
class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R > {};
/**
* Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors.
*/
template < class ObjectiveVector, class R >
class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R >
{};
class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R > {};
/**
* Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of objective vectors)
*/
template < class ObjectiveVector, class R >
class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R >
{};
class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R > {};
#endif /*MOEOMETRIC_H_*/

View file

@ -13,10 +13,10 @@
#ifndef MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_
#define MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_
#include <stdexcept>
#include <vector>
#include <utils/eoRealBounds.h>
#include <metric/moeoMetric.h>
/**
* Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors using normalized values.
* Then, indicator values lie in the interval [-1,1].
@ -33,16 +33,21 @@ public:
moeoNormalizedSolutionVsSolutionBinaryMetric()
{
bounds.resize(ObjectiveVector::Traits::nObjectives());
// initialize bounds in case someone does not want to use them
for (unsigned int i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
bounds[i] = eoRealInterval(0,1);
}
}
/**
* Sets the lower bound (_min) and the upper bound (_max) for the objective _obj
* _min lower bound
* _max upper bound
* _obj the objective index
* @param _min lower bound
* @param _max upper bound
* @param _obj the objective index
*/
void setup(double _min, double _max, unsigned _obj)
void setup(double _min, double _max, unsigned int _obj)
{
if (_min == _max)
{
@ -52,12 +57,13 @@ public:
bounds[_obj] = eoRealInterval(_min, _max);
}
/**
* Sets the lower bound and the upper bound for the objective _obj using a eoRealInterval object
* _realInterval the eoRealInterval object
* _obj the objective index
* @param _realInterval the eoRealInterval object
* @param _obj the objective index
*/
virtual void setup(eoRealInterval _realInterval, unsigned _obj)
virtual void setup(eoRealInterval _realInterval, unsigned int _obj)
{
bounds[_obj] = _realInterval;
}
@ -79,193 +85,4 @@ protected:
};
/**
* Additive epsilon binary metric allowing to compare two objective vectors as proposed in
* Zitzler E., Thiele L., Laumanns M., Fonseca C. M., Grunert da Fonseca V.:
* Performance Assessment of Multiobjective Optimizers: An Analysis and Review. IEEE Transactions on Evolutionary Computation 7(2), pp.117132 (2003).
*/
template < class ObjectiveVector >
class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
{
public:
/**
* Returns the minimal distance by which the objective vector _o1 must be translated in all objectives
* so that it weakly dominates the objective vector _o2
* @warning don't forget to set the bounds for every objective before the call of this function
* @param _o1 the first objective vector
* @param _o2 the second objective vector
*/
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{
// computation of the epsilon value for the first objective
double result = epsilon(_o1, _o2, 0);
// computation of the epsilon value for the other objectives
double tmp;
for (unsigned i=1; i<ObjectiveVector::Traits::nObjectives(); i++)
{
tmp = epsilon(_o1, _o2, i);
result = std::max(result, tmp);
}
// returns the maximum epsilon value
return result;
}
private:
/** the bounds for every objective */
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
/**
* Returns the epsilon value by which the objective vector _o1 must be translated in the objective _obj
* so that it dominates the objective vector _o2
* @param _o1 the first objective vector
* @param _o2 the second objective vector
* @param _obj the index of the objective
*/
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned _obj)
{
double result;
// if the objective _obj have to be minimized
if (ObjectiveVector::Traits::minimizing(_obj))
{
// _o1[_obj] - _o2[_obj]
result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
}
// if the objective _obj have to be maximized
else
{
// _o2[_obj] - _o1[_obj]
result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
}
return result;
}
};
/**
* Hypervolume binary metric allowing to compare two objective vectors as proposed in
* Zitzler E., Künzli S.: Indicator-Based Selection in Multiobjective Search. In Parallel Problem Solving from Nature (PPSN VIII).
* Lecture Notes in Computer Science 3242, Springer, Birmingham, UK pp.832842 (2004).
* This indicator is based on the hypervolume concept introduced in
* Zitzler, E., Thiele, L.: Multiobjective Optimization Using Evolutionary Algorithms - A Comparative Case Study.
* Parallel Problem Solving from Nature (PPSN-V), pp.292-301 (1998).
*/
template < class ObjectiveVector >
class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
{
public:
/**
* Ctor
* @param _rho value used to compute the reference point from the worst values for each objective (default : 1.1)
*/
moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho)
{
// not-a-maximization problem check
for (unsigned i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
{
if (ObjectiveVector::Traits::maximizing(i))
{
throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric");
}
}
// consistency check
if (rho < 1)
{
cout << "Warning, value used to compute the reference point rho for the hypervolume calculation must not be smaller than 1" << endl;
cout << "Adjusted to 1" << endl;
rho = 1;
}
}
/**
* Returns the volume of the space that is dominated by _o2 but not by _o1 with respect to a reference point computed using rho.
* @warning don't forget to set the bounds for every objective before the call of this function
* @param _o1 the first objective vector
* @param _o2 the second objective vector
*/
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
{
double result;
// if _o1 dominates _o2
if ( paretoComparator(_o1,_o2) )
{
result = - hypervolume(_o1, _o2, ObjectiveVector::Traits::nObjectives()-1);
}
else
{
result = hypervolume(_o2, _o1, ObjectiveVector::Traits::nObjectives()-1);
}
return result;
}
private:
/** value used to compute the reference point from the worst values for each objective */
double rho;
/** the bounds for every objective */
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
/** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
* Returns the volume of the space that is dominated by _o2 but not by _o1 with respect to a reference point computed using rho for the objective _obj.
* @param _o1 the first objective vector
* @param _o2 the second objective vector
* @param _obj the objective index
* @param _flag used for iteration, if _flag=true _o2 is not talen into account (default : false)
*/
double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned _obj, const bool _flag = false)
{
double result;
double range = rho * bounds[_obj].range();
double max = bounds[_obj].minimum() + range;
// value of _1 for the objective _obj
double v1 = _o1[_obj];
// value of _2 for the objective _obj (if _flag=true, v2=max)
double v2;
if (_flag)
{
v2 = max;
}
else
{
v2 = _o2[_obj];
}
// computation of the volume
if (_obj == 0)
{
if (v1 < v2)
{
result = (v2 - v1) / range;
}
else
{
result = 0;
}
}
else
{
if (v1 < v2)
{
result = ( hypervolume(_o1, _o2, _obj-1, true) * (v2 - v1) / range ) + ( hypervolume(_o1, _o2, _obj-1) * (max - v2) / range );
}
else
{
result = hypervolume(_o1, _o2, _obj-1) * (max - v2) / range;
}
}
return result;
}
};
#endif /*MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_*/

View file

@ -15,6 +15,7 @@
#include <eo>
<<<<<<< .courant
#include <MOEO.h>
#include <moeoArchiveObjectiveVectorSavingUpdater.h>
#include <moeoArchiveUpdater.h>
@ -46,9 +47,88 @@
#include <moeoStochTournamentSelect.h>
#include <moeoVector.h>
#include <metric/moeoBinaryMetricSavingUpdater.h>
=======
#include <algo/moeoAlgo.h>
#include <algo/moeoCombinedLS.h>
#include <algo/moeoEA.h>
#include <algo/moeoEasyEA.h>
#include <algo/moeoHybridLS.h>
#include <algo/moeoIBEA.h>
//#include <algo/moeoIBMOLS.h>
//#include <algo/moeoIteratedIBMOLS.h>
#include <algo/moeoLS.h>
#include <algo/moeoNSGA.h>
#include <algo/moeoNSGAII.h>
#include <archive/moeoArchive.h>
#include <comparator/moeoAggregativeComparator.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoDiversityThenFitnessComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <comparator/moeoGDominanceObjectiveVectorComparator.h>
#include <comparator/moeoObjectiveVectorComparator.h>
#include <comparator/moeoObjectiveObjectiveVectorComparator.h>
#include <comparator/moeoOneObjectiveComparator.h>
#include <comparator/moeoParetoObjectiveVectorComparator.h>
#include <core/MOEO.h>
#include <core/moeoBitVector.h>
#include <core/moeoEvalFunc.h>
#include <core/moeoObjectiveVector.h>
#include <core/moeoObjectiveVectorDouble.h>
#include <core/moeoObjectiveVectorTraits.h>
#include <core/moeoBitVector.h>
#include <core/moeoRealVector.h>
#include <distance/moeoDistance.h>
#include <distance/moeoDistanceMatrix.h>
#include <distance/moeoEuclideanDistance.h>
#include <distance/moeoManhattanDistance.h>
#include <distance/moeoNormalizedDistance.h>
#include <diversity/moeoCrowdingDistanceDiversityAssignment.h>
#include <diversity/moeoDiversityAssignment.h>
#include <diversity/moeoDummyDiversityAssignment.h>
#include <diversity/moeoFrontByFrontCrowdingDistanceDiversityAssignment.h>
#include <diversity/moeoFrontByFrontSharingDiversityAssignment.h>
#include <diversity/moeoSharingDiversityAssignment.h>
#include <fitness/moeoAchievementFitnessAssignment.h>
#include <fitness/moeoCriterionBasedFitnessAssignment.h>
#include <fitness/moeoDummyFitnessAssignment.h>
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
#include <fitness/moeoIndicatorBasedFitnessAssignment.h>
#include <fitness/moeoParetoBasedFitnessAssignment.h>
//#include <fitness/moeoReferencePointIndicatorBasedFitnessAssignment.h>
#include <fitness/moeoScalarFitnessAssignment.h>
#include <metric/moeoAdditiveEpsilonBinaryMetric.h>
>>>>>>> .fusion-droit.r399
#include <metric/moeoContributionMetric.h>
#include <metric/moeoEntropyMetric.h>
#include <metric/moeoHypervolumeBinaryMetric.h>
#include <metric/moeoMetric.h>
#include <metric/moeoNormalizedSolutionVsSolutionBinaryMetric.h>
#include <replacement/moeoElitistReplacement.h>
#include <replacement/moeoEnvironmentalReplacement.h>
#include <replacement/moeoGenerationalReplacement.h>
#include <replacement/moeoReplacement.h>
#include <selection/moeoDetTournamentSelect.h>
#include <selection/moeoRandomSelect.h>
#include <selection/moeoRouletteSelect.h>
#include <selection/moeoSelectFromPopAndArch.h>
#include <selection/moeoSelectOne.h>
#include <selection/moeoSelectors.h>
#include <selection/moeoStochTournamentSelect.h>
#include <utils/moeoArchiveObjectiveVectorSavingUpdater.h>
#include <utils/moeoArchiveUpdater.h>
#include <utils/moeoBinaryMetricSavingUpdater.h>
#include <utils/moeoConvertPopToObjectiveVectors.h>
#endif /*MOEO_*/

View file

@ -1,70 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoArchiveObjectiveVectorSavingUpdater.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
#define MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
#include <fstream>
#include <string>
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <moeoArchive.h>
#define MAX_BUFFER_SIZE 1000
/**
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
*/
template <class EOT>
class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
{
public:
/**
* Ctor
* @param _arch local archive
* @param _filename target filename
* @param _id own ID
*/
moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<EOT> & _arch, const std::string & _filename, int _id = -1) : arch(_arch), filename(_filename), id(_id), counter(0)
{}
/**
* Saves the fitness of the archive's members into the file
*/
void operator()() {
char buff[MAX_BUFFER_SIZE];
if (id == -1)
sprintf (buff, "%s.%u", filename.c_str(), counter ++);
else
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
std::ofstream f(buff);
for (unsigned i = 0; i < arch.size (); i++)
f << arch[i].objectiveVector() << std::endl;
f.close ();
}
private:
/** local archive */
moeoArchive<EOT> & arch;
/** target filename */
std::string filename;
/** own ID */
int id;
/** counter */
unsigned counter;
};
#endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/

View file

@ -1,133 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOCOMPARATOR_H_
#define MOEOCOMPARATOR_H_
#include <eoFunctor.h>
/**
* Functor allowing to compare two solutions.
*/
template < class MOEOT >
class moeoComparator : public eoBF < const MOEOT &, const MOEOT &, const bool >
{};
/**
* Functor allowing to compare two solutions according to their first objective value, then their second, and so on.
*/
template < class MOEOT >
class moeoObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 is greater than _moeo2 on the first objective, then on the second, and so on
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return _moeo1.objectiveVector() > _moeo2.objectiveVector();
}
};
/**
* Functor allowing to compare two solutions according to one objective.
*/
template < class MOEOT >
class moeoOneObjectiveComparator : public moeoComparator < MOEOT >
{
public:
/**
* Ctor.
* @param _obj the index of objective
*/
moeoOneObjectiveComparator(unsigned _obj) : obj(_obj)
{
if (obj > MOEOT::ObjectiveVector::nObjectives())
{
throw std::runtime_error("Problem with the index of objective in moeoOneObjectiveComparator");
}
}
/**
* Returns true if _moeo1 is greater than _moeo2 on the obj objective
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return _moeo1.objectiveVector()[obj] > _moeo2.objectiveVector()[obj];
}
private:
/** the index of objective */
unsigned obj;
};
/**
* Functor allowing to compare two solutions according to their fitness values, then according to their diversity values.
*/
template < class MOEOT >
class moeoFitnessThenDiversityComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 is greater than _moeo2 according to their fitness values, then according to their diversity values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.fitness() == _moeo2.fitness())
{
return _moeo1.diversity() > _moeo2.diversity();
}
else
{
return _moeo1.fitness() > _moeo2.fitness();
}
}
};
/**
* Functor allowing to compare two solutions according to their diversity values, then according to their fitness values.
*/
template < class MOEOT >
class moeoDiversityThenFitnessComparator : public moeoComparator < MOEOT >
{
public:
/**
* Returns true if _moeo1 is greater than _moeo2 according to their diversity values, then according to their fitness values
* @param _moeo1 the first solution
* @param _moeo2 the second solution
*/
const bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
if (_moeo1.diversity() == _moeo2.diversity())
{
return _moeo1.fitness() > _moeo2.fitness();
}
else
{
return _moeo1.diversity() > _moeo2.diversity();
}
}
};
#endif /*MOEOCOMPARATOR_H_*/

View file

@ -1,120 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEasyEA.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
#define _MOEOEASYEA_H
#include <apply.h>
#include <eoPopEvalFunc.h>
#include <eoContinue.h>
#include <eoTransform.h>
#include <eoBreed.h>
#include <eoMergeReduce.h>
#include <moeoEA.h>
#include <eoReplacement.h>
#include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h>
/**
* An easy class to design multi-objective evolutionary algorithms.
*/
template < class MOEOT >
class moeoEasyEA: public moeoEA < MOEOT >
{
public:
/**
* Ctor.
* @param _continuator the stopping criteria
* @param _eval the evaluation functions
* @param _breed the breeder
* @param _replace the replacment strategy
* @param _fitnessEval the fitness evaluation scheme
* @param _diversityEval the diversity evaluation scheme
* @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
*/
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoBreed < MOEOT > & _breed, eoReplacement < MOEOT > & _replace,
moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false)
:
continuator(_continuator), eval (_eval), loopEval(_eval), popEval(loopEval), breed(_breed), replace(_replace), fitnessEval(_fitnessEval),
diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
{}
/**
* 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;
popEval(empty_pop, _pop); // A first eval of pop.
bool firstTime = true;
do
{
try
{
unsigned pSize = _pop.size();
offspring.clear(); // new offspring
// fitness and diversity assignment (if you want to or if it is the first generation)
if (evalFitAndDivBeforeSelection || firstTime)
{
firstTime = false;
fitnessEval(_pop);
diversityEval(_pop);
}
breed(_pop, offspring);
popEval(_pop, offspring); // eval of parents + offspring if necessary
replace(_pop, offspring); // after replace, the new pop. is in _pop
if (pSize > _pop.size())
{
throw std::runtime_error("Population shrinking!");
}
else if (pSize < _pop.size())
{
throw std::runtime_error("Population growing!");
}
}
catch (std::exception& e)
{
std::string s = e.what();
s.append( " in moeoEasyEA");
throw std::runtime_error( s );
}
} while (continuator(_pop));
}
protected:
/** the stopping criteria */
eoContinue < MOEOT > & continuator;
/** the evaluation functions */
eoEvalFunc < MOEOT > & eval;
/** to evaluate the whole population */
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 */
moeoFitnessAssignment < MOEOT > & fitnessEval;
/** the diversity assignment strategy */
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;
};
#endif /*MOEOEASYEA_H_*/

View file

@ -1,118 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoFitnessAssignment.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOFITNESSASSIGNMENT_H_
#define MOEOFITNESSASSIGNMENT_H_
#include <eoFunctor.h>
#include <eoPop.h>
/**
* Functor that sets the fitness values of a whole population.
*/
template < class MOEOT >
class moeoFitnessAssignment : public eoUF < eoPop < MOEOT > &, void >
{
public:
/** 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 _objVec 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 _objVec the objective vector
*/
void updateByDeleting(eoPop < MOEOT > & _pop, ObjectiveVector & _objVec)
{
// nothing to do... ;-)
}
};
/**
* moeoScalarFitnessAssignment is a moeoFitnessAssignment for scalar strategies.
*/
template < class MOEOT >
class moeoScalarFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
/**
* moeoCriterionBasedFitnessAssignment is a moeoFitnessAssignment for criterion-based strategies.
*/
template < class MOEOT >
class moeoCriterionBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
/**
* moeoParetoBasedFitnessAssignment is a moeoFitnessAssignment for Pareto-based strategies.
*/
template < class MOEOT >
class moeoParetoBasedFitnessAssignment : public moeoFitnessAssignment < MOEOT >
{};
#endif /*MOEOFITNESSASSIGNMENT_H_*/

View file

@ -1,127 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoNSGAII.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEONSGAII_H_
#define MOEONSGAII_H_
#include <eoGeneralBreeder.h>
#include <eoBreed.h>
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoGenContinue.h>
#include <eoGenOp.h>
#include <eoPopEvalFunc.h>
#include <eoSGAGenOp.h>
#include <moeoCrowdingDistanceDiversityAssignment.h>
#include <moeoDetTournamentSelect.h>
#include <moeoElitistReplacement.h>
#include <moeoFastNonDominatedSortingFitnessAssignment.h>
/**
* The NSGA-II algorithm as described in:
* Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan : "A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II".
* In IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197 (April 2002).
* This class builds the NSGA-II algorithm only by using the components of the ParadisEO-MOEO framework.
*/
template < class MOEOT >
class moeoNSGAII: public moeoEA < MOEOT >
{
public:
/**
* This constructor builds the algorithm as descibed in the paper.
* @param _max_gen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII (unsigned _max_gen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > &_op) :
continuator (*(new eoGenContinue < MOEOT > (_max_gen))), eval (_eval), loopEval (_eval), popEval (loopEval), select (2), // binary tournament selection
replace (fitnessAssignment, diversityAssignment), genBreed (select, _op), breed (genBreed)
{}
/**
* Ctor taking _max_gen, crossover and mutation.
* @param _max_gen number of generations before stopping
* @param _eval evaluation function
* @param _crossover crossover
* @param _pCross crossover probability
* @param _mutation mutation
* @param _pMut mutation probability
*/
moeoNSGAII (unsigned _max_gen, eoEvalFunc < MOEOT > &_eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) :
continuator (*(new eoGenContinue < MOEOT > (_max_gen))), eval (_eval), loopEval (_eval), popEval (loopEval), select (2), // binary tournament selection
replace (fitnessAssignment, diversityAssignment), genBreed (select, *new eoSGAGenOp < MOEOT > (_crossover, _pCross, _mutation, _pMut)), breed (genBreed)
{}
/**
* Ctor taking a continuator instead of _gen_max.
* @param _continuator stopping criteria
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
continuator (_continuator), eval (_eval), loopEval (_eval), popEval (loopEval), select (2), // binary tournament selection
replace (fitnessAssignment, diversityAssignment), genBreed (select, _op), breed (genBreed)
{}
/**
* Apply a few generation of evolution to the population _pop.
* @param _pop the population
*/
virtual void operator () (eoPop < MOEOT > &_pop)
{
eoPop < MOEOT > offspring, empty_pop;
popEval (empty_pop, _pop); // a first eval of _pop
// evaluate fitness and diversity
fitnessAssignment(_pop);
diversityAssignment(_pop);
do
{
// generate offspring, worths are recalculated if necessary
breed (_pop, offspring);
// eval of offspring
popEval (_pop, offspring);
// after replace, the new pop is in _pop. Worths are recalculated if necessary
replace (_pop, offspring);
} while (continuator (_pop));
}
protected:
/** stopping criteria */
eoContinue < MOEOT > & continuator;
/** evaluation function */
eoEvalFunc < MOEOT > & eval;
/** to evaluate the whole population */
eoPopLoopEval < MOEOT > loopEval;
/** to evaluate the whole population */
eoPopEvalFunc < MOEOT > & popEval;
/** binary tournament selection */
moeoDetTournamentSelect < MOEOT > select;
/** elitist replacement */
moeoElitistReplacement < MOEOT > replace;
/** general breeder */
eoGeneralBreeder < MOEOT > genBreed;
/** breeder */
eoBreed < MOEOT > & breed;
/** fitness assignment used in NSGA-II */
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment;
/** Diversity assignment used in NSGA-II */
moeoCrowdingDistanceDiversityAssignment < MOEOT > diversityAssignment;
};
#endif /*MOEONSGAII_H_*/

View file

@ -1,165 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorComparator.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEVECTORCOMPARATOR_H_
#define MOEOOBJECTIVEVECTORCOMPARATOR_H_
#include <math.h>
#include <eoFunctor.h>
/**
* Abstract class allowing to compare 2 objective vectors.
* The template argument ObjectiveVector have to be a moeoObjectiveVector.
*/
template < class ObjectiveVector >
class moeoObjectiveVectorComparator : public eoBF < const ObjectiveVector &, const ObjectiveVector &, bool >
{};
/**
* This functor class allows to compare 2 objective vectors according to Pareto dominance.
*/
template < class ObjectiveVector >
class moeoParetoObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Returns true if _objectiveVector1 dominates _objectiveVector2
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
bool dom = false;
for (unsigned i=0; i<ObjectiveVector::nObjectives(); i++)
{
// first, we have to check if the 2 objective values are not equal for the ith objective
if ( fabs(_objectiveVector1[i] - _objectiveVector2[i]) > ObjectiveVector::Traits::tolerance() )
{
// if the ith objective have to be minimized...
if (ObjectiveVector::minimizing(i))
{
if (_objectiveVector1[i] < _objectiveVector2[i])
{
dom = true; //_objectiveVector1[i] is better than _objectiveVector2[i]
}
else
{
return false; //_objectiveVector1 cannot dominate _objectiveVector2
}
}
// if the ith objective have to be maximized...
else if (ObjectiveVector::maximizing(i))
{
if (_objectiveVector1[i] > _objectiveVector2[i])
{
dom = true; //_objectiveVector1[i] is better than _objectiveVector2[i]
}
else
{
return false; //_objectiveVector1 cannot dominate _objectiveVector2
}
}
}
}
return dom;
}
};
/**
* This functor class allows to compare 2 objective vectors according to g-dominance.
* The concept of g-dominance as been introduced in:
* J. Molina, L. V. Santana, A. G. Hernandez-Diaz, C. A. Coello Coello, R. Caballero,
* "g-dominance: Reference point based dominance" (2007)
*/
template < class ObjectiveVector >
class moeoGDominanceObjectiveVectorComparator : public moeoObjectiveVectorComparator < ObjectiveVector >
{
public:
/**
* Ctor.
* @param _ref the reference point
*/
moeoGDominanceObjectiveVectorComparator(ObjectiveVector _ref) : ref(_ref)
{}
/**
* Returns true if _objectiveVector1 g-dominates _objectiveVector2.
* @param _objectiveVector1 the first objective vector
* @param _objectiveVector2 the second objective vector
*/
bool operator()(const ObjectiveVector & _objectiveVector1, const ObjectiveVector & _objectiveVector2)
{
unsigned flag1 = flag(_objectiveVector1);
unsigned flag2 = flag(_objectiveVector2);
if (flag1==0)
{
// cannot dominate
return false;
}
else if ( (flag1==1) && (flag2==0) )
{
// dominates
return true;
}
else // (flag1==1) && (flag2==1)
{
// both are on the good region, so let's use the classical Pareto dominance
return paretoComparator(_objectiveVector1, _objectiveVector2);
}
}
private:
/** the reference point */
ObjectiveVector ref;
/** Pareto comparator */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/**
* Returns the flag of _objectiveVector according to the reference point
* @param _objectiveVector the first objective vector
*/
unsigned flag(const ObjectiveVector & _objectiveVector)
{
unsigned result=1;
for (unsigned i=0; i<ref.nObjectives(); i++)
{
if (_objectiveVector[i] > ref[i])
{
result=0;
}
}
if (result==0)
{
result=1;
for (unsigned i=0; i<ref.nObjectives(); i++)
{
if (_objectiveVector[i] < ref[i])
{
result=0;
}
}
}
return result;
}
};
#endif /*MOEOOBJECTIVEVECTORCOMPARATOR_H_*/

View file

@ -0,0 +1,11 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
#ifndef _MOEOMOVEINCREVAL_H
#define _MOEOMOVEINCREVAL_H
#include <eoFunctor.h>
template < class Move >
class moeoMoveIncrEval : public eoBF < const Move &, const typename Move::EOType &, typename Move::EOType::ObjectiveVector > {};
#endif

View file

@ -13,10 +13,12 @@
#ifndef MOEOELITISTREPLACEMENT_H_
#define MOEOELITISTREPLACEMENT_H_
#include <moeoReplacement.h>
#include <moeoComparator.h>
#include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <diversity/moeoDiversityAssignment.h>
#include <diversity/moeoDummyDiversityAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
#include <replacement/moeoReplacement.h>
/**
* Elitist replacement strategy that consists in keeping the N best individuals.
@ -27,42 +29,42 @@ public:
/**
* Full constructor.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
* @param _diversityAssignment the diversity assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator)
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator)
{}
/**
* Constructor without comparator. A moeoFitThenDivComparator is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
* @param _diversityAssignment the diversity assignment strategy
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator)
{}
/**
* Constructor without moeoDiversityAssignement. A dummy diversity is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (_comparator)
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator)
{}
/**
* Constructor without moeoDiversityAssignement nor moeoComparator.
* A moeoFitThenDivComparator and a dummy diversity are used as default.
* @param _evalFitness the fitness assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
*/
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
moeoElitistReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator)
{}
@ -73,16 +75,15 @@ public:
*/
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{
unsigned sz = _parents.size ();
unsigned int sz = _parents.size ();
// merges offspring and parents into a global population
_parents.reserve (_parents.size () + _offspring.size ());
copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
std::copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
// evaluates the fitness and the diversity of this global population
evalFitness (_parents);
evalDiversity (_parents);
fitnessAssignment (_parents);
diversityAssignment (_parents);
// sorts the whole population according to the comparator
Cmp cmp(comparator);
std::sort(_parents.begin(), _parents.end(), cmp);
std::sort(_parents.begin(), _parents.end(), comparator);
// finally, resize this global population
_parents.resize (sz);
// and clear the offspring population
@ -93,27 +94,23 @@ public:
protected:
/** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & evalFitness;
moeoFitnessAssignment < MOEOT > & fitnessAssignment;
/** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & evalDiversity;
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator;
/**
* This class is used to compare solutions in order to sort the population.
*/
moeoDiversityAssignment < MOEOT > & diversityAssignment;
/** a dummy diversity assignment can be used as default */
moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
/** a fitness then diversity comparator can be used as default */
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** this object is used to compare solutions in order to sort the population */
class Cmp
{
public:
/**
* Ctor.
* @param _comparator the comparator
* @param _comp the comparator
*/
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
Cmp(moeoComparator < MOEOT > & _comp) : comp(_comp)
{}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
@ -121,16 +118,12 @@ protected:
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return comparator(_moeo1,_moeo2);
return comp(_moeo2,_moeo1);
}
private:
/** the comparator */
moeoComparator < MOEOT > & comparator;
};
moeoComparator < MOEOT > & comp;
} comparator;
};

View file

@ -13,10 +13,11 @@
#ifndef MOEOENVIRONMENTALREPLACEMENT_H_
#define MOEOENVIRONMENTALREPLACEMENT_H_
#include <moeoReplacement.h>
#include <moeoComparator.h>
#include <moeoFitnessAssignment.h>
#include <moeoDiversityAssignment.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <diversity/moeoDiversityAssignment.h>
#include <fitness/moeoFitnessAssignment.h>
#include <replacement/moeoReplacement.h>
/**
* Environmental replacement strategy that consists in keeping the N best individuals by deleting individuals 1 by 1
@ -32,69 +33,74 @@ public:
/**
* Full constructor.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
* @param _diversityAssignment the diversity assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (_comparator)
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (_comparator)
{}
/**
* Constructor without comparator. A moeoFitThenDivComparator is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _evalDiversity the diversity assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
* @param _diversityAssignment the diversity assignment strategy
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoDiversityAssignment < MOEOT > & _evalDiversity) :
evalFitness (_evalFitness), evalDiversity (_evalDiversity), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoDiversityAssignment < MOEOT > & _diversityAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (_diversityAssignment), comparator (defaultComparator)
{}
/**
* Constructor without moeoDiversityAssignement. A dummy diversity is used as default.
* @param _evalFitness the fitness assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
* @param _comparator the comparator (used to compare 2 individuals)
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness, moeoComparator < MOEOT > & _comparator) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (_comparator)
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment, moeoComparator < MOEOT > & _comparator) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (_comparator)
{}
/**
* Constructor without moeoDiversityAssignement nor moeoComparator.
* A moeoFitThenDivComparator and a dummy diversity are used as default.
* @param _evalFitness the fitness assignment strategy
* @param _fitnessAssignment the fitness assignment strategy
*/
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _evalFitness) :
evalFitness (_evalFitness), evalDiversity (*(new moeoDummyDiversityAssignment < MOEOT >)), comparator (*(new moeoFitnessThenDiversityComparator < MOEOT >))
moeoEnvironmentalReplacement (moeoFitnessAssignment < MOEOT > & _fitnessAssignment) :
fitnessAssignment (_fitnessAssignment), diversityAssignment (defaultDiversity), comparator (defaultComparator)
{}
/**
* Replaces the first population by adding the individuals of the second one, sorting with a moeoComparator and resizing the whole population obtained.
* @param _parents the population composed of the parents (the population you want to replace)
* @param _offspring the offspring population
* @param _parents the population composed of the parents (the population you want to replace)
* @param _offspring the offspring population
*/
void operator () (eoPop < MOEOT > &_parents, eoPop < MOEOT > &_offspring)
{
unsigned sz = _parents.size();
unsigned int sz = _parents.size();
// merges offspring and parents into a global population
_parents.reserve (_parents.size() + _offspring.size());
copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
std::copy (_offspring.begin(), _offspring.end(), back_inserter(_parents));
// evaluates the fitness and the diversity of this global population
evalFitness (_parents);
evalDiversity (_parents);
fitnessAssignment (_parents);
diversityAssignment (_parents);
// remove individuals 1 by 1 and update the fitness values
Cmp cmp(comparator);
unsigned int worstIdx;
ObjectiveVector worstObjVec;
while (_parents.size() > sz)
{
std::sort (_parents.begin(), _parents.end(), cmp);
worstObjVec = _parents[_parents.size()-1].objectiveVector();
_parents.resize(_parents.size()-1);
evalFitness.updateByDeleting(_parents, worstObjVec);
evalDiversity.updateByDeleting(_parents, worstObjVec);
// the individual to delete
worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin();
worstObjVec = _parents[worstIdx].objectiveVector();
// remove the woorst individual
_parents[worstIdx] = _parents.back();
_parents.pop_back();
// update of the fitness and diversity values
fitnessAssignment.updateByDeleting(_parents, worstObjVec);
diversityAssignment.updateByDeleting(_parents, worstObjVec);
}
// clear the offspring population
_offspring.clear ();
@ -104,28 +110,23 @@ public:
protected:
/** the fitness assignment strategy */
moeoFitnessAssignment < MOEOT > & evalFitness;
moeoFitnessAssignment < MOEOT > & fitnessAssignment;
/** the diversity assignment strategy */
moeoDiversityAssignment < MOEOT > & evalDiversity;
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator;
/**
* This class is used to compare solutions in order to sort the population.
*/
moeoDiversityAssignment < MOEOT > & diversityAssignment;
/** a dummy diversity assignment can be used as default */
moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
/** a fitness then diversity comparator can be used as default */
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** this object is used to compare solutions in order to sort the population */
class Cmp
{
public:
/**
* Ctor.
* @param _comparator the comparator
* @param _comp the comparator
*/
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
Cmp(moeoComparator < MOEOT > & _comp) : comp(_comp)
{}
/**
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
* _moeo1 the first individual
@ -133,16 +134,12 @@ protected:
*/
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
{
return comparator(_moeo1,_moeo2);
return comp(_moeo1,_moeo2);
}
private:
/** the comparator */
moeoComparator < MOEOT > & comparator;
};
moeoComparator < MOEOT > & comp;
} comparator;
};

View file

@ -14,7 +14,7 @@
#define MOEOGENERATIONALREPLACEMENT_H_
#include <eoReplacement.h>
#include <moeoReplacement.h>
#include <replacement/moeoReplacement.h>
/**
* Generational replacement: only the new individuals are preserved.

View file

@ -19,7 +19,6 @@
* Replacement strategy for multi-objective optimization.
*/
template < class MOEOT >
class moeoReplacement : public eoReplacement < MOEOT >
{};
class moeoReplacement : public eoReplacement < MOEOT > {};
#endif /*MOEOREPLACEMENT_H_*/

View file

@ -13,15 +13,15 @@
#ifndef MOEODETTOURNAMENTSELECT_H_
#define MOEODETTOURNAMENTSELECT_H_
#include <moeoComparator.h>
#include <moeoSelectOne.h>
#include <moeoSelectors.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <selection/moeoSelectOne.h>
#include <selection/moeoSelectors.h>
/**
* Selection strategy that selects ONE individual by deterministic tournament.
*/
template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne <
MOEOT >
template < class MOEOT > class moeoDetTournamentSelect:public moeoSelectOne < MOEOT >
{
public:
@ -30,8 +30,7 @@ public:
* @param _comparator the comparator (used to compare 2 individuals)
* @param _tSize the number of individuals in the tournament (default: 2)
*/
moeoDetTournamentSelect (moeoComparator < MOEOT > &_comparator, unsigned _tSize = 2):
comparator (_comparator), tSize (_tSize)
moeoDetTournamentSelect (moeoComparator < MOEOT > & _comparator, unsigned int _tSize = 2) : comparator (_comparator), tSize (_tSize)
{
// consistency check
if (tSize < 2)
@ -44,12 +43,10 @@ public:
/**
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
* @param _tSize the number of individuals in the tournament (default: 2)
*/
moeoDetTournamentSelect (unsigned _tSize = 2):
comparator (*(new moeoFitnessThenDiversityComparator < MOEOT > ())),
tSize (_tSize)
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
* @param _tSize the number of individuals in the tournament (default: 2)
*/
moeoDetTournamentSelect (unsigned int _tSize = 2) : comparator (defaultComparator), tSize (_tSize)
{
// consistency check
if (tSize < 2)
@ -65,7 +62,7 @@ public:
* Apply the tournament to the given population
* @param _pop the population
*/
const MOEOT & operator () (const eoPop < MOEOT > &_pop)
const MOEOT & operator() (const eoPop < MOEOT > &_pop)
{
// use the selector
return mo_deterministic_tournament (_pop, tSize, comparator);
@ -75,10 +72,12 @@ public:
protected:
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > &comparator;
moeoComparator < MOEOT > & comparator;
/** a fitness then diversity comparator can be used as default */
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** the number of individuals in the tournament */
unsigned tSize;
unsigned int tSize;
};
#endif /*MOEODETTOURNAMENTSELECT_H_ */

View file

@ -13,8 +13,9 @@
#ifndef MOEORANDOMSELECT_H_
#define MOEORANDOMSELECT_H_
#include <moeoSelectOne.h>
#include <eoRandomSelect.h>
#include <selection/moeoSelectOne.h>
/**
* Selection strategy that selects only one element randomly from a whole population.

View file

@ -0,0 +1,62 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoRouletteSelect.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOROULETTESELECT_H_
#define MOEOROULETTESELECT_H_
#include <selection/moeoSelectOne.h>
#include <selection/moeoSelectors.h>
/**
* Selection strategy that selects ONE individual by using roulette wheel process.
* @WARNING This selection only uses fitness values (and not diversity values).
*/
template < class MOEOT >
class moeoRouletteSelect:public moeoSelectOne < MOEOT >
{
public:
/**
* Ctor.
* @param _tSize the number of individuals in the tournament (default: 2)
*/
moeoRouletteSelect (unsigned int _tSize = 2) : tSize (_tSize)
{
// consistency check
if (tSize < 2)
{
std::
cout << "Warning, Tournament size should be >= 2\nAdjusted to 2\n";
tSize = 2;
}
}
/**
* Apply the tournament to the given population
* @param _pop the population
*/
const MOEOT & operator () (const eoPop < MOEOT > & _pop)
{
// use the selector
return mo_roulette_wheel(_pop,tSize);
}
protected:
/** size */
double & tSize;
};
#endif /*MOEOROULETTESELECT_H_ */

View file

@ -15,9 +15,9 @@
#include <eoPop.h>
#include <utils/eoRNG.h>
#include <moeoArchive.h>
#include <moeoSelectOne.h>
#include <moeoRandomSelect.h>
#include <archive/moeoArchive.h>
#include <selection/moeoSelectOne.h>
#include <selection/moeoRandomSelect.h>
/**
* Elitist selection process that consists in choosing individuals in the archive as well as in the current population.
@ -38,6 +38,7 @@ public:
: popSelectOne(_popSelectOne), archSelectOne(_archSelectOne), arch(_arch), ratioFromPop(_ratioFromPop)
{}
/**
* Defaulr ctor - the archive's selection operator is a random selector
* @param _popSelectOne the population's selection operator
@ -48,6 +49,7 @@ public:
: popSelectOne(_popSelectOne), archSelectOne(randomSelectOne), arch(_arch), ratioFromPop(_ratioFromPop)
{}
/**
* The selection process
*/
@ -62,6 +64,7 @@ public:
return popSelectOne(pop);
}
/**
* Setups some population stats
*/

View file

@ -13,43 +13,40 @@
#ifndef MOEOSELECTORS_H_
#define MOEOSELECTORS_H_
#include <moeoComparator.h>
#include <comparator/moeoComparator.h>
template <class It,class MOEOT>
It mo_deterministic_tournament(It _begin, It _end, unsigned _t_size,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng)
It mo_deterministic_tournament(It _begin, It _end, unsigned int _t_size,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng)
{
It best = _begin + _gen.random(_end - _begin);
for (unsigned i = 0; i < _t_size - 1; ++i)
for (unsigned int i = 0; i < _t_size - 1; ++i)
{
It competitor = _begin + _gen.random(_end - _begin);
// compare the two individuals by using the comparator
if (_comparator(*best,*competitor))
if (_comparator(*best, *competitor))
// best "better" than competitor
best=competitor;
}
return best;
}
template <class MOEOT>
const MOEOT& mo_deterministic_tournament(const eoPop<MOEOT>& _pop, unsigned _t_size,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng)
const MOEOT& mo_deterministic_tournament(const eoPop<MOEOT>& _pop, unsigned int _t_size,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng)
{
return *mo_deterministic_tournament(_pop.begin(), _pop.end(),_t_size,_comparator, _gen);
}
template <class MOEOT>
MOEOT& mo_deterministic_tournament(eoPop<MOEOT>& _pop, unsigned _t_size,moeoComparator<MOEOT>& _comparator,eoRng& _gen = rng)
MOEOT& mo_deterministic_tournament(eoPop<MOEOT>& _pop, unsigned int _t_size,moeoComparator<MOEOT>& _comparator,eoRng& _gen = rng)
{
return *mo_deterministic_tournament(_pop.begin(), _pop.end(), _t_size,_comparator, _gen);
}
template <class It,class MOEOT>
It mo_stochastic_tournament(It _begin, It _end, double _t_rate,moeoComparator<MOEOT>& _comparator ,eoRng& _gen = rng)
{
@ -58,7 +55,7 @@ It mo_stochastic_tournament(It _begin, It _end, double _t_rate,moeoComparator<MO
bool return_better = _gen.flip(_t_rate);
if (_comparator(*i1 , *i2))
if (_comparator(*i1, *i2))
{
if (return_better) return i2;
// else
@ -75,12 +72,14 @@ It mo_stochastic_tournament(It _begin, It _end, double _t_rate,moeoComparator<MO
return i2;
}
template <class MOEOT>
const MOEOT& mo_stochastic_tournament(const eoPop<MOEOT>& _pop, double _t_rate,moeoComparator<MOEOT>& _comparator, eoRng& _gen = rng)
{
return *mo_stochastic_tournament(_pop.begin(), _pop.end(), _t_rate,_comparator, _gen);
}
template <class MOEOT>
MOEOT& mo_stochastic_tournament(eoPop<MOEOT>& _pop, double _t_rate, eoRng& _gen = rng)
{
@ -88,7 +87,6 @@ MOEOT& mo_stochastic_tournament(eoPop<MOEOT>& _pop, double _t_rate, eoRng& _gen
}
template <class It>
It mo_roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng)
{
@ -108,6 +106,7 @@ It mo_roulette_wheel(It _begin, It _end, double total, eoRng& _gen = rng)
return --i;
}
template <class MOEOT>
const MOEOT& mo_roulette_wheel(const eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng)
{
@ -126,6 +125,7 @@ const MOEOT& mo_roulette_wheel(const eoPop<MOEOT>& _pop, double total, eoRng& _g
return *--i;
}
template <class MOEOT>
MOEOT& mo_roulette_wheel(eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng)
{
@ -138,13 +138,14 @@ MOEOT& mo_roulette_wheel(eoPop<MOEOT>& _pop, double total, eoRng& _gen = rng)
while (roulette > 0.0)
{
// fitness ?
// fitness only
roulette -= static_cast<double>((i++)->fitness());
}
return *--i;
}
#endif /*MOEOSELECTORS_H_*/

View file

@ -13,8 +13,10 @@
#ifndef MOEOSTOCHTOURNAMENTSELECT_H_
#define MOEOSTOCHTOURNAMENTSELECT_H_
#include <moeoSelectOne.h>
#include <moeoSelectors.h>
#include <comparator/moeoComparator.h>
#include <comparator/moeoFitnessThenDiversityComparator.h>
#include <selection/moeoSelectOne.h>
#include <selection/moeoSelectors.h>
/**
* Selection strategy that selects ONE individual by stochastic tournament.
@ -28,45 +30,37 @@ public:
* @param _comparator the comparator (used to compare 2 individuals)
* @param _tRate the tournament rate
*/
moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) :
comparator (_comparator), tRate (_tRate)
moeoStochTournamentSelect (moeoComparator < MOEOT > & _comparator, double _tRate = 1.0) : comparator (_comparator), tRate (_tRate)
{
// consistency checks
if (tRate < 0.5)
{
std::
cerr <<
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
tRate = 0.55;
}
if (tRate > 1)
{
std::
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
tRate = 1;
}
}
/**
* Ctor without comparator. A moeoFitnessThenDiversityComparator is used as default.
* @param _tRate the tournament rate
*/
moeoStochTournamentSelect (double _tRate = 1.0)
:comparator (*(new moeoFitnessThenDiversityComparator < MOEOT > ())), tRate (_tRate)
moeoStochTournamentSelect (double _tRate = 1.0) : comparator (defaultComparator), tRate (_tRate)
{
// consistency checks
if (tRate < 0.5)
{
std::
cerr <<
"Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
std::cerr << "Warning, Tournament rate should be > 0.5\nAdjusted to 0.55\n";
tRate = 0.55;
}
if (tRate > 1)
{
std::
cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
std::cerr << "Warning, Tournament rate should be < 1\nAdjusted to 1\n";
tRate = 1;
}
}
@ -83,11 +77,12 @@ public:
}
protected:
/** the diversity assignment strategy */
/** the comparator (used to compare 2 individuals) */
moeoComparator < MOEOT > & comparator;
/** a fitness then diversity comparator can be used as default */
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
/** the tournament rate */
double tRate;

View file

@ -0,0 +1,94 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoArchiveObjectiveVectorSavingUpdater.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
#define MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_
#include <fstream>
#include <string>
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <archive/moeoArchive.h>
#define MAX_BUFFER_SIZE 1000
/**
* This class allows to save the objective vectors of the solutions contained in an archive into a file at each generation.
*/
template < class MOEOT >
class moeoArchiveObjectiveVectorSavingUpdater : public eoUpdater
{
public:
/**
* Ctor
* @param _arch local archive
* @param _filename target filename
* @param _count put this variable to true if you want a new file to be created each time () is called and to false if you only want the file to be updated
* @param _id own ID
*/
moeoArchiveObjectiveVectorSavingUpdater (moeoArchive<MOEOT> & _arch, const std::string & _filename, bool _count = false, int _id = -1) :
arch(_arch), filename(_filename), count(_count), counter(0), id(_id)
{}
/**
* Saves the fitness of the archive's members into the file
*/
void operator()() {
char buff[MAX_BUFFER_SIZE];
if (count)
{
if (id == -1)
{
sprintf (buff, "%s.%u", filename.c_str(), counter ++);
}
else
{
sprintf (buff, "%s.%u.%u", filename.c_str(), id, counter ++);
}
}
else
{
if (id == -1)
{
sprintf (buff, "%s", filename.c_str());
}
else
{
sprintf (buff, "%s.%u", filename.c_str(), id);
}
counter ++;
}
std::ofstream f(buff);
for (unsigned int i = 0; i < arch.size (); i++)
f << arch[i].objectiveVector() << std::endl;
f.close ();
}
private:
/** local archive */
moeoArchive<MOEOT> & arch;
/** target filename */
std::string filename;
/** this variable is set to true if a new file have to be created each time () is called and to false if the file only HAVE to be updated */
bool count;
/** counter */
unsigned int counter;
/** own ID */
int id;
};
#endif /*MOEOARCHIVEOBJECTIVEVECTORSAVINGUPDATER_H_*/

View file

@ -15,7 +15,7 @@
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <moeoArchive.h>
#include <archive/moeoArchive.h>
/**
* This class allows to update the archive at each generation with newly found non-dominated solutions.

View file

@ -15,6 +15,7 @@
#include <fstream>
#include <string>
#include <vector>
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <metric/moeoMetric.h>
@ -28,11 +29,10 @@ class moeoBinaryMetricSavingUpdater : public eoUpdater
{
public:
/**
* The objective vector type of a solution
*/
/** The objective vector type of a solution */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor
* @param _metric the binary metric comparing two Pareto sets
@ -43,6 +43,7 @@ public:
metric(_metric), pop(_pop), filename(_filename), counter(1)
{}
/**
* Saves the metric's value for the current generation
*/
@ -55,9 +56,9 @@ public:
// creation of the two Pareto sets
std::vector < ObjectiveVector > from;
std::vector < ObjectiveVector > to;
for (unsigned i=0; i<pop.size(); i++)
for (unsigned int i=0; i<pop.size(); i++)
from.push_back(pop[i].objectiveVector());
for (unsigned i=0 ; i<oldPop.size(); i++)
for (unsigned int i=0 ; i<oldPop.size(); i++)
to.push_back(oldPop[i].objectiveVector());
// writing the result into the file
std::ofstream f (filename.c_str(), std::ios::app);
@ -68,6 +69,7 @@ public:
}
}
private:
/** binary metric comparing two Pareto sets */
@ -81,7 +83,7 @@ private:
/** is it the first generation ? */
bool firstGen;
/** counter */
unsigned counter;
unsigned int counter;
};

View file

@ -13,6 +13,7 @@
#ifndef MOEOPOPTOOBJECTIVEVECTORS_H_
#define MOEOPOPTOOBJECTIVEVECTORS_H_
#include <vector>
#include <eoFunctor.h>
/**
@ -31,12 +32,13 @@ public:
{
std::vector < ObjectiveVector > result;
result.resize(_pop.size());
for (unsigned i=0; i<_pop.size(); i++)
for (unsigned int i=0; i<_pop.size(); i++)
{
result.push_back(_pop[i].objectiveVector());
}
return result;
}
};
#endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/