modif cmake configuration

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1277 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2008-12-03 14:41:25 +00:00
commit 350bdfc7de
1261 changed files with 144616 additions and 0 deletions

View file

@ -0,0 +1,355 @@
/*
* <MOEO.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 MOEO_H_
#define MOEO_H_
#include <iostream>
#include <stdexcept>
#include <string>
#include <EO.h>
/**
* Base class allowing to represent a solution (an individual) for multi-objective optimization.
* The template argument MOEOObjectiveVector allows to represent the solution in the objective space (it can be a moeoObjectiveVector object).
* 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.
*/
/*
template < typename DataType, typename DataTypeEx > struct Wrapper {
Wrapper() {}
Wrapper( const DataType& data )
: embededData( data ) {}
Wrapper( const Wrapper& wrapper )
: embededData( wrapper.embededData ), embededDataEx( wrapper.embededDataEx ) {}
operator const DataType& () const { return embededData; }
Wrapper& operator= ( const Wrapper& wrapper ) {
embededData = wrapper.embededData;
embededDataEx = wrapper.embededDataEx;
return *this;
}
Wrapper& operator= ( const DataType& data ) {
embededData = data;
return *this;
}
DataType embededData;
DataTypeEx embededDataEx;
};
**/
template < class MOEOObjectiveVector, class MOEOFitness=double, class MOEODiversity=double >
class MOEO : public EO < MOEOObjectiveVector >
{
public:
/** the objective vector type of a solution */
typedef MOEOObjectiveVector ObjectiveVector;
/** the fitness type of a solution */
typedef MOEOFitness Fitness;
// typedef Wrapper< MOEOFitness, MOEOObjectiveVector > Fitness;
/** the diversity type of a solution */
typedef MOEODiversity Diversity;
/**
* Ctor
*/
MOEO()
{
// default values for every parameters
objectiveVectorValue = ObjectiveVector();
fitnessValue = Fitness();
diversityValue = Diversity();
// invalidate all
invalidate();
}
/**
* Virtual dtor
*/
virtual ~MOEO()
{};
/**
* Returns the objective vector of the current solution
*/
ObjectiveVector objectiveVector() const
{
if ( invalidObjectiveVector() )
{
throw std::runtime_error("invalid objective vector in MOEO");
}
return objectiveVectorValue;
}
/**
* Sets the objective vector of the current solution
* @param _objectiveVectorValue the new objective vector
*/
void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
{
objectiveVectorValue = _objectiveVectorValue;
invalidObjectiveVectorValue = false;
}
/**
* Sets the objective vector as invalid
*/
void invalidateObjectiveVector()
{
invalidObjectiveVectorValue = true;
}
/**
* Returns true if the objective vector is invalid, false otherwise
*/
bool invalidObjectiveVector() const
{
return invalidObjectiveVectorValue;
}
/**
* Returns the fitness value of the current solution
*/
Fitness fitness() const
{
if ( invalidFitness() )
{
throw std::runtime_error("invalid fitness in MOEO");
}
// const_cast< Fitness& >( fitnessValue ).embededDataEx = objectiveVectorValue;
return fitnessValue;
}
/**
* Sets the fitness value of the current solution
* @param _fitnessValue the new fitness value
*/
void fitness(const Fitness & _fitnessValue)
{
fitnessValue = _fitnessValue;
invalidFitnessValue = false;
}
/**
* Sets the fitness value as invalid
*/
void invalidateFitness()
{
invalidFitnessValue = true;
}
/**
* Returns true if the fitness value is invalid, false otherwise
*/
bool invalidFitness() const
{
return invalidFitnessValue;
}
/**
* Returns the diversity value of the current solution
*/
Diversity diversity() const
{
if ( invalidDiversity() )
{
throw std::runtime_error("invalid diversity in MOEO");
}
return diversityValue;
}
/**
* Sets the diversity value of the current solution
* @param _diversityValue the new diversity value
*/
void diversity(const Diversity & _diversityValue)
{
diversityValue = _diversityValue;
invalidDiversityValue = false;
}
/**
* Sets the diversity value as invalid
*/
void invalidateDiversity()
{
invalidDiversityValue = true;
}
/**
* Returns true if the diversity value is invalid, false otherwise
*/
bool invalidDiversity() const
{
return invalidDiversityValue;
}
/**
* Sets the objective vector, the fitness value and the diversity value as invalid
*/
void invalidate()
{
invalidateObjectiveVector();
invalidateFitness();
invalidateDiversity();
}
/**
* Returns true if the objective values are invalid, false otherwise
*/
bool invalid() const
{
return invalidObjectiveVector();
}
/**
* Returns true if the objective vector of the current solution is smaller than the objective vector of _other on the first objective,
* then on the second, and so on (can be usefull for sorting/printing).
* You should implement another function in the sub-class of MOEO to have another sorting mecanism.
* @param _other the other MOEO object to compare with
*/
bool operator<(const MOEO & _other) const
{
return objectiveVector() < _other.objectiveVector();
}
/**
* Return the class id (the class name as a std::string)
*/
virtual std::string className() const
{
return "MOEO";
}
/**
* Writing object
* @param _os output stream
*/
virtual void printOn(std::ostream & _os) const
{
if ( invalidObjectiveVector() )
{
_os << "INVALID\t";
}
else
{
_os << objectiveVectorValue << '\t';
}
}
/**
* Reading object
* @param _is input stream
*/
virtual void readFrom(std::istream & _is)
{
std::string objectiveVector_str;
int pos = _is.tellg();
_is >> objectiveVector_str;
if (objectiveVector_str == "INVALID")
{
invalidateObjectiveVector();
}
else
{
invalidObjectiveVectorValue = false;
_is.seekg(pos); // rewind
_is >> objectiveVectorValue;
}
}
private:
/** the objective vector of this solution */
ObjectiveVector objectiveVectorValue;
/** true if the objective vector is invalid */
bool invalidObjectiveVectorValue;
/** the fitness value of this solution */
Fitness fitnessValue;
/** true if the fitness value is invalid */
bool invalidFitnessValue;
/** the diversity value of this solution */
Diversity diversityValue;
/** true if the diversity value is invalid */
bool invalidDiversityValue;
};
#endif /*MOEO_H_*/

