Perturb and acceptCrit added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1728 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-30 09:59:08 +00:00
commit c2771d8a3a
10 changed files with 690 additions and 8 deletions

View file

@ -47,6 +47,7 @@ public:
/**
* Default Constructor
* @param _monOp an eoMonOp (pertubation operator)
* @param _fullEval a full evaluation function
*/
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval){}

View file

@ -30,5 +30,79 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#ifndef _moNeighborhoodPerturb_h
#define _moNeighborhoodPerturb_h
#include <eval/moEval.h>
#include <perturb/moPerturbation.h>
/**
* Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search)
*/
template< class Neighbor, class OtherNH >
class moNeighborhoodPerturb : public moPerturbation<Neighbor>{
public:
typedef typename Neighbor::EOT EOT;
typedef typename OtherNH::Neighbor OtherN;
/**
* Default Constructor
* @param _otherNeighborhood a neighborhood
* @param _eval an Evaluation Function
*/
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherN>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){}
/**
* Apply move on the solution
* @param _solution the current solution
* @return true
*/
virtual bool operator()(EOT& _solution){
if(otherNeighborhood.hasNeighbor(_solution)){
eval(_solution, current);
current.move(_solution);
_solution.fitness(current.fitness());
}
return true;
}
/**
* Init the neighborhood
* @param _sol the current solution
*/
virtual void init(EOT & _sol){
if(otherNeighborhood.hasNeighbor(_sol))
otherNeighborhood.init(_sol, current);
}
/**
* ReInit the neighborhood because a move was done
* @param _sol the current solution
* @param _neighbor unused neighbor (always empty)
*/
virtual void add(EOT & _sol, Neighbor & _neighbor){
(*this).init(_sol);
}
/**
* Explore another neighbor because no move was done
* @param _sol the current solution
* @param _neighbor unused neighbor (always empty)
*/
virtual void update(EOT & _sol, Neighbor & _neighbor){
if(otherNeighborhood.cont(_sol))
otherNeighborhood.next(_sol, current);
else
(*this).init(_sol);
}
/**
* NOTHING TO DO
*/
virtual void clearMemory(){}
private:
OtherNH& otherNeighborhood;
moEval<OtherN>& eval;
OtherN current;
};
#endif

View file

@ -31,4 +31,47 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#define _moRestartPerturb_h
#include <eoEvalFunc.h>
#include <eoInit.h>
#include <perturb/moPerturbation.h>
#include <memory/moCountMoveMemory.h>
/**
* Restart Perturbation : restart when maximum number of iteration with no improvement is reached
*/
template< class Neighbor >
class moRestartPerturb : public moPerturbation<Neighbor>, public moCountMoveMemory<Neighbor> {
public:
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
* @param _init an initializer of solution
* @param _fullEval a full evaluation function
* @param _threshold maximum number of iteration with no improvement
*/
moRestartPerturb(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fullEval, unsigned int _threshold):init(_init), fullEval(_fullEval), threshold(_threshold) {}
/**
* Apply restart when necessary
* @param _solution to restart
* @return true
*/
bool operator()(EOT& _solution){
if((*this).getCounter()>= threshold){
init(_solution);
fullEval(_solution);
(*this).initCounter();
}
return true;
}
private:
eoInit<EOT>& init;
eoEvalFunc<EOT>& fullEval;
unsigned int threshold;
};
#endif