EvolvingObjects
eoFeasibleRatioStat.h
00001 /*
00002 
00003 (c) 2010 Thales group
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; version 2
00008     of the License.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 Contact: http://eodev.sourceforge.net
00020 
00021 Authors:
00022     Johann Dréo <johann.dreo@thalesgroup.com>
00023 
00024 */
00025 
00026 #ifndef _eoFeasibleRatioStat_h_
00027 #define _eoFeasibleRatioStat_h_
00028 
00029 #include <algorithm>
00030 
00031 #include <eoDualFitness.h>
00032 #include <utils/eoLogger.h>
00033 
00034 #include "eoStat.h"
00035 
00040 template<class EOT>
00041 class eoFeasibleRatioStat : public eoStat< EOT, double >
00042 {
00043 public:
00044     using eoStat<EOT, double>::value;
00045 
00046     eoFeasibleRatioStat( std::string description = "FeasibleRatio" ) : eoStat<EOT,double>( 0.0, description ) {}
00047 
00048     virtual void operator()( const eoPop<EOT> & pop )
00049     {
00050 #ifndef NDEBUG
00051         assert( pop.size() > 0 );
00052 
00053         double count = static_cast<double>( std::count_if( pop.begin(), pop.end(), eoIsFeasible<EOT> ) );
00054         double size = static_cast<double>( pop.size() );
00055         double ratio = count/size;
00056         eo::log << eo::xdebug << "eoFeasibleRatioStat: " << count << " / " << size << " = " << ratio << std::endl;
00057         value() = ratio;
00058 #else
00059         value() = static_cast<double>( std::count_if( pop.begin(), pop.end(), eoIsFeasible<EOT> ) ) / static_cast<double>( pop.size() );
00060 #endif
00061     }
00062 
00063  virtual std::string className(void) const { return "eoFeasibleRatioStat"; }
00064 };
00065 
00066 #endif // _eoFeasibleRatioStat_h_
 All Classes Namespaces Files Functions Variables Typedefs Friends