Merge from rc2.0

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2713 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
quemy 2012-07-19 09:53:26 +00:00
commit 409a1b21b8
1731 changed files with 104909 additions and 64375 deletions

View file

@ -0,0 +1,120 @@
/*
* <moeoArchiveObjectiveVectorSavingUpdater.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.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

@ -0,0 +1,80 @@
/*
* <moeoArchiveUpdater.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOARCHIVEUPDATER_H_
#define MOEOARCHIVEUPDATER_H_
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <archive/moeoArchive.h>
/**
* This class allows to update the archive at each generation with newly found non-dominated solutions.
*/
template < class MOEOT >
class moeoArchiveUpdater : public eoUpdater
{
public:
/**
* Ctor
* @param _arch an archive of non-dominated solutions
* @param _pop the main population
*/
moeoArchiveUpdater(moeoArchive < MOEOT > & _arch, const eoPop < MOEOT > & _pop) : arch(_arch), pop(_pop)
{}
/**
* Updates the archive with newly found non-dominated solutions contained in the main population
*/
void operator()()
{
arch(pop);
}
private:
/** the archive of non-dominated solutions */
moeoArchive < MOEOT > & arch;
/** the main population */
const eoPop < MOEOT > & pop;
};
#endif /*MOEOARCHIVEUPDATER_H_*/

View file

@ -0,0 +1,91 @@
/*
* <moeoComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2009
*
*
* Waldo Cancino, Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOAVERAGEOBJVECSTAT_H_
#define MOEOAVERAGEOBJVECSTAT_H_
#include <utils/moeoObjVecStat.h>
/** Calculates average scores for each objective
*/
template <class MOEOT> class moeoAverageObjVecStat : public moeoObjVecStat<MOEOT>
{
public :
using moeoObjVecStat<MOEOT>::value;
typedef typename moeoObjVecStat<MOEOT>::ObjectiveVector ObjectiveVector;
moeoAverageObjVecStat(std::string _description = "Average Objective Vector")
: moeoObjVecStat<MOEOT>(_description) {}
virtual std::string className(void) const { return "moeoAverageObjVecStat"; }
private :
typedef typename MOEOT::ObjectiveVector::Type Type;
template<typename T> struct sumObjVec
{
sumObjVec(unsigned _which) : which(_which) {}
Type operator()(Type &result, const MOEOT& _obj)
{
return result + _obj.objectiveVector()[which];
}
unsigned which;
};
// Specialization for pareto fitness
void doit(const eoPop<MOEOT>& _pop)
{
typedef typename moeoObjVecStat<MOEOT>::Traits traits;
value().resize(traits::nObjectives());
for (unsigned o = 0; o < value().size(); ++o)
{
value()[o] = std::accumulate(_pop.begin(), _pop.end(), Type(), sumObjVec<Type>(o));
value()[o] /= _pop.size();
}
}
};
#endif

View file

@ -0,0 +1,110 @@
/*
* <moeoComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2009
*
*
* Waldo Cancino, Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOBESTOBJVECSTAT_H_
#define MOEOBESTOBJVECSTAT_H_
#include <utils/moeoObjVecStat.h>
/** Calculate the best solution for each objective (extreme points
*/
template <class MOEOT>
class moeoBestObjVecStat : public moeoObjVecStat<MOEOT>
{
public:
using moeoObjVecStat<MOEOT>::value;
typedef typename moeoObjVecStat<MOEOT>::ObjectiveVector ObjectiveVector;
moeoBestObjVecStat(std::string _description = "Best ")
: moeoObjVecStat<MOEOT>(_description)
{}
virtual std::string className(void) const { return "moeoBestObjVecStat"; }
/**
Return the best solutions for an given objective function
* @param which the objective function number
*/
const MOEOT & bestindividuals(unsigned int which) {
typedef typename moeoObjVecStat<MOEOT>::Traits traits;
if(which > traits::nObjectives() ) throw std::logic_error("which is larger than the number of objectives");
return *(best_individuals[which]);
}
private :
/** Vector of iterators pointing to best individuals for each objective function */
std::vector<typename eoPop<MOEOT>::const_iterator> best_individuals;
struct CmpObjVec
{
CmpObjVec(unsigned _which, bool _maxim) : which(_which), maxim(_maxim) {}
bool operator()(const MOEOT& a, const MOEOT& b)
{
if (maxim)
return a.objectiveVector()[which] < b.objectiveVector()[which];
return a.objectiveVector()[which] > b.objectiveVector()[which];
}
unsigned which;
bool maxim;
};
// Specialization for objective vector
void doit(const eoPop<MOEOT>& _pop)
{
typedef typename moeoObjVecStat<MOEOT>::Traits traits;
value().resize(traits::nObjectives());
for (unsigned o = 0; o < traits::nObjectives(); ++o)
{
typename eoPop<MOEOT>::const_iterator it = std::max_element(_pop.begin(), _pop.end(), CmpObjVec(o, traits::maximizing(o)));
value()[o] = it->objectiveVector()[o];
best_individuals.push_back( it );
}
}
// default
};
#endif

View file

@ -0,0 +1,119 @@
/*
* <moeoBinaryMetricSavingUpdater.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOBINARYMETRICSAVINGUPDATER_H_
#define MOEOBINARYMETRICSAVINGUPDATER_H_
#include <fstream>
#include <string>
#include <vector>
#include <eoPop.h>
#include <utils/eoUpdater.h>
#include <metric/moeoMetric.h>
/**
* This class allows to save the progression of a binary metric comparing the objective vectors of the current population (or archive)
* with the objective vectors of the population (or archive) of the generation (n-1) into a file
*/
template < class MOEOT >
class moeoBinaryMetricSavingUpdater : public eoUpdater
{
public:
/** The objective vector type of a solution */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Ctor
* @param _metric the binary metric comparing two Pareto sets
* @param _pop the main population
* @param _filename the target filename
*/
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
metric(_metric), pop(_pop), filename(_filename), counter(1), firstGen(true)
{}
/**
* Saves the metric's value for the current generation
*/
void operator()()
{
if (pop.size())
{
if (firstGen)
{
firstGen = false;
}
else
{
// creation of the two Pareto sets
std::vector < ObjectiveVector > from;
std::vector < ObjectiveVector > to;
for (unsigned int i=0; i<pop.size(); i++)
from.push_back(pop[i].objectiveVector());
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);
f << counter++ << ' ' << metric(from,to) << std::endl;
f.close();
}
oldPop = pop;
}
}
private:
/** binary metric comparing two Pareto sets */
moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
/** main population */
const eoPop < MOEOT > & pop;
/** (n-1) population */
eoPop< MOEOT > oldPop;
/** target filename */
std::string filename;
/** is it the first generation ? */
bool firstGen;
/** counter */
unsigned int counter;
};
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/

View file

@ -0,0 +1,69 @@
/*
* <moeoConvertPopToObjectiveVectors.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOPOPTOOBJECTIVEVECTORS_H_
#define MOEOPOPTOOBJECTIVEVECTORS_H_
#include <vector>
#include <eoFunctor.h>
/**
* Functor allowing to get a vector of objective vectors from a population
*/
template < class MOEOT, class ObjectiveVector = typename MOEOT::ObjectiveVector >
class moeoConvertPopToObjectiveVectors : public eoUF < const eoPop < MOEOT >, const std::vector < ObjectiveVector > >
{
public:
/**
* Returns a vector of the objective vectors from the population _pop
* @param _pop the population
*/
const std::vector < ObjectiveVector > operator()(const eoPop < MOEOT > _pop)
{
std::vector < ObjectiveVector > result;
result.resize(_pop.size());
for (unsigned int i=0; i<_pop.size(); i++)
{
result.push_back(_pop[i].objectiveVector());
}
return result;
}
};
#endif /*MOEOPOPTOOBJECTIVEVECTORS_H_*/

View file

@ -0,0 +1,235 @@
/*
* <moeoDominanceMatrix.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008
* (C) OPAC Team, LIFL, 2002-2008
*
* Arnaud Liefooghe
* Jeremie Humeau
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
// moeoDominanceMatrix.h
//-----------------------------------------------------------------------------
#ifndef MOEODOMINANCEMATRIX_H_
#define MOEODOMINANCEMATRIX_H_
#include <set>
/**
* moeoDominanceMatrix allow to know if an MOEOT dominates another one or not. Can be apply on one or two eoPop.
*/
template <class MOEOT>
class moeoDominanceMatrix: public eoBF< eoPop< MOEOT >&, eoPop< MOEOT >& , void>,eoUF<eoPop <MOEOT>&,void>, std::vector < std::vector<bool> > {
public:
using std::vector< std::vector<bool> >::size;
using std::vector< std::vector<bool> >::resize;
using std::vector< std::vector<bool> >::operator[];
using std::vector< std::vector<bool> >::begin;
using std::vector< std::vector<bool> >::end;
/** The type for objective vector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
/**
* Constructor which allow to choose the comparator
* @param _nocopy boolean allow to consider copy and doublons as bad element whose were dominated by all other MOEOT
* @param _comparator the comparator you want to use for the comparaison of two MOEOT
*/
moeoDominanceMatrix(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, bool _nocopy=true):std::vector < std::vector<bool> >(),comparator(_comparator), nocopy(_nocopy) {}
/**
* Default constructor with paretoComparator
* @param _nocopy boolean allow to consider copy and doublons as bad element whose were dominated by all other MOEOT
*/
moeoDominanceMatrix(bool _nocopy=false):std::vector < std::vector<bool> >(),comparator(paretoComparator), nocopy(_nocopy) {}
/**
* Filling up the Dominance Matrix on one population
* @param _pop first population
*/
void operator()(eoPop<MOEOT>& _pop) {
eoPop <MOEOT> dummyPop;
(*this).operator()(_pop, dummyPop);
}
/**
* Filling up the Dominance Matrix of first and second population (if you have only one population, the second must be empty)
* @param _pop1 first population
* @param _pop2 second population
*/
void operator()(eoPop<MOEOT>& _pop1,eoPop<MOEOT>& _pop2) {
//Initialization
unsigned int i= _pop1.size();
unsigned int j= _pop2.size();
resize(i+j);
countVector.resize(i+j);
rankVector.resize(i+j);
for (unsigned int k=0; k < i+j; k++) {
(*this)[k].resize(i+j);
countVector[k]=0;
rankVector[k]=0;
for (unsigned l=0; l<i+j; l++)
(*this)[k][l]=false;
}
//filling up of matrix, count and rank vectors
for (unsigned int k=0; k<i+j-1; k++) {
for (unsigned int l=k+1; l<i+j; l++) {
if ( (k < i) && (l < i) ) {
if ( comparator(_pop1[l].objectiveVector(), _pop1[k].objectiveVector())) {
(*this)[k][l]=true;
countVector[k]++;
rankVector[l]++;
}
else if ( comparator(_pop1[k].objectiveVector(), _pop1[l].objectiveVector())) {
(*this)[l][k]=true;
countVector[l]++;
rankVector[k]++;
}
else if (nocopy && (_pop1[k].objectiveVector() == _pop1[l].objectiveVector()))
copySet.insert(l);
}
else if (( (k < i) && (l >= i) )) {
if ( comparator(_pop2[l-i].objectiveVector(), _pop1[k].objectiveVector())) {
(*this)[k][l]=true;
countVector[k]++;
rankVector[l]++;
}
else if ( comparator(_pop1[k].objectiveVector(), _pop2[l-i].objectiveVector())) {
(*this)[l][k]=true;
countVector[l]++;
rankVector[k]++;
}
else if (nocopy && (_pop1[k].objectiveVector() == _pop2[l-i].objectiveVector()))
copySet.insert(l);
}
else {
if ( comparator(_pop2[l-i].objectiveVector(), _pop2[k-i].objectiveVector())) {
(*this)[k][l]=true;
countVector[k]++;
rankVector[l]++;
}
else if ( comparator(_pop2[k-i].objectiveVector(), _pop2[l-i].objectiveVector())) {
(*this)[l][k]=true;
countVector[l]++;
rankVector[k]++;
}
else if (nocopy && (_pop2[k-i].objectiveVector() == _pop2[l-i].objectiveVector()))
copySet.insert(l);
}
}
}
//if we don't want copy, matrix, rankVector and countVector are updating
if (nocopy) {
std::set<unsigned int>::iterator it=copySet.begin();
while (it!=copySet.end()) {
for (unsigned int l=0; l< (*this).size(); l++) {
if (!(*this)[l][*it]) {
(*this)[l][*it]=true;
countVector[l]++;
}
}
it++;
}
it=copySet.begin();
while (it!=copySet.end()) {
for (unsigned int l=0; l< (*this).size(); l++) {
if ((*this)[*it][l]) {
(*this)[*it][l]=false;
rankVector[l]--;
}
}
it++;
}
it=copySet.begin();
while (it!=copySet.end()) {
countVector[*it]=0;
rankVector[*it]=(*this).size()-copySet.size();
it++;
}
}
/*
for(unsigned k=0; k<i+j; k++)
for(unsigned l=0; l<i+j; l++){
std::cout << (*this)[k][l];
if(l==i+j-1)
std::cout << "\n";
else
std::cout << " ";
}
for(unsigned k=0; k<i+j; k++){
std::cout << "rank " << k << " : " << rankVector[k] << "\n";
std::cout << "count " << k << " : " << countVector[k] << "\n";
}*/
}
/**
* @param _i the index of the element that we want RankDominanceFitness
* @return RankDominanceFitness of element of index _i
*/
double rank(unsigned int _i) {
return rankVector[_i];
}
/**
* @param _i the index of the element that we want CountDominanceFitness
* @return CountDominanceFitness of element of index _i
*/
double count(unsigned int _i) {
return countVector[_i];
}
private:
/** Functor to compare two objective vectors */
moeoObjectiveVectorComparator < ObjectiveVector > & comparator;
/** Functor to compare two objective vectors according to Pareto dominance relation */
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
/** boolean allow or not to pull away a copy*/
bool nocopy;
/** vector contains CountDominanceFitnessAssignment */
std::vector<double> countVector;
/** vector contains CountRankFitnessAssignment */
std::vector<double> rankVector;
/** vector contains index of copys */
std::set<unsigned int> copySet;
};
#endif /*MOEODOMINANCEMATRIX_H_*/

