update metric
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@264 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
2e7e817428
commit
e926d39359
5 changed files with 570 additions and 358 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// moeoBinaryMetricSavingUpdater.h
|
// moeoBinaryMetricSavingUpdater.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -20,75 +20,69 @@
|
||||||
#include <metric/moeoMetric.h>
|
#include <metric/moeoMetric.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class allows to save the progression of a binary metric comparing the fitness values of the current population (or archive)
|
* This class allows to save the progression of a binary metric comparing the objective vectors of the current population (or archive)
|
||||||
* with the fitness values of the population (or archive) of the generation (n-1) into a file
|
* with the objective vectors of the population (or archive) of the generation (n-1) into a file
|
||||||
*/
|
*/
|
||||||
template < class EOT > class moeoBinaryMetricSavingUpdater:public eoUpdater
|
template < class MOEOT >
|
||||||
|
class moeoBinaryMetricSavingUpdater : public eoUpdater
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fitness type of a solution
|
* The objective vector type of a solution
|
||||||
*/
|
*/
|
||||||
typedef typename EOT::Fitness EOFitness;
|
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor
|
* Ctor
|
||||||
* @param _metric the binary metric comparing two Pareto sets
|
* @param _metric the binary metric comparing two Pareto sets
|
||||||
* @param _pop the main population
|
* @param _pop the main population
|
||||||
* @param _filename the target filename
|
* @param _filename the target filename
|
||||||
*/
|
*/
|
||||||
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBM < EOT, double >&_metric,
|
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
|
||||||
const eoPop < EOT > &_pop,
|
metric(_metric), pop(_pop), filename(_filename), counter(1)
|
||||||
std::string _filename):metric (_metric),
|
{}
|
||||||
pop (_pop), filename (_filename), counter (1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the metric's value for the current generation
|
* Saves the metric's value for the current generation
|
||||||
*/
|
*/
|
||||||
void operator () ()
|
void operator()() {
|
||||||
{
|
if (pop.size()) {
|
||||||
if (pop.size ())
|
if (firstGen) {
|
||||||
{
|
firstGen = false;
|
||||||
if (firstGen)
|
}
|
||||||
{
|
else {
|
||||||
firstGen = false;
|
// creation of the two Pareto sets
|
||||||
}
|
std::vector < ObjectiveVector > from;
|
||||||
else
|
std::vector < ObjectiveVector > to;
|
||||||
{
|
for (unsigned i=0; i<pop.size(); i++)
|
||||||
// creation of the two Pareto sets
|
from.push_back(pop[i].objectiveVector());
|
||||||
std::vector < EOFitness > from;
|
for (unsigned i=0 ; i<oldPop.size(); i++)
|
||||||
std::vector < EOFitness > to;
|
to.push_back(oldPop[i].objectiveVector());
|
||||||
for (unsigned i = 0; i < pop.size (); i++)
|
// writing the result into the file
|
||||||
from.push_back (pop[i].fitness ());
|
std::ofstream f (filename.c_str(), std::ios::app);
|
||||||
for (unsigned i = 0; i < oldPop.size (); i++)
|
f << counter++ << ' ' << metric(from,to) << std::endl;
|
||||||
to.push_back (oldPop[i].fitness ());
|
f.close();
|
||||||
// writing the result into the file
|
}
|
||||||
std::ofstream f (filename.c_str (), std::ios::app);
|
oldPop = pop;
|
||||||
f << counter++ << ' ' << metric (from, to) << std::endl;
|
}
|
||||||
f.close ();
|
}
|
||||||
}
|
|
||||||
oldPop = pop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** binary metric comparing two Pareto sets */
|
/** binary metric comparing two Pareto sets */
|
||||||
moeoVectorVsVectorBM < EOT, double >&metric;
|
moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & metric;
|
||||||
/** main population */
|
/** main population */
|
||||||
const eoPop < EOT > &pop;
|
const eoPop < MOEOT > & pop;
|
||||||
/** (n-1) population */
|
/** (n-1) population */
|
||||||
eoPop < EOT > oldPop;
|
eoPop< MOEOT > oldPop;
|
||||||
/** target filename */
|
/** target filename */
|
||||||
std::string filename;
|
std::string filename;
|
||||||
/** is it the first generation ? */
|
/** is it the first generation ? */
|
||||||
bool firstGen;
|
bool firstGen;
|
||||||
/** counter */
|
/** counter */
|
||||||
unsigned counter;
|
unsigned counter;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_ */
|
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// moeoContributionMetric.h
|
// moeoContributionMetric.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -17,100 +17,82 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contribution metric evaluates the proportion of non-dominated solutions given by a Pareto set relatively to another Pareto set
|
* The contribution metric evaluates the proportion of non-dominated solutions given by a Pareto set relatively to another Pareto set
|
||||||
*
|
|
||||||
* (Meunier, Talbi, Reininger: 'A multiobjective genetic algorithm for radio network optimization', in Proc. of the 2000 Congress on Evolutionary Computation, IEEE Press, pp. 317-324)
|
* (Meunier, Talbi, Reininger: 'A multiobjective genetic algorithm for radio network optimization', in Proc. of the 2000 Congress on Evolutionary Computation, IEEE Press, pp. 317-324)
|
||||||
*/
|
*/
|
||||||
template < class EOT > class moeoContributionMetric:public moeoVectorVsVectorBM < EOT,
|
template < class ObjectiveVector >
|
||||||
double >
|
class moeoContributionMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fitness type of a solution
|
* Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
||||||
*/
|
* @param _set1 the first Pareto set
|
||||||
typedef typename EOT::Fitness EOFitness;
|
* @param _set2 the second Pareto set
|
||||||
|
*/
|
||||||
/**
|
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
|
||||||
* Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
unsigned c = card_C(_set1, _set2);
|
||||||
* @param _set1 the first Pareto set
|
unsigned w1 = card_W(_set1, _set2);
|
||||||
* @param _set2 the second Pareto set
|
unsigned n1 = card_N(_set1, _set2);
|
||||||
*/
|
unsigned w2 = card_W(_set2, _set1);
|
||||||
double operator () (const std::vector < EOFitness > &_set1,
|
unsigned n2 = card_N(_set2, _set1);
|
||||||
const std::vector < EOFitness > &_set2)
|
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
|
||||||
{
|
}
|
||||||
unsigned c = card_C (_set1, _set2);
|
|
||||||
unsigned w1 = card_W (_set1, _set2);
|
|
||||||
unsigned n1 = card_N (_set1, _set2);
|
|
||||||
unsigned w2 = card_W (_set2, _set1);
|
|
||||||
unsigned n2 = card_N (_set2, _set1);
|
|
||||||
return (double) (c / 2.0 + w1 + n1) / (c + w1 + n1 + w2 + n2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of solutions both in '_set1' and '_set2'
|
* Returns the number of solutions both in '_set1' and '_set2'
|
||||||
* @param _set1 the first Pareto set
|
* @param _set1 the first Pareto set
|
||||||
* @param _set2 the second Pareto set
|
* @param _set2 the second Pareto set
|
||||||
*/
|
*/
|
||||||
unsigned card_C (const std::vector < EOFitness > &_set1,
|
unsigned card_C (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
|
||||||
const std::vector < EOFitness > &_set2)
|
unsigned c=0;
|
||||||
{
|
for (unsigned i=0; i<_set1.size(); i++)
|
||||||
unsigned c = 0;
|
for (unsigned j=0; j<_set2.size(); j++)
|
||||||
for (unsigned i = 0; i < _set1.size (); i++)
|
if (_set1[i] == _set2[j]) {
|
||||||
for (unsigned j = 0; j < _set2.size (); j++)
|
c++;
|
||||||
if (_set1[i] == _set2[j])
|
break;
|
||||||
{
|
}
|
||||||
c++;
|
return c;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of solutions in '_set1' dominating at least one solution of '_set2'
|
* Returns the number of solutions in '_set1' dominating at least one solution of '_set2'
|
||||||
* @param _set1 the first Pareto set
|
* @param _set1 the first Pareto set
|
||||||
* @param _set2 the second Pareto set
|
* @param _set2 the second Pareto set
|
||||||
*/
|
*/
|
||||||
unsigned card_W (const std::vector < EOFitness > &_set1,
|
unsigned card_W (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
|
||||||
const std::vector < EOFitness > &_set2)
|
unsigned w=0;
|
||||||
{
|
for (unsigned i=0; i<_set1.size(); i++)
|
||||||
unsigned w = 0;
|
for (unsigned j=0; j<_set2.size(); j++)
|
||||||
for (unsigned i = 0; i < _set1.size (); i++)
|
if (_set1[i].dominates(_set2[j])) {
|
||||||
for (unsigned j = 0; j < _set2.size (); j++)
|
w++;
|
||||||
if (_set1[i].dominates (_set2[j]))
|
break;
|
||||||
{
|
}
|
||||||
w++;
|
return w;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of solutions in '_set1' having no relation of dominance with those from '_set2'
|
* Returns the number of solutions in '_set1' having no relation of dominance with those from '_set2'
|
||||||
* @param _set1 the first Pareto set
|
* @param _set1 the first Pareto set
|
||||||
* @param _set2 the second Pareto set
|
* @param _set2 the second Pareto set
|
||||||
*/
|
*/
|
||||||
unsigned card_N (const std::vector < EOFitness > &_set1,
|
unsigned card_N (const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
|
||||||
const std::vector < EOFitness > &_set2)
|
unsigned n=0;
|
||||||
{
|
for (unsigned i=0; i<_set1.size(); i++) {
|
||||||
unsigned n = 0;
|
bool domin_rel = false;
|
||||||
for (unsigned i = 0; i < _set1.size (); i++)
|
for (unsigned j=0; j<_set2.size(); j++)
|
||||||
{
|
if (_set1[i].dominates(_set2[j]) || _set2[j].dominates(_set1 [i])) {
|
||||||
bool domin_rel = false;
|
domin_rel = true;
|
||||||
for (unsigned j = 0; j < _set2.size (); j++)
|
break;
|
||||||
if (_set1[i].dominates (_set2[j]) || _set2[j].dominates (_set1[i]))
|
}
|
||||||
{
|
if (! domin_rel)
|
||||||
domin_rel = true;
|
n++;
|
||||||
break;
|
}
|
||||||
}
|
return n;
|
||||||
if (!domin_rel)
|
}
|
||||||
n++;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*MOEOCONTRIBUTIONMETRIC_H_ */
|
#endif /*MOEOCONTRIBUTIONMETRIC_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// moeoEntropyMetric.h
|
// moeoEntropyMetric.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -16,164 +16,162 @@
|
||||||
#include <metric/moeoMetric.h>
|
#include <metric/moeoMetric.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entropy gives an idea of the diversity of a Pareto set relatively to another Pareto set
|
* The entropy gives an idea of the diversity of a Pareto set relatively to another
|
||||||
*
|
|
||||||
* (Basseur, Seynhaeve, Talbi: 'Design of Multi-objective Evolutionary Algorithms: Application to the Flow-shop Scheduling Problem', in Proc. of the 2002 Congress on Evolutionary Computation, IEEE Press, pp. 1155-1156)
|
* (Basseur, Seynhaeve, Talbi: 'Design of Multi-objective Evolutionary Algorithms: Application to the Flow-shop Scheduling Problem', in Proc. of the 2002 Congress on Evolutionary Computation, IEEE Press, pp. 1155-1156)
|
||||||
*/
|
*/
|
||||||
template < class EOT > class moeoEntropyMetric:public moeoVectorVsVectorBM < EOT,
|
template < class ObjectiveVector >
|
||||||
double >
|
class moeoEntropyMetric : public moeoVectorVsVectorBinaryMetric < ObjectiveVector, double >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fitness type of a solution
|
* Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
||||||
*/
|
* @param _set1 the first Pareto set
|
||||||
typedef typename EOT::Fitness EOFitness;
|
* @param _set2 the second Pareto set
|
||||||
|
*/
|
||||||
|
double operator()(const std::vector < ObjectiveVector > & _set1, const std::vector < ObjectiveVector > & _set2) {
|
||||||
|
// normalization
|
||||||
|
std::vector< ObjectiveVector > set1 = _set1;
|
||||||
|
std::vector< ObjectiveVector > set2= _set2;
|
||||||
|
removeDominated (set1);
|
||||||
|
removeDominated (set2);
|
||||||
|
prenormalize (set1);
|
||||||
|
normalize (set1);
|
||||||
|
normalize (set2);
|
||||||
|
|
||||||
/**
|
// making of PO*
|
||||||
* Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
std::vector< ObjectiveVector > star; // rotf :-)
|
||||||
* @param _set1 the first Pareto set
|
computeUnion (set1, set2, star);
|
||||||
* @param _set2 the second Pareto set
|
removeDominated (star);
|
||||||
*/
|
|
||||||
double operator () (const std::vector < EOFitness > &_set1,
|
|
||||||
const std::vector < EOFitness > &_set2)
|
|
||||||
{
|
|
||||||
// normalization
|
|
||||||
std::vector < EOFitness > set1 = _set1;
|
|
||||||
std::vector < EOFitness > set2 = _set2;
|
|
||||||
removeDominated (set1);
|
|
||||||
removeDominated (set2);
|
|
||||||
prenormalize (set1);
|
|
||||||
normalize (set1);
|
|
||||||
normalize (set2);
|
|
||||||
|
|
||||||
// making of PO*
|
// making of PO1 U PO*
|
||||||
std::vector < EOFitness > star; // rotf :-)
|
std::vector< ObjectiveVector > union_set1_star; // rotf again ...
|
||||||
computeUnion (set1, set2, star);
|
computeUnion (set1, star, union_set1_star);
|
||||||
removeDominated (star);
|
|
||||||
|
|
||||||
// making of PO1 U PO*
|
unsigned C = union_set1_star.size();
|
||||||
std::vector < EOFitness > union_set1_star; // rotf again ...
|
float omega=0;
|
||||||
computeUnion (set1, star, union_set1_star);
|
float entropy=0;
|
||||||
|
|
||||||
unsigned C = union_set1_star.size ();
|
for (unsigned i=0 ; i<C ; i++) {
|
||||||
float omega = 0;
|
unsigned N_i = howManyInNicheOf (union_set1_star, union_set1_star[i], star.size());
|
||||||
float entropy = 0;
|
unsigned n_i = howManyInNicheOf (set1, union_set1_star[i], star.size());
|
||||||
|
if (n_i > 0) {
|
||||||
for (unsigned i = 0; i < C; i++)
|
omega += 1.0 / N_i;
|
||||||
{
|
entropy += (float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0));
|
||||||
unsigned N_i =
|
}
|
||||||
howManyInNicheOf (union_set1_star, union_set1_star[i],
|
}
|
||||||
star.size ());
|
entropy /= - log (omega);
|
||||||
unsigned n_i =
|
entropy *= log (2.0);
|
||||||
howManyInNicheOf (set1, union_set1_star[i], star.size ());
|
return entropy;
|
||||||
if (n_i > 0)
|
}
|
||||||
{
|
|
||||||
omega += 1.0 / N_i;
|
|
||||||
entropy +=
|
|
||||||
(float) n_i / (N_i * C) * log (((float) n_i / C) / log (2.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entropy /= -log (omega);
|
|
||||||
entropy *= log (2.0);
|
|
||||||
return entropy;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector < double >vect_min_val;
|
/** vector of min values */
|
||||||
std::vector < double >vect_max_val;
|
std::vector<double> vect_min_val;
|
||||||
|
/** vector of max values */
|
||||||
|
std::vector<double> vect_max_val;
|
||||||
|
|
||||||
void removeDominated (std::vector < EOFitness > &_f)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < _f.size (); i++)
|
|
||||||
{
|
|
||||||
bool dom = false;
|
|
||||||
for (unsigned j = 0; j < _f.size (); j++)
|
|
||||||
if (i != j && _f[j].dominates (_f[i]))
|
|
||||||
{
|
|
||||||
dom = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (dom)
|
|
||||||
{
|
|
||||||
_f[i] = _f.back ();
|
|
||||||
_f.pop_back ();
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void prenormalize (const std::vector < EOFitness > &_f)
|
/**
|
||||||
{
|
* Removes the dominated individuals contained in _f
|
||||||
vect_min_val.clear ();
|
* @param _f a Pareto set
|
||||||
vect_max_val.clear ();
|
*/
|
||||||
|
void removeDominated(std::vector < ObjectiveVector > & _f) {
|
||||||
|
for (unsigned i=0 ; i<_f.size(); i++) {
|
||||||
|
bool dom = false;
|
||||||
|
for (unsigned j=0; j<_f.size(); j++)
|
||||||
|
if (i != j && _f[j].dominates(_f[i])) {
|
||||||
|
dom = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (dom) {
|
||||||
|
_f[i] = _f.back();
|
||||||
|
_f.pop_back();
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned char i = 0; i < EOFitness::fitness_traits::nObjectives ();
|
|
||||||
i++)
|
|
||||||
{
|
|
||||||
float min_val = _f.front ()[i], max_val = min_val;
|
|
||||||
for (unsigned j = 1; j < _f.size (); j++)
|
|
||||||
{
|
|
||||||
if (_f[j][i] < min_val)
|
|
||||||
min_val = _f[j][i];
|
|
||||||
if (_f[j][i] > max_val)
|
|
||||||
max_val = _f[j][i];
|
|
||||||
}
|
|
||||||
vect_min_val.push_back (min_val);
|
|
||||||
vect_max_val.push_back (max_val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void normalize (std::vector < EOFitness > &_f)
|
/**
|
||||||
{
|
* Prenormalization
|
||||||
for (unsigned i = 0; i < EOFitness::fitness_traits::nObjectives (); i++)
|
* @param _f a Pareto set
|
||||||
for (unsigned j = 0; j < _f.size (); j++)
|
*/
|
||||||
_f[j][i] =
|
void prenormalize (const std::vector< ObjectiveVector > & _f) {
|
||||||
(_f[j][i] - vect_min_val[i]) / (vect_max_val[i] - vect_min_val[i]);
|
vect_min_val.clear();
|
||||||
}
|
vect_max_val.clear();
|
||||||
|
|
||||||
void computeUnion (const std::vector < EOFitness > &_f1,
|
for (unsigned char i=0 ; i<ObjectiveVector::nObjectives(); i++) {
|
||||||
const std::vector < EOFitness > &_f2,
|
float min_val = _f.front()[i], max_val = min_val;
|
||||||
std::vector < EOFitness > &_f)
|
for (unsigned j=1 ; j<_f.size(); j++) {
|
||||||
{
|
if (_f[j][i] < min_val)
|
||||||
_f = _f1;
|
min_val = _f[j][i];
|
||||||
for (unsigned i = 0; i < _f2.size (); i++)
|
if (_f[j][i]>max_val)
|
||||||
{
|
max_val = _f[j][i];
|
||||||
bool b = false;
|
}
|
||||||
for (unsigned j = 0; j < _f1.size (); j++)
|
vect_min_val.push_back(min_val);
|
||||||
if (_f1[j] == _f2[i])
|
vect_max_val.push_back (max_val);
|
||||||
{
|
}
|
||||||
b = true;
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!b)
|
|
||||||
_f.push_back (_f2[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned howManyInNicheOf (const std::vector < EOFitness > &_f,
|
|
||||||
const EOFitness & _s, unsigned _size)
|
|
||||||
{
|
|
||||||
unsigned n = 0;
|
|
||||||
for (unsigned i = 0; i < _f.size (); i++)
|
|
||||||
{
|
|
||||||
if (euclidianDistance (_f[i], _s) < (_s.size () / (double) _size))
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
double euclidianDistance (const EOFitness & _set1, const EOFitness & _to,
|
/**
|
||||||
unsigned _deg = 2)
|
* Normalization
|
||||||
{
|
* @param _f a Pareto set
|
||||||
double dist = 0;
|
*/
|
||||||
for (unsigned i = 0; i < _set1.size (); i++)
|
void normalize (std::vector< ObjectiveVector > & _f) {
|
||||||
dist += pow (fabs (_set1[i] - _to[i]), (int) _deg);
|
for (unsigned i=0 ; i<ObjectiveVector::nObjectives(); i++)
|
||||||
return pow (dist, 1.0 / _deg);
|
for (unsigned j=0; j<_f.size(); j++)
|
||||||
}
|
_f[j][i] = (_f[j][i] - vect_min_val[i]) / (vect_max_val[i] - vect_min_val[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computation of the union of _f1 and _f2 in _f
|
||||||
|
* @param _f1 the first Pareto set
|
||||||
|
* @param _f2 the second Pareto set
|
||||||
|
* @param _f the final Pareto set
|
||||||
|
*/
|
||||||
|
void computeUnion(const std::vector< ObjectiveVector > & _f1, const std::vector< ObjectiveVector > & _f2, std::vector< ObjectiveVector > & _f) {
|
||||||
|
_f = _f1 ;
|
||||||
|
for (unsigned i=0; i<_f2.size(); i++) {
|
||||||
|
bool b = false;
|
||||||
|
for (unsigned j=0; j<_f1.size(); j ++)
|
||||||
|
if (_f1[j] == _f2[i]) {
|
||||||
|
b = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (! b)
|
||||||
|
_f.push_back(_f2[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many in niche
|
||||||
|
*/
|
||||||
|
unsigned howManyInNicheOf (const std::vector< ObjectiveVector > & _f, const ObjectiveVector & _s, unsigned _size) {
|
||||||
|
unsigned n=0;
|
||||||
|
for (unsigned i=0 ; i<_f.size(); i++) {
|
||||||
|
if (euclidianDistance(_f[i], _s) < (_s.size() / (double) _size))
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Euclidian distance
|
||||||
|
*/
|
||||||
|
double euclidianDistance (const ObjectiveVector & _set1, const ObjectiveVector & _to, unsigned _deg = 2) {
|
||||||
|
double dist=0;
|
||||||
|
for (unsigned i=0; i<_set1.size(); i++)
|
||||||
|
dist += pow(fabs(_set1[i] - _to[i]), (int)_deg);
|
||||||
|
return pow(dist, 1.0 / _deg);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*MOEOENTROPYMETRIC_H_ */
|
#endif /*MOEOENTROPYMETRIC_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// moeoMetric.h
|
// moeoMetric.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -16,91 +16,58 @@
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for performance metrics (also called quality indicators)
|
* Base class for performance metrics (also known as quality indicators).
|
||||||
*/
|
*/
|
||||||
class moeoMetric:public eoFunctorBase
|
class moeoMetric : public eoFunctorBase
|
||||||
{
|
{};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for unary metrics
|
* Base class for unary metrics.
|
||||||
*/
|
*/
|
||||||
template < class A, class R > class moeoUM:public eoUF < A, R >,
|
template < class A, class R >
|
||||||
public moeoMetric
|
class moeoUnaryMetric : public eoUF < A, R >, public moeoMetric
|
||||||
{
|
{};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for binary metrics
|
* Base class for binary metrics.
|
||||||
*/
|
*/
|
||||||
template < class A1, class A2, class R > class moeoBM:public eoBF < A1, A2, R >,
|
template < class A1, class A2, class R >
|
||||||
public moeoMetric
|
class moeoBinaryMetric : public eoBF < A1, A2, R >, public moeoMetric
|
||||||
{
|
{};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for unary metrics dedicated to the performance evaluation of a single solution's Pareto fitness
|
* Base class for unary metrics dedicated to the performance evaluation of a single solution's objective vector.
|
||||||
*/
|
*/
|
||||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoSolutionUM:public moeoUM <
|
template < class ObjectiveVector, class R >
|
||||||
const
|
class moeoSolutionUnaryMetric : public moeoUnaryMetric < const ObjectiveVector &, R >
|
||||||
EOFitness &,
|
{};
|
||||||
R >
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of Pareto fitnesses)
|
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of objective vectors)
|
||||||
*/
|
*/
|
||||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoVectorUM:public moeoUM <
|
template < class ObjectiveVector, class R >
|
||||||
const
|
class moeoVectorUnaryMetric : public moeoUnaryMetric < const std::vector < ObjectiveVector > &, R >
|
||||||
std::vector <
|
{};
|
||||||
EOFitness > &,
|
|
||||||
R >
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for binary metrics dedicated to the performance comparison between two solutions's Pareto fitnesses
|
* Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors.
|
||||||
*/
|
*/
|
||||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoSolutionVsSolutionBM:public moeoBM <
|
template < class ObjectiveVector, class R >
|
||||||
const
|
class moeoSolutionVsSolutionBinaryMetric : public moeoBinaryMetric < const ObjectiveVector &, const ObjectiveVector &, R >
|
||||||
EOFitness &, const
|
{};
|
||||||
EOFitness &,
|
|
||||||
R >
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for binary metrics dedicated to the performance comparison between a Pareto set (a vector of Pareto fitnesses) and a single solution's Pareto fitness
|
* Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of objective vectors)
|
||||||
*/
|
*/
|
||||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoVectorVsSolutionBM:public moeoBM <
|
template < class ObjectiveVector, class R >
|
||||||
const
|
class moeoVectorVsVectorBinaryMetric : public moeoBinaryMetric < const std::vector < ObjectiveVector > &, const std::vector < ObjectiveVector > &, R >
|
||||||
std::vector <
|
{};
|
||||||
EOFitness > &, const
|
|
||||||
EOFitness &,
|
|
||||||
R >
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
#endif /*MOEOMETRIC_H_*/
|
||||||
* Base class for binary metrics dedicated to the performance comparison between two Pareto sets (two vectors of Pareto fitnesses)
|
|
||||||
*/
|
|
||||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoVectorVsVectorBM:public moeoBM <
|
|
||||||
const
|
|
||||||
std::vector <
|
|
||||||
EOFitness > &, const
|
|
||||||
std::vector <
|
|
||||||
EOFitness > &,
|
|
||||||
R >
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /*MOEOMETRIC_H_ */
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,271 @@
|
||||||
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// moeoNormalizedSolutionVsSolutionBinaryMetric.h
|
||||||
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
|
/*
|
||||||
|
This library...
|
||||||
|
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_
|
||||||
|
#define MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <metric/moeoMetric.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for binary metrics dedicated to the performance comparison between two solutions's objective vectors using normalized values.
|
||||||
|
* Then, indicator values lie in the interval [-1,1].
|
||||||
|
* Note that you have to set the bounds for every objective before using the operator().
|
||||||
|
*/
|
||||||
|
template < class ObjectiveVector, class R >
|
||||||
|
class moeoNormalizedSolutionVsSolutionBinaryMetric : public moeoSolutionVsSolutionBinaryMetric < ObjectiveVector, R >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default ctr for any moeoNormalizedSolutionVsSolutionBinaryMetric object
|
||||||
|
*/
|
||||||
|
moeoNormalizedSolutionVsSolutionBinaryMetric()
|
||||||
|
{
|
||||||
|
bounds.resize(ObjectiveVector::Traits::nObjectives());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the lower bound (_min) and the upper bound (_max) for the objective _obj
|
||||||
|
* _min lower bound
|
||||||
|
* _max upper bound
|
||||||
|
* _obj the objective index
|
||||||
|
*/
|
||||||
|
void setup(double _min, double _max, unsigned _obj)
|
||||||
|
{
|
||||||
|
if (_min == _max)
|
||||||
|
{
|
||||||
|
_min -= tiny();
|
||||||
|
_max += tiny();
|
||||||
|
}
|
||||||
|
bounds[_obj] = eoRealInterval(_min, _max);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the lower bound and the upper bound for the objective _obj using a eoRealInterval object
|
||||||
|
* _realInterval the eoRealInterval object
|
||||||
|
* _obj the objective index
|
||||||
|
*/
|
||||||
|
virtual void setup(eoRealInterval _realInterval, unsigned _obj)
|
||||||
|
{
|
||||||
|
bounds[_obj] = _realInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a very small value that can be used to avoid extreme cases (where the min bound == the max bound)
|
||||||
|
*/
|
||||||
|
static double tiny()
|
||||||
|
{
|
||||||
|
return 1e-6;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/** the bounds for every objective (bounds[i] = bounds for the objective i) */
|
||||||
|
std::vector < eoRealInterval > bounds;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additive epsilon binary metric allowing to compare two objective vectors as proposed in
|
||||||
|
* Zitzler E., Thiele L., Laumanns M., Fonseca C. M., Grunert da Fonseca V.:
|
||||||
|
* Performance Assessment of Multiobjective Optimizers: An Analysis and Review. IEEE Transactions on Evolutionary Computation 7(2), pp.117–132 (2003).
|
||||||
|
*/
|
||||||
|
template < class ObjectiveVector >
|
||||||
|
class moeoAdditiveEpsilonBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the minimal distance by which the objective vector _o1 must be translated in all objectives
|
||||||
|
* so that it weakly dominates the objective vector _o2
|
||||||
|
* @warning don't forget to set the bounds for every objective before the call of this function
|
||||||
|
* @param _o1 the first objective vector
|
||||||
|
* @param _o2 the second objective vector
|
||||||
|
*/
|
||||||
|
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
|
||||||
|
{
|
||||||
|
// computation of the epsilon value for the first objective
|
||||||
|
double result = epsilon(_o1, _o2, 0);
|
||||||
|
// computation of the epsilon value for the other objectives
|
||||||
|
double tmp;
|
||||||
|
for (unsigned i=1; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||||
|
{
|
||||||
|
tmp = epsilon(_o1, _o2, i);
|
||||||
|
result = std::max(result, tmp);
|
||||||
|
}
|
||||||
|
// returns the maximum epsilon value
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** the bounds for every objective */
|
||||||
|
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the epsilon value by which the objective vector _o1 must be translated in the objective _obj
|
||||||
|
* so that it dominates the objective vector _o2
|
||||||
|
* @param _o1 the first objective vector
|
||||||
|
* @param _o2 the second objective vector
|
||||||
|
* @param _obj the index of the objective
|
||||||
|
*/
|
||||||
|
double epsilon(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned _obj)
|
||||||
|
{
|
||||||
|
double result;
|
||||||
|
// if the objective _obj have to be minimized
|
||||||
|
if (ObjectiveVector::Traits::minimizing(_obj))
|
||||||
|
{
|
||||||
|
// _o1[_obj] - _o2[_obj]
|
||||||
|
result = ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
|
||||||
|
}
|
||||||
|
// if the objective _obj have to be maximized
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// _o2[_obj] - _o1[_obj]
|
||||||
|
result = ( (_o2[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() ) - ( (_o1[_obj] - bounds[_obj].minimum()) / bounds[_obj].range() );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hypervolume binary metric allowing to compare two objective vectors as proposed in
|
||||||
|
* Zitzler E., Künzli S.: Indicator-Based Selection in Multiobjective Search. In Parallel Problem Solving from Nature (PPSN VIII).
|
||||||
|
* Lecture Notes in Computer Science 3242, Springer, Birmingham, UK pp.832–842 (2004).
|
||||||
|
* This indicator is based on the hypervolume concept introduced in
|
||||||
|
* Zitzler, E., Thiele, L.: Multiobjective Optimization Using Evolutionary Algorithms - A Comparative Case Study.
|
||||||
|
* Parallel Problem Solving from Nature (PPSN-V), pp.292-301 (1998).
|
||||||
|
*/
|
||||||
|
template < class ObjectiveVector >
|
||||||
|
class moeoHypervolumeBinaryMetric : public moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor
|
||||||
|
* @param _rho value used to compute the reference point from the worst values for each objective (default : 1.1)
|
||||||
|
*/
|
||||||
|
moeoHypervolumeBinaryMetric(double _rho = 1.1) : rho(_rho)
|
||||||
|
{
|
||||||
|
// not-a-maximization problem check
|
||||||
|
for (unsigned i=0; i<ObjectiveVector::Traits::nObjectives(); i++)
|
||||||
|
{
|
||||||
|
if (ObjectiveVector::Traits::maximizing(i))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Hypervolume binary metric not yet implemented for a maximization problem in moeoHypervolumeBinaryMetric");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// consistency check
|
||||||
|
if (rho < 1)
|
||||||
|
{
|
||||||
|
cout << "Warning, value used to compute the reference point rho for the hypervolume calculation must not be smaller than 1" << endl;
|
||||||
|
cout << "Adjusted to 1" << endl;
|
||||||
|
rho = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the volume of the space that is dominated by _o2 but not by _o1 with respect to a reference point computed using rho.
|
||||||
|
* @warning don't forget to set the bounds for every objective before the call of this function
|
||||||
|
* @param _o1 the first objective vector
|
||||||
|
* @param _o2 the second objective vector
|
||||||
|
*/
|
||||||
|
double operator()(const ObjectiveVector & _o1, const ObjectiveVector & _o2)
|
||||||
|
{
|
||||||
|
double result;
|
||||||
|
// if _o1 dominates _o2
|
||||||
|
if ( paretoComparator(_o1,_o2) )
|
||||||
|
{
|
||||||
|
result = - hypervolume(_o1, _o2, ObjectiveVector::Traits::nObjectives()-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = hypervolume(_o2, _o1, ObjectiveVector::Traits::nObjectives()-1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** value used to compute the reference point from the worst values for each objective */
|
||||||
|
double rho;
|
||||||
|
/** the bounds for every objective */
|
||||||
|
using moeoNormalizedSolutionVsSolutionBinaryMetric < ObjectiveVector, double > :: bounds;
|
||||||
|
/** Functor to compare two objective vectors according to Pareto dominance relation */
|
||||||
|
moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the volume of the space that is dominated by _o2 but not by _o1 with respect to a reference point computed using rho for the objective _obj.
|
||||||
|
* @param _o1 the first objective vector
|
||||||
|
* @param _o2 the second objective vector
|
||||||
|
* @param _obj the objective index
|
||||||
|
* @param _flag used for iteration, if _flag=true _o2 is not talen into account (default : false)
|
||||||
|
*/
|
||||||
|
double hypervolume(const ObjectiveVector & _o1, const ObjectiveVector & _o2, const unsigned _obj, const bool _flag = false)
|
||||||
|
{
|
||||||
|
double result;
|
||||||
|
double range = rho * bounds[_obj].range();
|
||||||
|
double max = bounds[_obj].minimum() + range;
|
||||||
|
// value of _1 for the objective _obj
|
||||||
|
double v1 = _o1[_obj];
|
||||||
|
// value of _2 for the objective _obj (if _flag=true, v2=max)
|
||||||
|
double v2;
|
||||||
|
if (_flag)
|
||||||
|
{
|
||||||
|
v2 = max;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v2 = _o2[_obj];
|
||||||
|
}
|
||||||
|
// computation of the volume
|
||||||
|
if (_obj == 0)
|
||||||
|
{
|
||||||
|
if (v1 < v2)
|
||||||
|
{
|
||||||
|
result = (v2 - v1) / range;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (v1 < v2)
|
||||||
|
{
|
||||||
|
result = ( hypervolume(_o1, _o2, _obj-1, true) * (v2 - v1) / range ) + ( hypervolume(_o1, _o2, _obj-1) * (max - v2) / range );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = hypervolume(_o1, _o2, _obj-1) * (max - v2) / range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*MOEONORMALIZEDSOLUTIONVSSOLUTIONBINARYMETRIC_H_*/
|
||||||
Loading…
Add table
Add a link
Reference in a new issue