diff --git a/branches/newMo/src/explorer/moMetropolisHastingExplorer.h b/branches/newMo/src/explorer/moMetropolisHastingExplorer.h index 7e47cd9f8..392091307 100644 --- a/branches/newMo/src/explorer/moMetropolisHastingExplorer.h +++ b/branches/newMo/src/explorer/moMetropolisHastingExplorer.h @@ -35,6 +35,8 @@ #ifndef _moMetropolisHastingExplorer_h #define _moMetropolisHastingExplorer_h +#include + #include #include #include @@ -67,6 +69,9 @@ public: 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(); + if(!neighborhood.isRandom()){ + std::cout << "moMetropolisHastingExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } /** diff --git a/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h b/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h index c6f46909c..e8cf78f38 100644 --- a/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h +++ b/branches/newMo/src/explorer/moRandomNeutralWalkExplorer.h @@ -69,6 +69,9 @@ public: nbStep(_nbStep) { isAccept = false; current=new Neighbor(); + if(!neighborhood.isRandom()){ + std::cout << "moRandomNeutralWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } /** diff --git a/branches/newMo/src/explorer/moRandomWalkExplorer.h b/branches/newMo/src/explorer/moRandomWalkExplorer.h index 047216940..3e975366b 100644 --- a/branches/newMo/src/explorer/moRandomWalkExplorer.h +++ b/branches/newMo/src/explorer/moRandomWalkExplorer.h @@ -63,6 +63,9 @@ public: current=new Neighbor(); // number of step done step = 0; + if(!neighborhood.isRandom()){ + std::cout << "moRandomWalkExplorer::Warning -> the neighborhood used is not random" << std::endl; + } } /** diff --git a/branches/newMo/src/explorer/moTSExplorer.h b/branches/newMo/src/explorer/moTSExplorer.h index 321a9c071..173ac90f3 100644 --- a/branches/newMo/src/explorer/moTSExplorer.h +++ b/branches/newMo/src/explorer/moTSExplorer.h @@ -110,8 +110,7 @@ public: */ virtual void updateParam(EOT& _solution) { - if ((*this).moveApplied()) - { + if ((*this).moveApplied()){ tabuList.add(_solution, *best); intensification.add(_solution, *best); diversification.add(_solution, *best); @@ -126,10 +125,9 @@ public: /** - * terminate : NOTHING TO DO + * terminate : _solution becomes the best so far */ - virtual void terminate(EOT & _solution) - { + virtual void terminate(EOT & _solution){ _solution= bestSoFar; }; diff --git a/branches/newMo/src/memory/moSolVectorTabuList.h b/branches/newMo/src/memory/moSolVectorTabuList.h index 59a710ac1..17628f7a8 100644 --- a/branches/newMo/src/memory/moSolVectorTabuList.h +++ b/branches/newMo/src/memory/moSolVectorTabuList.h @@ -17,8 +17,9 @@ public: /** * Constructor * @param _maxSize maximum size of the tabu list + * @param _howlong how many iteration a move is tabu */ - moSolVectorTabuList(unsigned int _maxSize) : maxSize(_maxSize){ + moSolVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong){ tabuList.reserve(_maxSize); tabuList.resize(0); } @@ -38,12 +39,18 @@ public: * @param _neighbor the current neighbor (unused) */ virtual void add(EOT & _sol, Neighbor & _neighbor){ - if(tabuList.size() < maxSize) - tabuList.push_back(_sol); - else{ - tabuList[index%maxSize] = _sol; - index++; - } + + if(tabuList.size() < maxSize){ + std::pair tmp; + tmp.first=_sol; + tmp.second=howlong; + tabuList.push_back(tmp); + } + else{ + tabuList[index%maxSize].first = _sol; + tabuList[index%maxSize].second = howlong; + index++; + } } /** @@ -51,7 +58,10 @@ public: * @param _sol the current solution * @param _neighbor the current neighbor (unused) */ - virtual void update(EOT & _sol, Neighbor & _neighbor){} + virtual void update(EOT & _sol, Neighbor & _neighbor){ + for(unsigned int i=0; i 0 && tabuList[i].second > 0 && tabuList[i].first == tmp) || (howlong==0 && tabuList[i].first==tmp)) return true; } return false; @@ -79,9 +89,13 @@ public: private: - - std::vector tabuList; + //tabu list + std::vector< std::pair > tabuList; + //maximum size of the tabu list unsigned int maxSize; + //how many iteration a move is tabu + unsigned int howlong; + //index on the tabulist unsigned long index; }; diff --git a/branches/newMo/src/neighborhood/moNeighborhood.h b/branches/newMo/src/neighborhood/moNeighborhood.h index 47757ff65..bb3ca6d8f 100644 --- a/branches/newMo/src/neighborhood/moNeighborhood.h +++ b/branches/newMo/src/neighborhood/moNeighborhood.h @@ -54,6 +54,13 @@ public: */ moNeighborhood(){} + /** + * @return if the neighborhood is random + */ + virtual bool isRandom(){ + return false; + } + /** * Test if a solution has (again) a Neighbor * @param _solution the related solution diff --git a/branches/newMo/src/neighborhood/moRndNeighborhood.h b/branches/newMo/src/neighborhood/moRndNeighborhood.h index 501f37696..2192bec57 100644 --- a/branches/newMo/src/neighborhood/moRndNeighborhood.h +++ b/branches/newMo/src/neighborhood/moRndNeighborhood.h @@ -33,6 +33,13 @@ Contact: paradiseo-help@lists.gforge.inria.fr #include template< class Neighbor > -class moRndNeighborhood : virtual public moNeighborhood{}; +class moRndNeighborhood : virtual public moNeighborhood{ + +public: + + bool isRandom(){ + return true; + } +}; #endif diff --git a/branches/newMo/test/moTestClass.h b/branches/newMo/test/moTestClass.h index 0087e4f45..7350d7628 100644 --- a/branches/newMo/test/moTestClass.h +++ b/branches/newMo/test/moTestClass.h @@ -51,12 +51,10 @@ #include #include - - typedef eoBit bitVector; typedef moBitNeighbor bitNeighbor ; -class moDummyRndNeighborhood: public moOrderNeighborhood, public moRndNeighborhood { +class moDummyRndNeighborhood: public moOrderNeighborhood/*, public moRndNeighborhood*/{ public: moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood(a){} }; diff --git a/branches/newMo/test/t-moBestImprAspiration.cpp b/branches/newMo/test/t-moBestImprAspiration.cpp index 9baef9494..a7910ba80 100644 --- a/branches/newMo/test/t-moBestImprAspiration.cpp +++ b/branches/newMo/test/t-moBestImprAspiration.cpp @@ -59,6 +59,8 @@ int main(){ n3.fitness(3); n4.fitness(3); + + //verification qu'on update bien le best so far quand il faut test.init(sol1); assert(test.getBest()==sol1); assert(!test(sol2,n2)); diff --git a/branches/newMo/test/t-moCheckpoint.cpp b/branches/newMo/test/t-moCheckpoint.cpp index 524f75121..fb9b788e7 100644 --- a/branches/newMo/test/t-moCheckpoint.cpp +++ b/branches/newMo/test/t-moCheckpoint.cpp @@ -52,6 +52,8 @@ int main(){ s.fitness(17); + + //verification que toutes les operateurs sont bien apellés moSolutionStat< eoBit< eoMinimizingFitness > > stat; updater1 up1(a); updater1 up2(b); diff --git a/branches/newMo/test/t-moCounterMonitorSaver.cpp b/branches/newMo/test/t-moCounterMonitorSaver.cpp index 39b4cb9e2..7ea014147 100644 --- a/branches/newMo/test/t-moCounterMonitorSaver.cpp +++ b/branches/newMo/test/t-moCounterMonitorSaver.cpp @@ -48,6 +48,8 @@ int main(){ moCounterMonitorSaver test(3, mon1); test.add(mon2); + //on verifie qu'on apelle les moniteurs seulement tout les 3 itération + test(); assert(a==2 && b==11); test(); @@ -56,6 +58,8 @@ int main(){ assert(a==2 && b==11); test(); assert(a==3 && b==12); + + //test du lastCall test.lastCall(); assert(a==4 && b==13); diff --git a/branches/newMo/test/t-moDistanceStat.cpp b/branches/newMo/test/t-moDistanceStat.cpp index 8ed407839..8a8434817 100644 --- a/branches/newMo/test/t-moDistanceStat.cpp +++ b/branches/newMo/test/t-moDistanceStat.cpp @@ -54,6 +54,8 @@ int main(){ sol3.push_back(true); sol3.push_back(true); + //verification de la stat avec une distance de Hamming + eoHammingDistance< eoBit > dist; moDistanceStat< eoBit > test(dist, sol1); diff --git a/branches/newMo/test/t-moFirstImprExplorer.cpp b/branches/newMo/test/t-moFirstImprExplorer.cpp index 4cbca875b..6506ec753 100644 --- a/branches/newMo/test/t-moFirstImprExplorer.cpp +++ b/branches/newMo/test/t-moFirstImprExplorer.cpp @@ -40,6 +40,7 @@ int main(){ std::cout << "[t-moFirstImprExplorer] => START" << std::endl; + //Instanciation eoBit sol(4, true); sol.fitness(4); bitNeighborhood nh(4); @@ -49,6 +50,8 @@ int main(){ moFirstImprExplorer test(nh, eval, ncomp, sncomp); + //on verifie qu'on améliore peut continuer à explorer tant qu'on améliore la solution + test(sol); assert(test.accept(sol)); test.move(sol); diff --git a/branches/newMo/test/t-moHCneutralExplorer.cpp b/branches/newMo/test/t-moHCneutralExplorer.cpp index 83ecd5346..cc7f65a6a 100644 --- a/branches/newMo/test/t-moHCneutralExplorer.cpp +++ b/branches/newMo/test/t-moHCneutralExplorer.cpp @@ -40,6 +40,7 @@ int main(){ std::cout << "[t-moHCneutralExplorer] => START" << std::endl; + //Instanciation eoBit sol(4, true); sol.fitness(4); bitNeighborhood nh(4); @@ -49,6 +50,8 @@ int main(){ moHCneutralExplorer test(nh, eval, ncomp, sncomp,3); + //on verifie qu'on ameliore bien la solution et que l'exploration dure 3 itérations + test.initParam(sol); test(sol); assert(test.accept(sol)); @@ -57,7 +60,7 @@ int main(){ test.updateParam(sol); assert(test.isContinue(sol)); - + //les affichages permettent de voir qu'on prend pas toujours les mm voisins(lancer plusieurs fois l'exe) std::cout << sol << std::endl; test(sol); diff --git a/branches/newMo/test/t-moMetropolisHastingExplorer.cpp b/branches/newMo/test/t-moMetropolisHastingExplorer.cpp index bd4f99efa..8ddd4f8ef 100644 --- a/branches/newMo/test/t-moMetropolisHastingExplorer.cpp +++ b/branches/newMo/test/t-moMetropolisHastingExplorer.cpp @@ -38,6 +38,7 @@ int main(){ std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl; + //Instanciation eoBit sol(4, true); sol.fitness(4); bitNeighborhood nh(4); @@ -47,6 +48,7 @@ int main(){ moMetropolisHastingExplorer test(nh, eval, ncomp, sncomp, 3); + //test de l'acceptation d'un voisin améliorant test.initParam(sol); test(sol); assert(test.accept(sol)); @@ -57,6 +59,7 @@ int main(){ unsigned int oui=0, non=0; + //test de l'acceptation d'un voisin non améliorant for(unsigned int i=0; i<1000; i++){ test(sol); if(test.accept(sol)) @@ -70,11 +73,13 @@ int main(){ assert(oui > 700 && oui < 800); //verification grossiere + //test du critere d'arret test.updateParam(sol); assert(test.isContinue(sol)); test.updateParam(sol); assert(!test.isContinue(sol)); + //test de l'acceptation d'un voisin sol[0]=false; sol[1]=false; sol[2]=false; diff --git a/branches/newMo/test/t-moNeighbor.cpp b/branches/newMo/test/t-moNeighbor.cpp index e5ca0ccee..d703f8ce4 100644 --- a/branches/newMo/test/t-moNeighbor.cpp +++ b/branches/newMo/test/t-moNeighbor.cpp @@ -41,15 +41,16 @@ int main(){ std::cout << "[t-moNeighbor] => START" << std::endl; + //test constructor moDummyNeighbor test1, test2; test1.fitness(3); + //test operateur d'affectation test2=test1; - assert(test1.fitness()==test2.fitness()); + //test operateur de copy moDummyNeighbor test3(test1); - assert(test1.fitness()==test3.fitness()); test1.printOn(std::cout); diff --git a/branches/newMo/test/t-moRandomNeutralWalkExplorer.cpp b/branches/newMo/test/t-moRandomNeutralWalkExplorer.cpp index 3b7b18d0a..483525b1e 100644 --- a/branches/newMo/test/t-moRandomNeutralWalkExplorer.cpp +++ b/branches/newMo/test/t-moRandomNeutralWalkExplorer.cpp @@ -45,6 +45,8 @@ int main(){ dummyEvalOneMax eval2(4); moSolNeighborComparator sncomp; + //test avec la fonction d'eval classique + //on verifie qu'on ne trouve pas de voisin de mm fitness moRandomNeutralWalkExplorer test(nh, eval, sncomp, 3); test.initParam(sol); @@ -52,6 +54,8 @@ int main(){ assert(!test.accept(sol)); assert(!test.isContinue(sol)); + //test avec une fonction d'eval bidon qui renvoie toujours la mm fitness + //on peut donc verifier qu'on s'arette au bout des 3 itérations. moRandomNeutralWalkExplorer test2(nh, eval2, sncomp, 3); sol.fitness(2); diff --git a/branches/newMo/test/t-moRandomWalkExplorer.cpp b/branches/newMo/test/t-moRandomWalkExplorer.cpp index ec7bdeadb..460988d2b 100644 --- a/branches/newMo/test/t-moRandomWalkExplorer.cpp +++ b/branches/newMo/test/t-moRandomWalkExplorer.cpp @@ -43,6 +43,8 @@ int main(){ bitNeighborhood nh(4); evalOneMax eval(4); + //test avec un neighbordhood ordonné + //Du coup on verifie juste qu'on a bien une evolution de la solution et qu'on fait 3 pas avant d'arreter l'exploration moRandomWalkExplorer test(nh, eval, 3); test.initParam(sol); diff --git a/branches/newMo/test/t-moRndWithReplNeighborhood.cpp b/branches/newMo/test/t-moRndWithReplNeighborhood.cpp index 41c70fd57..110b4e824 100644 --- a/branches/newMo/test/t-moRndWithReplNeighborhood.cpp +++ b/branches/newMo/test/t-moRndWithReplNeighborhood.cpp @@ -51,6 +51,7 @@ int main(){ test.init(sol,n); + //on s'assure qu'on a bien toujours bien l'index 0, 1 ou 2 qui est renvoyé for(unsigned int i=0; i<100; i++){ a=n.index(); diff --git a/branches/newMo/test/t-moRndWithoutReplNeighborhood.cpp b/branches/newMo/test/t-moRndWithoutReplNeighborhood.cpp index 28119afce..c8ed7e426 100644 --- a/branches/newMo/test/t-moRndWithoutReplNeighborhood.cpp +++ b/branches/newMo/test/t-moRndWithoutReplNeighborhood.cpp @@ -43,12 +43,15 @@ int main(){ eoBit sol; moBitNeighbor n; + //instanciation moRndWithoutReplNeighborhood< moBitNeighbor > test(3); moRndWithoutReplNeighborhood< moBitNeighbor > test2(0); + //on verifie que test a bien des voisins et que test2 n'en a pas assert(test.hasNeighbor(sol)); assert(!test2.hasNeighbor(sol)); + //on recupere successivement les index test.init(sol, n); assert(test.cont(sol)); a=test.position(); @@ -59,6 +62,7 @@ int main(){ assert(!test.cont(sol)); c=test.position(); + //on s'assure qu'on a bien 0, 1 et 2 (dans un ordre aléatoire) assert(a==0 || b==0 || c==0); assert(a==1 || b==1 || c==1); assert(a==2 || b==2 || c==2); diff --git a/branches/newMo/test/t-moSimpleHCneutralExplorer.cpp b/branches/newMo/test/t-moSimpleHCneutralExplorer.cpp index 1abc956a8..7d32c5a0d 100644 --- a/branches/newMo/test/t-moSimpleHCneutralExplorer.cpp +++ b/branches/newMo/test/t-moSimpleHCneutralExplorer.cpp @@ -40,6 +40,7 @@ int main(){ std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl; + //instanciation eoBit sol(4, true); sol.fitness(4); bitNeighborhood nh(4); @@ -49,6 +50,7 @@ int main(){ moSimpleHCneutralExplorer test(nh, eval, ncomp, sncomp); + //test qu'on ameliore bien a chaque itération test.initParam(sol); test(sol); assert(test.accept(sol)); @@ -57,6 +59,7 @@ int main(){ assert(test.isContinue(sol)); test.updateParam(sol); + //les affichages permettent de voir qu'on choisit pas toujours les mm voisins améliorant (lancer plusieurs fois l'exe) std::cout << sol << std::endl; test(sol); diff --git a/branches/newMo/test/t-moSolVectorTabuList.cpp b/branches/newMo/test/t-moSolVectorTabuList.cpp index e62f5803c..7f792b40a 100644 --- a/branches/newMo/test/t-moSolVectorTabuList.cpp +++ b/branches/newMo/test/t-moSolVectorTabuList.cpp @@ -38,7 +38,8 @@ int main(){ std::cout << "[t-moSolVectorTabuList] => START" << std::endl; - moSolVectorTabuList test(2); + //test without countdown + moSolVectorTabuList test(2,0); bitNeighbor n1; bitNeighbor n2; bitNeighbor n3; @@ -58,8 +59,13 @@ int main(){ sol4[0]=false; sol4[1]=false; + //init test.init(sol1); + + //ajout d'une sol tabu test.add(sol1,n1); + + //verification des voisins de chaques sol assert(test.check(sol2,n1)); assert(!test.check(sol2,n2)); assert(!test.check(sol2,n3)); @@ -88,6 +94,59 @@ int main(){ assert(!test.check(sol2,n1)); assert(test.check(sol2,n2)); + //test with a countdown at 3 + moSolVectorTabuList test2(2,2); + test2.init(sol1); + test2.add(sol1,n1); + assert(test2.check(sol2,n1)); + assert(!test2.check(sol2,n2)); + assert(!test2.check(sol2,n3)); + assert(!test2.check(sol2,n4)); + + assert(!test2.check(sol3,n1)); + assert(test2.check(sol3,n2)); + assert(!test2.check(sol3,n3)); + assert(!test2.check(sol3,n4)); + + assert(!test2.check(sol4,n1)); + assert(!test2.check(sol4,n2)); + assert(!test2.check(sol4,n3)); + assert(!test2.check(sol4,n4)); + + //coutdown sol1 -> 1 + test2.update(sol1,n1); + assert(test2.check(sol2,n1)); + assert(!test2.check(sol2,n2)); + assert(!test2.check(sol2,n3)); + assert(!test2.check(sol2,n4)); + + assert(!test2.check(sol3,n1)); + assert(test2.check(sol3,n2)); + assert(!test2.check(sol3,n3)); + assert(!test2.check(sol3,n4)); + + assert(!test2.check(sol4,n1)); + assert(!test2.check(sol4,n2)); + assert(!test2.check(sol4,n3)); + assert(!test2.check(sol4,n4)); + + //coutdown sol1 -> 0 : sol1 is no longer tabu + test2.update(sol1,n1); + assert(!test2.check(sol2,n1)); + assert(!test2.check(sol2,n2)); + assert(!test2.check(sol2,n3)); + assert(!test2.check(sol2,n4)); + + assert(!test2.check(sol3,n1)); + assert(!test2.check(sol3,n2)); + assert(!test2.check(sol3,n3)); + assert(!test2.check(sol3,n4)); + + assert(!test2.check(sol4,n1)); + assert(!test2.check(sol4,n2)); + assert(!test2.check(sol4,n3)); + assert(!test2.check(sol4,n4)); + std::cout << "[t-moSolVectorTabuList] => OK" << std::endl; return EXIT_SUCCESS; diff --git a/branches/newMo/test/t-moSolutionStat.cpp b/branches/newMo/test/t-moSolutionStat.cpp index 9b32758b5..c17c67fe2 100644 --- a/branches/newMo/test/t-moSolutionStat.cpp +++ b/branches/newMo/test/t-moSolutionStat.cpp @@ -48,6 +48,7 @@ int main(){ moSolutionStat< eoBit > test; test(s); + //on verifie que la solution est bien enregistré assert(test.value()[0]); assert(test.value()[1]); diff --git a/branches/newMo/test/t-moTSExplorer.cpp b/branches/newMo/test/t-moTSExplorer.cpp index 30acd75be..ba72bdbd1 100644 --- a/branches/newMo/test/t-moTSExplorer.cpp +++ b/branches/newMo/test/t-moTSExplorer.cpp @@ -42,6 +42,7 @@ int main(){ std::cout << "[t-moTSExplorer] => START" << std::endl; + //instansiation eoBit sol(4, true); sol.fitness(4); bitNeighborhood nh(4); @@ -51,7 +52,7 @@ int main(){ moSolNeighborComparator sncomp; moDummyIntensification intens; moDummyDiversification diver; - moSolVectorTabuList tabuList(4); + moSolVectorTabuList tabuList(4,0); moBestImprAspiration aspir; moTSExplorer test(nh, eval, ncomp, sncomp, tabuList, intens, diver, aspir); @@ -152,6 +153,7 @@ int main(){ test3.moveApplied(true); test3.updateParam(sol2); + //on a rempli la liste tabu pour que tout les voisins soit tabu test3(sol2); assert(!test3.accept(sol2)); diff --git a/branches/newMo/tutorial/oneMax/application/testSimpleTS.cpp b/branches/newMo/tutorial/oneMax/application/testSimpleTS.cpp index ca996cb6a..6cdd51093 100644 --- a/branches/newMo/tutorial/oneMax/application/testSimpleTS.cpp +++ b/branches/newMo/tutorial/oneMax/application/testSimpleTS.cpp @@ -151,7 +151,7 @@ void main_function(int argc, char **argv) * * ========================================================= */ - moSolVectorTabuList tl(10); + moSolVectorTabuList tl(10,10); moDummyIntensification inten; moDummyDiversification div; moBestImprAspiration asp;