Modifies PhyloMOEA clases in order to compile to last Paradiseo-MOEO svn version

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1363 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
wcancino 2009-01-23 11:31:18 +00:00
commit 68ec20fd66
6 changed files with 125 additions and 96 deletions

View file

@ -7,7 +7,8 @@
#include <PhyloMOEO_archive.h> #include <PhyloMOEO_archive.h>
#include <PhyloMOEOProbMatrixContainerUpdater.h> #include <PhyloMOEOProbMatrixContainerUpdater.h>
#include <moeoNSGAII2.h> #include <moeoNSGAII2.h>
#include <moeoObjVecStat.h> #include <utils/moeoBestObjVecStat.h>
#include <utils/moeoAverageObjVecStat.h>
#include <PhyloMOEOPartitionStat.h> #include <PhyloMOEOPartitionStat.h>
#include <eoCountedFileMonitor.h> #include <eoCountedFileMonitor.h>
#include <eoSingleFileCountedStateSaver.h> #include <eoSingleFileCountedStateSaver.h>
@ -165,7 +166,7 @@ int main(int argc, char *argv[])
cout << " done\n"; cout << " done\n";
PhyloMOEOFinalSolutionsArchive finalsolutions; PhyloMOEOFinalSolutionsArchive finalsolutions;
finalsolutions.update(population); finalsolutions.operator()(population);
//remove_final_solutions( population ); //remove_final_solutions( population );
// optimize remaining solutions // optimize remaining solutions
@ -202,7 +203,7 @@ int main(int argc, char *argv[])
cout << "\nCalculating Pareto-optimal Solutions..."; cout << "\nCalculating Pareto-optimal Solutions...";
PhyloMOEOParetoSolutionsArchive paretosolutions; PhyloMOEOParetoSolutionsArchive paretosolutions;
paretosolutions.update(finalsolutions); paretosolutions.operator()(finalsolutions);
paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores"); paretosolutions.save_scores(path + datafile + "_pareto_scores_" + expid + ".txt","#Pareto Solutions Scores");
paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt"); paretosolutions.save_trees(path + datafile + "_pareto_trees_" + expid + ".txt");
cout << " done\n"; cout << " done\n";

View file

@ -20,7 +20,7 @@
#ifndef PHYLOMOEOPARTITONSTAT_H_ #ifndef PHYLOMOEOPARTITONSTAT_H_
#define PHYLOMOEOPARTITONSTAT_H_ #define PHYLOMOEOPARTITONSTAT_H_
#include <PhyloMOEA/moeoObjVecStat.h> #include <moeoObjVecStat.h>
#include <PhyloMOEO.h> #include <PhyloMOEO.h>
//#include <utils.h> //#include <utils.h>

View file

@ -20,7 +20,7 @@
#ifndef PHYLOMOEO_ARCHIVE_H #ifndef PHYLOMOEO_ARCHIVE_H
#define PHYLOMOEO_ARCHIVE_H #define PHYLOMOEO_ARCHIVE_H
#include <PhyloMOEA/PhyloMOEO.h> #include <PhyloMOEO.h>
typedef moeoArchive<PhyloMOEO> PhyloMOEOArchive; typedef moeoArchive<PhyloMOEO> PhyloMOEOArchive;
typedef PhyloMOEOArchive PhyloMOEOPFArchive; typedef PhyloMOEOArchive PhyloMOEOPFArchive;
@ -28,7 +28,7 @@ typedef PhyloMOEOArchive PhyloMOEOPFArchive;
class PhyloMOEOParetoSolutionsArchive:public moeoArchive<PhyloMOEO> class PhyloMOEOParetoSolutionsArchive:public moeoUnboundedArchive<PhyloMOEO>
{ {
public: public:
void save_trees( std::string filename, string title="" ) void save_trees( std::string filename, string title="" )
@ -65,6 +65,7 @@ class PhyloMOEOParetoSolutionsArchive:public moeoArchive<PhyloMOEO>
class PhyloMOEODummyArchive:public PhyloMOEOParetoSolutionsArchive class PhyloMOEODummyArchive:public PhyloMOEOParetoSolutionsArchive
{ {
public: public:
void update(const eoPop < PhyloMOEO > & _pop) void update(const eoPop < PhyloMOEO > & _pop)
{ {
std::copy(_pop.begin(), _pop.end(), back_inserter(*this) ); std::copy(_pop.begin(), _pop.end(), back_inserter(*this) );
@ -74,8 +75,15 @@ class PhyloMOEODummyArchive:public PhyloMOEOParetoSolutionsArchive
class PhyloMOEOFinalSolutionsArchive: public PhyloMOEOParetoSolutionsArchive class PhyloMOEOFinalSolutionsArchive: public PhyloMOEOParetoSolutionsArchive
{ {
public: public:
// overwrite the default operator
void operator()(const eoPop < PhyloMOEO > & _pop) { update(_pop); }
protected:
void update(const eoPop < PhyloMOEO > & _pop) void update(const eoPop < PhyloMOEO > & _pop)
{ {
std::copy(_pop.begin(), _pop.end(), back_inserter(*this) ); std::copy(_pop.begin(), _pop.end(), back_inserter(*this) );
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;

View file

@ -44,7 +44,7 @@
#include <diversity/moeoDummyDiversityAssignment.h> #include <diversity/moeoDummyDiversityAssignment.h>
#include <fitness/moeoFitnessAssignment.h> #include <fitness/moeoFitnessAssignment.h>
#include <replacement/moeoReplacement.h> #include <replacement/moeoReplacement.h>
#include <PhyloMOEA/vectorSortIndex.h> #include <vectorSortIndex.h>
/** /**
* Elitist replacement strategy that consists in keeping the N best individuals. * Elitist replacement strategy that consists in keeping the N best individuals.

View file

@ -40,7 +40,7 @@
#include <diversity/moeoCrowdingDiversityAssignment.h> #include <diversity/moeoCrowdingDiversityAssignment.h>
#include <comparator/moeoFitnessThenDiversityComparator.h> #include <comparator/moeoFitnessThenDiversityComparator.h>
#include <PhyloMOEA/moeoPtrComparator.h> #include <moeoPtrComparator.h>
/** /**
@ -91,12 +91,12 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
} }
// sort the whole pop according to fitness values // sort the whole pop according to fitness values
moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator; moeoFitnessThenDiversityComparator < MOEOT > fitnessComparator;
std::vector<const MOEOT *> sortedptrpop; std::vector<MOEOT *> sortedptrpop;
sortedptrpop.resize(_pop.size()); sortedptrpop.resize(_pop.size());
// due to intensive sort operations for this diversity assignment, // due to intensive sort operations for this diversity assignment,
// it is more efficient to perform sorts using only pointers to the // it is more efficient to perform sorts using only pointers to the
// population members in order to avoid copy of individuals // population members in order to avoid copy of individuals
std::transform( _pop.begin(), _pop.end(), sortedptrpop.begin(), typename eoPop<MOEOT>::Ref()); for(int i=0; i< _pop.size(); i++) sortedptrpop[i] = & (_pop[i]);
//sort the pointers to population members //sort the pointers to population members
moeoPtrComparator<MOEOT> cmp2( fitnessComparator); moeoPtrComparator<MOEOT> cmp2( fitnessComparator);
std::sort(sortedptrpop.begin(), sortedptrpop.end(), cmp2); std::sort(sortedptrpop.begin(), sortedptrpop.end(), cmp2);
@ -111,7 +111,7 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
{ {
for (unsigned int i=a; i<=b; i++) for (unsigned int i=a; i<=b; i++)
{ {
((MOEOT *)sortedptrpop[i])->diversity(inf()); sortedptrpop[i]->diversity(inf());
//_pop[i].diversity(inf()); //_pop[i].diversity(inf());
} }
} }
@ -136,13 +136,13 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
max += tiny(); max += tiny();
} }
// set the diversity value to infiny for min and max // set the diversity value to infiny for min and max
((MOEOT *)sortedptrpop[a])->diversity(inf()); sortedptrpop[a]->diversity(inf());
((MOEOT *)sortedptrpop[b])->diversity(inf()); sortedptrpop[b]->diversity(inf());
// set the diversity values for the other individuals // set the diversity values for the other individuals
for (unsigned int i=a+1; i<b; i++) for (unsigned int i=a+1; i<b; i++)
{ {
distance = ( (sortedptrpop[i-1])->objectiveVector()[obj] - (sortedptrpop[i+1])->objectiveVector()[obj]) / (max-min); distance = ( sortedptrpop[i-1]->objectiveVector()[obj] - sortedptrpop[i+1]->objectiveVector()[obj] ) / (max-min);
((MOEOT *)sortedptrpop[i])->diversity(sortedptrpop[i]->diversity() + distance); sortedptrpop[i]->diversity(sortedptrpop[i]->diversity() + distance);
} }
} }
} }
@ -159,7 +159,7 @@ class moeoFrontByFrontCrowdingDiversityAssignment2 : public moeoCrowdingDiversit
* @param _start the index to start from * @param _start the index to start from
*/ */
unsigned int lastIndex (std::vector<const MOEOT *> & _pop, unsigned int _start) unsigned int lastIndex (std::vector<MOEOT *> & _pop, unsigned int _start)
{ {
unsigned int i=_start; unsigned int i=_start;
while ( (i<_pop.size()-1) && (_pop[i]->fitness()==_pop[i+1]->fitness()) ) while ( (i<_pop.size()-1) && (_pop[i]->fitness()==_pop[i+1]->fitness()) )

View file

@ -1,7 +1,7 @@
/* /*
* <moeoNSGAII.h> * <moeoNSGAII.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2008
* *
* Arnaud Liefooghe * Arnaud Liefooghe
* *
@ -39,6 +39,7 @@
#define MOEONSGAII2_H_ #define MOEONSGAII2_H_
#include <eoBreed.h> #include <eoBreed.h>
#include <eoCloneOps.h>
#include <eoContinue.h> #include <eoContinue.h>
#include <eoEvalFunc.h> #include <eoEvalFunc.h>
#include <eoGenContinue.h> #include <eoGenContinue.h>
@ -47,18 +48,14 @@
#include <eoPopEvalFunc.h> #include <eoPopEvalFunc.h>
#include <eoSGAGenOp.h> #include <eoSGAGenOp.h>
#include <algo/moeoEA.h> #include <algo/moeoEA.h>
#include <PhyloMOEA/moeoFrontByFrontCrowdingDiversityAssignment2.h> #include <moeoFrontByFrontCrowdingDiversityAssignment2.h>
#include <fitness/moeoFastNonDominatedSortingFitnessAssignment.h> #include <fitness/moeoDominanceDepthFitnessAssignment.h>
#include <PhyloMOEA/moeoElitistReplacement2.h> #include <replacement/moeoElitistReplacement.h>
#include <selection/moeoDetTournamentSelect.h> #include <selection/moeoDetTournamentSelect.h>
#include <eoCloneOps.h>
/** /**
* NSGA-II (Non-dominated Sorting Genetic Algorithm II) as described in: * NSGA-II (Non-dominated Sorting Genetic Algorithm II).
* Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan : "A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II". * Deb, K., S. Agrawal, A. Pratap, and T. Meyarivan. A fast elitist non-dominated sorting genetic algorithm for multi-objective optimization: NSGA-II. IEEE Transactions on Evolutionary Computation, Vol. 6, No 2, pp 182-197 (2002).
* 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. * This class builds the NSGA-II algorithm only by using the fine-grained components of the ParadisEO-MOEO framework.
*/ */
template < class MOEOT > template < class MOEOT >
@ -66,35 +63,9 @@ class moeoNSGAII2: public moeoEA < MOEOT >
{ {
public: public:
/**
* Simple ctor with a eoGenOp.
* @param _maxGen number of generations before stopping
* @param _eval evaluation function
* @param _op variation operator
*/
moeoNSGAII2 (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
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
*/
moeoNSGAII2 (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0),
genBreed(select, _op), breed(genBreed)
{}
/** /**
* Ctor with a crossover, a mutation and their corresponding rates. * Ctor with a crossover, a mutation and their corresponding rates.
* @param _maxGen number of generations before stopping * @param _maxGen maximum number of generations before stopping
* @param _eval evaluation function * @param _eval evaluation function
* @param _crossover crossover * @param _crossover crossover
* @param _pCross crossover probability * @param _pCross crossover probability
@ -102,40 +73,60 @@ class moeoNSGAII2: public moeoEA < MOEOT >
* @param _pMut mutation probability * @param _pMut mutation probability
*/ */
moeoNSGAII2 (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) : moeoNSGAII2 (unsigned int _maxGen, eoEvalFunc < MOEOT > & _eval, eoQuadOp < MOEOT > & _crossover, double _pCross, eoMonOp < MOEOT > & _mutation, double _pMut) :
defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), popEval(_eval), select (2), defaultGenContinuator(_maxGen), continuator(defaultGenContinuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), select (2), selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut), genBreed (select, defaultSGAGenOp), breed (genBreed), replace (fitnessAssignment, diversityAssignment)
replace (fitnessAssignment, diversityAssignment), defaultSGAGenOp(_crossover, _pCross, _mutation, _pMut),
genBreed (select, defaultSGAGenOp), breed (genBreed)
{} {}
/** /**
* Ctor with a continuator (instead of _maxGen) and a eoGenOp. * Ctor with a eoContinue and a eoGenOp.
* @param _continuator stopping criteria * @param _continuator stopping criteria
* @param _eval evaluation function * @param _eval evaluation function
* @param _op variation operator * @param _op variation operators
*/ */
moeoNSGAII2 (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) : moeoNSGAII2 (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoGenOp < MOEOT > & _op) :
defaultGenContinuator(0), continuator(_continuator), popEval(_eval), select(2), defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval), select(2),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), genBreed(select, _op), breed(genBreed), replace (fitnessAssignment, diversityAssignment)
genBreed(select, _op), breed(genBreed)
{} {}
/** /**
* Ctor with a continuator (instead of _maxGen) and a eoTransform. * Ctor with a eoContinue, a eoPopEval and a eoGenOp.
* @param _continuator stopping criteria
* @param _popEval population evaluation function
* @param _op variation operators
*/
moeoNSGAII2 (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoGenOp < MOEOT > & _op) :
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval), select(2),
selectMany(select,0.0), selectTransform(defaultSelect, defaultTransform), defaultSGAGenOp(defaultQuadOp, 1.0, defaultMonOp, 1.0), genBreed(select, _op), breed(genBreed), replace (fitnessAssignment, diversityAssignment)
{}
/**
* Ctor with a eoContinue and a eoTransform.
* @param _continuator stopping criteria * @param _continuator stopping criteria
* @param _eval evaluation function * @param _eval evaluation function
* @param _op variation operator * @param _transform variation operator
*/ */
moeoNSGAII2 (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _op) : moeoNSGAII2 (eoContinue < MOEOT > & _continuator, eoEvalFunc < MOEOT > & _eval, eoTransform < MOEOT > & _transform) :
continuator(_continuator), popEval(_eval), select(2), defaultGenContinuator(0), continuator(_continuator), eval(_eval), defaultPopEval(_eval), popEval(defaultPopEval),
replace(fitnessAssignment, diversityAssignment), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), select(2), selectMany(select, 1.0), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), genBreed(select, defaultSGAGenOp), breed(selectTransform), replace(fitnessAssignment, diversityAssignment)
genBreed(select, _op), breed(genBreed)
{} {}
/** /**
* Apply a few generation of evolution to the population _pop until the stopping criteria is verified. * Ctor with a eoContinue, a eoPopEval and a eoTransform.
* @param _continuator stopping criteria
* @param _popEval population evaluation function
* @param _transform variation operator
*/
moeoNSGAII2 (eoContinue < MOEOT > & _continuator, eoPopEvalFunc < MOEOT > & _popEval, eoTransform < MOEOT > & _transform) :
defaultGenContinuator(0), continuator(_continuator), eval(defaultEval), defaultPopEval(eval), popEval(_popEval),
select(2), selectMany(select, 1.0), selectTransform(selectMany, _transform), defaultSGAGenOp(defaultQuadOp, 0.0, defaultMonOp, 0.0), genBreed(select, defaultSGAGenOp), breed(selectTransform), replace(fitnessAssignment, diversityAssignment)
{}
/**
* Apply a the algorithm to the population _pop until the stopping criteria is satified.
* @param _pop the population * @param _pop the population
*/ */
virtual void operator () (eoPop < MOEOT > &_pop) virtual void operator () (eoPop < MOEOT > &_pop)
@ -164,26 +155,55 @@ class moeoNSGAII2: public moeoEA < MOEOT >
eoGenContinue < MOEOT > defaultGenContinuator; eoGenContinue < MOEOT > defaultGenContinuator;
/** stopping criteria */ /** stopping criteria */
eoContinue < MOEOT > & continuator; eoContinue < MOEOT > & continuator;
/** default eval */
class DummyEval : public eoEvalFunc < MOEOT >
{
public:
void operator()(MOEOT &) {}
}
defaultEval;
/** evaluation function */
eoEvalFunc < MOEOT > & eval;
/** default popEval */
eoPopLoopEval < MOEOT > defaultPopEval;
/** evaluation function used to evaluate the whole population */ /** evaluation function used to evaluate the whole population */
eoPopLoopEval < MOEOT > popEval; eoPopEvalFunc < MOEOT > & popEval;
/** default select */
class DummySelect : public eoSelect < MOEOT >
{
public :
void operator()(const eoPop<MOEOT>&, eoPop<MOEOT>&) {}
}
defaultSelect;
/** binary tournament selection */ /** binary tournament selection */
moeoDetTournamentSelect < MOEOT > select; moeoDetTournamentSelect < MOEOT > select;
/** fitness assignment used in NSGA-II */ /** default select many */
moeoFastNonDominatedSortingFitnessAssignment < MOEOT > fitnessAssignment; eoSelectMany < MOEOT > selectMany;
/** diversity assignment used in NSGA-II */ /** select transform */
moeoFrontByFrontCrowdingDiversityAssignment2 < MOEOT > diversityAssignment; eoSelectTransform < MOEOT > selectTransform;
/** elitist replacement */
moeoElitistReplacement2 < MOEOT > replace;
/** a default crossover */ /** a default crossover */
eoQuadCloneOp < MOEOT > defaultQuadOp; eoQuadCloneOp < MOEOT > defaultQuadOp;
/** 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;
/** default transform */
class DummyTransform : public eoTransform < MOEOT >
{
public :
void operator()(eoPop<MOEOT>&) {}
}
defaultTransform;
/** general breeder */ /** general breeder */
eoGeneralBreeder < MOEOT > genBreed; eoGeneralBreeder < MOEOT > genBreed;
/** breeder */ /** breeder */
eoBreed < MOEOT > & breed; eoBreed < MOEOT > & breed;
/** fitness assignment used in NSGA */
moeoDominanceDepthFitnessAssignment < MOEOT > fitnessAssignment;
/** diversity assignment used in NSGA-II */
moeoFrontByFrontCrowdingDiversityAssignment2 < MOEOT > diversityAssignment;
/** elitist replacement */
moeoElitistReplacement < MOEOT > replace;
}; };