tests added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1700 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-18 15:01:16 +00:00
commit 5c3260d712
8 changed files with 331 additions and 55 deletions

View file

@ -59,7 +59,7 @@ public:
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator a solution vs neighbor comparator
*/
moFirstImprExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
moFirstImprExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
isAccept = false;
current=new Neighbor();
}
@ -92,7 +92,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

View file

@ -40,7 +40,7 @@
#include <comparator/moSolNeighborComparator.h>
/**
* Explorer for a simple Hill-climbing
* Explorer for a neutral Hill-climbing
*/
template< class Neighborhood >
class moHCneutralExplorer : public moSimpleHCneutralExplorer<Neighborhood>
@ -64,13 +64,13 @@ public:
* @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum step to do
*/
moHCneutralExplorer(Neighborhood& _neighborhood,
moHCneutralExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep) :
moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator), nbStep(_nbStep) {
}
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep) :
moSimpleHCneutralExplorer<Neighborhood>(_neighborhood, _eval, _neighborComparator, _solNeighborComparator),
nbStep(_nbStep){}
/**
* Destructor
@ -102,7 +102,7 @@ public:
* @return true there is some steps to do
*/
virtual bool isContinue(EOT & _solution) {
return (step < nbStep) && isAccept ;
return (step < nbStep) && isAccept ;
};
/**
@ -111,14 +111,8 @@ public:
* @return true if the best neighbor ameliorate the fitness or is equals
*/
virtual bool accept(EOT & _solution) {
if(neighborhood.hasNeighbor(_solution)){
isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ;
std::cout << bestVector.size() << " " << bestVector[0] << " " ;
if (isAccept)
std::cout << "true" << std::endl;
else
std::cout << "false" << std::endl;
}
if(neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator(_solution, bestVector[0]) || solNeighborComparator.equals(_solution, bestVector[0]) ;
return isAccept;
};

View file

@ -38,9 +38,11 @@
#include <explorer/moNeighborhoodExplorer.h>
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <vector>
#include <utils/eoRNG.h>
/**
* Explorer for a simple Hill-climbing
* Explorer for a simple neutral Hill-climbing
*/
template< class Neighborhood >
class moSimpleHCneutralExplorer : public moNeighborhoodExplorer<Neighborhood>
@ -59,12 +61,13 @@ public:
* @param _neighborComparator a neighbor comparator
* @param _solNeighborComparator solution vs neighbor comparator
*/
moSimpleHCneutralExplorer(Neighborhood& _neighborhood,
moSimpleHCneutralExplorer(Neighborhood& _neighborhood,
moEval<Neighbor>& _eval,
moNeighborComparator<Neighbor>& _neighborComparator,
moSolNeighborComparator<Neighbor>& _solNeighborComparator) :
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator) {
moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
neighborComparator(_neighborComparator),
solNeighborComparator(_solNeighborComparator) {
isAccept = false;
current=new Neighbor();
}
@ -103,39 +106,39 @@ 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
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));
//initialize the best neighbor
bestVector.push_back(*current);
//initialize the best neighbor
bestVector.push_back(*current);
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//test all others neighbors
while (neighborhood.cont(_solution)) {
//next neighbor
neighborhood.next(_solution, (*current));
//eval
eval(_solution, (*current));
//eval
eval(_solution, (*current));
//if we found a better neighbor, update the best
if (neighborComparator(bestVector[0], (*current))) {
bestVector.clear();
bestVector.push_back(*current);
} else //if the current is equals to previous best solutions then update vector of the best solution
if (neighborComparator.equals((*current), bestVector[0]))
bestVector.push_back(*current);
}
} else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
//if we found a better neighbor, update the best
if (neighborComparator(bestVector[0], (*current))) {
bestVector.clear();
bestVector.push_back(*current);
}
else if (neighborComparator.equals((*current), bestVector[0])) //if the current is equals to previous best solutions then update vector of the best solution
bestVector.push_back(*current);
}
}
else {
//if _solution hasn't neighbor,
isAccept=false;
}
};
/**
* continue if a move is accepted
@ -167,10 +170,9 @@ public:
* @return true if the best neighbor ameliorate the fitness
*/
virtual bool accept(EOT & _solution) {
if(neighborhood.hasNeighbor(_solution)){
isAccept = solNeighborComparator(_solution, bestVector[0]) ;
}
return isAccept;
if(neighborhood.hasNeighbor(_solution))
isAccept = solNeighborComparator(_solution, bestVector[0]) ;
return isAccept;
};
protected:

View file

@ -36,7 +36,6 @@ SET (TEST_LIST
t-moOrderNeighborhood
t-moFullEvalByCopy
t-moFullEvalByModif
t-moSimpleHCexplorer
t-moNeighborComparator
t-moSolNeighborComparator
t-moTrueContinuator
@ -48,6 +47,11 @@ SET (TEST_LIST
t-moCounterMonitorSaver
t-moSolutionStat
t-moCheckpoint
t-moSimpleHCexplorer
t-moSimpleHCneutralExplorer
t-moHCneutralExplorer
t-moFirstImprExplorer
)
FOREACH (test ${TEST_LIST})

View file

@ -0,0 +1,90 @@
/*
<t-moFirstImprExplorer.cpp>
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 <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <explorer/moFirstImprExplorer.h>
#include "moTestClass.h"
#include <iostream>
#include <cstdlib>
#include <cassert>
int main(){
std::cout << "[t-moFirstImprExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
moFirstImprExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(!sol[0]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
assert(!sol[1]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
assert(!sol[2]);
assert(test.isContinue(sol));
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==0);
assert(!sol[3]);
assert(test.isContinue(sol));
test(sol);
assert(!test.accept(sol));
assert(sol.fitness()==0);
assert(!test.isContinue(sol));
std::cout << "[t-moFirstImprExplorer] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,89 @@
/*
<t-moHCneutralExplorer.cpp>
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 <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <explorer/moHCneutralExplorer.h>
#include "moTestClass.h"
#include <iostream>
#include <cstdlib>
#include <cassert>
int main(){
std::cout << "[t-moHCneutralExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
moHCneutralExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp,3);
test.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
test.updateParam(sol);
assert(test.isContinue(sol));
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
test.updateParam(sol);
assert(test.isContinue(sol));
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
test.updateParam(sol);
assert(!test.isContinue(sol));
std::cout << sol << std::endl;
std::cout << "[t-moHCneutralExplorer] => OK" << std::endl;
return EXIT_SUCCESS;
}

View file

@ -78,7 +78,7 @@ int main(){
//verif de move -> on affecte la fitness du best d'avant
test.move(sol);
//hasNeighbor() retourne vrai et on ameliore la pas fitness donc on doit pas continuer
//hasNeighbor() retourne vrai et on ameliore pas la fitness donc on doit pas continuer
test(sol);
test(sol);
test.accept(sol);

View file

@ -0,0 +1,98 @@
/*
<t-moSimpleHCneutralExplorer.cpp>
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 <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <explorer/moSimpleHCneutralExplorer.h>
#include "moTestClass.h"
#include <iostream>
#include <cstdlib>
#include <cassert>
int main(){
std::cout << "[t-moSimpleHCneutralExplorer] => START" << std::endl;
eoBit<eoMinimizingFitness> sol(4, true);
sol.fitness(4);
bitNeighborhood nh(4);
evalOneMax eval(4);
moNeighborComparator<bitNeighbor> ncomp;
moSolNeighborComparator<bitNeighbor> sncomp;
moSimpleHCneutralExplorer<bitNeighborhood> test(nh, eval, ncomp, sncomp);
test.initParam(sol);
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==3);
assert(test.isContinue(sol));
test.updateParam(sol);
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==2);
assert(test.isContinue(sol));
test.updateParam(sol);
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==1);
assert(test.isContinue(sol));
test.updateParam(sol);
std::cout << sol << std::endl;
test(sol);
assert(test.accept(sol));
test.move(sol);
assert(sol.fitness()==0);
assert(test.isContinue(sol));
test.updateParam(sol);
test(sol);
assert(!test.accept(sol));
assert(sol.fitness()==0);
assert(!test.isContinue(sol));
test.updateParam(sol);
std::cout << "[t-moSimpleHCneutralExplorer] => OK" << std::endl;
return EXIT_SUCCESS;
}