View file

@ -0,0 +1,108 @@
/*
* <moeoBitVector.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 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=double, class MOEODiversity=double >
class moeoBitVector : public moeoVector < MOEOObjectiveVector, bool, MOEOFitness, MOEODiversity >
{
public:
using moeoVector < MOEOObjectiveVector, bool, MOEOFitness, MOEODiversity > :: begin;
using moeoVector < MOEOObjectiveVector, bool, MOEOFitness, MOEODiversity > :: end;
using moeoVector < MOEOObjectiveVector, bool, MOEOFitness, MOEODiversity > :: resize;
using moeoVector < MOEOObjectiveVector, bool, MOEOFitness, MOEODiversity > :: 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, bool, MOEOFitness, MOEODiversity >(_size, _value)
{}
/**
* Returns the class name as a std::string
*/
virtual std::string className() const
{
return "moeoBitVector";
}
/**
* 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,50 @@
/*
* <moeoEvalFunc.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 MOEOEVALFUNC_H_
#define MOEOEVALFUNC_H_
#include <eoEvalFunc.h>
/*
* Functor that evaluates one MOEO by setting all its objective values.
*/
template < class MOEOT >
class moeoEvalFunc : public eoEvalFunc< MOEOT >
{};
#endif /*MOEOEVALFUNC_H_*/

View file

@ -0,0 +1,71 @@
/*
* <moeoIntVector.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
*
* Arnaud Liefooghe
* Jérémie 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
*
*/
//-----------------------------------------------------------------------------
#ifndef MOEOINTVECTOR_H_
#define MOEOINTVECTOR_H_
#include <core/moeoVector.h>
/**
* This class is an implementation of a simple double-valued moeoVector.
*/
template < class MOEOObjectiveVector, class MOEOFitness=double, class MOEODiversity=double >
class moeoIntVector : public moeoVector < MOEOObjectiveVector, int, MOEOFitness, MOEODiversity >
{
public:
/**
* Ctor
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type GeneType)
*/
moeoIntVector(unsigned int _size = 0, int _value = 0) : moeoVector< MOEOObjectiveVector, int, MOEOFitness, MOEODiversity >(_size, _value)
{}
/**
* Returns the class name as a std::string
*/
virtual std::string className() const
{
return "moeoIntVector";
}
};
#endif /*MOEOINTVECTOR_H_*/

View file

@ -0,0 +1,116 @@
/*
* <moeoObjectiveVector.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 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

@ -0,0 +1,42 @@
/*
* <moeoObjectiveVectorTraits.cpp>
* 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
*
*/
//-----------------------------------------------------------------------------
#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

@ -0,0 +1,130 @@
/*
* <moeoObjectiveVectorTraits.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 MOEOOBJECTIVEVECTORTRAITS_H_
#define MOEOOBJECTIVEVECTORTRAITS_H_
#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.
*/
class moeoObjectiveVectorTraits
{
public:
/**
* Parameters setting
* @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)
{
// in case the number of objectives was already set to a different value
if ( nObj && (nObj != _nObjectives) )
{
std::cout << "WARNING\n";
std::cout << "WARNING : the number of objectives are changing\n";
std::cout << "WARNING : Make sure all existing objects are destroyed\n";
std::cout << "WARNING\n";
}
// number of objectives
nObj = _nObjectives;
// min/max vector
bObj = _bObjectives;
// in case the number of objectives and the min/max vector size don't match
if (nObj != bObj.size())
throw std::runtime_error("Number of objectives and min/max size don't match in moeoObjectiveVectorTraits::setup");
}
/**
* Returns the number of objectives
*/
static unsigned int nObjectives()
{
// in case the number of objectives would not be assigned yet
if (! nObj)
throw std::runtime_error("Number of objectives not assigned in moeoObjectiveVectorTraits");
return nObj;
}
/**
* Returns true if the _ith objective have to be minimized
* @param _i the index
*/
static bool minimizing(unsigned int _i)
{
// in case there would be a wrong index
if (_i >= bObj.size())
throw std::runtime_error("Wrong index in moeoObjectiveVectorTraits");
return bObj[_i];
}
/**
* Returns true if the _ith objective have to be maximized
* @param _i the index
*/
static bool maximizing(unsigned int _i)
{
return (! minimizing(_i));
}
/**
* Returns the tolerance value (to compare solutions)
*/
static double tolerance()
{
return 1e-10;
}
private:
/** The number of objectives */
static unsigned int nObj;
/** The min/max vector */
static std::vector < bool > bObj;
};
#endif /*MOEOOBJECTIVEVECTORTRAITS_H_*/

View file

@ -0,0 +1,191 @@
/*
* <moeoRealObjectiveVector.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 MOEOREALOBJECTIVEVECTOR_H_
#define MOEOREALOBJECTIVEVECTOR_H_
#include <iostream>
#include <math.h>
#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 real values,
* i.e. that an objective value is represented using a double, and this for any objective.
*/
template < class ObjectiveVectorTraits >
class moeoRealObjectiveVector : public moeoObjectiveVector < ObjectiveVectorTraits, double >
{
public:
using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
/**
* Ctor
*/
moeoRealObjectiveVector(double _value = 0.0) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_value)
{}
/**
* Ctor from a vector of doubles
* @param _v the std::vector < double >
*/
moeoRealObjectiveVector(std::vector < double > & _v) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_v)
{}
/**
* Returns true if the current objective vector dominates _other according to the Pareto dominance relation
* (but it's better to use a moeoObjectiveVectorComparator object to compare solutions)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool dominates(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
moeoParetoObjectiveVectorComparator < moeoRealObjectiveVector<ObjectiveVectorTraits> > comparator;
return comparator(_other, *this);
}
/**
* Returns true if the current objective vector is equal to _other (according to a tolerance value)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool operator==(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
for (unsigned int i=0; i < size(); i++)
{
if ( fabs(operator[](i) - _other[i]) > ObjectiveVectorTraits::tolerance() )
{
return false;
}
}
return true;
}
/**
* Returns true if the current objective vector is different than _other (according to a tolerance value)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool operator!=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
return ! operator==(_other);
}
/**
* Returns true if the current objective vector is smaller than _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool operator<(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
moeoObjectiveObjectiveVectorComparator < moeoRealObjectiveVector < ObjectiveVectorTraits > > cmp;
return cmp(*this, _other);
}
/**
* Returns true if the current objective vector is greater than _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool operator>(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
return _other < *this;
}
/**
* Returns true if the current objective vector is smaller than or equal to _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool operator<=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
return operator==(_other) || operator<(_other);
}
/**
* Returns true if the current objective vector is greater than or equal to _other on the first objective, then on the second, and so on
* (can be usefull for sorting/printing)
* @param _other the other moeoRealObjectiveVector object to compare with
*/
bool operator>=(const moeoRealObjectiveVector < ObjectiveVectorTraits > & _other) const
{
return operator==(_other) || operator>(_other);
}
};
/**
* Output for a moeoRealObjectiveVector object
* @param _os output stream
* @param _objectiveVector the objective vector to write
*/
template < class ObjectiveVectorTraits >
std::ostream & operator<<(std::ostream & _os, const moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
{
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_os << _objectiveVector[i] << '\t';
}
return _os;
}
/**
* Input for a moeoRealObjectiveVector object
* @param _is input stream
* @param _objectiveVector the objective vector to read
*/
template < class ObjectiveVectorTraits >
std::istream & operator>>(std::istream & _is, moeoRealObjectiveVector < ObjectiveVectorTraits > & _objectiveVector)
{
_objectiveVector = moeoRealObjectiveVector < ObjectiveVectorTraits > ();
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_is >> _objectiveVector[i];
}
return _is;
}
#endif /*MOEOREALOBJECTIVEVECTOR_H_*/

View file

@ -0,0 +1,70 @@
/*
* <moeoRealVector.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 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=double, class MOEODiversity=double >
class moeoRealVector : public moeoVector < MOEOObjectiveVector, double, MOEOFitness, MOEODiversity >
{
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, double, MOEOFitness, MOEODiversity >(_size, _value)
{}
/**
* Returns the class name as a std::string
*/
virtual std::string className() const
{
return "moeoRealVector";
}
};
#endif /*MOEOREALVECTOR_H_*/

View file

@ -0,0 +1,168 @@
/*
* <moeoVector.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 MOEOVECTOR_H_
#define MOEOVECTOR_H_
#include <iterator>
#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).
* GeneType must have the following methods: void ctor (needed for the std::vector<>), copy ctor.
*/
template < class MOEOObjectiveVector, class GeneType, class MOEOFitness=double, class MOEODiversity=double >
class moeoVector : public MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >, public std::vector < GeneType >
{
public:
using MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity > :: invalidate;
using std::vector < GeneType > :: operator[];
using std::vector < GeneType > :: begin;
using std::vector < GeneType > :: end;
using std::vector < GeneType > :: resize;
using std::vector < GeneType > :: size;
/** the atomic type */
typedef GeneType AtomType;
/** the container type */
typedef std::vector < GeneType > ContainerType;
/**
* Default ctor.
* @param _size Length of vector (default is 0)
* @param _value Initial value of all elements (default is default value of type 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
*/
void value(const std::vector < GeneType > & _v)
{
if (_v.size() != size()) // safety check
{
if (size()) // NOT an initial empty std::vector
{
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();
}
/**
* To avoid conflicts between MOEO::operator< and std::vector<GeneType>::operator<
* @param _moeo the object to compare with
*/
bool operator<(const moeoVector< MOEOObjectiveVector, GeneType, MOEOFitness, MOEODiversity> & _moeo) const
{
return MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::operator<(_moeo);
}
/**
* 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<AtomType>(_os, " "));
}
/**
* Reading object
* @param _is input stream
*/
virtual void readFrom(std::istream & _is)
{
MOEO < MOEOObjectiveVector, MOEOFitness, MOEODiversity >::readFrom(_is);
unsigned int sz;
_is >> sz;
resize(sz);
unsigned int i;
for (i = 0; i < sz; ++i)
{
AtomType atom;
_is >> atom;
operator[](i) = atom;
}
}
};
/**
* To avoid conflicts between MOEO::operator< and std::vector<double>::operator<
* @param _moeo1 the first object to compare
* @param _moeo2 the second object to compare
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
bool operator<(const moeoVector< MOEOObjectiveVector, GeneType, MOEOFitness, MOEODiversity> & _moeo1, const moeoVector< MOEOObjectiveVector, GeneType, MOEOFitness, MOEODiversity > & _moeo2)
{
return _moeo1.operator<(_moeo2);
}
/**
* To avoid conflicts between MOEO::operator> and std::vector<double>::operator>
* @param _moeo1 the first object to compare
* @param _moeo2 the second object to compare
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity, class GeneType >
bool operator>(const moeoVector< MOEOObjectiveVector, GeneType, MOEOFitness, MOEODiversity> & _moeo1, const moeoVector< MOEOObjectiveVector, GeneType, MOEOFitness, MOEODiversity > & _moeo2)
{
return _moeo1.operator>(_moeo2);
}
#endif /*MOEOVECTOR_H_*/