update the use of the comparator
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@332 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
3a08572935
commit
14216e1af4
2 changed files with 12 additions and 39 deletions
|
|
@ -81,8 +81,7 @@ public:
|
||||||
fitnessAssignment (_parents);
|
fitnessAssignment (_parents);
|
||||||
diversityAssignment (_parents);
|
diversityAssignment (_parents);
|
||||||
// sorts the whole population according to the comparator
|
// sorts the whole population according to the comparator
|
||||||
Cmp cmp(comparator);
|
std::sort(_parents.begin(), _parents.end(), comparator);
|
||||||
std::sort(_parents.begin(), _parents.end(), cmp);
|
|
||||||
// finally, resize this global population
|
// finally, resize this global population
|
||||||
_parents.resize (sz);
|
_parents.resize (sz);
|
||||||
// and clear the offspring population
|
// and clear the offspring population
|
||||||
|
|
@ -98,27 +97,18 @@ protected:
|
||||||
moeoDiversityAssignment < MOEOT > & diversityAssignment;
|
moeoDiversityAssignment < MOEOT > & diversityAssignment;
|
||||||
/** a dummy diversity assignment can be used as default */
|
/** a dummy diversity assignment can be used as default */
|
||||||
moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
|
moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
|
||||||
/** the comparator (used to compare 2 individuals) */
|
|
||||||
moeoComparator < MOEOT > & comparator;
|
|
||||||
/** a fitness then diversity comparator can be used as default */
|
/** a fitness then diversity comparator can be used as default */
|
||||||
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
||||||
|
/** this object is used to compare solutions in order to sort the population */
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to compare solutions in order to sort the population.
|
|
||||||
*/
|
|
||||||
class Cmp
|
class Cmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor.
|
* Ctor.
|
||||||
* @param _comparator the comparator
|
* @param _comparator the comparator
|
||||||
*/
|
*/
|
||||||
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
|
Cmp(moeoComparator < MOEOT > & _comp) : comp(_comp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
|
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
|
||||||
* _moeo1 the first individual
|
* _moeo1 the first individual
|
||||||
|
|
@ -126,16 +116,12 @@ protected:
|
||||||
*/
|
*/
|
||||||
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||||
{
|
{
|
||||||
return comparator(_moeo2,_moeo1);
|
return comp(_moeo2,_moeo1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** the comparator */
|
/** the comparator */
|
||||||
moeoComparator < MOEOT > & comparator;
|
moeoComparator < MOEOT > & comp;
|
||||||
|
} comparator;
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,13 +86,12 @@ public:
|
||||||
fitnessAssignment (_parents);
|
fitnessAssignment (_parents);
|
||||||
diversityAssignment (_parents);
|
diversityAssignment (_parents);
|
||||||
// remove individuals 1 by 1 and update the fitness values
|
// remove individuals 1 by 1 and update the fitness values
|
||||||
Cmp cmp(comparator);
|
|
||||||
unsigned worstIdx;
|
unsigned worstIdx;
|
||||||
ObjectiveVector worstObjVec;
|
ObjectiveVector worstObjVec;
|
||||||
while (_parents.size() > sz)
|
while (_parents.size() > sz)
|
||||||
{
|
{
|
||||||
// the individual to delete
|
// the individual to delete
|
||||||
worstIdx = std::min_element(_parents.begin(), _parents.end(), cmp) - _parents.begin();
|
worstIdx = std::min_element(_parents.begin(), _parents.end(), comparator) - _parents.begin();
|
||||||
worstObjVec = _parents[worstIdx].objectiveVector();
|
worstObjVec = _parents[worstIdx].objectiveVector();
|
||||||
// remove the woorst individual
|
// remove the woorst individual
|
||||||
_parents[worstIdx] = _parents.back();
|
_parents[worstIdx] = _parents.back();
|
||||||
|
|
@ -115,26 +114,18 @@ protected:
|
||||||
moeoDiversityAssignment < MOEOT > & diversityAssignment;
|
moeoDiversityAssignment < MOEOT > & diversityAssignment;
|
||||||
/** a dummy diversity assignment can be used as default */
|
/** a dummy diversity assignment can be used as default */
|
||||||
moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
|
moeoDummyDiversityAssignment < MOEOT > defaultDiversity;
|
||||||
/** the comparator (used to compare 2 individuals) */
|
|
||||||
moeoComparator < MOEOT > & comparator;
|
|
||||||
/** a fitness then diversity comparator can be used as default */
|
/** a fitness then diversity comparator can be used as default */
|
||||||
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
moeoFitnessThenDiversityComparator < MOEOT > defaultComparator;
|
||||||
|
/** this object is used to compare solutions in order to sort the population */
|
||||||
/**
|
|
||||||
* This class is used to compare solutions in order to sort the population.
|
|
||||||
*/
|
|
||||||
class Cmp
|
class Cmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor.
|
* Ctor.
|
||||||
* @param _comparator the comparator
|
* @param _comparator the comparator
|
||||||
*/
|
*/
|
||||||
Cmp(moeoComparator < MOEOT > & _comparator) : comparator(_comparator)
|
Cmp(moeoComparator < MOEOT > & _comp) : comp(_comp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
|
* Returns true if _moeo1 is greater than _moeo2 according to the comparator
|
||||||
* _moeo1 the first individual
|
* _moeo1 the first individual
|
||||||
|
|
@ -142,16 +133,12 @@ protected:
|
||||||
*/
|
*/
|
||||||
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
bool operator()(const MOEOT & _moeo1, const MOEOT & _moeo2)
|
||||||
{
|
{
|
||||||
return comparator(_moeo1,_moeo2);
|
return comp(_moeo1,_moeo2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** the comparator */
|
/** the comparator */
|
||||||
moeoComparator < MOEOT > & comparator;
|
moeoComparator < MOEOT > & comp;
|
||||||
|
} comparator;
|
||||||
};
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue