doc de moSimpleHCexplorer
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1657 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
0c7e11a8b5
commit
69fc53a6be
2 changed files with 68 additions and 28 deletions
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
#include <explorer/moNeighborhoodExplorer.h>
|
#include <explorer/moNeighborhoodExplorer.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Explorer for a simple Hill-climbing
|
||||||
|
*/
|
||||||
template< class Neighborhood >
|
template< class Neighborhood >
|
||||||
class moSimpleHCexplorer : public moNeighborhoodExplorer<Neighborhood>
|
class moSimpleHCexplorer : public moNeighborhoodExplorer<Neighborhood>
|
||||||
{
|
{
|
||||||
|
|
@ -14,61 +17,97 @@ public:
|
||||||
using moNeighborhoodExplorer<Neighborhood>::eval;
|
using moNeighborhoodExplorer<Neighborhood>::eval;
|
||||||
using moNeighborhoodExplorer<Neighborhood>::comparator;
|
using moNeighborhoodExplorer<Neighborhood>::comparator;
|
||||||
|
|
||||||
// empty constructor
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param _neighborhood the neighborhood
|
||||||
|
* @param _eval the evaluation function
|
||||||
|
* @param _comparator a neighbor comparator
|
||||||
|
*/
|
||||||
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _comparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval, _comparator){
|
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _comparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval, _comparator){
|
||||||
isAccept = false;
|
isAccept = false;
|
||||||
current=new Neighbor();
|
current=new Neighbor();
|
||||||
best=new Neighbor();
|
best=new Neighbor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initParam: NOTHING TO DO
|
||||||
|
*/
|
||||||
virtual void initParam(EOT & solution){};
|
virtual void initParam(EOT & solution){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updateParam: NOTHING TO DO
|
||||||
|
*/
|
||||||
virtual void updateParam(EOT & solution){};
|
virtual void updateParam(EOT & solution){};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* terminate: NOTHING TO DO
|
||||||
|
*/
|
||||||
virtual void terminate(EOT & solution){};
|
virtual void terminate(EOT & solution){};
|
||||||
|
|
||||||
virtual void operator() (EOT & solution) {
|
/**
|
||||||
|
* Explore the neighborhood of a solution
|
||||||
|
* @param _solution
|
||||||
|
*/
|
||||||
|
virtual void operator()(EOT & _solution){
|
||||||
|
|
||||||
//est qu'on peut initializer
|
//est qu'on peut initializer
|
||||||
|
//Test if _solution has a Neighbor
|
||||||
|
if(neighborhood.hasNeighbor(_solution)){
|
||||||
|
//init the first neighbor
|
||||||
|
neighborhood.init(_solution, (*current));
|
||||||
|
|
||||||
if(neighborhood.hasNeighbor(solution)){
|
//eval the _solution moved with the neighbor and stock the result in the neighbor
|
||||||
neighborhood.init(solution, (*current));
|
eval(_solution, (*current));
|
||||||
|
|
||||||
eval(solution, (*current));
|
|
||||||
|
|
||||||
std::cout <<"sol et neighbor:"<< solution << ", "<< (*current) << std::endl;
|
|
||||||
|
|
||||||
|
//initialize the best neighbor
|
||||||
(*best) = (*current);
|
(*best) = (*current);
|
||||||
|
|
||||||
while (neighborhood.cont(solution)) {
|
//test all others neighbors
|
||||||
neighborhood.next(solution, (*current));
|
while (neighborhood.cont(_solution)) {
|
||||||
|
//next neighbor
|
||||||
eval(solution, (*current));
|
neighborhood.next(_solution, (*current));
|
||||||
std::cout <<"sol et neighbor:"<< solution << ", "<< (*current) << std::endl;
|
//eval
|
||||||
|
eval(_solution, (*current));
|
||||||
|
//if we found a better neighbor, update the best
|
||||||
if (comparator((*current), (*best))) {
|
if (comparator((*current), (*best))) {
|
||||||
(*best) = (*current);
|
(*best) = (*current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
//if _solution hasn't neighbor,
|
||||||
isAccept=false;
|
isAccept=false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool isContinue(EOT & solution) {
|
/**
|
||||||
|
* continue if a move is accepted
|
||||||
|
* @param _solution the solution
|
||||||
|
* @return true if an ameliorated neighbor was be found
|
||||||
|
*/
|
||||||
|
virtual bool isContinue(EOT & _solution) {
|
||||||
return isAccept ;
|
return isAccept ;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void move(EOT & solution) {
|
/**
|
||||||
|
* move the solution with the best neighbor
|
||||||
(*best).move(solution);
|
* @param _solution the solution to move
|
||||||
|
*/
|
||||||
solution.fitness((*best).fitness());
|
virtual void move(EOT & _solution) {
|
||||||
|
//move the solution
|
||||||
|
(*best).move(_solution);
|
||||||
|
//update its fitness
|
||||||
|
_solution.fitness((*best).fitness());
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool accept(EOT & solution) {
|
/**
|
||||||
if(neighborhood.hasNeighbor(solution)){
|
* accept test if an amelirated neighbor was be found
|
||||||
isAccept = (solution.fitness() < (*best).fitness()) ;
|
* @param _solution the solution
|
||||||
|
* @return true if the best neighbor ameliorate the fitness
|
||||||
|
*/
|
||||||
|
virtual bool accept(EOT & _solution) {
|
||||||
|
if(neighborhood.hasNeighbor(_solution)){
|
||||||
|
isAccept = (_solution.fitness() < (*best).fitness()) ;
|
||||||
}
|
}
|
||||||
return isAccept;
|
return isAccept;
|
||||||
};
|
};
|
||||||
|
|
@ -76,8 +115,8 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// attention il faut que le constructeur vide existe
|
// attention il faut que le constructeur vide existe
|
||||||
|
//(Pointeurs) on the best and the current neighbor
|
||||||
Neighbor* best;
|
Neighbor* best;
|
||||||
|
|
||||||
Neighbor* current;
|
Neighbor* current;
|
||||||
|
|
||||||
// true if the move is accepted
|
// true if the move is accepted
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ using namespace std;
|
||||||
#include <neighborhood/moBitNeighborhood.h>
|
#include <neighborhood/moBitNeighborhood.h>
|
||||||
|
|
||||||
#include <eval/moFullEvalByModif.h>
|
#include <eval/moFullEvalByModif.h>
|
||||||
|
#include <eval/moFullEvalByCopy.h>
|
||||||
|
|
||||||
|
|
||||||
#include <oneMaxBitNeighbor.h>
|
#include <oneMaxBitNeighbor.h>
|
||||||
|
|
@ -124,7 +125,7 @@ void main_function(int argc, char **argv)
|
||||||
|
|
||||||
FuncOneMax<Indi> eval(vecSize);
|
FuncOneMax<Indi> eval(vecSize);
|
||||||
|
|
||||||
moFullEvalByModif<moBitNeighbor<unsigned int> > fulleval(eval);
|
moFullEvalByCopy<moBitNeighbor<unsigned int> > fulleval(eval);
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue