From 7e08ca9892a959a207a42fcd217d2f8af528e9a3 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Fri, 23 Apr 2010 15:53:21 +0000 Subject: [PATCH] git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1746 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/perturb/moNeighborhoodPerturb.h | 11 ++- .../src/perturb/moRestartPerturb.h | 6 +- trunk/paradiseo-mo/test/CMakeLists.txt | 1 + .../test/t-moNeighborhoodPerturb.cpp | 91 +++++++++++++++++++ .../paradiseo-mo/test/t-moRestartPerturb.cpp | 74 +++++++++++++++ 5 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 trunk/paradiseo-mo/test/t-moNeighborhoodPerturb.cpp diff --git a/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h b/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h index 4e02c22ab..88b946a2f 100644 --- a/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h +++ b/trunk/paradiseo-mo/src/perturb/moNeighborhoodPerturb.h @@ -32,23 +32,24 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include +#include /** * Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search) */ -template< class Neighbor, class OtherNH > +template< class Neighbor, class OtherNeighbor > class moNeighborhoodPerturb : public moPerturbation{ public: typedef typename Neighbor::EOT EOT; - typedef typename OtherNH::Neighbor OtherN; + typedef moNeighborhood OtherNH; /** * Default Constructor * @param _otherNeighborhood a neighborhood * @param _eval an Evaluation Function */ - moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){} + moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){} /** * Apply move on the solution @@ -101,8 +102,8 @@ public: private: OtherNH& otherNeighborhood; - moEval& eval; - OtherN current; + moEval& eval; + OtherNeighbor current; }; #endif diff --git a/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h b/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h index d86bad67c..015685159 100644 --- a/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h +++ b/trunk/paradiseo-mo/src/perturb/moRestartPerturb.h @@ -51,7 +51,7 @@ public: * @param _fullEval a full evaluation function * @param _threshold maximum number of iteration with no improvement */ - moRestartPerturb(eoInit& _init, eoEvalFunc& _fullEval, unsigned int _threshold):init(_init), fullEval(_fullEval), threshold(_threshold) {} + moRestartPerturb(eoInit& _initializer, eoEvalFunc& _fullEval, unsigned int _threshold):initializer(_initializer), fullEval(_fullEval), threshold(_threshold) {} /** * Apply restart when necessary @@ -60,7 +60,7 @@ public: */ bool operator()(EOT& _solution){ if((*this).getCounter()>= threshold){ - init(_solution); + initializer(_solution); fullEval(_solution); (*this).initCounter(); } @@ -68,7 +68,7 @@ public: } private: - eoInit& init; + eoInit& initializer; eoEvalFunc& fullEval; unsigned int threshold; }; diff --git a/trunk/paradiseo-mo/test/CMakeLists.txt b/trunk/paradiseo-mo/test/CMakeLists.txt index f9e0f6778..671561aa4 100644 --- a/trunk/paradiseo-mo/test/CMakeLists.txt +++ b/trunk/paradiseo-mo/test/CMakeLists.txt @@ -69,6 +69,7 @@ SET (TEST_LIST t-moCountMoveMemory t-moMonOpPerturb t-moRestartPerturb + t-moNeighborhoodPerturb ) FOREACH (test ${TEST_LIST}) diff --git a/trunk/paradiseo-mo/test/t-moNeighborhoodPerturb.cpp b/trunk/paradiseo-mo/test/t-moNeighborhoodPerturb.cpp new file mode 100644 index 000000000..bee0fa439 --- /dev/null +++ b/trunk/paradiseo-mo/test/t-moNeighborhoodPerturb.cpp @@ -0,0 +1,91 @@ +/* + +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 "moTestClass.h" + +#include +#include +#include + +typedef moOrderNeighborhood Neighborhood; + +int main(){ + + std::cout << "[t-moNeighborhoodPerturb] => START" << std::endl; + + oneMaxFullEval eval; + + moFullEvalByCopy moeval(eval); + + bitVector sol; + sol.resize(3); + sol[0]=0; + sol[1]=0; + sol[2]=0; + + sol.fitness(0); + + Neighborhood nh(3); + + bitNeighbor n; + + moNeighborhoodPerturb test(nh, moeval); + + //test update + test.init(sol); + test(sol); + assert(sol[0]==1 && sol[1]==0 && sol[2]==0); + test.update(sol, n); + test(sol); + assert(sol[0]==1 && sol[1]==1 && sol[2]==0); + test.update(sol, n); + test(sol); + assert(sol[0]==1 && sol[1]==1 && sol[2]==1); + test.update(sol, n); + test(sol); + assert(sol[0]==0 && sol[1]==1 && sol[2]==1); + + //test add + + test.add(sol, n); + test(sol); + assert(sol[0]==1 && sol[1]==1 && sol[2]==1); + + test.clearMemory(); + + + std::cout << "[t-moNeighborhoodPerturb] => OK" << std::endl; + + return EXIT_SUCCESS; +} + diff --git a/trunk/paradiseo-mo/test/t-moRestartPerturb.cpp b/trunk/paradiseo-mo/test/t-moRestartPerturb.cpp index 8d8983874..aa1d14d01 100644 --- a/trunk/paradiseo-mo/test/t-moRestartPerturb.cpp +++ b/trunk/paradiseo-mo/test/t-moRestartPerturb.cpp @@ -31,10 +31,84 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include #include +#include +#include +#include + +#include +#include + +typedef eoInt QUEEN; + +class dummyInit : public eoInit +{ +public: + dummyInit(unsigned int _size):size(_size){} + + void operator()(QUEEN& _sol){ + _sol.resize(0); + for(unsigned int i=0; i START" << std::endl; + QUEEN queen; + moShiftNeighbor n; + + dummyInit initializer(4); + + queenFullEval eval; + + moRestartPerturb > test(initializer, eval, 3); + + queen.resize(4); + queen[0]=1; + queen[1]=2; + queen[2]=0; + queen[3]=3; + + test.init(queen); + + test(queen); + assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3); + test.update(queen,n); //first noMove + test(queen); + assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3); + test.update(queen,n); //second noMove + test(queen); + assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3); + test.update(queen,n); //third noMove + test(queen);//here the perturb should be called + assert(queen[0]==0 && queen[1]==1 && queen[2]==2 && queen[3]==3); + + queen[0]=1; + queen[1]=2; + queen[2]=0; + queen[3]=3; + + //Retry the same test to verify counter is been reinit to 0 + + test(queen); + assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3); + test.update(queen,n); //first noMove + test(queen); + assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3); + test.update(queen,n); //second noMove + test(queen); + assert(queen[0]==1 && queen[1]==2 && queen[2]==0 && queen[3]==3); + test.update(queen,n); //third noMove + test(queen); //here the perturb should be called + assert(queen[0]==0 && queen[1]==1 && queen[2]==2 && queen[3]==3); std::cout << "[t-moRestartPerturb] => OK" << std::endl;