Allow scalar init of dual fitness; add a pop splitter
Scalar init of a dual fitness is dangerous, thus adds an explicit security against use of a partially initialized object. Use the pop splitter in the dual stat switch and in the MOEO dual fitness assignment.
This commit is contained in:
parent
39621f8711
commit
4af7f3d1bc
2 changed files with 124 additions and 75 deletions
|
|
@ -1,12 +1,14 @@
|
|||
|
||||
#ifndef MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_
|
||||
#define MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_
|
||||
|
||||
#include <fitness/moeoExpBinaryIndicatorBasedFitnessAssignment.h>
|
||||
|
||||
template<class MOEOT>
|
||||
class moeoExpBinaryIndicatorBasedDualFitnessAssignment : public moeoExpBinaryIndicatorBasedFitnessAssignment<MOEOT>
|
||||
{
|
||||
protected:
|
||||
eoPop<MOEOT> _feasible_pop;
|
||||
eoPop<MOEOT> _unfeasible_pop;
|
||||
eoDualPopSplit<MOEOT> _pop_split;
|
||||
|
||||
public:
|
||||
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||
|
|
@ -26,20 +28,24 @@ public:
|
|||
*/
|
||||
virtual void operator()( eoPop<MOEOT>& pop )
|
||||
{
|
||||
// separate the pop in the members
|
||||
split( pop );
|
||||
// separate the pop in feasible/unfeasible
|
||||
_pop_split( pop );
|
||||
|
||||
eoPop<MOEOT>* ppop;
|
||||
// if there is at least one feasible individual, it will supersede all the unfeasible ones
|
||||
if( _feasible_pop.size() == 0 ) {
|
||||
ppop = & _unfeasible_pop;
|
||||
// if there is at least one feasible individual,
|
||||
// it will supersede all the unfeasible ones
|
||||
if( _pop_split.feasible().size() == 0 ) {
|
||||
ppop = & _pop_split.unfeasible();
|
||||
} else {
|
||||
ppop = & _feasible_pop;
|
||||
ppop = & _pop_split.feasible();
|
||||
}
|
||||
|
||||
this->setup(*ppop);
|
||||
this->computeValues(*ppop);
|
||||
this->setFitnesses(*ppop);
|
||||
this->setFitnesses(*ppop); // NOTE: this alter individuals
|
||||
|
||||
// bring back altered individuals in the pop
|
||||
pop = _pop_split.merge();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -47,25 +53,6 @@ protected:
|
|||
|
||||
using moeoExpBinaryIndicatorBasedFitnessAssignment<MOEOT>::kappa;
|
||||
|
||||
//! Split up the population in two: in one pop the feasible individual, in the other the feasible ones
|
||||
virtual void split( eoPop<MOEOT> & pop )
|
||||
{
|
||||
// clear previously used populations
|
||||
_feasible_pop.clear();
|
||||
_unfeasible_pop.clear();
|
||||
_feasible_pop.reserve(pop.size());
|
||||
_unfeasible_pop.reserve(pop.size());
|
||||
|
||||
for( typename eoPop<MOEOT>::iterator it=pop.begin(), end=pop.end(); it != end; ++it ) {
|
||||
// The ObjectiveVector should implement "is_feasible"
|
||||
if( it->objectiveVector().is_feasible() ) {
|
||||
_feasible_pop.push_back( *it );
|
||||
} else {
|
||||
_unfeasible_pop.push_back( *it );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute every indicator value in values (values[i] = I(_v[i], _o))
|
||||
* @param _pop the population
|
||||
|
|
@ -112,3 +99,4 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
#endif // MOEOEXPBINARYINDICATORBASEDDUALFITNESSASSIGNMENT_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue