Documentation and tests added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1697 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e6d874bc1b
commit
92251dc96f
20 changed files with 626 additions and 247 deletions
|
|
@ -52,8 +52,9 @@ public :
|
|||
/**
|
||||
* Default constructor (moCheckpoint must have at least one continuator)
|
||||
* @param _cont a continuator
|
||||
* @param _interval frequency to compute statistical operators
|
||||
*/
|
||||
moCheckpoint(moContinuator<Neighborhood>& _cont) {
|
||||
moCheckpoint(moContinuator<Neighborhood>& _cont, unsigned int _interval=1):interval(_interval), counter(0){
|
||||
continuators.push_back(&_cont);
|
||||
}
|
||||
|
||||
|
|
@ -112,8 +113,11 @@ public :
|
|||
unsigned i;
|
||||
bool bContinue = true;
|
||||
|
||||
for (i = 0; i < stats.size(); ++i)
|
||||
(*stats[i])(_sol);
|
||||
for (i = 0; i < stats.size(); ++i){
|
||||
if(counter % interval == 0)
|
||||
(*stats[i])(_sol);
|
||||
counter++;
|
||||
}
|
||||
|
||||
for (i = 0; i < updaters.size(); ++i)
|
||||
(*updaters[i])();
|
||||
|
|
@ -154,6 +158,9 @@ private :
|
|||
/** updaters vector */
|
||||
std::vector<eoUpdater*> updaters;
|
||||
|
||||
unsigned int interval;
|
||||
unsigned int counter;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@ public:
|
|||
* Init Continuator parameters
|
||||
* @param _solution the related solution
|
||||
*/
|
||||
virtual void init(EOT& _solution) { } ;
|
||||
virtual void init(EOT& _solution){};
|
||||
|
||||
/**
|
||||
* Last Call to terminate the checkpoint
|
||||
* @param _solution the related solution
|
||||
*/
|
||||
virtual void lastCall(EOT& _solution){}
|
||||
virtual void lastCall(EOT& _solution){};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
<moFitnessStat.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef moCounterStat_h
|
||||
#define moCoutnerStat_h
|
||||
|
||||
#include <continuator/moStat.h>
|
||||
|
||||
/**
|
||||
* The actual class that will be used as base for all statistics
|
||||
* that need to be calculated over the solution
|
||||
* It is a moStatBase AND an eoValueParam so it can be used in Monitors.
|
||||
*/
|
||||
template <class EOT, class T>
|
||||
class moCounterStat : public moStat< EOT, T >
|
||||
{
|
||||
public :
|
||||
moCounterStat(unsigned int _interval, moStat<EOT, T> & _solStat): moStat<EOT, T >(0, "every"), interval(_interval){
|
||||
solStats.push_back(&_solStat);
|
||||
}
|
||||
|
||||
void add(moStat<EOT, T>& _stat) {
|
||||
solStats.push_back(&_stat);
|
||||
}
|
||||
|
||||
|
||||
virtual void operator()(EOT & _sol) {
|
||||
if (++counter % interval == 0)
|
||||
for (unsigned i = 0; i < solStats.size(); ++i)
|
||||
(*solStats[i])(_sol);
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "moCounterStat"; }
|
||||
|
||||
private:
|
||||
unsigned int counter, interval;
|
||||
|
||||
std::vector<moStat<EOT, T>* > solStats;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -42,29 +42,41 @@
|
|||
* The statistic gives the distance to a reference solution
|
||||
* The reference solution could be the global optimum, or the best knowed solution
|
||||
* It allows to compute the Fitness-Distance correlation (FDC)
|
||||
*/
|
||||
*/
|
||||
template <class EOT, class T = double>
|
||||
class moDistanceStat : public moStat<EOT, T>
|
||||
{
|
||||
public :
|
||||
using moStat< EOT, T >::value;
|
||||
|
||||
moDistanceStat(eoDistance<EOT> & _dist, EOT & _ref)
|
||||
: moStat<EOT, T>(0, "distance"), dist(_dist), refSolution(_ref)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _dist a distance
|
||||
* @param _ref the reference solution
|
||||
*/
|
||||
moDistanceStat(eoDistance<EOT> & _dist, EOT & _ref): moStat<EOT, T>(0, "distance"), dist(_dist), refSolution(_ref){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
value() = dist(_sol, refSolution);
|
||||
}
|
||||
/**
|
||||
* Compute distance between a solution and the reference solution
|
||||
* @param _sol a solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = dist(_sol, refSolution);
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "moDistanceStat"; }
|
||||
/**
|
||||
* @return name of the class
|
||||
*/
|
||||
virtual std::string className(void) const { return "moDistanceStat"; }
|
||||
|
||||
private:
|
||||
eoDistance<EOT> & dist;
|
||||
// the reference solution does not change during the run
|
||||
// it could be the best solution knowed of the problem
|
||||
EOT refSolution;
|
||||
/** the distance */
|
||||
eoDistance<EOT> & dist;
|
||||
/**
|
||||
* the reference solution does not change during the run
|
||||
* it could be the best solution knowed of the problem
|
||||
*/
|
||||
EOT refSolution;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -49,15 +49,25 @@ public :
|
|||
typedef T Fitness;
|
||||
using moStat< EOT, Fitness >::value;
|
||||
|
||||
moFitnessStat(std::string _description = "fitness")
|
||||
: moStat<EOT, Fitness>(Fitness(), _description)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _description a description of the stat
|
||||
*/
|
||||
moFitnessStat(std::string _description = "fitness"):
|
||||
moStat<EOT, Fitness>(Fitness(), _description){}
|
||||
|
||||
/**
|
||||
* store fitness value
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
value() = _sol.fitness();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the class
|
||||
*/
|
||||
virtual std::string className(void) const { return "moFitnessStat"; }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -39,10 +39,8 @@
|
|||
#include <continuator/moNeighborhoodStat.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* From moNeighborhoodStat, to compute the max fitness in the neighborhood
|
||||
*
|
||||
*/
|
||||
*/
|
||||
template< class Neighborhood >
|
||||
class moMaxNeighborStat : public moStat<typename Neighborhood::EOT, typename Neighborhood::EOT::Fitness>
|
||||
{
|
||||
|
|
@ -52,19 +50,29 @@ public :
|
|||
|
||||
using moStat< EOT, Fitness >::value;
|
||||
|
||||
moMaxNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moMaxNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the max fitness in the neighborhood
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = nhStat.getMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moMaxNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,10 +39,8 @@
|
|||
#include <continuator/moNeighborhoodStat.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* From moNeighborhoodStat, to compute the min fitness in the neighborhood
|
||||
*
|
||||
*/
|
||||
*/
|
||||
template< class Neighborhood >
|
||||
class moMinNeighborStat : public moStat<typename Neighborhood::EOT, typename Neighborhood::EOT::Fitness>
|
||||
{
|
||||
|
|
@ -52,19 +50,29 @@ public :
|
|||
|
||||
using moStat< EOT, Fitness >::value;
|
||||
|
||||
moMinNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moMinNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, Fitness>(Fitness(), "min"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the worst fitness in the neighborhood
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = nhStat.getMin();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moMinNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -53,19 +53,29 @@ public :
|
|||
|
||||
using moStat< EOT, unsigned >::value;
|
||||
|
||||
moNbInfNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, unsigned>(0, "nb inf"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moNbInfNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, unsigned>(0, "nb inf"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the number of solutions in the neighborhood with (strictly) lower fitness than the current solution
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = nhStat.getNbInf();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moNbInfNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -53,19 +53,29 @@ public :
|
|||
|
||||
using moStat< EOT, unsigned >::value;
|
||||
|
||||
moNbSupNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, unsigned>(0, "nb sup"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moNbSupNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, unsigned>(0, "nb sup"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the number of solutions in the neighborhood with better fitness than the current solution
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = nhStat.getNbSup();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moNbSupNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
<moNeigborhoodStat.h>
|
||||
<moNeighborhoodStat.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
|
@ -32,8 +32,8 @@
|
|||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef moNeigborhoodStat_h
|
||||
#define moNeigborhoodStat_h
|
||||
#ifndef moNeighborhoodStat_h
|
||||
#define moNeighborhoodStat_h
|
||||
|
||||
#include <continuator/moStat.h>
|
||||
|
||||
|
|
@ -44,9 +44,9 @@
|
|||
/**
|
||||
* All possible statitic on the neighborhood fitness
|
||||
* to combine with other specific statistic to print them
|
||||
*/
|
||||
*/
|
||||
template< class Neighborhood >
|
||||
class moNeigborhoodStat : public moStat<typename Neighborhood::EOT, bool>
|
||||
class moNeighborhoodStat : public moStat<typename Neighborhood::EOT, bool>
|
||||
{
|
||||
public :
|
||||
typedef typename Neighborhood::EOT EOT ;
|
||||
|
|
@ -55,104 +55,161 @@ public :
|
|||
|
||||
using moStat< EOT, bool >::value;
|
||||
|
||||
moNeigborhoodStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval,
|
||||
moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator)
|
||||
: moStat<EOT, bool>(true, "neighborhood"),
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _neighborhood a neighborhood
|
||||
* @param _eval an evaluation function
|
||||
* @param _neighborComparator a neighbor Comparator
|
||||
* @param _solNeighborComparator a comparator between a solution and a neighbor
|
||||
*/
|
||||
moNeighborhoodStat(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator):
|
||||
moStat<EOT, bool>(true, "neighborhood"),
|
||||
neighborhood(_neighborhood), eval(_eval),
|
||||
neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator)
|
||||
{}
|
||||
neighborComparator(_neighborComparator),
|
||||
solNeighborComparator(_solNeighborComparator)
|
||||
{}
|
||||
|
||||
virtual void operator()(EOT & _solution)
|
||||
{
|
||||
Neighbor current ;
|
||||
Neighbor best ;
|
||||
Neighbor lowest ;
|
||||
/**
|
||||
* Compute classical statistics of a solution's neighborhood
|
||||
* @param _solution the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution){
|
||||
Neighbor current ;
|
||||
Neighbor best ;
|
||||
Neighbor lowest ;
|
||||
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, current);
|
||||
if(neighborhood.hasNeighbor(_solution)){
|
||||
//init the first neighbor
|
||||
neighborhood.init(_solution, current);
|
||||
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, current);
|
||||
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||
eval(_solution, current);
|
||||
|
||||
// init the statistics
|
||||
value() = true;
|
||||
// init the statistics
|
||||
value() = true;
|
||||
|
||||
mean = current.fitness();
|
||||
sd = mean * mean;
|
||||
mean = current.fitness();
|
||||
sd = mean * mean;
|
||||
nb = 1;
|
||||
nbInf = 0;
|
||||
nbEqual = 0;
|
||||
nbSup = 0;
|
||||
|
||||
nb = 1;
|
||||
nbInf = 0;
|
||||
nbEqual = 0;
|
||||
nbSup = 0;
|
||||
if (solNeighborComparator.equals(_solution, current))
|
||||
nbEqual++;
|
||||
else if (solNeighborComparator(_solution, current))
|
||||
nbSup++;
|
||||
else
|
||||
nbInf++;
|
||||
|
||||
if (solNeighborComparator.equals(_solution, current))
|
||||
nbEqual++;
|
||||
else
|
||||
if (solNeighborComparator(_solution, current))
|
||||
nbSup++;
|
||||
else
|
||||
nbInf++;
|
||||
//initialize the best neighbor
|
||||
best = current;
|
||||
lowest = current;
|
||||
|
||||
//initialize the best neighbor
|
||||
best = current;
|
||||
lowest = current;
|
||||
//test all others neighbors
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, current);
|
||||
//eval
|
||||
eval(_solution, current);
|
||||
|
||||
//test all others neighbors
|
||||
while (neighborhood.cont(_solution)) {
|
||||
//next neighbor
|
||||
neighborhood.next(_solution, current);
|
||||
//eval
|
||||
eval(_solution, current);
|
||||
|
||||
mean += current.fitness();
|
||||
sd += current.fitness() * current.fitness();
|
||||
nb++;
|
||||
mean += current.fitness();
|
||||
sd += current.fitness() * current.fitness();
|
||||
nb++;
|
||||
|
||||
if (solNeighborComparator.equals(_solution, current))
|
||||
nbEqual++;
|
||||
else
|
||||
if (solNeighborComparator(_solution, current))
|
||||
nbSup++;
|
||||
else
|
||||
nbInf++;
|
||||
if (solNeighborComparator.equals(_solution, current))
|
||||
nbEqual++;
|
||||
else if (solNeighborComparator(_solution, current))
|
||||
nbSup++;
|
||||
else
|
||||
nbInf++;
|
||||
|
||||
//if we found a better neighbor, update the best
|
||||
if (neighborComparator(best, current))
|
||||
best = current;
|
||||
//if we found a better neighbor, update the best
|
||||
if (neighborComparator(best, current))
|
||||
best = current;
|
||||
|
||||
if (neighborComparator(current, lowest))
|
||||
lowest = current;
|
||||
}
|
||||
if (neighborComparator(current, lowest))
|
||||
lowest = current;
|
||||
}
|
||||
|
||||
max = best.fitness();
|
||||
min = lowest.fitness();
|
||||
max = best.fitness();
|
||||
min = lowest.fitness();
|
||||
|
||||
mean /= nb;
|
||||
if (nb > 1)
|
||||
sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) );
|
||||
else
|
||||
sd = 0.0;
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
value() = false;
|
||||
}
|
||||
mean /= nb;
|
||||
if (nb > 1)
|
||||
sd = sqrt( (sd - nb * mean * mean) / (nb - 1.0) );
|
||||
else
|
||||
sd = 0.0;
|
||||
}
|
||||
else{
|
||||
//if _solution hasn't neighbor,
|
||||
value() = false;
|
||||
}
|
||||
}
|
||||
|
||||
Fitness getMin() { return min ; }
|
||||
Fitness getMax() { return max ; }
|
||||
double getMean() { return mean ; }
|
||||
double getSD() { return sd ; }
|
||||
|
||||
unsigned getSize() { return nb ; }
|
||||
unsigned getNbSup() { return nbSup ; }
|
||||
unsigned getNbEqual() { return nbEqual ; }
|
||||
unsigned getNbInf() { return nbInf ; }
|
||||
/**
|
||||
* @return the worst fitness value found in the neighborhood
|
||||
*/
|
||||
Fitness getMin(){
|
||||
return min;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the best fitness value found in the neighborhood
|
||||
*/
|
||||
Fitness getMax(){
|
||||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mean fitness value of the neighborhood
|
||||
*/
|
||||
double getMean(){
|
||||
return mean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the standard deviation value of the neighborhood
|
||||
*/
|
||||
double getSD(){
|
||||
return sd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the size of the neighborhood
|
||||
*/
|
||||
unsigned getSize(){
|
||||
return nb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of neighbors having a better fitness than the current solution
|
||||
*/
|
||||
unsigned getNbSup(){
|
||||
return nbSup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of neighbors having the same fitness than the current solution
|
||||
*/
|
||||
unsigned getNbEqual(){
|
||||
return nbEqual;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of neighbors having a worst fitness than the current solution
|
||||
*/
|
||||
unsigned getNbInf() {
|
||||
return nbInf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moNeigborhoodStat"; }
|
||||
|
||||
private:
|
||||
|
||||
// to explore the neighborhood
|
||||
Neighborhood& neighborhood ;
|
||||
moEval<Neighbor>& eval;
|
||||
|
|
@ -163,13 +220,14 @@ private:
|
|||
|
||||
// the stastics of the fitness
|
||||
Fitness max, min;
|
||||
//mean and standard deviation
|
||||
double mean, sd ;
|
||||
|
||||
// number of neighbors in the neighborhood;
|
||||
unsigned nb;
|
||||
unsigned int nb;
|
||||
|
||||
// number of neighbors with lower, equal and higher fitness
|
||||
unsigned nbInf, nbEqual, nbSup ;
|
||||
unsigned int nbInf, nbEqual, nbSup ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,12 +39,10 @@
|
|||
#include <continuator/moNeighborhoodStat.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* From moNeighborhoodStat, to compute the neutral degree of the solution
|
||||
* which is the number of solutions in the neighborhood
|
||||
* with equals fitness
|
||||
*
|
||||
*/
|
||||
*/
|
||||
template< class Neighborhood >
|
||||
class moNeutralDegreeNeighborStat : public moStat<typename Neighborhood::EOT, unsigned>
|
||||
{
|
||||
|
|
@ -54,19 +52,29 @@ public :
|
|||
|
||||
using moStat< EOT, unsigned >::value;
|
||||
|
||||
moNeutralDegreeNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, unsigned>(0, "neutral degree"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moNeutralDegreeNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, unsigned>(0, "neutral degree"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the neutral degree of the solution which is the number of solutions in the neighborhood with equals fitness
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = nhStat.getNbEqual();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moNeutralDegreeNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,10 +39,8 @@
|
|||
#include <continuator/moNeighborhoodStat.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* From moNeighborhoodStat, to compute the average and the standard deviation of fitness in the neighborhood
|
||||
*
|
||||
*/
|
||||
*/
|
||||
template< class Neighborhood >
|
||||
class moSecondMomentNeighborStat : public moStat<typename Neighborhood::EOT, std::pair<double, double> >
|
||||
{
|
||||
|
|
@ -52,20 +50,30 @@ public :
|
|||
|
||||
using moStat< EOT, std::pair<double, double> >::value;
|
||||
|
||||
moSecondMomentNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, std::pair<double, double> >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moSecondMomentNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, std::pair<double, double> >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the average and the standard deviation of fitness in the neighborhood
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value().first = nhStat.getMean();
|
||||
value().second = nhStat.getSD();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moSecondMomentNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,10 +39,9 @@
|
|||
#include <continuator/moNeighborhoodStat.h>
|
||||
|
||||
/**
|
||||
*
|
||||
* From moNeighborhoodStat, to compute the number of solutions in the neighborhood
|
||||
*
|
||||
*/
|
||||
*/
|
||||
template< class Neighborhood >
|
||||
class moSizeNeighborStat : public moStat<typename Neighborhood::EOT, unsigned>
|
||||
{
|
||||
|
|
@ -52,19 +51,29 @@ public :
|
|||
|
||||
using moStat< EOT, unsigned >::value;
|
||||
|
||||
moSizeNeighborStat(moNeigborhoodStat<Neighborhood> & _nhStat)
|
||||
: moStat<EOT, unsigned>(0, "size"), nhStat(_nhStat)
|
||||
{}
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _nhStat a neighborhoodStat
|
||||
*/
|
||||
moSizeNeighborStat(moNeighborhoodStat<Neighborhood> & _nhStat):
|
||||
moStat<EOT, unsigned>(0, "size"), nhStat(_nhStat){}
|
||||
|
||||
virtual void operator()(EOT & _sol)
|
||||
{
|
||||
/**
|
||||
* Set the number of solutions in the neighborhood
|
||||
* @param _sol the corresponding solution
|
||||
*/
|
||||
virtual void operator()(EOT & _sol){
|
||||
value() = nhStat.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class name
|
||||
*/
|
||||
virtual std::string className(void) const { return "moSizeNeighborStat"; }
|
||||
|
||||
private:
|
||||
moNeigborhoodStat<Neighborhood> & nhStat;
|
||||
/** moNeighborhoodStat */
|
||||
moNeighborhoodStat<Neighborhood> & nhStat;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@
|
|||
#include <continuator/moCheckpoint.h>
|
||||
#include <continuator/moContinuator.h>
|
||||
#include <continuator/moCounterMonitorSaver.h>
|
||||
#include <continuator/moCounterStat.h>
|
||||
#include <continuator/moDistanceStat.h>
|
||||
#include <continuator/moFitnessStat.h>
|
||||
#include <continuator/moMaxNeighborStat.h>
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ SET (TEST_LIST
|
|||
t-moTrueContinuator
|
||||
t-moRndWithoutReplNeighborhood
|
||||
t-moRndWithReplNeighborhood
|
||||
t-moFitnessStat
|
||||
t-moDistanceStat
|
||||
t-moNeighborhoodStat
|
||||
)
|
||||
|
||||
FOREACH (test ${TEST_LIST})
|
||||
|
|
|
|||
|
|
@ -40,6 +40,16 @@
|
|||
#include <neighborhood/moNeighbor.h>
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
#include <eval/moEval.h>
|
||||
|
||||
#include <ga/eoBit.h>
|
||||
#include <eoScalarFitness.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
|
||||
typedef eoBit<eoMinimizingFitness> bitVector;
|
||||
typedef moBitNeighbor<eoMinimizingFitness> bitNeighbor ;
|
||||
typedef moOrderNeighborhood<bitNeighbor> bitNeighborhood ;
|
||||
|
||||
typedef EO<int> Solution;
|
||||
|
||||
|
|
@ -90,4 +100,24 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class evalOneMax : public moEval< bitNeighbor >
|
||||
{
|
||||
private:
|
||||
unsigned size;
|
||||
|
||||
public:
|
||||
evalOneMax(unsigned _size) : size(_size) {};
|
||||
|
||||
~evalOneMax(void) {} ;
|
||||
|
||||
void operator() (bitVector& _sol, bitNeighbor& _n) {
|
||||
unsigned int fit = _sol.fitness();
|
||||
if(_sol[_n.index()])
|
||||
fit--;
|
||||
else
|
||||
fit++;
|
||||
_n.fitness(fit);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
70
branches/newMo/test/t-moDistanceStat.cpp
Normal file
70
branches/newMo/test/t-moDistanceStat.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
<t-moDistanceStat.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
#include <continuator/moDistanceStat.h>
|
||||
#include <utils/eoDistance.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int main(){
|
||||
|
||||
std::cout << "[t-moDistanceStat] => START" << std::endl;
|
||||
|
||||
eoBit<int> sol1;
|
||||
eoBit<int> sol2;
|
||||
eoBit<int> sol3;
|
||||
sol1.push_back(true);
|
||||
sol1.push_back(false);
|
||||
sol1.push_back(true);
|
||||
|
||||
sol2.push_back(true);
|
||||
sol2.push_back(true);
|
||||
sol2.push_back(false);
|
||||
|
||||
sol3.push_back(true);
|
||||
sol3.push_back(true);
|
||||
sol3.push_back(true);
|
||||
|
||||
eoHammingDistance< eoBit<int> > dist;
|
||||
|
||||
moDistanceStat< eoBit<int> > test(dist, sol1);
|
||||
|
||||
test(sol2);
|
||||
assert(test.value()==2);
|
||||
test(sol3);
|
||||
assert(test.value()==1);
|
||||
|
||||
std::cout << "[t-moDistanceStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
57
branches/newMo/test/t-moFitnessStat.cpp
Normal file
57
branches/newMo/test/t-moFitnessStat.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
<t-moFitnessStat.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <continuator/moFitnessStat.h>
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
int main(){
|
||||
|
||||
std::cout << "[t-moFitnessStat] => START" << std::endl;
|
||||
|
||||
eoBit<int> sol;
|
||||
|
||||
moFitnessStat< eoBit<int> > test;
|
||||
sol.fitness(3);
|
||||
test(sol);
|
||||
assert(test.value()==3);
|
||||
|
||||
sol.fitness(12);
|
||||
test(sol);
|
||||
assert(test.value()==12);
|
||||
|
||||
|
||||
std::cout << "[t-moFitnessStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
144
branches/newMo/test/t-moNeighborhoodStat.cpp
Normal file
144
branches/newMo/test/t-moNeighborhoodStat.cpp
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
<t-moNeighborhoodStat.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#include <continuator/moNeighborhoodStat.h>
|
||||
#include <continuator/moMaxNeighborStat.h>
|
||||
#include <continuator/moMinNeighborStat.h>
|
||||
#include <continuator/moNbInfNeighborStat.h>
|
||||
#include <continuator/moNbSupNeighborStat.h>
|
||||
#include <continuator/moNeutralDegreeNeighborStat.h>
|
||||
#include <continuator/moSecondMomentNeighborStat.h>
|
||||
#include <continuator/moSizeNeighborStat.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include "moTestClass.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
/*
|
||||
* Tests all classes depending of moNeighborhoodStat.h
|
||||
*/
|
||||
int main(){
|
||||
|
||||
//test de moNeighborhoodStat.h
|
||||
std::cout << "[t-moNeighborhoodStat] => START" << std::endl;
|
||||
|
||||
moNeighborComparator<bitNeighbor> neighborComp;
|
||||
moSolNeighborComparator<bitNeighbor> solNeighborComp;
|
||||
evalOneMax eval(10);
|
||||
|
||||
bitNeighborhood n(10);
|
||||
|
||||
bitVector sol;
|
||||
|
||||
sol.push_back(true);
|
||||
sol.push_back(false);
|
||||
sol.push_back(true);
|
||||
sol.push_back(true);
|
||||
sol.push_back(false);
|
||||
sol.push_back(true);
|
||||
sol.push_back(false);
|
||||
sol.push_back(true);
|
||||
sol.push_back(true);
|
||||
sol.push_back(true);
|
||||
|
||||
sol.fitness(7);
|
||||
|
||||
|
||||
moNeighborhoodStat<bitNeighborhood> test(n, eval, neighborComp, solNeighborComp);
|
||||
|
||||
test(sol);
|
||||
|
||||
assert(test.getMin()==8);
|
||||
assert(test.getMax()==6);
|
||||
assert(test.getMean()==6.6);
|
||||
double sd=test.getSD();
|
||||
assert(test.getSD()>0.966 && test.getSD()<0.967);
|
||||
assert(test.getSize()==10);
|
||||
assert(test.getNbSup()==7);
|
||||
assert(test.getNbInf()==3);
|
||||
assert(test.getNbEqual()==0);
|
||||
|
||||
std::cout << "[t-moNeighborhoodStat] => OK" << std::endl;
|
||||
|
||||
//test of moMaxNeighborStat.h
|
||||
std::cout << "[t-moMaxNeighborStat] => START" << std::endl;
|
||||
moMaxNeighborStat<bitNeighborhood> test2(test);
|
||||
test2(sol);
|
||||
assert(test2.value()==6);
|
||||
std::cout << "[t-moMaxNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moMinNeighborStat.h
|
||||
std::cout << "[t-moMinNeighborStat] => START" << std::endl;
|
||||
moMinNeighborStat<bitNeighborhood> test3(test);
|
||||
test3(sol);
|
||||
assert(test3.value()==8);
|
||||
std::cout << "[t-moMinNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moNbInfNeighborStat.h
|
||||
std::cout << "[t-moNbInfNeighborStat] => START" << std::endl;
|
||||
moNbInfNeighborStat<bitNeighborhood> test4(test);
|
||||
test4(sol);
|
||||
assert(test4.value()==3);
|
||||
std::cout << "[t-moNbInfNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moNbSupNeighborStat.h
|
||||
std::cout << "[t-moNbSupNeighborStat] => START" << std::endl;
|
||||
moNbSupNeighborStat<bitNeighborhood> test5(test);
|
||||
test5(sol);
|
||||
assert(test5.value()==7);
|
||||
std::cout << "[t-moNbSupNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moNeutralDegreeNeighborStat.h
|
||||
std::cout << "[t-moNeutralDegreeNeighborStat] => START" << std::endl;
|
||||
moNeutralDegreeNeighborStat<bitNeighborhood> test6(test);
|
||||
test6(sol);
|
||||
assert(test6.value()==0);
|
||||
std::cout << "[t-moNeutralDegreeNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moSecondMomentNeighborStat.h
|
||||
std::cout << "[t-moSecondMomentNeighborStat] => START" << std::endl;
|
||||
moSecondMomentNeighborStat<bitNeighborhood> test7(test);
|
||||
test7(sol);
|
||||
assert(test7.value().first==6.6);
|
||||
assert(test7.value().second > 0.966 && test7.value().second < 0.967);
|
||||
std::cout << "[t-moSecondMomentNeighborStat] => OK" << std::endl;
|
||||
|
||||
//test of moSizeNeighborStat.h
|
||||
std::cout << "[t-moSizeNeighborStat] => START" << std::endl;
|
||||
moSizeNeighborStat<bitNeighborhood> test8(test);
|
||||
test8(sol);
|
||||
assert(test8.value()==10);
|
||||
std::cout << "[t-moSizeNeighborStat] => OK" << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ void main_function(int argc, char **argv)
|
|||
moDistanceStat<Indi, unsigned> distStat(distance, solution); // distance from the intial solution
|
||||
|
||||
moOrderNeighborhood<Neighbor> nh(vecSize);
|
||||
moNeigborhoodStat< moOrderNeighborhood<Neighbor> > neighborhoodStat(nh, nhEval, comparator, solComparator);
|
||||
moNeighborhoodStat< moOrderNeighborhood<Neighbor> > neighborhoodStat(nh, nhEval, comparator, solComparator);
|
||||
moMinNeighborStat< moOrderNeighborhood<Neighbor> > minStat(neighborhoodStat);
|
||||
moSecondMomentNeighborStat< moOrderNeighborhood<Neighbor> > secondMomentStat(neighborhoodStat);
|
||||
moMaxNeighborStat< moOrderNeighborhood<Neighbor> > maxStat(neighborhoodStat);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue