tests added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1701 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-18 16:26:25 +00:00
commit 44f971d492
8 changed files with 202 additions and 55 deletions

View file

@ -39,6 +39,8 @@
#include <comparator/moNeighborComparator.h>
#include <comparator/moSolNeighborComparator.h>
#include <utils/eoRNG.h>
/**
* 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<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), neighborComparator(_neighborComparator), solNeighborComparator(_solNeighborComparator), nbStep(_nbStep) {
moMetropolisHastingExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _neighborComparator, moSolNeighborComparator<Neighbor>& _solNeighborComparator, unsigned int _nbStep) : moNeighborhoodExplorer<Neighborhood>(_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;
};

View file

@ -60,13 +60,13 @@ public:
* @param _solNeighborComparator a solution vs neighbor comparator
* @param _nbStep maximum number of step to do
*/
moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval,
moRandomNeutralWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval,
moSolNeighborComparator<Neighbor>& _solNeighborComparator,
unsigned _nbStep)
: moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval),
solNeighborComparator(_solNeighborComparator),
nbStep(_nbStep) {
isAccept = false;
unsigned _nbStep):
moNeighborhoodExplorer<Neighborhood>(_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:

View file

@ -40,7 +40,7 @@
#include <comparator/moSolNeighborComparator.h>
/**
* Explorer for a first imporvement heuristic
* Explorer for a random walk explorer
*/
template< class Neighborhood >
class moRandomWalkExplorer : public moNeighborhoodExplorer<Neighborhood>
@ -58,11 +58,11 @@ public:
* @param _eval the evaluation function
* @param _nbStep maximum number of step to do
*/
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _nbStep) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval), nbStep(_nbStep) {
moRandomWalkExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, unsigned _nbStep) : moNeighborhoodExplorer<Neighborhood>(_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;
};