/* (c) 2013 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 */ #ifndef MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_ #define MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_ #include template class moeoExpBinaryIndicatorBasedDualFitnessAssignment : public moeoExpBinaryIndicatorBasedFitnessAssignment { protected: eoDualPopSplit _pop_split; public: typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename ObjectiveVector::Type Type; typedef typename MOEOT::Fitness Fitness; using moeoExpBinaryIndicatorBasedFitnessAssignment::values; moeoExpBinaryIndicatorBasedDualFitnessAssignment( moeoNormalizedSolutionVsSolutionBinaryMetric & metric, const double kappa = 0.05 ) : moeoExpBinaryIndicatorBasedFitnessAssignment( metric, kappa ) {} /*! If the population is homogeneous (only composed of feasible individuals or unfeasible ones), * then apply the operators on the whole population. * But, if there is at least one feasible individual, then apply them only on the feasible individuals. */ virtual void operator()( eoPop& pop ) { // separate the pop in feasible/unfeasible _pop_split( pop ); // if there is at least one feasible individual, // it will supersede all the unfeasible ones if( _pop_split.unfeasible().size() != 0 ) { this->setup(_pop_split.unfeasible()); this->computeValues(_pop_split.unfeasible()); this->setFitnesses(_pop_split.unfeasible()); // NOTE: this alter individuals } if( _pop_split.feasible().size() != 0 ) { this->setup(_pop_split.feasible()); this->computeValues(_pop_split.feasible()); this->setFitnesses(_pop_split.feasible()); // NOTE: this alter individuals } // bring back altered individuals in the pop // pop = _pop_split.merge(); eoPop merged = _pop_split.merge(); assert( pop.size() == merged.size()); for( unsigned int i=0; i::kappa; using moeoExpBinaryIndicatorBasedFitnessAssignment::metric; /** * Sets the bounds for every objective using the min and the max value for every objective vector of _pop * @param _pop the population */ void setup(const eoPop < MOEOT > & _pop) { Type worst, best; typename MOEOT::ObjectiveVector::Type::Compare cmp; for (unsigned int i=0; i & pop) { values.clear(); values.resize(pop.size()); for (unsigned int i=0; i & pop) { for (unsigned int i=0; icomputeFitness(i), pop[i].fitness().is_feasible() ); } } virtual Fitness computeFitness(const unsigned int _idx) { // Fitness result( 0.0, values[_idx][_idx].is_feasible() ); Fitness result( 0.0, values[_idx][_idx].is_feasible() ); for (unsigned int i=0; i & pop, ObjectiveVector & objVec) { _pop_split(pop); if( objVec.is_feasible() ) { setup(_pop_split.feasible()); updateFitnessByDeleting( _pop_split.feasible(), objVec); } else { setup(_pop_split.unfeasible()); updateFitnessByDeleting( _pop_split.unfeasible(), objVec ); } // pop = _pop_split.merge(); eoPop merged = _pop_split.merge(); assert( pop.size() == merged.size()); for( unsigned int i=0; i & pop, ObjectiveVector & objVec ) { std::vector < double > v; v.resize(pop.size()); for (unsigned int i=0; i T confine( T n ) { T tmax = std::numeric_limits::max(); T tmin = -1 * tmax; tmin.is_feasible( n.is_feasible() ); tmax.is_feasible( n.is_feasible() ); if( n < tmin ) { return tmin; } else if( n > tmax ) { return tmax; } else { return n; } } }; #endif // MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_