moeoEasyEA constructors corrected and tested
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1267 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
274fa75560
commit
1309736161
4 changed files with 81 additions and 117 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* <moeoEasyEA.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
* (C) OPAC Team, LIFL, 2002-2008
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
|
|
@ -56,11 +56,11 @@
|
|||
*/
|
||||
template < class MOEOT >
|
||||
class moeoEasyEA: public moeoEA < MOEOT >
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor taking a breed and merge.
|
||||
* Ctor taking a breed.
|
||||
* @param _continuator the stopping criteria
|
||||
* @param _eval the evaluation functions
|
||||
* @param _breed the breeder
|
||||
|
|
@ -69,16 +69,13 @@ class moeoEasyEA: public moeoEA < MOEOT >
|
|||
* @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)
|
||||
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), replace(_replace), fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor taking a breed, a merge and a eoPopEval.
|
||||
* Ctor taking a breed and a popEval.
|
||||
* @param _continuator the stopping criteria
|
||||
* @param _popEval the evaluation functions for the whole population
|
||||
* @param _breed the breeder
|
||||
|
|
@ -87,35 +84,13 @@ class moeoEasyEA: public moeoEA < MOEOT >
|
|||
* @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)
|
||||
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), 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.
|
||||
* Ctor taking a select and a transform.
|
||||
* @param _continuator the stopping criteria
|
||||
* @param _eval the evaluation functions
|
||||
* @param _select the selection scheme
|
||||
|
|
@ -125,31 +100,24 @@ class moeoEasyEA: public moeoEA < MOEOT >
|
|||
* @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)
|
||||
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), replace(_replace), fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* Ctor taking a select, a transform, a merge and a reduce.
|
||||
* Ctor taking a select, a transform.and a popEval
|
||||
* @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 _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, 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)
|
||||
moeoEasyEA(eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoSelect < MOEOT > & _select, eoTransform < MOEOT > & _transform, moeoReplacement < MOEOT > & _replace, moeoFitnessAssignment < MOEOT > & _fitnessEval, moeoDiversityAssignment < MOEOT > & _diversityEval, bool _evalFitAndDivBeforeSelection = false) :
|
||||
continuator(_continuator), eval(dummyEval), loopEval(dummyEval), popEval(_popEval), selectTransform(_select, _transform), breed(selectTransform), replace(_replace), fitnessEval(_fitnessEval), diversityEval(_diversityEval), evalFitAndDivBeforeSelection(_evalFitAndDivBeforeSelection)
|
||||
{}
|
||||
|
||||
|
||||
|
|
@ -159,67 +127,82 @@ class moeoEasyEA: public moeoEA < MOEOT >
|
|||
*/
|
||||
virtual void operator()(eoPop < MOEOT > & _pop)
|
||||
{
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval(empty_pop, _pop); // A first eval of pop.
|
||||
bool firstTime = true;
|
||||
do
|
||||
eoPop < MOEOT > offspring, empty_pop;
|
||||
popEval(empty_pop, _pop); // A first eval of pop.
|
||||
bool firstTime = true;
|
||||
do
|
||||
{
|
||||
try
|
||||
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)
|
||||
//std::cout << "eval ou first time" << std::endl;
|
||||
if (evalFitAndDivBeforeSelection || firstTime)
|
||||
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;
|
||||
//std::cout << "fitness eval" << std::endl;
|
||||
fitnessEval(_pop);
|
||||
//std::cout << "diversity eval" << std::endl;
|
||||
diversityEval(_pop);
|
||||
firstTime = false;
|
||||
//std::cout << "fitness eval" << std::endl;
|
||||
fitnessEval(_pop);
|
||||
//std::cout << "diversity eval" << std::endl;
|
||||
diversityEval(_pop);
|
||||
}
|
||||
//std::cout << "breed" << std::endl;
|
||||
breed(_pop, offspring);
|
||||
//std::cout << "pop eval" << std::endl;
|
||||
popEval(_pop, offspring); // eval of parents + offspring if necessary
|
||||
//std::cout << "replace" << std::endl;
|
||||
replace(_pop, offspring); // after replace, the new pop. is in _pop
|
||||
if (pSize > _pop.size())
|
||||
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!");
|
||||
throw std::runtime_error("Population shrinking!");
|
||||
}
|
||||
else if (pSize < _pop.size())
|
||||
else if (pSize < _pop.size())
|
||||
{
|
||||
throw std::runtime_error("Population growing!");
|
||||
throw std::runtime_error("Population growing!");
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::string s = e.what();
|
||||
s.append( " in moeoEasyEA");
|
||||
throw std::runtime_error( s );
|
||||
std::string s = e.what();
|
||||
s.append( " in moeoEasyEA");
|
||||
throw std::runtime_error( s );
|
||||
}
|
||||
}
|
||||
while (continuator(_pop));
|
||||
while (continuator(_pop));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
/** the stopping criteria */
|
||||
eoContinue < MOEOT > & continuator;
|
||||
/** a dummy eval */
|
||||
class eoDummyEval : public eoEvalFunc < MOEOT >
|
||||
{
|
||||
public:
|
||||
void operator()(MOEOT &) {}
|
||||
}
|
||||
dummyEval;
|
||||
/** the evaluation functions */
|
||||
eoEvalFunc < MOEOT > & eval;
|
||||
/** to evaluate the whole population */
|
||||
eoPopLoopEval < MOEOT > loopEval;
|
||||
/** to evaluate the whole population */
|
||||
eoPopEvalFunc < MOEOT > & popEval;
|
||||
/** dummy select */
|
||||
class DummySelect : public eoSelect < MOEOT >
|
||||
{
|
||||
public :
|
||||
void operator()(const eoPop<MOEOT>&, eoPop<MOEOT>&) {}
|
||||
}
|
||||
dummySelect;
|
||||
/** breed: a select followed by a transform */
|
||||
eoSelectTransform < MOEOT > selectTransform;
|
||||
/** dummy transform */
|
||||
class DummyTransform : public eoTransform < MOEOT >
|
||||
{
|
||||
public :
|
||||
void operator()(eoPop<MOEOT>&) {}
|
||||
}
|
||||
dummyTransform;
|
||||
/** 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 */
|
||||
|
|
@ -228,35 +211,7 @@ class moeoEasyEA: public moeoEA < MOEOT >
|
|||
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_*/
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@
|
|||
#include <algo/moeoLS.h>
|
||||
#include <algo/moeoNSGA.h>
|
||||
#include <algo/moeoNSGAII.h>
|
||||
#include <algo/moeoSEEA.h>
|
||||
#include <algo/moeoSPEA2.h>
|
||||
|
||||
#include <archive/moeoArchive.h>
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ SET (TEST_LIST
|
|||
t-moeoIBEA
|
||||
t-moeoNSGA
|
||||
t-moeoNSGAII
|
||||
t-moeoSEEA
|
||||
t-moeoMax3Obj
|
||||
t-moeoEasyEA
|
||||
t-moeoDominanceCountFitnessAssignment
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* <t-moeoEasyEA.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
* (C) OPAC Team, LIFL, 2002-2008
|
||||
*
|
||||
* Arnaud Liefooghe
|
||||
*
|
||||
|
|
@ -88,11 +88,14 @@ int main()
|
|||
std::cout << "[moeoEasyEA]" << std::endl;
|
||||
|
||||
TestEval eval;
|
||||
eoPopLoopEval <Solution> loopEval(eval);
|
||||
eoPopEvalFunc <Solution> & popEval(loopEval);
|
||||
eoQuadCloneOp < Solution > xover;
|
||||
eoUniformMutation < Solution > mutation(0.05);
|
||||
eoSequentialOp < Solution > op;
|
||||
op.add(xover, 1.0);
|
||||
op.add(mutation, 1.0);
|
||||
eoSGATransform < Solution > transform(xover, 1.0, mutation, 1.0);
|
||||
eoRealVectorBounds bounds(1, 1.0, 2.0);
|
||||
eoRealInitBounded < Solution > init(bounds);
|
||||
eoPop < Solution > pop(20, init);
|
||||
|
|
@ -100,15 +103,19 @@ int main()
|
|||
moeoFastNonDominatedSortingFitnessAssignment < Solution > fitnessAssignment;
|
||||
moeoFrontByFrontCrowdingDiversityAssignment < Solution > diversityAssignment;
|
||||
moeoFitnessThenDiversityComparator < Solution > comparator;
|
||||
moeoDetTournamentSelect < Solution > select(comparator, 2);
|
||||
moeoDetTournamentSelect < Solution > selectOne(comparator, 2);
|
||||
moeoElitistReplacement < Solution > replace(fitnessAssignment, diversityAssignment, comparator);
|
||||
eoGeneralBreeder < Solution > breed(select, op);
|
||||
eoGeneralBreeder < Solution > breed(selectOne, op);
|
||||
eoSelectMany < Solution > select(selectOne, 1.0);
|
||||
|
||||
// build EA
|
||||
moeoEasyEA < Solution > algo (term, eval, breed, replace, fitnessAssignment, diversityAssignment);
|
||||
moeoEasyEA < Solution > algo1 (term, eval, breed, replace, fitnessAssignment, diversityAssignment);
|
||||
moeoEasyEA < Solution > algo2 (term, popEval, breed, replace, fitnessAssignment, diversityAssignment);
|
||||
moeoEasyEA < Solution > algo3 (term, eval, select, transform, replace, fitnessAssignment, diversityAssignment);
|
||||
moeoEasyEA < Solution > algo4 (term, popEval, select, transform, replace, fitnessAssignment, diversityAssignment);
|
||||
|
||||
// run the algo
|
||||
algo(pop);
|
||||
algo4(pop);
|
||||
|
||||
// final pop
|
||||
std::cout << "Final population" << std::endl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue