EvolvingObjects
eoDualFitness< BaseType, Compare > Class Template Reference

A fitness class that permits to compare feasible and unfeasible individuals and guaranties that a feasible individual will always be better than an unfeasible one. More...

#include <eoDualFitness.h>

List of all members.

Public Member Functions

 eoDualFitness ()
 Empty initialization.
 eoDualFitness (const eoDualFitness &other)
 Copy constructor.
 eoDualFitness (const BaseType &v, const bool &is_feasible)
 Constructor from explicit value/feasibility.
 eoDualFitness (const std::pair< BaseType, bool > &dual)
 From a std::pair (first element is the value, second is the feasibility)
 operator BaseType (void) const
 Conversion operator: it permits to use a fitness instance as its scalar type, if needed.
bool is_feasible () const
BaseType value () const
eoDualFitnessoperator= (const std::pair< BaseType, bool > &v)
 Copy operator from a std::pair.
template<class F , class Cmp >
eoDualFitness< F, Cmp > & operator= (const eoDualFitness< BaseType, Compare > &other)
 Copy operator from another eoDualFitness.
bool operator< (const eoDualFitness &other) const
 Comparison that separate feasible individuals from unfeasible ones. Feasible are always better.
bool operator> (const eoDualFitness &other) const
 Greater: if the other is lesser than me.
bool operator<= (const eoDualFitness &other) const
 Less or equal: if the other is not lesser than me.
bool operator>= (const eoDualFitness &other) const
 Greater or equal: if the other is not greater than me.
bool operator== (const eoDualFitness &other) const
 Equal: if the other is equal to me.
template<class F , class Cmp >
eoDualFitness< F, Cmp > operator+ (const eoDualFitness< F, Cmp > &that)
template<class F , class Cmp >
eoDualFitness< F, Cmp > operator- (const eoDualFitness< F, Cmp > &that)

Protected Attributes

BaseType _value
 Scalar type of the fitness (generally a double)
bool _is_feasible
 Flag that marks if the individual is feasible.

Friends

template<class F , class Cmp >
eoDualFitness< F, Cmp > & operator+= (eoDualFitness< F, Cmp > &from, const eoDualFitness< F, Cmp > &that)
 Add a given fitness to the current one.
template<class F , class Cmp >
eoDualFitness< F, Cmp > & operator-= (eoDualFitness< F, Cmp > &from, const eoDualFitness< F, Cmp > &that)
 Substract a given fitness to the current one.
template<class F , class Cmp >
std::ostream & operator<< (std::ostream &os, const eoDualFitness< F, Cmp > &f)
 Print an eoDualFitness instance as a pair of numbers, separated by a space.
template<class F , class Cmp >
std::istream & operator>> (std::istream &is, eoDualFitness< F, Cmp > &f)
 Read an eoDualFitness instance as a pair of numbers, separated by a space.

Detailed Description

template<class BaseType, class Compare>
class eoDualFitness< BaseType, Compare >

A fitness class that permits to compare feasible and unfeasible individuals and guaranties that a feasible individual will always be better than an unfeasible one.

Use this class as fitness if you have some kind of individuals that must be always considered as better than others while having the same fitness type.

Wraps a scalar fitness _values such as a double or int, with the option of maximizing (using less<BaseType>,

See also:
eoMaximizingDualFitness) or minimizing (using greater<BaseType>,
eoMinimizingDualFitness).

Suitable constructors, assignments and casts are defined to work with those quantities as if they were a pair of: a BaseType and a boolean.

When changing the fitness, you can use: individual.fitness( std::make_pair<BaseType,bool>( fitness, feasibility ) );

Be aware that, when printing or reading an eDualFitness instance on a iostream, friend IO classes use a space separator.

This class overrides operator<() to use the Compare template argument and handle feasibility. Over operators are coded using this sole function.

Standard arithmetic operators are provided to add or substract dual fitnesses. They behave as expected for the fitness value and gives priority to unfeasible fitness (i.e. when adding or substracting dual fitness, the only case when the result will be a feasible fitness is when both are feasible, else the result is an unfeasibe fitness)

Definition at line 68 of file eoDualFitness.h.


Constructor & Destructor Documentation

template<class BaseType, class Compare>
eoDualFitness< BaseType, Compare >::eoDualFitness ( ) [inline]

Empty initialization.

Unfeasible by default

Definition at line 83 of file eoDualFitness.h.


Member Function Documentation

template<class BaseType, class Compare>
eoDualFitness< BaseType, Compare >::operator BaseType ( void  ) const [inline]

Conversion operator: it permits to use a fitness instance as its scalar type, if needed.

 For example, this is possible: eoDualFitness<double,std::less<double> > fit; double val = 1.0; fit = val; val = fit;

Definition at line 114 of file eoDualFitness.h.

References eoDualFitness< BaseType, Compare >::_value.

template<class BaseType, class Compare>
bool eoDualFitness< BaseType, Compare >::operator< ( const eoDualFitness< BaseType, Compare > &  other) const [inline]

Comparison that separate feasible individuals from unfeasible ones. Feasible are always better.

Use less as a default comparison operator (see the "Compare" template of the class to change this behaviour,

See also:
eoMinimizingDualFitness for an example).

Definition at line 152 of file eoDualFitness.h.

References eoDualFitness< BaseType, Compare >::_is_feasible, and eoDualFitness< BaseType, Compare >::_value.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends