New style for MOEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@788 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2007-11-16 11:29:25 +00:00
commit 39709d3d12
103 changed files with 2607 additions and 2521 deletions

View file

@ -1,4 +1,4 @@
/*
/*
* <MOEO.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -57,8 +57,8 @@
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class MOEO : public EO < MOEOObjectiveVector >
{
public:
{
public:
/** the objective vector type of a solution */
typedef MOEOObjectiveVector ObjectiveVector;
@ -75,32 +75,33 @@ public:
*/
MOEO()
{
// default values for every parameters
objectiveVectorValue = ObjectiveVector();
fitnessValue = Fitness();
diversityValue = Diversity();
// invalidate all
invalidate();
// default values for every parameters
objectiveVectorValue = ObjectiveVector();
fitnessValue = Fitness();
diversityValue = Diversity();
// invalidate all
invalidate();
}
/**
* Virtual dtor
*/
virtual ~MOEO() {};
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;
}
}
/**
@ -109,8 +110,8 @@ public:
*/
void objectiveVector(const ObjectiveVector & _objectiveVectorValue)
{
objectiveVectorValue = _objectiveVectorValue;
invalidObjectiveVectorValue = false;
objectiveVectorValue = _objectiveVectorValue;
invalidObjectiveVectorValue = false;
}
@ -119,7 +120,7 @@ public:
*/
void invalidateObjectiveVector()
{
invalidObjectiveVectorValue = true;
invalidObjectiveVectorValue = true;
}
@ -127,22 +128,22 @@ public:
* 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;
}
}
/**
@ -151,8 +152,8 @@ public:
*/
void fitness(const Fitness & _fitnessValue)
{
fitnessValue = _fitnessValue;
invalidFitnessValue = false;
fitnessValue = _fitnessValue;
invalidFitnessValue = false;
}
@ -161,7 +162,7 @@ public:
*/
void invalidateFitness()
{
invalidFitnessValue = true;
invalidFitnessValue = true;
}
@ -169,22 +170,22 @@ public:
* 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;
}
}
/**
@ -193,8 +194,8 @@ public:
*/
void diversity(const Diversity & _diversityValue)
{
diversityValue = _diversityValue;
invalidDiversityValue = false;
diversityValue = _diversityValue;
invalidDiversityValue = false;
}
@ -203,7 +204,7 @@ public:
*/
void invalidateDiversity()
{
invalidDiversityValue = true;
invalidDiversityValue = true;
}
@ -211,9 +212,9 @@ public:
* Returns true if the diversity value is invalid, false otherwise
*/
bool invalidDiversity() const
{
{
return invalidDiversityValue;
}
}
/**
@ -221,9 +222,9 @@ public:
*/
void invalidate()
{
invalidateObjectiveVector();
invalidateFitness();
invalidateDiversity();
invalidateObjectiveVector();
invalidateFitness();
invalidateDiversity();
}
@ -231,9 +232,9 @@ public:
* Returns true if the fitness value is invalid, false otherwise
*/
bool invalid() const
{
{
return invalidObjectiveVector();
}
}
/**
@ -243,18 +244,18 @@ public:
* @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";
}
}
/**
@ -262,16 +263,16 @@ public:
* @param _os output stream
*/
virtual void printOn(std::ostream & _os) const
{
{
if ( invalidObjectiveVector() )
{
{
_os << "INVALID\t";
}
}
else
{
{
_os << objectiveVectorValue << '\t';
}
}
}
}
/**
@ -280,23 +281,23 @@ public:
*/
virtual void readFrom(std::istream & _is)
{
std::string objectiveVector_str;
int pos = _is.tellg();
_is >> objectiveVector_str;
if (objectiveVector_str == "INVALID")
std::string objectiveVector_str;
int pos = _is.tellg();
_is >> objectiveVector_str;
if (objectiveVector_str == "INVALID")
{
invalidateObjectiveVector();
invalidateObjectiveVector();
}
else
else
{
invalidObjectiveVectorValue = false;
_is.seekg(pos); // rewind
_is >> objectiveVectorValue;
invalidObjectiveVectorValue = false;
_is.seekg(pos); // rewind
_is >> objectiveVectorValue;
}
}
private:
private:
/** the objective vector of this solution */
ObjectiveVector objectiveVectorValue;
@ -311,6 +312,6 @@ private:
/** true if the diversity value is invalid */
bool invalidDiversityValue;
};
};
#endif /*MOEO_H_*/