tests added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1700 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
500987685b
commit
5c3260d712
8 changed files with 331 additions and 55 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue