From 92251dc96fb1c1be1147886656a915e64a2cd2aa Mon Sep 17 00:00:00 2001 From: jhumeau Date: Wed, 17 Mar 2010 16:51:45 +0000 Subject: [PATCH] Documentation and tests added git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1697 331e1502-861f-0410-8da2-ba01fb791d7f --- branches/newMo/src/continuator/moCheckpoint.h | 13 +- .../newMo/src/continuator/moContinuator.h | 4 +- .../newMo/src/continuator/moCounterStat.h | 72 ------ .../newMo/src/continuator/moDistanceStat.h | 38 ++- .../newMo/src/continuator/moFitnessStat.h | 16 +- .../newMo/src/continuator/moMaxNeighborStat.h | 26 +- .../newMo/src/continuator/moMinNeighborStat.h | 28 ++- .../src/continuator/moNbInfNeighborStat.h | 24 +- .../src/continuator/moNbSupNeighborStat.h | 22 +- .../src/continuator/moNeighborhoodStat.h | 226 +++++++++++------- .../continuator/moNeutralDegreeNeighborStat.h | 26 +- .../continuator/moSecondMomentNeighborStat.h | 26 +- .../src/continuator/moSizeNeighborStat.h | 25 +- branches/newMo/src/newmo.h | 1 - branches/newMo/test/CMakeLists.txt | 3 + branches/newMo/test/moTestClass.h | 30 +++ branches/newMo/test/t-moDistanceStat.cpp | 70 ++++++ branches/newMo/test/t-moFitnessStat.cpp | 57 +++++ branches/newMo/test/t-moNeighborhoodStat.cpp | 144 +++++++++++ .../application/testRandomNeutralWalk.cpp | 2 +- 20 files changed, 616 insertions(+), 237 deletions(-) delete mode 100644 branches/newMo/src/continuator/moCounterStat.h create mode 100644 branches/newMo/test/t-moDistanceStat.cpp create mode 100644 branches/newMo/test/t-moFitnessStat.cpp create mode 100644 branches/newMo/test/t-moNeighborhoodStat.cpp diff --git a/branches/newMo/src/continuator/moCheckpoint.h b/branches/newMo/src/continuator/moCheckpoint.h index 95d68f1f8..eb6af2d2b 100644 --- a/branches/newMo/src/continuator/moCheckpoint.h +++ b/branches/newMo/src/continuator/moCheckpoint.h @@ -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& _cont) { + moCheckpoint(moContinuator& _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 updaters; + unsigned int interval; + unsigned int counter; + }; diff --git a/branches/newMo/src/continuator/moContinuator.h b/branches/newMo/src/continuator/moContinuator.h index 57061a115..e2bef885c 100644 --- a/branches/newMo/src/continuator/moContinuator.h +++ b/branches/newMo/src/continuator/moContinuator.h @@ -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 diff --git a/branches/newMo/src/continuator/moCounterStat.h b/branches/newMo/src/continuator/moCounterStat.h deleted file mode 100644 index c0f28e0d2..000000000 --- a/branches/newMo/src/continuator/moCounterStat.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - - 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 - -/** - * 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 moCounterStat : public moStat< EOT, T > -{ -public : - moCounterStat(unsigned int _interval, moStat & _solStat): moStat(0, "every"), interval(_interval){ - solStats.push_back(&_solStat); - } - - void add(moStat& _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* > solStats; -}; - -#endif diff --git a/branches/newMo/src/continuator/moDistanceStat.h b/branches/newMo/src/continuator/moDistanceStat.h index 3e639115d..61ab9ad04 100644 --- a/branches/newMo/src/continuator/moDistanceStat.h +++ b/branches/newMo/src/continuator/moDistanceStat.h @@ -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 moDistanceStat : public moStat { public : using moStat< EOT, T >::value; - moDistanceStat(eoDistance & _dist, EOT & _ref) - : moStat(0, "distance"), dist(_dist), refSolution(_ref) - {} + /** + * Default Constructor + * @param _dist a distance + * @param _ref the reference solution + */ + moDistanceStat(eoDistance & _dist, EOT & _ref): moStat(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 & 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 & dist; + /** + * the reference solution does not change during the run + * it could be the best solution knowed of the problem + */ + EOT refSolution; }; diff --git a/branches/newMo/src/continuator/moFitnessStat.h b/branches/newMo/src/continuator/moFitnessStat.h index ed32dbe17..bf660055c 100644 --- a/branches/newMo/src/continuator/moFitnessStat.h +++ b/branches/newMo/src/continuator/moFitnessStat.h @@ -49,15 +49,25 @@ public : typedef T Fitness; using moStat< EOT, Fitness >::value; - moFitnessStat(std::string _description = "fitness") - : moStat(Fitness(), _description) - {} + /** + * Default Constructor + * @param _description a description of the stat + */ + moFitnessStat(std::string _description = "fitness"): + moStat(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"; } }; diff --git a/branches/newMo/src/continuator/moMaxNeighborStat.h b/branches/newMo/src/continuator/moMaxNeighborStat.h index efc58b370..9b54739b7 100644 --- a/branches/newMo/src/continuator/moMaxNeighborStat.h +++ b/branches/newMo/src/continuator/moMaxNeighborStat.h @@ -39,10 +39,8 @@ #include /** - * * From moNeighborhoodStat, to compute the max fitness in the neighborhood - * -*/ + */ template< class Neighborhood > class moMaxNeighborStat : public moStat { @@ -52,19 +50,29 @@ public : using moStat< EOT, Fitness >::value; - moMaxNeighborStat(moNeigborhoodStat & _nhStat) - : moStat(Fitness(), "min"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moMaxNeighborStat(moNeighborhoodStat & _nhStat): + moStat(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/continuator/moMinNeighborStat.h b/branches/newMo/src/continuator/moMinNeighborStat.h index 15d5f6c2b..bfc215018 100644 --- a/branches/newMo/src/continuator/moMinNeighborStat.h +++ b/branches/newMo/src/continuator/moMinNeighborStat.h @@ -39,10 +39,8 @@ #include /** - * * From moNeighborhoodStat, to compute the min fitness in the neighborhood - * -*/ + */ template< class Neighborhood > class moMinNeighborStat : public moStat { @@ -52,19 +50,29 @@ public : using moStat< EOT, Fitness >::value; - moMinNeighborStat(moNeigborhoodStat & _nhStat) - : moStat(Fitness(), "min"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moMinNeighborStat(moNeighborhoodStat & _nhStat): + moStat(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/continuator/moNbInfNeighborStat.h b/branches/newMo/src/continuator/moNbInfNeighborStat.h index 6a5339134..9b40de5a8 100644 --- a/branches/newMo/src/continuator/moNbInfNeighborStat.h +++ b/branches/newMo/src/continuator/moNbInfNeighborStat.h @@ -53,19 +53,29 @@ public : using moStat< EOT, unsigned >::value; - moNbInfNeighborStat(moNeigborhoodStat & _nhStat) - : moStat(0, "nb inf"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moNbInfNeighborStat(moNeighborhoodStat & _nhStat): + moStat(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/continuator/moNbSupNeighborStat.h b/branches/newMo/src/continuator/moNbSupNeighborStat.h index e2293c180..9e2fdfba2 100644 --- a/branches/newMo/src/continuator/moNbSupNeighborStat.h +++ b/branches/newMo/src/continuator/moNbSupNeighborStat.h @@ -53,19 +53,29 @@ public : using moStat< EOT, unsigned >::value; - moNbSupNeighborStat(moNeigborhoodStat & _nhStat) - : moStat(0, "nb sup"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moNbSupNeighborStat(moNeighborhoodStat & _nhStat): + moStat(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/continuator/moNeighborhoodStat.h b/branches/newMo/src/continuator/moNeighborhoodStat.h index ddfceaa30..128eec6d9 100644 --- a/branches/newMo/src/continuator/moNeighborhoodStat.h +++ b/branches/newMo/src/continuator/moNeighborhoodStat.h @@ -1,5 +1,5 @@ /* - + 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 @@ -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 +class moNeighborhoodStat : public moStat { public : typedef typename Neighborhood::EOT EOT ; @@ -55,104 +55,161 @@ public : using moStat< EOT, bool >::value; - moNeigborhoodStat(Neighborhood& _neighborhood, moEval& _eval, - moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator) - : moStat(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& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator): + moStat(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& 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 diff --git a/branches/newMo/src/continuator/moNeutralDegreeNeighborStat.h b/branches/newMo/src/continuator/moNeutralDegreeNeighborStat.h index fd361f0ab..d09994ed4 100644 --- a/branches/newMo/src/continuator/moNeutralDegreeNeighborStat.h +++ b/branches/newMo/src/continuator/moNeutralDegreeNeighborStat.h @@ -39,12 +39,10 @@ #include /** - * * 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 { @@ -54,19 +52,29 @@ public : using moStat< EOT, unsigned >::value; - moNeutralDegreeNeighborStat(moNeigborhoodStat & _nhStat) - : moStat(0, "neutral degree"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moNeutralDegreeNeighborStat(moNeighborhoodStat & _nhStat): + moStat(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/continuator/moSecondMomentNeighborStat.h b/branches/newMo/src/continuator/moSecondMomentNeighborStat.h index e8ed75c18..e7ed41f41 100644 --- a/branches/newMo/src/continuator/moSecondMomentNeighborStat.h +++ b/branches/newMo/src/continuator/moSecondMomentNeighborStat.h @@ -39,10 +39,8 @@ #include /** - * * From moNeighborhoodStat, to compute the average and the standard deviation of fitness in the neighborhood - * -*/ + */ template< class Neighborhood > class moSecondMomentNeighborStat : public moStat > { @@ -52,20 +50,30 @@ public : using moStat< EOT, std::pair >::value; - moSecondMomentNeighborStat(moNeigborhoodStat & _nhStat) - : moStat >(std::make_pair(0.0,0.0), "average and stdev"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moSecondMomentNeighborStat(moNeighborhoodStat & _nhStat): + moStat >(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/continuator/moSizeNeighborStat.h b/branches/newMo/src/continuator/moSizeNeighborStat.h index decb2d2ca..8f8d73dcc 100644 --- a/branches/newMo/src/continuator/moSizeNeighborStat.h +++ b/branches/newMo/src/continuator/moSizeNeighborStat.h @@ -39,10 +39,9 @@ #include /** - * * From moNeighborhoodStat, to compute the number of solutions in the neighborhood * -*/ + */ template< class Neighborhood > class moSizeNeighborStat : public moStat { @@ -52,19 +51,29 @@ public : using moStat< EOT, unsigned >::value; - moSizeNeighborStat(moNeigborhoodStat & _nhStat) - : moStat(0, "size"), nhStat(_nhStat) - {} + /** + * Default Constructor + * @param _nhStat a neighborhoodStat + */ + moSizeNeighborStat(moNeighborhoodStat & _nhStat): + moStat(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 & nhStat; + /** moNeighborhoodStat */ + moNeighborhoodStat & nhStat; }; #endif diff --git a/branches/newMo/src/newmo.h b/branches/newMo/src/newmo.h index c13383419..3d3961008 100755 --- a/branches/newMo/src/newmo.h +++ b/branches/newMo/src/newmo.h @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include diff --git a/branches/newMo/test/CMakeLists.txt b/branches/newMo/test/CMakeLists.txt index 7847e1734..2dbec2a13 100644 --- a/branches/newMo/test/CMakeLists.txt +++ b/branches/newMo/test/CMakeLists.txt @@ -42,6 +42,9 @@ SET (TEST_LIST t-moTrueContinuator t-moRndWithoutReplNeighborhood t-moRndWithReplNeighborhood + t-moFitnessStat + t-moDistanceStat + t-moNeighborhoodStat ) FOREACH (test ${TEST_LIST}) diff --git a/branches/newMo/test/moTestClass.h b/branches/newMo/test/moTestClass.h index c97c5e94a..52e02459e 100644 --- a/branches/newMo/test/moTestClass.h +++ b/branches/newMo/test/moTestClass.h @@ -40,6 +40,16 @@ #include #include #include +#include + +#include +#include +#include +#include + +typedef eoBit bitVector; +typedef moBitNeighbor bitNeighbor ; +typedef moOrderNeighborhood bitNeighborhood ; typedef EO 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 diff --git a/branches/newMo/test/t-moDistanceStat.cpp b/branches/newMo/test/t-moDistanceStat.cpp new file mode 100644 index 000000000..3f3909143 --- /dev/null +++ b/branches/newMo/test/t-moDistanceStat.cpp @@ -0,0 +1,70 @@ +/* + +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 +#include +#include + +#include +#include +#include + +int main(){ + + std::cout << "[t-moDistanceStat] => START" << std::endl; + + eoBit sol1; + eoBit sol2; + eoBit 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 > dist; + + moDistanceStat< eoBit > 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; +} + diff --git a/branches/newMo/test/t-moFitnessStat.cpp b/branches/newMo/test/t-moFitnessStat.cpp new file mode 100644 index 000000000..c705896a6 --- /dev/null +++ b/branches/newMo/test/t-moFitnessStat.cpp @@ -0,0 +1,57 @@ +/* + +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 +#include + +#include +#include +#include + +int main(){ + + std::cout << "[t-moFitnessStat] => START" << std::endl; + + eoBit sol; + + moFitnessStat< eoBit > 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; +} + diff --git a/branches/newMo/test/t-moNeighborhoodStat.cpp b/branches/newMo/test/t-moNeighborhoodStat.cpp new file mode 100644 index 000000000..043974e10 --- /dev/null +++ b/branches/newMo/test/t-moNeighborhoodStat.cpp @@ -0,0 +1,144 @@ +/* + +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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "moTestClass.h" + +#include +#include +#include + +/* + * Tests all classes depending of moNeighborhoodStat.h + */ +int main(){ + + //test de moNeighborhoodStat.h + std::cout << "[t-moNeighborhoodStat] => START" << std::endl; + + moNeighborComparator neighborComp; + moSolNeighborComparator 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 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 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 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 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 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 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 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 test8(test); + test8(sol); + assert(test8.value()==10); + std::cout << "[t-moSizeNeighborStat] => OK" << std::endl; + + return EXIT_SUCCESS; +} + diff --git a/branches/newMo/tutorial/oneMax/application/testRandomNeutralWalk.cpp b/branches/newMo/tutorial/oneMax/application/testRandomNeutralWalk.cpp index 9b6b46e03..2c1b77b90 100644 --- a/branches/newMo/tutorial/oneMax/application/testRandomNeutralWalk.cpp +++ b/branches/newMo/tutorial/oneMax/application/testRandomNeutralWalk.cpp @@ -203,7 +203,7 @@ void main_function(int argc, char **argv) moDistanceStat distStat(distance, solution); // distance from the intial solution moOrderNeighborhood nh(vecSize); - moNeigborhoodStat< moOrderNeighborhood > neighborhoodStat(nh, nhEval, comparator, solComparator); + moNeighborhoodStat< moOrderNeighborhood > neighborhoodStat(nh, nhEval, comparator, solComparator); moMinNeighborStat< moOrderNeighborhood > minStat(neighborhoodStat); moSecondMomentNeighborStat< moOrderNeighborhood > secondMomentStat(neighborhoodStat); moMaxNeighborStat< moOrderNeighborhood > maxStat(neighborhoodStat);