Constructor revised

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1614 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2009-10-14 09:44:06 +00:00
commit 348da5c52c
3 changed files with 38 additions and 21 deletions

View file

@ -76,7 +76,7 @@ public:
* @param _max the max size for the pop * @param _max the max size for the pop
*/ */
moeoASEEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) : moeoASEEA (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), breed (selectTransform), archive(_archive) defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), transform(_crossover, _pCross, _mutation, _pMut), selectTransform(selectMany, transform), breed (selectTransform), archive(_archive)
{} {}
@ -84,11 +84,15 @@ public:
* Ctor with a eoContinue. * Ctor with a eoContinue.
* @param _continuator stopping criteria * @param _continuator stopping criteria
* @param _eval evaluation function * @param _eval evaluation function
* @param _crossover crossover
* @param _pCross crossover probability
* @param _mutation mutation
* @param _pMut mutation probability
* @param _archive archive * @param _archive archive
* @param _max the max size for the pop * @param _max the max size for the pop
*/ */
moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, moeoArchive < MOEOT > & _archive, unsigned int _max) : moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) :
defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), breed(selectTransform), archive(_archive) defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), transform(_crossover, _pCross, _mutation, _pMut), selectTransform(selectMany, transform), breed(selectTransform), archive(_archive)
{} {}
@ -96,11 +100,15 @@ public:
* Ctor with a eoContinue, a eoPopEval. * Ctor with a eoContinue, a eoPopEval.
* @param _continuator stopping criteria * @param _continuator stopping criteria
* @param _popEval population evaluation function * @param _popEval population evaluation function
* @param _crossover crossover
* @param _pCross crossover probability
* @param _mutation mutation
* @param _pMut mutation probability
* @param _archive archive * @param _archive archive
* @param _max the max size for the pop * @param _max the max size for the pop
*/ */
moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, moeoArchive < MOEOT > & _archive, unsigned int _max) : moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut, moeoArchive < MOEOT > & _archive, unsigned int _max) :
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), breed(selectTransform), archive(_archive) defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), transform(_crossover, _pCross, _mutation, _pMut), selectTransform(selectMany, transform), breed(selectTransform), archive(_archive)
{} {}
@ -113,7 +121,7 @@ public:
* @param _max the max size for the pop * @param _max the max size for the pop
*/ */
moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _transform, moeoArchive < MOEOT > & _archive, unsigned int _max) : moeoASEEA (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _transform, moeoArchive < MOEOT > & _archive, unsigned int _max) :
defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), breed(selectTransform), archive(_archive) defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), selectMany(_archive, _max), transform(defaultQuadOp, 0.0, defaultMonOp, 0.0), selectTransform(selectMany, _transform), breed(selectTransform), archive(_archive)
{} {}
@ -126,7 +134,7 @@ public:
* @param _max the max size for the pop * @param _max the max size for the pop
*/ */
moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoTransform < MOEOT > & _transform, moeoArchive < MOEOT > & _archive, unsigned int _max) : moeoASEEA (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoTransform < MOEOT > & _transform, moeoArchive < MOEOT > & _archive, unsigned int _max) :
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), breed(selectTransform), archive(_archive) defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), selectMany(_archive, _max), transform(defaultQuadOp, 0.0, defaultMonOp, 0.0), selectTransform(selectMany, _transform), breed(selectTransform), archive(_archive)
{} {}
@ -159,12 +167,6 @@ protected:
void operator()(MOEOT &) {} void operator()(MOEOT &) {}
}defaultEval; }defaultEval;
/** default select */
class DummySelect : public eoSelect < MOEOT >{
public :
void operator()(const eoPop<MOEOT>&, eoPop<MOEOT>&) {}
}defaultSelect;
/** default transform */ /** default transform */
class DummyTransform : public eoTransform < MOEOT >{ class DummyTransform : public eoTransform < MOEOT >{
public : public :
@ -183,6 +185,8 @@ protected:
eoPopEvalFunc < MOEOT > & popEval; eoPopEvalFunc < MOEOT > & popEval;
/** default select many */ /** default select many */
moeoDetArchiveSelect < MOEOT > selectMany; // A REMPLACER !!!!!!!!!!! => add/moeoDetArchiveSelect.h moeoDetArchiveSelect < MOEOT > selectMany; // A REMPLACER !!!!!!!!!!! => add/moeoDetArchiveSelect.h
/** eoTransform */
eoSGATransform < MOEOT > transform;
/** select transform */ /** select transform */
eoSelectTransform < MOEOT > selectTransform; eoSelectTransform < MOEOT > selectTransform;
/** a default crossover */ /** a default crossover */
@ -190,7 +194,9 @@ protected:
/** a default mutation */ /** a default mutation */
eoMonCloneOp < MOEOT > defaultMonOp; eoMonCloneOp < MOEOT > defaultMonOp;
/** an object for genetic operators (used as default) */ /** an object for genetic operators (used as default) */
eoSGAGenOp < MOEOT > defaultSGAGenOp; //eoSGAGenOp < MOEOT > defaultSGAGenOp;
/** an object for genetic operators (used as default) */
//eoSGAGenOp < MOEOT >& genOp;
/** breeder */ /** breeder */
eoBreed < MOEOT > & breed; eoBreed < MOEOT > & breed;
/**archive */ /**archive */

View file

@ -57,15 +57,16 @@ class moeoDetArchiveSelect : public eoSelect<MOEOT>
* @param _source compatibility parameter, not used * @param _source compatibility parameter, not used
* @param _dest destination population, selected from archive * @param _dest destination population, selected from archive
*/ */
virtual void operator()(const eoPop < MOEOT > & _source, eoPop < MOEOT > & _dest) void operator()(const eoPop < MOEOT > & _source, eoPop < MOEOT > & _dest)
{ {
if(max < min){ if(max < min){
std::cout << "Warning! moeoDetArchiveSelect: min value > max value!!! Nothing is done." << std::endl; std::cout << "Warning! moeoDetArchiveSelect: min value > max value!!! Nothing is done." << std::endl;
} }
else{ else{
unsigned int archive_size = archive.size(); unsigned int archive_size = archive.size();
_dest.resize(0); _dest.resize(0);
if (archive_size >= min && archive_size<= max){ if ((archive_size >= min) && (archive_size <= max)){
for (int i=0; i<archive_size; i++) for (int i=0; i<archive_size; i++)
_dest.push_back(archive[i]); _dest.push_back(archive[i]);
} }
@ -79,11 +80,12 @@ class moeoDetArchiveSelect : public eoSelect<MOEOT>
_dest.push_back(archive[permutation[i]]); _dest.push_back(archive[permutation[i]]);
} }
else { else {
for (int i=0; i<min; i++) for (int i=0; i<min; i++){
_dest.push_back(archive[i%archive_size]); _dest.push_back(archive[i%archive_size]);
} }
} }
} }
}
private : private :
/** archive used to select MOEOT*/ /** archive used to select MOEOT*/

View file

@ -76,7 +76,7 @@ public:
{ {
ObjectiveVector objVec; ObjectiveVector objVec;
objVec[0] = _sol[0]; objVec[0] = _sol[0];
objVec[1] = _sol[0] * _sol[0]; objVec[1] = 1 / (_sol[0]+1);
_sol.objectiveVector(objVec); _sol.objectiveVector(objVec);
} }
}; };
@ -87,11 +87,15 @@ int main()
TestEval eval; TestEval eval;
eoQuadCloneOp < Solution > xover; eoQuadCloneOp < Solution > xover;
eoUniformMutation < Solution > mutation(0.05); eoUniformMutation < Solution > mutation(1.0);
eoRealVectorBounds bounds(1, 1.0, 2.0); eoRealVectorBounds bounds(1, 1.0, 2.0);
eoRealInitBounded < Solution > init(bounds); eoRealInitBounded < Solution > init(bounds);
eoPop < Solution > pop(20, init); eoPop < Solution > pop(20, init);
for(int i=0; i<pop.size(); i++)
eval(pop[i]);
eoSGATransform < Solution > transform(xover, 0.1, mutation, 0.1); eoSGATransform < Solution > transform(xover, 0.1, mutation, 0.1);
eoGenContinue <Solution > continuator(10); eoGenContinue <Solution > continuator(10);
moeoUnboundedArchive < Solution > archive; moeoUnboundedArchive < Solution > archive;
@ -100,12 +104,17 @@ int main()
// build ASSEA // build ASSEA
moeoASEEA <Solution> algo1(10, eval, xover, 0.1, mutation, 0.5, archive, 10); moeoASEEA <Solution> algo1(10, eval, xover, 0.1, mutation, 0.5, archive, 10);
moeoASEEA <Solution> algo2(continuator, popEval, archive, 10); moeoASEEA <Solution> algo2(continuator, popEval, xover, 0.1, mutation, 1.0, archive, 10);
moeoASEEA <Solution> algo3(continuator, eval, archive, 10); moeoASEEA <Solution> algo3(continuator, eval, xover, 0.1, mutation, 1.0, archive, 10);
moeoASEEA <Solution> algo4(continuator, popEval, transform, archive, 10); moeoASEEA <Solution> algo4(continuator, popEval, transform, archive, 10);
moeoASEEA <Solution> algo5(continuator, eval, transform, archive, 10); moeoASEEA <Solution> algo5(continuator, eval, transform, archive, 10);
// run the algo // run the algo
algo1(pop);
algo2(pop);
algo3(pop);
algo4(pop);
algo5(pop); algo5(pop);
std::cout << " OK\n"; std::cout << " OK\n";