Stat object to compute ratio of feasible indviduals in a pop using eoDualFitness
This commit is contained in:
parent
91ab6b8296
commit
47c4f58eb8
3 changed files with 89 additions and 3 deletions
|
|
@ -50,6 +50,11 @@ Authors:
|
||||||
*
|
*
|
||||||
* This class overrides operator<() to use the Compare template argument and handle feasibility.
|
* This class overrides operator<() to use the Compare template argument and handle feasibility.
|
||||||
* Over operators are coded using this sole function.
|
* 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)
|
||||||
*/
|
*/
|
||||||
template <class BaseType, class Compare >
|
template <class BaseType, class Compare >
|
||||||
class eoDualFitness
|
class eoDualFitness
|
||||||
|
|
@ -90,6 +95,11 @@ public:
|
||||||
_is_feasible(dual.second)
|
_is_feasible(dual.second)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
inline bool is_feasible() const
|
||||||
|
{
|
||||||
|
return _is_feasible;
|
||||||
|
}
|
||||||
|
|
||||||
//! Copy operator
|
//! Copy operator
|
||||||
eoDualFitness& operator=(const eoDualFitness& other)
|
eoDualFitness& operator=(const eoDualFitness& other)
|
||||||
{
|
{
|
||||||
|
|
@ -216,5 +226,11 @@ typedef eoDualFitness<double, std::less<double> > eoMaximizingDualFitness;
|
||||||
//! Compare dual fitnesses as if we were minimizing
|
//! Compare dual fitnesses as if we were minimizing
|
||||||
typedef eoDualFitness<double, std::greater<double> > eoMinimizingDualFitness;
|
typedef eoDualFitness<double, std::greater<double> > eoMinimizingDualFitness;
|
||||||
|
|
||||||
|
//! A predicate that returns the feasibility of a given dual fitness
|
||||||
|
/** Use this in STL algorithm that use binary predicates (e.g. count_if, find_if, etc.)
|
||||||
|
*/
|
||||||
|
template< class EOT>
|
||||||
|
bool eoIsFeasible ( const EOT & sol ) { return sol.fitness().is_feasible(); }
|
||||||
|
|
||||||
#endif // _eoDualFitness_h_
|
#endif // _eoDualFitness_h_
|
||||||
|
|
||||||
|
|
|
||||||
65
eo/src/utils/eoFeasibleRatioStat.h
Normal file
65
eo/src/utils/eoFeasibleRatioStat.h
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
(c) 2010 Thales group
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; version 2
|
||||||
|
of the License.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
Contact: http://eodev.sourceforge.net
|
||||||
|
|
||||||
|
Authors:
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _eoFeasibleRatioStat_h_
|
||||||
|
#define _eoFeasibleRatioStat_h_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <eoDualFitness.h>
|
||||||
|
#include <utils/eoLogger.h>
|
||||||
|
|
||||||
|
#include "eoStat.h"
|
||||||
|
|
||||||
|
//! Ratio of the number of individuals with a feasible dual fitness in the population (@see eoDualFitness)
|
||||||
|
template<class EOT>
|
||||||
|
class eoFeasibleRatioStat : public eoStat< EOT, double >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using eoStat<EOT, double>::value;
|
||||||
|
|
||||||
|
eoFeasibleRatioStat( std::string description = "FeasibleRatio" ) : eoStat<EOT,double>( 0.0, description ) {}
|
||||||
|
|
||||||
|
virtual void operator()( const eoPop<EOT> & pop )
|
||||||
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert( pop.size() > 0 );
|
||||||
|
|
||||||
|
double count = static_cast<double>( std::count_if( pop.begin(), pop.end(), eoIsFeasible<EOT> ) );
|
||||||
|
double size = static_cast<double>( pop.size() );
|
||||||
|
double ratio = count/size;
|
||||||
|
eo::log << eo::xdebug << "eoFeasibleRatioStat: " << count << " / " << size << " = " << ratio << std::endl;
|
||||||
|
value() = ratio;
|
||||||
|
#else
|
||||||
|
value() = static_cast<double>( std::count_if( pop.begin(), pop.end(), eoIsFeasible<EOT> ) ) / static_cast<double>( pop.size() );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string className(void) const { return "eoFeasibleRatioStat"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _eoFeasibleRatioStat_h_
|
||||||
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// eoStat.h
|
// eoStat.h
|
||||||
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
// (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
|
||||||
|
// (c) 2010 Thales group
|
||||||
/*
|
/*
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -18,9 +19,13 @@
|
||||||
License along with this library; if not, write to the Free Software
|
License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
Contact: http://eodev.sourceforge.net
|
||||||
Marc.Schoenauer@polytechnique.fr
|
|
||||||
mkeijzer@dhi.dk
|
Authors:
|
||||||
|
todos@geneura.ugr.es, http://geneura.ugr.es
|
||||||
|
Marc.Schoenauer@polytechnique.fr
|
||||||
|
mkeijzer@dhi.dk
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue