git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@17 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
130ceaf36e
commit
7768209973
13 changed files with 0 additions and 1195 deletions
|
|
@ -1,94 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoBinaryMetricSavingUpdater.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOBINARYMETRICSAVINGUPDATER_H_
|
||||
#define MOEOBINARYMETRICSAVINGUPDATER_H_
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoUpdater.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)
|
||||
* with the fitness values of the population (or archive) of the generation (n-1) into a file
|
||||
*/
|
||||
template < class EOT > class moeoBinaryMetricSavingUpdater:public eoUpdater
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The fitness type of a solution
|
||||
*/
|
||||
typedef typename EOT::Fitness EOFitness;
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _metric the binary metric comparing two Pareto sets
|
||||
* @param _pop the main population
|
||||
* @param _filename the target filename
|
||||
*/
|
||||
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBM < EOT, double >&_metric,
|
||||
const eoPop < EOT > &_pop,
|
||||
std::string _filename):metric (_metric),
|
||||
pop (_pop), filename (_filename), counter (1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the metric's value for the current generation
|
||||
*/
|
||||
void operator () ()
|
||||
{
|
||||
if (pop.size ())
|
||||
{
|
||||
if (firstGen)
|
||||
{
|
||||
firstGen = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// creation of the two Pareto sets
|
||||
std::vector < EOFitness > from;
|
||||
std::vector < EOFitness > to;
|
||||
for (unsigned i = 0; i < pop.size (); i++)
|
||||
from.push_back (pop[i].fitness ());
|
||||
for (unsigned i = 0; i < oldPop.size (); i++)
|
||||
to.push_back (oldPop[i].fitness ());
|
||||
// writing the result into the file
|
||||
std::ofstream f (filename.c_str (), std::ios::app);
|
||||
f << counter++ << ' ' << metric (from, to) << std::endl;
|
||||
f.close ();
|
||||
}
|
||||
oldPop = pop;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** binary metric comparing two Pareto sets */
|
||||
moeoVectorVsVectorBM < EOT, double >&metric;
|
||||
/** main population */
|
||||
const eoPop < EOT > &pop;
|
||||
/** (n-1) population */
|
||||
eoPop < EOT > oldPop;
|
||||
/** target filename */
|
||||
std::string filename;
|
||||
/** is it the first generation ? */
|
||||
bool firstGen;
|
||||
/** counter */
|
||||
unsigned counter;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOBINARYMETRICSAVINGUPDATER_H_ */
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoContributionMetric.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOCONTRIBUTIONMETRIC_H_
|
||||
#define MOEOCONTRIBUTIONMETRIC_H_
|
||||
|
||||
#include <metric/moeoMetric.h>
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
template < class EOT > class moeoContributionMetric:public moeoVectorVsVectorBM < EOT,
|
||||
double >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The fitness type of a solution
|
||||
*/
|
||||
typedef typename EOT::Fitness EOFitness;
|
||||
|
||||
/**
|
||||
* Returns the contribution of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
double operator () (const std::vector < EOFitness > &_set1,
|
||||
const std::vector < EOFitness > &_set2)
|
||||
{
|
||||
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:
|
||||
|
||||
/**
|
||||
* Returns the number of solutions both in '_set1' and '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
unsigned card_C (const std::vector < EOFitness > &_set1,
|
||||
const std::vector < EOFitness > &_set2)
|
||||
{
|
||||
unsigned c = 0;
|
||||
for (unsigned i = 0; i < _set1.size (); i++)
|
||||
for (unsigned j = 0; j < _set2.size (); j++)
|
||||
if (_set1[i] == _set2[j])
|
||||
{
|
||||
c++;
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of solutions in '_set1' dominating at least one solution of '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
unsigned card_W (const std::vector < EOFitness > &_set1,
|
||||
const std::vector < EOFitness > &_set2)
|
||||
{
|
||||
unsigned w = 0;
|
||||
for (unsigned i = 0; i < _set1.size (); i++)
|
||||
for (unsigned j = 0; j < _set2.size (); j++)
|
||||
if (_set1[i].dominates (_set2[j]))
|
||||
{
|
||||
w++;
|
||||
break;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of solutions in '_set1' having no relation of dominance with those from '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
unsigned card_N (const std::vector < EOFitness > &_set1,
|
||||
const std::vector < EOFitness > &_set2)
|
||||
{
|
||||
unsigned n = 0;
|
||||
for (unsigned i = 0; i < _set1.size (); i++)
|
||||
{
|
||||
bool domin_rel = false;
|
||||
for (unsigned j = 0; j < _set2.size (); j++)
|
||||
if (_set1[i].dominates (_set2[j]) || _set2[j].dominates (_set1[i]))
|
||||
{
|
||||
domin_rel = true;
|
||||
break;
|
||||
}
|
||||
if (!domin_rel)
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOCONTRIBUTIONMETRIC_H_ */
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoEntropyMetric.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOENTROPYMETRIC_H_
|
||||
#define MOEOENTROPYMETRIC_H_
|
||||
|
||||
#include <metric/moeoMetric.h>
|
||||
|
||||
/**
|
||||
* The entropy gives an idea of the diversity of a Pareto set relatively to another Pareto set
|
||||
*
|
||||
* (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,
|
||||
double >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The fitness type of a solution
|
||||
*/
|
||||
typedef typename EOT::Fitness EOFitness;
|
||||
|
||||
/**
|
||||
* Returns the entropy of the Pareto set '_set1' relatively to the Pareto set '_set2'
|
||||
* @param _set1 the first Pareto set
|
||||
* @param _set2 the second Pareto set
|
||||
*/
|
||||
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*
|
||||
std::vector < EOFitness > star; // rotf :-)
|
||||
computeUnion (set1, set2, star);
|
||||
removeDominated (star);
|
||||
|
||||
// making of PO1 U PO*
|
||||
std::vector < EOFitness > union_set1_star; // rotf again ...
|
||||
computeUnion (set1, star, union_set1_star);
|
||||
|
||||
unsigned C = union_set1_star.size ();
|
||||
float omega = 0;
|
||||
float entropy = 0;
|
||||
|
||||
for (unsigned i = 0; i < C; i++)
|
||||
{
|
||||
unsigned N_i = howManyInNicheOf (union_set1_star, union_set1_star[i],
|
||||
star.size ());
|
||||
unsigned n_i =
|
||||
howManyInNicheOf (set1, union_set1_star[i], star.size ());
|
||||
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:
|
||||
|
||||
std::vector < double >vect_min_val;
|
||||
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)
|
||||
{
|
||||
vect_min_val.clear ();
|
||||
vect_max_val.clear ();
|
||||
|
||||
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)
|
||||
{
|
||||
for (unsigned i = 0; i < EOFitness::fitness_traits::nObjectives (); i++)
|
||||
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]);
|
||||
}
|
||||
|
||||
void computeUnion (const std::vector < EOFitness > &_f1,
|
||||
const std::vector < EOFitness > &_f2,
|
||||
std::vector < EOFitness > &_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]);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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_ */
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoMetric.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOMETRIC_H_
|
||||
#define MOEOMETRIC_H_
|
||||
|
||||
#include <eoFunctor.h>
|
||||
|
||||
/**
|
||||
* Base class for performance metrics (also called quality indicators)
|
||||
*/
|
||||
class moeoMetric:public eoFunctorBase
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for unary metrics
|
||||
*/
|
||||
template < class A, class R > class moeoUM:public eoUF < A, R >,
|
||||
public moeoMetric
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for binary metrics
|
||||
*/
|
||||
template < class A1, class A2, class R > class moeoBM:public eoBF < A1, A2, R >,
|
||||
public moeoMetric
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for unary metrics dedicated to the performance evaluation of a single solution's Pareto fitness
|
||||
*/
|
||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoSolutionUM:public moeoUM <
|
||||
const
|
||||
EOFitness &,
|
||||
R >
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for unary metrics dedicated to the performance evaluation of a Pareto set (a vector of Pareto fitnesses)
|
||||
*/
|
||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoVectorUM:public moeoUM <
|
||||
const
|
||||
std::vector <
|
||||
EOFitness > &,
|
||||
R >
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Base class for binary metrics dedicated to the performance comparison between two solutions's Pareto fitnesses
|
||||
*/
|
||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoSolutionVsSolutionBM:public moeoBM <
|
||||
const
|
||||
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
|
||||
*/
|
||||
template < class EOT, class R, class EOFitness = typename EOT::Fitness > class moeoVectorVsSolutionBM:public moeoBM <
|
||||
const
|
||||
std::vector <
|
||||
EOFitness > &, const
|
||||
EOFitness &,
|
||||
R >
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 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_ */
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeo.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEO_H_
|
||||
#define MOEO_H_
|
||||
|
||||
#include <eo>
|
||||
|
||||
#include <moeoArchiveFitnessSavingUpdater.h>
|
||||
#include <moeoArchiveUpdater.h>
|
||||
#include <moeoArchive.h>
|
||||
#include <moeoCombinedMOLS.h>
|
||||
#include <moeoHybridMOLS.h>
|
||||
#include <moeoMOLS.h>
|
||||
#include <moeoReplacement.h>
|
||||
#include <moeoSelectOneFromPopAndArch.h>
|
||||
#include <metric/moeoBinaryMetricSavingUpdater.h>
|
||||
#include <metric/moeoContributionMetric.h>
|
||||
#include <metric/moeoEntropyMetric.h>
|
||||
#include <metric/moeoMetric.h>
|
||||
|
||||
#endif /*MOEO_H_ */
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoArchive.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOARCHIVE_H_
|
||||
#define MOEOARCHIVE_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
|
||||
/**
|
||||
* An archive is a secondary population that stores non-dominated solutions
|
||||
*/
|
||||
template < class EOT > class moeoArchive:public eoPop < EOT >
|
||||
{
|
||||
public:
|
||||
|
||||
using std::vector < EOT >::size;
|
||||
using std::vector < EOT >::operator[];
|
||||
using std::vector < EOT >::back;
|
||||
using std::vector < EOT >::pop_back;
|
||||
|
||||
/**
|
||||
* The fitness type of a solution
|
||||
*/
|
||||
typedef typename EOT::Fitness EOFitness;
|
||||
|
||||
/**
|
||||
* Returns true if the current archive dominates _fit
|
||||
* @param _fit the (Pareto) fitness to compare with the current archive
|
||||
*/
|
||||
bool dominates (const EOFitness & _fit) const
|
||||
{
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
if (operator[](i).fitness ().dominates (_fit))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current archive contains _fit
|
||||
* @param _fit the (Pareto) fitness to search within the current archive
|
||||
*/
|
||||
bool contains (const EOFitness & _fit) const
|
||||
{
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
if (operator[](i).fitness () == _fit)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the archive with a given individual _eo
|
||||
* @param _eo the given individual
|
||||
*/
|
||||
void update (const EOT & _eo)
|
||||
{
|
||||
// Removing the dominated solutions from the archive
|
||||
for (unsigned j = 0; j < size ();)
|
||||
{
|
||||
if (_eo.fitness ().dominates (operator[](j).fitness ()))
|
||||
{
|
||||
operator[](j) = back ();
|
||||
pop_back ();
|
||||
}
|
||||
else if (_eo.fitness () == operator[](j).fitness ())
|
||||
{
|
||||
operator[](j) = back ();
|
||||
pop_back ();
|
||||
}
|
||||
else
|
||||
j++;
|
||||
}
|
||||
|
||||
// Dominated ?
|
||||
bool dom = false;
|
||||
for (unsigned j = 0; j < size (); j++)
|
||||
if (operator [](j).fitness ().dominates (_eo.fitness ()))
|
||||
{
|
||||
dom = true;
|
||||
break;
|
||||
}
|
||||
if (!dom)
|
||||
push_back (_eo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the archive with a given population _pop
|
||||
* @param _pop the given population
|
||||
*/
|
||||
void update (const eoPop < EOT > &_pop)
|
||||
{
|
||||
for (unsigned i = 0; i < _pop.size (); i++)
|
||||
update (_pop[i]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVE_H_ */
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoArchiveFitnessSavingUpdater.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOARCHIVEFITNESSSAVINGUPDATER_H_
|
||||
#define MOEOARCHIVEFITNESSSAVINGUPDATER_H_
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoUpdater.h>
|
||||
#include <moeoArchive.h>
|
||||
|
||||
#define MAX_BUFFER_SIZE 1000
|
||||
|
||||
/**
|
||||
* This class allows to save the fitnesses of solutions contained in an archive into a file at each generation.
|
||||
*/
|
||||
template < class EOT > class moeoArchiveFitnessSavingUpdater:public eoUpdater
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _arch local archive
|
||||
* @param _filename target filename
|
||||
* @param _id own ID
|
||||
*/
|
||||
moeoArchiveFitnessSavingUpdater (moeoArchive < EOT > &_arch, const std::string & _filename = "Res/Arch", int _id = -1):arch (_arch), filename (_filename), id (_id),
|
||||
counter
|
||||
(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the fitness of the archive's members into the file
|
||||
*/
|
||||
void operator () ()
|
||||
{
|
||||
char buff[MAX_BUFFER_SIZE];
|
||||
if (id == -1)
|
||||
sprintf (buff, "%s.%u", filename.c_str (), counter++);
|
||||
else
|
||||
sprintf (buff, "%s.%u.%u", filename.c_str (), id, counter++);
|
||||
std::ofstream f (buff);
|
||||
for (unsigned i = 0; i < arch.size (); i++)
|
||||
f << arch[i].fitness () << std::endl;
|
||||
f.close ();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** local archive */
|
||||
moeoArchive < EOT > &arch;
|
||||
/** target filename */
|
||||
std::string filename;
|
||||
/** own ID */
|
||||
int id;
|
||||
/** counter */
|
||||
unsigned counter;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEFITNESSSAVINGUPDATER_H_ */
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoArchiveUpdater.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOARCHIVEUPDATER_H_
|
||||
#define MOEOARCHIVEUPDATER_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoUpdater.h>
|
||||
#include <moeoArchive.h>
|
||||
|
||||
/**
|
||||
* This class allows to update the archive at each generation with newly found non-dominated solutions
|
||||
*/
|
||||
template < class EOT > class moeoArchiveUpdater:public eoUpdater
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _arch an archive of non-dominated solutions
|
||||
* @param _pop the main population
|
||||
*/
|
||||
moeoArchiveUpdater (moeoArchive < EOT > &_arch,
|
||||
const eoPop < EOT > &_pop):arch (_arch), pop (_pop)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the archive with newly found non-dominated solutions contained in the main population
|
||||
*/
|
||||
void operator () ()
|
||||
{
|
||||
arch.update (pop);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** the archive of non-dominated solutions */
|
||||
moeoArchive < EOT > &arch;
|
||||
/** the main population */
|
||||
const eoPop < EOT > &pop;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOARCHIVEUPDATER_H_ */
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoCombinedMOLS.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOCOMBINEDMOLS_H_
|
||||
#define MOEOCOMBINEDMOLS_H_
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
#include <moeoArchive.h>
|
||||
#include <moeoMOLS.h>
|
||||
|
||||
/**
|
||||
* This class allows to embed a set of local searches that are sequentially applied,
|
||||
* and so working and updating the same archive of non-dominated solutions
|
||||
*/
|
||||
template < class EOT > class moeoCombinedMOLS:public moeoMOLS < EOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _eval the full evaluator of a solution
|
||||
* @param _first_ls the first multi-objective local search to add
|
||||
*/
|
||||
moeoCombinedMOLS (eoEvalFunc < EOT > &_eval, moeoMOLS < EOT > &_first_ls):eval
|
||||
(_eval)
|
||||
{
|
||||
combinedMOLS.push_back (&_first_ls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new local search to combine
|
||||
* @param _ls the multi-objective local search to add
|
||||
*/
|
||||
void add (moeoMOLS < EOT > &_ls)
|
||||
{
|
||||
combinedMOLS.push_back (&_ls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives a new solution in order to explore the neigborhood.
|
||||
* The new non-dominated solutions are added to the archive
|
||||
* @param _eo the solution
|
||||
* @param _arch the archive of non-dominated solutions
|
||||
*/
|
||||
void operator () (const EOT & _eo, moeoArchive < EOT > &_arch)
|
||||
{
|
||||
eval (const_cast < EOT & >(_eo));
|
||||
for (unsigned i = 0; i < combinedMOLS.size (); i++)
|
||||
combinedMOLS[i]->operator ()(_eo, _arch);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** the full evaluator of a solution */
|
||||
eoEvalFunc < EOT > &eval;
|
||||
/** the vector that contains the combined MOLS */
|
||||
std::vector < moeoMOLS < EOT > *>combinedMOLS;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOCOMBINEDMOLS_H_ */
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoHybridMOLS.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOHYBRIDMOLS_H_
|
||||
#define MOEOHYBRIDMOLS_H_
|
||||
|
||||
#include <eoContinue.h>
|
||||
#include <eoPop.h>
|
||||
#include <eoUpdater.h>
|
||||
#include <eoSelect.h>
|
||||
#include <moeoArchive.h>
|
||||
#include <moeoMOLS.h>
|
||||
|
||||
/**
|
||||
* This class allows to apply a multi-objective local search to a number of selected individuals contained in the archive
|
||||
* at every generation until a stopping criteria is verified.
|
||||
*/
|
||||
template < class EOT > class moeoHybridMOLS:public eoUpdater
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _term stopping criteria
|
||||
* @param _select selector
|
||||
* @param _mols a multi-objective local search
|
||||
* @param _arch the archive
|
||||
*/
|
||||
eoHybridMOLS (eoContinue < EOT > &_term, eoSelect < EOT > &_select, moeoMOLS < EOT > &_mols, moeoArchive < EOT > &_arch):term (_term), select (_select), mols (_mols),
|
||||
arch
|
||||
(_arch)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the multi-objective local search to selected individuals contained in the archive if the stopping criteria is not verified
|
||||
*/
|
||||
void operator () ()
|
||||
{
|
||||
if (!cont (arch))
|
||||
{
|
||||
// selection of solutions
|
||||
eoPop < EOT > selectedSolutions;
|
||||
select (arch, selectedSolutions);
|
||||
// apply the local search to every selected solution
|
||||
for (unsigned i = 0; i < selectedSolutions.size (); i++)
|
||||
mols (selectedSolutions[i], arch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** stopping criteria*/
|
||||
eoContinue < EOT > &term;
|
||||
/** selector */
|
||||
eoSelect < EOT > &select;
|
||||
/** multi-objective local search */
|
||||
moeoMOLS < EOT > &mols;
|
||||
/** archive */
|
||||
moeoArchive < EOT > &arch;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOHYBRIDMOLS_H_ */
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoMOLS.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOMOLS_H_
|
||||
#define MOEOMOLS_H_
|
||||
|
||||
#include <eoFunctor.h>
|
||||
#include <moeoArchive.h>
|
||||
|
||||
/**
|
||||
* Abstract class for local searches applied to multi-objective optimization.
|
||||
* Starting from only one solution, it produces a set of new non-dominated solutions.
|
||||
*/
|
||||
template < class EOT > class moeoMOLS:public eoBF < const EOT &, moeoArchive < EOT > &,
|
||||
void >
|
||||
{
|
||||
};
|
||||
|
||||
#endif /*MOEOMOLS_H_ */
|
||||
|
|
@ -1,169 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoReplacement.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOREPLACEMENT_H_
|
||||
#define MOEOREPLACEMENT_H_
|
||||
|
||||
#include <eoPerf2Worth.h>
|
||||
#include <eoPop.h>
|
||||
#include <eoReplacement.h>
|
||||
|
||||
|
||||
/**
|
||||
* Replacement strategy for multi-objective optimization
|
||||
*/
|
||||
template < class EOT, class WorthT > class moeoReplacement:public eoReplacement <
|
||||
EOT >
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Keep all the best individuals
|
||||
* (almost cut-and-pasted from eoNDPlusReplacement, (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2002)
|
||||
*/
|
||||
template < class EOT, class WorthT =
|
||||
double >class moeoElitistReplacement:public moeoReplacement < EOT, WorthT >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param _perf2worth the functor class to transform raw fitnesses into fitness for selection
|
||||
*/
|
||||
moeoElitistReplacement (eoPerf2Worth < EOT,
|
||||
WorthT > &_perf2worth):perf2worth (_perf2worth)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* replacement - result in _parents
|
||||
* @param _parents parents population
|
||||
* @param _offspring offspring population
|
||||
*/
|
||||
void operator () (eoPop < EOT > &_parents, eoPop < EOT > &_offspring)
|
||||
{
|
||||
unsigned size = _parents.size ();
|
||||
_parents.reserve (_parents.size () + _offspring.size ());
|
||||
copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
|
||||
|
||||
// calculate worths
|
||||
perf2worth (_parents);
|
||||
perf2worth.sort_pop (_parents);
|
||||
perf2worth.resize (_parents, size);
|
||||
|
||||
_offspring.clear ();
|
||||
}
|
||||
|
||||
private:
|
||||
/** the functor object to transform raw fitnesses into fitness for selection */
|
||||
eoPerf2Worth < EOT, WorthT > &perf2worth;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Same than moeoElitistReplacement except that distinct individuals are privilegied
|
||||
*/
|
||||
template < class EOT, class WorthT =
|
||||
double >class moeoDisctinctElitistReplacement:public moeoReplacement < EOT,
|
||||
WorthT >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* constructor
|
||||
* @param _perf2worth the functor class to transform raw fitnesses into fitness for selection
|
||||
*/
|
||||
moeoDisctinctElitistReplacement (eoPerf2Worth < EOT,
|
||||
WorthT >
|
||||
&_perf2worth):perf2worth (_perf2worth)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* replacement - result in _parents
|
||||
* @param _parents parents population
|
||||
* @param _offspring offspring population
|
||||
*/
|
||||
void operator () (eoPop < EOT > &_parents, eoPop < EOT > &_offspring)
|
||||
{
|
||||
unsigned size = _parents.size ();
|
||||
_parents.reserve (_parents.size () + _offspring.size ());
|
||||
copy (_offspring.begin (), _offspring.end (), back_inserter (_parents));
|
||||
|
||||
// creation of the new population (of size 'size')
|
||||
createNewPop (_parents, size);
|
||||
|
||||
_offspring.clear ();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** the functor object to transform raw fitnesses into fitness for selection */
|
||||
eoPerf2Worth < EOT, WorthT > &perf2worth;
|
||||
|
||||
|
||||
/**
|
||||
* creation of the new population of size _size
|
||||
* @param _pop the initial population (will be modified)
|
||||
* @param _size the size of the population to create
|
||||
*/
|
||||
void createNewPop (eoPop < EOT > &_pop, unsigned _size)
|
||||
{
|
||||
// the number of occurences for each individual
|
||||
std::map < EOT, unsigned >nb_occurences;
|
||||
for (unsigned i = 0; i < _pop.size (); i++)
|
||||
nb_occurences[_pop[i]] = 0;
|
||||
// the new population
|
||||
eoPop < EOT > new_pop;
|
||||
new_pop.reserve (_pop.size ());
|
||||
for (unsigned i = 0; i < _pop.size (); i++)
|
||||
{
|
||||
if (nb_occurences[_pop[i]] == 0)
|
||||
new_pop.push_back (_pop[i]);
|
||||
nb_occurences[_pop[i]]++;
|
||||
}
|
||||
|
||||
// calculate worths (on the new population)
|
||||
perf2worth (new_pop);
|
||||
perf2worth.sort_pop (new_pop);
|
||||
|
||||
// if case there's not enough individuals in the population...
|
||||
unsigned new_pop_size_init = new_pop.size ();
|
||||
unsigned k = 0;
|
||||
while (new_pop.size () < _size)
|
||||
{
|
||||
if (k < new_pop_size_init)
|
||||
{
|
||||
if (nb_occurences[new_pop[k]] > 1)
|
||||
{
|
||||
new_pop.push_back (new_pop[k]);
|
||||
nb_occurences[new_pop[k]]--;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
else
|
||||
k = 0;
|
||||
}
|
||||
|
||||
// resize and swap the populations
|
||||
perf2worth.resize (new_pop, _size);
|
||||
_pop.resize (_size);
|
||||
_pop.swap (new_pop);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOREPLACEMENT_H_ */
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// moeoSelectOneFormPopAndArch.h
|
||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
||||
/*
|
||||
This library...
|
||||
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef MOEOSELECTONEFROMPOPANDARCH_H_
|
||||
#define MOEOSELECTONEFROMPOPANDARCH_H_
|
||||
|
||||
#include <eoPop.h>
|
||||
#include <eoRandomSelect.h>
|
||||
#include <eoSelectOne.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <moeoArchive.h>
|
||||
|
||||
/**
|
||||
* Elitist selection process that consists in choosing individuals in the archive as well as in the current population.
|
||||
*/
|
||||
template < class EOT > class moeoSelectOneFromPopAndArch:public eoSelectOne <
|
||||
EOT >
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Ctor
|
||||
* @param _popSelectOne the population's selection operator
|
||||
* @param _archSelectOne the archive's selection operator
|
||||
* @param _arch the archive
|
||||
* @param _ratioFromPop the ratio of selected individuals from the population
|
||||
*/
|
||||
moeoSelectOneFromPopAndArch (eoSelectOne < EOT > &_popSelectOne, eoSelectOne < EOT > _archSelectOne, moeoArchive < EOT > &_arch, double _ratioFromPop = 0.5):popSelectOne (_popSelectOne), archSelectOne (_archSelectOne), arch (_arch),
|
||||
ratioFromPop
|
||||
(_ratioFromPop)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctor - the archive's selection operator is a random selector
|
||||
* @param _popSelectOne the population's selection operator
|
||||
* @param _arch the archive
|
||||
* @param _ratioFromPop the ratio of selected individuals from the population
|
||||
*/
|
||||
moeoSelectOneFromPopAndArch (eoSelectOne < EOT > &_popSelectOne, moeoArchive < EOT > &_arch, double _ratioFromPop = 0.5):popSelectOne (_popSelectOne), archSelectOne (randomSelect), arch (_arch),
|
||||
ratioFromPop
|
||||
(_ratioFromPop)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* The selection process
|
||||
*/
|
||||
virtual const EOT & operator () (const eoPop < EOT > &pop)
|
||||
{
|
||||
if (arch.size () > 0)
|
||||
if (rng.flip (ratioFromPop))
|
||||
return popSelectOne (pop);
|
||||
else
|
||||
return archSelectOne (arch);
|
||||
else
|
||||
return popSelectOne (pop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups some population stats
|
||||
*/
|
||||
virtual void setup (const eoPop < EOT > &_pop)
|
||||
{
|
||||
popSelectOne.setup (_pop);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** The population's selection operator */
|
||||
eoSelectOne < EOT > &popSelectOne;
|
||||
/** The archive's selection operator */
|
||||
eoSelectOne < EOT > &archSelectOne;
|
||||
/** the archive */
|
||||
moeoArchive < EOT > &arch;
|
||||
/** the ratio of selected individuals from the population*/
|
||||
double ratioFromPop;
|
||||
/** the random selection operator */
|
||||
eoRandomSelect < EOT > randomSelect;
|
||||
|
||||
};
|
||||
|
||||
#endif /*MOEOSELECTONEFROMPOPANDARCH_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue