Doc and tests added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1706 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-23 15:14:04 +00:00
commit baf31d0c30
25 changed files with 159 additions and 26 deletions

View file

@ -51,12 +51,10 @@
#include <utils/eoMonitor.h>
#include <utils/eoUpdater.h>
typedef eoBit<eoMinimizingFitness> bitVector;
typedef moBitNeighbor<eoMinimizingFitness> bitNeighbor ;
class moDummyRndNeighborhood: public moOrderNeighborhood<bitNeighbor>, public moRndNeighborhood<bitNeighbor> {
class moDummyRndNeighborhood: public moOrderNeighborhood<bitNeighbor>/*, public moRndNeighborhood<bitNeighbor>*/{
public:
moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood<bitNeighbor>(a){}
};

View file

@ -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));

View file

@ -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);

View file

@ -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);

View file

@ -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<int> > dist;
moDistanceStat< eoBit<int> > test(dist, sol1);

View file

@ -40,6 +40,7 @@ int main(){
std::cout << "[t-moFirstImprExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
@ -49,6 +50,8 @@ int main(){
moFirstImprExplorer<bitNeighborhood> 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);

View file

@ -40,6 +40,7 @@ int main(){
std::cout << "[t-moHCneutralExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
@ -49,6 +50,8 @@ int main(){
moHCneutralExplorer<bitNeighborhood> 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);

View file

@ -38,6 +38,7 @@ int main(){
std::cout << "[t-moMetropolisHastingExplorer] => START" << std::endl;
//Instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
@ -47,6 +48,7 @@ int main(){
moMetropolisHastingExplorer<bitNeighborhood> 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;

View file

@ -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);

View file

@ -45,6 +45,8 @@ int main(){
dummyEvalOneMax eval2(4);
moSolNeighborComparator<bitNeighbor> sncomp;
//test avec la fonction d'eval classique
//on verifie qu'on ne trouve pas de voisin de mm fitness
moRandomNeutralWalkExplorer<bitNeighborhood> 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<bitNeighborhood> test2(nh, eval2, sncomp, 3);
sol.fitness(2);

View file

@ -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<bitNeighborhood> test(nh, eval, 3);
test.initParam(sol);

View file

@ -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();

View file

@ -43,12 +43,15 @@ int main(){
eoBit<int> sol;
moBitNeighbor<int> n;
//instanciation
moRndWithoutReplNeighborhood< moBitNeighbor<int> > test(3);
moRndWithoutReplNeighborhood< moBitNeighbor<int> > 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);

View file

@ -40,6 +40,7 @@ int main(){
std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl;
//instanciation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
@ -49,6 +50,7 @@ int main(){
moSimpleHCneutralExplorer<bitNeighborhood> 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);

View file

@ -38,7 +38,8 @@ int main(){
std::cout << "[t-moSolVectorTabuList] => START" << std::endl;
moSolVectorTabuList<bitNeighbor> test(2);
//test without countdown
moSolVectorTabuList<bitNeighbor> 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<bitNeighbor> 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;

View file

@ -48,6 +48,7 @@ int main(){
moSolutionStat< eoBit<unsigned int > > test;
test(s);
//on verifie que la solution est bien enregistré
assert(test.value()[0]);
assert(test.value()[1]);

View file

@ -42,6 +42,7 @@ int main(){
std::cout << "[t-moTSExplorer] => START" << std::endl;
//instansiation
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
@ -51,7 +52,7 @@ int main(){
moSolNeighborComparator<bitNeighbor> sncomp;
moDummyIntensification<bitNeighbor> intens;
moDummyDiversification<bitNeighbor> diver;
moSolVectorTabuList<bitNeighbor> tabuList(4);
moSolVectorTabuList<bitNeighbor> tabuList(4,0);
moBestImprAspiration<bitNeighbor> aspir;
moTSExplorer<bitNeighborhood> 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));