diff --git a/branches/newMo/src/explorer/moMetropolisHastingExplorer.h b/branches/newMo/src/explorer/moMetropolisHastingExplorer.h index ff937dbdd..f343b3b4b 100644 --- a/branches/newMo/src/explorer/moMetropolisHastingExplorer.h +++ b/branches/newMo/src/explorer/moMetropolisHastingExplorer.h @@ -39,6 +39,8 @@ #include #include +#include + /** * Explorer for the Metropolis-Hasting Sampling * Only the symetric case is considered when Q(x,y) = Q(y,x) @@ -61,7 +63,7 @@ public: * @param _solNeighborComparator a solution vs neighbor comparator * @param _nbStep maximum number of step to do */ - moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) { + moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval& _eval, moNeighborComparator& _neighborComparator, moSolNeighborComparator& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) { isAccept = false; current=new Neighbor(); } @@ -78,8 +80,8 @@ public: * @param _solution the solution (unused here) */ virtual void initParam(EOT & _solution){ - step = 0; - isAccept = true; + step = 0; + isAccept = true; }; /** @@ -87,7 +89,7 @@ public: * @param _solution the solution (unused here) */ virtual void updateParam(EOT & _solution){ - step++; + step++; }; /** @@ -138,19 +140,23 @@ public: }; /** - * accept test if an amelirated neighbor was be found + * accept test if an ameliorated neighbor was be found * @param _solution the solution * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { + double alpha=0.0; if(neighborhood.hasNeighbor(_solution)){ - if (solNeighborComparator(_solution, *current)) - isAccept = true; - else { - double alpha = (double) current->fitness() / (double) _solution.fitness(); - - isAccept = (rng.uniform() < alpha) ; - } + if (solNeighborComparator(_solution, *current)) + isAccept = true; + else{ + if(_solution.fitness() != 0){ + alpha = (double) current->fitness() / (double) _solution.fitness(); + isAccept = (rng.uniform() < alpha) ; + } + else + isAccept = false; + } } return isAccept; }; diff --git a/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h b/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h index f98b461b1..33260e3c9 100644 --- a/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h +++ b/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h @@ -60,13 +60,13 @@ public: * @param _solNeighborComparator a solution vs neighbor comparator * @param _nbStep maximum number of step to do */ - moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval& _eval, + moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval& _eval, moSolNeighborComparator& _solNeighborComparator, - unsigned _nbStep) - : moNeighborhoodExplorer(_neighborhood, _eval), - solNeighborComparator(_solNeighborComparator), - nbStep(_nbStep) { - isAccept = false; + unsigned _nbStep): + moNeighborhoodExplorer(_neighborhood, _eval), + solNeighborComparator(_solNeighborComparator), + nbStep(_nbStep) { + isAccept = false; current=new Neighbor(); } @@ -81,15 +81,15 @@ public: * initialization of the number of step to be done */ virtual void initParam(EOT & solution){ - step = 0; - isAccept = true; + step = 0; + isAccept = true; }; /** * increase the number of step */ virtual void updateParam(EOT & solution){ - step++; + step++; }; /** @@ -102,27 +102,27 @@ public: * @param _solution */ virtual void operator()(EOT & _solution){ - //Test if _solution has a Neighbor - if(neighborhood.hasNeighbor(_solution)){ - //init the first neighbor - neighborhood.init(_solution, (*current)); + //Test if _solution has a Neighbor + 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)); - //test all others neighbors - while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) { - //next neighbor - neighborhood.next(_solution, (*current)); - //eval - eval(_solution, (*current)); - } - } - else{ - //if _solution hasn't neighbor, - isAccept=false; - } - }; + //test all others neighbors + while (! solNeighborComparator.equals(_solution, *current) && neighborhood.cont(_solution)) { + //next neighbor + neighborhood.next(_solution, (*current)); + //eval + eval(_solution, (*current)); + } + } + else{ + //if _solution hasn't neighbor, + isAccept=false; + } + }; /** * continue if there is a neighbor and it is remainds some steps to do @@ -130,7 +130,7 @@ public: * @return true there is some steps to do */ virtual bool isContinue(EOT & _solution) { - return (step < nbStep) && isAccept ; + return (step < nbStep) && isAccept ; }; /** @@ -145,15 +145,14 @@ public: }; /** - * accept test if an amelirated neighbor was be found + * accept test if an ameliorated neighbor was be found * @param _solution the solution * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)){ - isAccept = solNeighborComparator.equals(_solution, (*current)) ; - } - return isAccept; + if(neighborhood.hasNeighbor(_solution)) + isAccept = solNeighborComparator.equals(_solution, (*current)) ; + return isAccept; }; private: diff --git a/branches/newMo/src/explorer/moRandomWalkExplorer.h b/branches/newMo/src/explorer/moRandomWalkExplorer.h index 96b546d06..047216940 100644 --- a/branches/newMo/src/explorer/moRandomWalkExplorer.h +++ b/branches/newMo/src/explorer/moRandomWalkExplorer.h @@ -40,7 +40,7 @@ #include /** - * Explorer for a first imporvement heuristic + * Explorer for a random walk explorer */ template< class Neighborhood > class moRandomWalkExplorer : public moNeighborhoodExplorer @@ -58,11 +58,11 @@ public: * @param _eval the evaluation function * @param _nbStep maximum number of step to do */ - moRandomWalkExplorer(Neighborhood& _neighborhood, moEval& _eval, unsigned _nbStep) : moNeighborhoodExplorer(_neighborhood, _eval), nbStep(_nbStep) { + moRandomWalkExplorer(Neighborhood& _neighborhood, moEval& _eval, unsigned _nbStep) : moNeighborhoodExplorer(_neighborhood, _eval), nbStep(_nbStep) { isAccept = false; current=new Neighbor(); - // number of step done - step = 0; + // number of step done + step = 0; } /** @@ -98,7 +98,6 @@ public: */ virtual void operator()(EOT & _solution){ - //est qu'on peut initializer //Test if _solution has a Neighbor if(neighborhood.hasNeighbor(_solution)){ //init the first neighbor @@ -141,9 +140,8 @@ public: * @return true if the best neighbor ameliorate the fitness */ virtual bool accept(EOT & _solution) { - if(neighborhood.hasNeighbor(_solution)){ + if(neighborhood.hasNeighbor(_solution)) isAccept = true ; - } return isAccept; }; diff --git a/branches/newMo/src/memory/moDiversification.h b/branches/newMo/src/memory/moDiversification.h index 0a697300a..91cb5b3de 100644 --- a/branches/newMo/src/memory/moDiversification.h +++ b/branches/newMo/src/memory/moDiversification.h @@ -2,6 +2,7 @@ #define _moDiversification_h #include +#include /** * Abstract class for diversification strategy diff --git a/branches/newMo/src/memory/moIntensification.h b/branches/newMo/src/memory/moIntensification.h index 2d85ee6ed..65b9bb1ad 100644 --- a/branches/newMo/src/memory/moIntensification.h +++ b/branches/newMo/src/memory/moIntensification.h @@ -2,6 +2,7 @@ #define _moIntensification_h #include +#include /** * Abstract class for intensification strategy diff --git a/branches/newMo/test/CMakeLists.txt b/branches/newMo/test/CMakeLists.txt index 09401702b..7bcabceaf 100644 --- a/branches/newMo/test/CMakeLists.txt +++ b/branches/newMo/test/CMakeLists.txt @@ -47,10 +47,12 @@ SET (TEST_LIST t-moCounterMonitorSaver t-moSolutionStat t-moCheckpoint + t-moDummyMemory t-moSimpleHCexplorer t-moSimpleHCneutralExplorer t-moHCneutralExplorer t-moFirstImprExplorer + t-moRandomWalkExplorer ) diff --git a/branches/newMo/test/t-moDummyMemory.cpp b/branches/newMo/test/t-moDummyMemory.cpp new file mode 100644 index 000000000..5d965da43 --- /dev/null +++ b/branches/newMo/test/t-moDummyMemory.cpp @@ -0,0 +1,63 @@ +/* + +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 "moTestClass.h" + +#include +#include +#include + +int main(){ + + std::cout << "[t-moDummyMemory] => START" << std::endl; + + eoBit sol(4); + bitNeighbor n; + moDummyDiversification test1; + test1.init(sol); + test1.add(sol, n); + test1.update(sol, n); + test1.clearMemory(); + assert(!test1(sol)); + + moDummyIntensification test2; + test2.init(sol); + test2.add(sol, n); + test2.update(sol, n); + test2.clearMemory(); + assert(!test2(sol)); + + + std::cout << "[t-moDummyMemory] => OK" << std::endl; + + return EXIT_SUCCESS; +} + diff --git a/branches/newMo/test/t-moRandomWalkExplorer.cpp b/branches/newMo/test/t-moRandomWalkExplorer.cpp new file mode 100644 index 000000000..ec7bdeadb --- /dev/null +++ b/branches/newMo/test/t-moRandomWalkExplorer.cpp @@ -0,0 +1,77 @@ +/* + +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 "moTestClass.h" + +#include +#include +#include + +int main(){ + + std::cout << "[t-moRandomWalkExplorer] => START" << std::endl; + + eoBit sol(4, true); + sol.fitness(4); + bitNeighborhood nh(4); + evalOneMax eval(4); + + moRandomWalkExplorer test(nh, eval, 3); + + test.initParam(sol); + + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + test.updateParam(sol); + assert(test.isContinue(sol)); + + + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==4); + test.updateParam(sol); + assert(test.isContinue(sol)); + + test(sol); + assert(test.accept(sol)); + test.move(sol); + assert(sol.fitness()==3); + assert(!sol[0]); + test.updateParam(sol); + assert(!test.isContinue(sol)); + + std::cout << "[t-moRandomWalkExplorer] => OK" << std::endl; + + return EXIT_SUCCESS; +} +