View file

@ -0,0 +1,48 @@
#ifndef moeoFullEvalByCopy_H
#define moeoFullEvalByCopy_H
#include <eoEvalFunc.h>
#include <eval/moEval.h>
/**
* Evaluation by copy
*/
template<class Neighbor>
class moeoFullEvalByCopy : public moEval<Neighbor>
{
public:
typedef typename moEval<Neighbor>::EOT EOT;
typedef typename moEval<Neighbor>::Fitness Fitness;
/**
* Ctor
* @param _eval the full evaluation object
*/
moeoFullEvalByCopy(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
/**
* Full evaluation of the neighbor by copy
* @param _sol current solution
* @param _neighbor the neighbor to be evaluated
*/
void operator()(EOT & _sol, Neighbor & _neighbor)
{
// tmp solution
EOT tmp(_sol);
// move tmp solution wrt _neighbor
_neighbor.move(tmp);
// eval copy
tmp.invalidate();
eval(tmp);
// set the fitness value to the neighbor
_neighbor.fitness(tmp.objectiveVector());
}
private:
/** the full evaluation object */
eoEvalFunc<EOT> & eval;
};
#endif

View file

@ -0,0 +1,70 @@
/*
* <moeoComparator.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2009
*
*
* Waldo Cancino, Arnaud Liefooghe
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJVECSTAT_H_
#define MOEOOBJVECSTAT_H_
#include <utils/eoStat.h>
/**
This base class is a specialization of eoStat which is useful
to compute statistics for each objective function
*/
#if defined(_MSC_VER) && (_MSC_VER < 1300)
template <class MOEOT>
class moeoObjVecStat : public eoStat<MOEOT, MOEOT::ObjectiveVector>
#else
template <class MOEOT>
class moeoObjVecStat : public eoStat<MOEOT, typename MOEOT::ObjectiveVector>
#endif
{
public:
using eoStat<MOEOT, typename MOEOT::ObjectiveVector>::value;
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
typedef typename MOEOT::ObjectiveVector::Traits Traits;
moeoObjVecStat(std::string _description = "")
: eoStat<MOEOT, ObjectiveVector>(ObjectiveVector(), _description)
{}
virtual void operator()(const eoPop<MOEOT>& _pop) { doit(_pop); };
private:
virtual void doit(const eoPop<MOEOT> &_pop) = 0;
};
#endif

View file

@ -0,0 +1,304 @@
/*
* <moeoObjectiveVectorNormalizer.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2009
*
* Legillon François
*
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
* Contact: paradiseo-help@lists.gforge.inria.fr
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJVECNORM_H_
#define MOEOOBJVECNORM_H_
#include <eoPop.h>
#include <utils/eoRealBounds.h>
/**
class to normalize each dimension of objectiveVectors
*/
template <class MOEOT>
class moeoObjectiveVectorNormalizer
{
public:
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
typedef typename MOEOT::ObjectiveVector::Type Type;
typedef typename std::vector<std::vector<Type> > Scale;
typedef eoRealInterval Bounds;
/**
constructor with a supplied scale, usefull if you tweak your scale
@param _scale the scale for noramlzation
@param max_param the returned values will be between 0 and max
*/
moeoObjectiveVectorNormalizer(Scale _scale=make_dummy_scale(),Type max_param=100):scale(_scale),max(max_param)
{}
/**
constructor to create a normalizer from a given population
@param _pop the population to analyse to create the scale
@param max_param the returned values will be between 0 and max
*/
moeoObjectiveVectorNormalizer(eoPop<MOEOT> &_pop, Type max_param=100):scale(make_scale_from_pop(_pop,max_param)),max(max_param)
{}
/**
constructor to create a normalizer with given boundaries
@param _boundaries the supplied vectors should have their values between thos boundaries
@param max_param the returned values will be between 0 and max
**/
moeoObjectiveVectorNormalizer(std::vector<Bounds> &_boundaries, Type max_param=100):scale(make_scale_from_bounds(_boundaries,max_param)), max(max_param)
{}
/**
constructor to create a normalizer from bounds
@param _bounds the supplied vectors should have their value in those bounds
@param max_param the returned values will be between 0 and max
**/
moeoObjectiveVectorNormalizer(Bounds &_bounds, Type max_param=100 ):scale(make_scale_from_bounds(_bounds,max_param)), max(max_param)
{}
/**
constructor to create a normalizer from a worst vector and a best vector
@param _worst the worst possible vector
@param _best the best possible vector
@param max_param the maximum value for returned objectives
*/
moeoObjectiveVectorNormalizer(const ObjectiveVector &_best,const ObjectiveVector &_worst, Type max_param=100 ):scale(make_scale_from_minmax(_best,_worst,max_param)), max(max_param)
{}
/**
* Creates a scale which can be used in conjonction with a normalizer
* @param _pop the population to analyse
* @param max_param worst vector is set to it
* @return a scale to use with the normalizer
*/
static Scale make_scale_from_pop(eoPop<MOEOT> &_pop, Type max_param=100){
Scale res;
if (_pop.empty()) {
std::cout<<"makeScale in moeoObjectiveVEctorNormalizer.h: pop is empty"<<std::endl;
return res;
}
unsigned int dim=_pop[0].objectiveVector().nObjectives();
std::vector<Type> amps;
std::vector<Type> mins;
unsigned int num_amp_max=0;
//recherche des min et du max, par dimension
for (unsigned int i=0;i<dim;i++){
Type min=_pop[0].objectiveVector()[i];
Type max=_pop[0].objectiveVector()[i];
unsigned int pop_size=_pop.size();
for (unsigned int j=0;j<pop_size;j++){
if (_pop[j].objectiveVector()[i]< min) min=_pop[j].objectiveVector()[i];
if (_pop[j].objectiveVector()[i]> max) max=_pop[j].objectiveVector()[i];
}
amps.push_back(max-min);
mins.push_back(min);
if (max-min>amps[num_amp_max])
num_amp_max=i;
}
Type amp_max=amps[num_amp_max];
for (unsigned int i=0;i<dim;i++){
std::vector<Type> coefs;
if(!max_param){
coefs.push_back(amps[i]==0?1:amp_max/amps[i]);
}
else{
coefs.push_back(amps[i]==0?1:max_param/amps[i]);
}
coefs.push_back(mins[i]);
res.push_back(coefs);
}
return res;
}
/**
create a scale from bounds
@param _boundaries the boundaries
@param max the maximum for returned values
@return a scale
*/
static Scale make_scale_from_bounds(const std::vector<Bounds> &_boundaries,Type max=100){
Scale res;
for (unsigned i=0;i<_boundaries.size();i++){
std::vector<Type> coeff;
coeff.push_back(max/(_boundaries[i].maximum()-_boundaries[i].minimum()));
coeff.push_back(_boundaries[i].minimum());
res.push_back(coeff);
}
return res;
}
/**
create a scale from bounds
@param bounds the bounds (the same for each dimension)
@param max the maximum for returned values
@return a scale
*/
static Scale make_scale_from_bounds(const Bounds &bounds,Type max=100){
Scale res;
unsigned int dim=MOEOT::ObjectiveVector::nObjectives();
for (unsigned i=0;i<dim;i++){
std::vector<Type> coeff;
coeff.push_back(max/(bounds.maximum()-bounds.minimum()));
coeff.push_back(bounds.minimum());
res.push_back(coeff);
}
return res;
}
/**
create a scale from a point with minimums in each dimension, and a point with ther max in each dimension
@param best the point with all mins
@param worst the point with all maxs
@param max the maximum for returned values
@return a scale
*/
static Scale make_scale_from_minmax(const ObjectiveVector &best, const ObjectiveVector &worst,Type max=100){
Scale res;
for (unsigned i=0;i<worst.nObjectives();i++){
std::vector<Type> coeff;
coeff.push_back(max/(worst[i]-best[i]));
coeff.push_back(best[i]);
res.push_back(coeff);
}
return res;
}
/**
create a default scale that does nothing when applied
@return a dummy scale
*/
static Scale make_dummy_scale(){
unsigned int dim=MOEOT::ObjectiveVector::nObjectives();
Scale res;
for (unsigned int i=0;i<dim;i++){
std::vector<Type> coeff;
coeff.push_back(1);
coeff.push_back(0);
res.push_back(coeff);
}
return res;
}
/**
* main fonction, normalize a vector. All objective returned vectors will be between 0 and max previously
* supplied, be carefull about a possible rounding error.
* @param _vec the vector
* @return the normalized vector
*/
virtual ObjectiveVector operator()(const ObjectiveVector &_vec){
unsigned int dim=_vec.nObjectives();
ObjectiveVector res;
for (unsigned int i=0;i<dim;i++){
res[i]=(_vec[i]-scale[i][1])*scale[i][0];
}
return res;
}
/**
normalize a population
@param pop the population to normalize
@return a vector of normalized Objective vectors
*/
std::vector<ObjectiveVector> operator()(const eoPop<MOEOT> &pop){
std::vector<ObjectiveVector> res;
for (unsigned int i=0;i<pop.size();i++){
res.push_back(operator()(pop[i].objectiveVector()));
}
return res;
}
/**
fast(to use, not in complexity) function to normalize a population
@param pop the population to normalize
@param max the returned values will be between 0 and max
@return a vector of normalized Objective vectors < max
*/
static std::vector<ObjectiveVector> normalize(const eoPop<MOEOT> &pop, Type &max){
moeoObjectiveVectorNormalizer normalizer(pop,true, max);
return normalizer(pop);
}
/**
Change the scale according to a new pop. Should be called everytime pop is updated
@param pop population to analyse
*/
void update_by_pop(eoPop<MOEOT> pop){
scale=make_scale_from_pop(pop,max);
}
/** change the scale with the worst point and the best point
@param _max the worst point
@param _min the best point
*/
void update_by_min_max(const ObjectiveVector &_min,const ObjectiveVector &_max){
scale=make_scale_from_minmax(_min,_max,max);
}
/** change the scale according to given boundaries
@param boundaries a vector of bounds corresponding to the bounds in each dimension
*/
void update_by_bounds(const std::vector<Bounds> &boundaries){
scale=make_scale_from_bounds(boundaries);
}
/** change the scale according to bounds,them same is used in each dimension
@param bounds bounds corresponding to the bounds in each dimension
*/
void update_by_bounds(const Bounds &bounds){
scale=make_scale_from_bounds(bounds);
}
/**
updates the scale
@param _scale the new scale
*/
void update_scale(Scale _scale){
scale=_scale;
}
/**
change the maximum returned by the normalizer (if the scale is adapted)
@param _max the maximum returned
*/
void change_max(Type _max){
for (unsigned int i=0;i<scale.size();i++){
if (max) scale[i][0]=scale[i][0]*_max/max;
}
max=_max;
}
private:
Scale scale;
Type max;
};
#endif