merge ParadisEO-MOEO v-1.0

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@400 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
liefooga 2007-06-26 13:28:59 +00:00
commit 8b7d5260fb
724 changed files with 63305 additions and 2757 deletions

View file

@ -0,0 +1,291 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// MOEO.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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 < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
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;
/** 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");
}
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 fitness value is 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,9 @@
lib_LIBRARIES = libmoeo.a
libmoeo_a_SOURCES = moeoObjectiveVectorTraits.cpp
pkginclude_HEADERS = moeoObjectiveVectorTraits.h
INCLUDES = -I$(EO_DIR)/src/ -I$(top_srcdir)/src/
AM_CXXFLAGS = -Wall -ansi -pedantic

View file

@ -0,0 +1,74 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoBitVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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, class MOEODiversity >
class moeoBitVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool >
{
public:
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: begin;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: end;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: resize;
using moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, bool > :: 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, MOEOFitness, MOEODiversity, bool >(_size, _value)
{}
/**
* 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,24 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoEvalFunc.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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,91 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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,166 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorDouble.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
*/
//-----------------------------------------------------------------------------
#ifndef MOEOOBJECTIVEVECTORDOUBLE_H_
#define MOEOOBJECTIVEVECTORDOUBLE_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 doubles,
* i.e. that an objective value is represented using a double, and this for any objective.
*/
template < class ObjectiveVectorTraits >
class moeoObjectiveVectorDouble : public moeoObjectiveVector < ObjectiveVectorTraits, double >
{
public:
using moeoObjectiveVector < ObjectiveVectorTraits, double >::size;
using moeoObjectiveVector < ObjectiveVectorTraits, double >::operator[];
/**
* Ctor
*/
moeoObjectiveVectorDouble(double _value = 0.0) : moeoObjectiveVector < ObjectiveVectorTraits, double > (_value)
{}
/**
* Ctor from a vector of doubles
* @param _v the std::vector < double >
*/
moeoObjectiveVectorDouble(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 moeoObjectiveVectorDouble object to compare with
*/
bool dominates(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
moeoParetoObjectiveVectorComparator < moeoObjectiveVectorDouble<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 moeoObjectiveVectorDouble object to compare with
*/
bool operator==(const moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble object to compare with
*/
bool operator!=(const moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble object to compare with
*/
bool operator<(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
moeoObjectiveObjectiveVectorComparator < moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble object to compare with
*/
bool operator>(const moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble object to compare with
*/
bool operator<=(const moeoObjectiveVectorDouble < 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 moeoObjectiveVectorDouble object to compare with
*/
bool operator>=(const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _other) const
{
return operator==(_other) || operator>(_other);
}
};
/**
* Output for a moeoObjectiveVectorDouble object
* @param _os output stream
* @param _objectiveVector the objective vector to write
*/
template < class ObjectiveVectorTraits >
std::ostream & operator<<(std::ostream & _os, const moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
{
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_os << _objectiveVector[i] << '\t';
}
return _os;
}
/**
* Input for a moeoObjectiveVectorDouble object
* @param _is input stream
* @param _objectiveVector the objective vector to read
*/
template < class ObjectiveVectorTraits >
std::istream & operator>>(std::istream & _is, moeoObjectiveVectorDouble < ObjectiveVectorTraits > & _objectiveVector)
{
_objectiveVector = moeoObjectiveVectorDouble < ObjectiveVectorTraits > ();
for (unsigned int i=0; i<_objectiveVector.size(); i++)
{
_is >> _objectiveVector[i];
}
return _is;
}
#endif /*MOEOOBJECTIVEVECTORDOUBLE_H_*/

View file

@ -0,0 +1,17 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorTraits.cpp
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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,103 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoObjectiveVectorTraits.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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-6;
}
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,36 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoRealVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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, class MOEODiversity >
class moeoRealVector : public moeoVector < MOEOObjectiveVector, MOEOFitness, MOEODiversity, double >
{
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, MOEOFitness, MOEODiversity, double >(_size, _value)
{}
};
#endif /*MOEOREALVECTOR_H_*/

View file

@ -0,0 +1,143 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// moeoVector.h
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
/*
This library...
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.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 MOEOFitness, class MOEODiversity, class GeneType >
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, MOEOFitness, MOEODiversity, GeneType> & _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, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _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, MOEOFitness, MOEODiversity, GeneType> & _moeo1, const moeoVector< MOEOObjectiveVector, MOEOFitness, MOEODiversity, GeneType> & _moeo2)
{
return _moeo1.operator>(_moeo2);
}
#endif /*MOEOVECTOR_H_*/