Full Eval modifié
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1656 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
c3085595bf
commit
0c7e11a8b5
3 changed files with 24 additions and 21 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
#define moFullEvalByCopy_H
|
#define moFullEvalByCopy_H
|
||||||
|
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
#include <moEval.h>
|
#include <eval/moEval.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -12,8 +12,8 @@ template<class Neighbor>
|
||||||
class moFullEvalByCopy : public moEval<Neighbor>
|
class moFullEvalByCopy : public moEval<Neighbor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using moEval<Neighbor>::EOT EOT;
|
typedef typename moEval<Neighbor>::EOT EOT;
|
||||||
using moEval<Neighbor>::Fitness Fitness;
|
typedef typename moEval<Neighbor>::Fitness Fitness;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ctor
|
* Ctor
|
||||||
|
|
@ -31,7 +31,7 @@ public:
|
||||||
// tmp solution
|
// tmp solution
|
||||||
EOT tmp(_sol);
|
EOT tmp(_sol);
|
||||||
// move tmp solution wrt _neighbor
|
// move tmp solution wrt _neighbor
|
||||||
_neighbor.(tmp);
|
_neighbor.move(tmp);
|
||||||
// eval copy
|
// eval copy
|
||||||
tmp.invalidate();
|
tmp.invalidate();
|
||||||
eval(tmp);
|
eval(tmp);
|
||||||
|
|
|
||||||
|
|
@ -27,24 +27,27 @@ public:
|
||||||
*/
|
*/
|
||||||
void operator()(EOT & _sol, BackableNeighbor & _neighbor)
|
void operator()(EOT & _sol, BackableNeighbor & _neighbor)
|
||||||
{
|
{
|
||||||
// tmp fitness value of the current solution
|
// tmp fitness value of the current solution
|
||||||
Fitness tmpFit;
|
Fitness tmpFit;
|
||||||
|
|
||||||
// save current fitness value
|
// save current fitness value
|
||||||
tmpFit = _sol.fitness();
|
tmpFit = _sol.fitness();
|
||||||
|
|
||||||
// move the current solution wrt _neighbor
|
// move the current solution wrt _neighbor
|
||||||
_neighbor.move(_sol);
|
_neighbor.move(_sol);
|
||||||
// eval the modified solution
|
|
||||||
_sol.invalidate();
|
|
||||||
eval(_sol);
|
|
||||||
// set the fitness value to the neighbor
|
|
||||||
_neighbor.fitness(_sol.fitness());
|
|
||||||
// move the current solution back
|
|
||||||
_neighbor.moveBack(_sol);
|
|
||||||
// set the fitness back
|
|
||||||
_sol.fitness(tmpFit);
|
|
||||||
|
|
||||||
|
// eval the modified solution
|
||||||
|
_sol.invalidate();
|
||||||
|
eval(_sol);
|
||||||
|
|
||||||
|
// set the fitness value to the neighbor
|
||||||
|
_neighbor.fitness(_sol.fitness());
|
||||||
|
|
||||||
|
// move the current solution back
|
||||||
|
_neighbor.moveBack(_sol);
|
||||||
|
|
||||||
|
// set the fitness back
|
||||||
|
_sol.fitness(tmpFit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
61
branches/newMo/src/unused/moFullEvalBitNeighbor.h
Normal file
61
branches/newMo/src/unused/moFullEvalBitNeighbor.h
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#ifndef _fullEvalBitNeighbor_h
|
||||||
|
#define _fullEvalBitNeighbor_h
|
||||||
|
|
||||||
|
#include <neighborhood/moBitNeighbor.h>
|
||||||
|
#include <ga.h>
|
||||||
|
|
||||||
|
template< class Fitness >
|
||||||
|
class moFullEvalBitNeighbor : public moFullEvalByModif<moBitNeighbor<Fitness> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef eoBit<Fitness> EOType ;
|
||||||
|
|
||||||
|
using moBitNeighbor<Fitness>::bit ;
|
||||||
|
|
||||||
|
// empty constructor needed
|
||||||
|
moFullEvalBitNeighbor() : moBitNeighbor<Fitness>() { } ;
|
||||||
|
|
||||||
|
moFullEvalBitNeighbor(unsigned b) : moBitNeighbor<Fitness>(bit) { } ;
|
||||||
|
|
||||||
|
/*
|
||||||
|
make the evaluation of the current neighbor and update the information on this neighbor
|
||||||
|
*/
|
||||||
|
virtual void eval(EOType & solution) {
|
||||||
|
Fitness fit = solution.fitness();
|
||||||
|
|
||||||
|
solution[bit] = solution[bit]?false:true ;
|
||||||
|
|
||||||
|
(*fullEval)(solution);
|
||||||
|
|
||||||
|
fitness(solution.fitness());
|
||||||
|
|
||||||
|
solution[bit] = solution[bit]?false:true ;
|
||||||
|
|
||||||
|
solution.fitness(fit);
|
||||||
|
};
|
||||||
|
|
||||||
|
static void setFullEvalFunc(eoEvalFunc<EOType> & eval) {
|
||||||
|
fullEval = & eval ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static eoEvalFunc<EOType> * fullEval ;
|
||||||
|
|
||||||
|
/** Return the class id.
|
||||||
|
* @return the class name as a std::string
|
||||||
|
*/
|
||||||
|
virtual std::string className() const { return "moFullEvalBitNeighbor"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class Fitness>
|
||||||
|
eoEvalFunc< eoBit<Fitness> > * moFullEvalBitNeighbor<Fitness>::fullEval = NULL ;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// coding: iso-8859-1
|
||||||
|
// mode: C++
|
||||||
|
// c-file-offsets: ((c . 0))
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// fill-column: 80
|
||||||
|
// End:
|
||||||
Loading…
Reference in a new issue