Modifications 22/02/2007

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@183 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2007-02-22 15:38:01 +00:00
commit 8312d91a84
19 changed files with 930 additions and 805 deletions

View file

@ -31,250 +31,253 @@
* operator '<' et '>' ???
* !!!!!!!!!!!!!!!!!!!!!!!
*/
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity >
class MOEO : public EO < MOEOFitness >
template < class MOEOObjectiveVector, class MOEOFitness, class MOEODiversity > class MOEO:public EO <
MOEOFitness
>
{
public:
/** the objective vector type of a solution */
typedef MOEOObjectiveVector ObjectiveVector;
typedef MOEOObjectiveVector ObjectiveVector;
/** the fitness type of a solution */
typedef MOEOFitness Fitness;
typedef MOEOFitness Fitness;
/** the diversity type of a solution */
typedef MOEODiversity Diversity;
typedef MOEODiversity Diversity;
/**
* Ctor
*/
MOEO()
{
// default values for every parameters
objectiveVectorValue = ObjectiveVector();
fitnessValue = Fitness();
diversityValue = Diversity();
// invalidate all
invalidate();
}
MOEO ()
{
// 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");
}
return objectiveVectorValue;
}
ObjectiveVector objectiveVector () const
{
if (invalidObjectiveVector ())
{
throw std::runtime_error ("invalid objective vector");
}
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;
}
void objectiveVector (const ObjectiveVector & _objectiveVectorValue)
{
objectiveVectorValue = _objectiveVectorValue;
invalidObjectiveVectorValue = false;
}
/**
* Sets the objective vector as invalid
*/
void invalidateObjectiveVector()
{
invalidObjectiveVectorValue = true;
}
void invalidateObjectiveVector ()
{
invalidObjectiveVectorValue = true;
}
/**
* Returns true if the objective vector is invalid, false otherwise
*/
bool invalidObjectiveVector() const
{
return invalidObjectiveVectorValue;
}
bool invalidObjectiveVector () const
{
return invalidObjectiveVectorValue;
}
/**
* Returns the fitness value of the current solution
*/
Fitness fitness() const
{
if ( invalidFitness() )
{
throw std::runtime_error("invalid fitness");
}
return fitnessValue;
}
Fitness fitness () const
{
if (invalidFitness ())
{
throw std::runtime_error ("invalid fitness");
}
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;
}
void fitness (const Fitness & _fitnessValue)
{
fitnessValue = _fitnessValue;
invalidFitnessValue = false;
}
/**
* Sets the fitness value as invalid
*/
void invalidateFitness()
{
invalidFitnessValue = true;
}
void invalidateFitness ()
{
invalidFitnessValue = true;
}
/**
* Returns true if the fitness value is invalid, false otherwise
*/
bool invalidFitness() const
{
return invalidFitnessValue;
}
bool invalidFitness () const
{
return invalidFitnessValue;
}
/**
* Returns the diversity value of the current solution
*/
Diversity diversity() const
{
if ( invalidDiversity() )
{
throw std::runtime_error("invalid diversity");
}
return diversityValue;
}
Diversity diversity () const
{
if (invalidDiversity ())
{
throw std::runtime_error ("invalid diversity");
}
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;
}
void diversity (const Diversity & _diversityValue)
{
diversityValue = _diversityValue;
invalidDiversityValue = false;
}
/**
* Sets the diversity value as invalid
*/
void invalidateDiversity()
{
invalidDiversityValue = true;
}
void invalidateDiversity ()
{
invalidDiversityValue = true;
}
/**
* Returns true if the diversity value is invalid, false otherwise
*/
bool invalidDiversity() const
{
return invalidDiversityValue;
}
bool invalidDiversity () const
{
return invalidDiversityValue;
}
/**
* Sets the objective vector, the fitness value and the diversity value as invalid
*/
void invalidate()
{
invalidateObjectiveVector();
invalidateFitness();
invalidateDiversity();
}
void invalidate ()
{
invalidateObjectiveVector ();
invalidateFitness ();
invalidateDiversity ();
}
/**
* Returns true if the fitness value is invalid, false otherwise
*/
bool invalid() const
{
return invalidObjectiveVector();
}
*/
bool invalid () const
{
return invalidObjectiveVector ();
}
/**
* Return the class id (the class name as a std::string)
*/
virtual std::string className() const
{
return "MOEO";
}
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';
}
}
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;
}
}
*/
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;
ObjectiveVector objectiveVectorValue;
/** true if the objective vector is invalid */
bool invalidObjectiveVectorValue;
bool invalidObjectiveVectorValue;
/** the fitness value of this solution */
Fitness fitnessValue;
Fitness fitnessValue;
/** true if the fitness value is invalid */
bool invalidFitnessValue;
bool invalidFitnessValue;
/** the diversity value of this solution */
Diversity diversityValue;
Diversity diversityValue;
/** true if the diversity value is invalid */
bool invalidDiversityValue;
bool invalidDiversityValue;
};
#endif /*MOEO_H_*/
#endif /*MOEO_H_ */