git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1650 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
jhumeau 2010-01-18 17:29:10 +00:00
commit 0f370ac9e1
14 changed files with 269 additions and 185 deletions

View file

@ -0,0 +1,20 @@
#ifndef _BackableNeighbor_h
#define _BackableNeighbor_h
/*
neighbor with a move back function to use in a moFullEvalByModif
*/
template< class EOT , class Fitness >
class moBackableNeighbor : moNeighbor<EOT, Fitness>
{
public:
/*
* the move back function
* @param _solution the solution to moveBack
*/
virtual moveBack(EOT & _solution) = 0;
};
#endif

View file

@ -1,46 +0,0 @@
#ifndef _fullEvalNeighbor_h
#define _fullEvalNeighbor_h
/*
neighbor with full evaluation
*/
template< class EOT , class Fitness >
class moFullEvalNeighbor : moNeighbor<EOT, Fitness>
{
public:
// empty constructor
moFullEvalNeighbor(eoEvalFunc<EOT> & _eval) : fulleval(_eval) { } ;
/*
make the evaluation of the current neighbor and update the information on this neighbor
*/
virtual void eval(EOT & solution) {
Fitness fit = solution.fitness();
move(solution);
fulleval(solution);
moveBack(solution);
fitness = solution.fitness();
solution.fitness(fit);
};
virtual moveBack(EOT & solution) ;
private:
eoEvalFunc<EOT> & fulleval ;
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -16,41 +16,35 @@ template< class M , class Fitness >
{
public:
typedef typename M::EOType EOT;
typedef typename M::EOType EOT;
// empty constructor
moMoveNeighbor() {_move=new M();};
moMoveNeighbor() {
move=new M();
};
~moMoveNeighbor() {delete _move;};
~moMoveNeighbor() {
delete move;
};
// copy constructeur
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor<EOT, Fitness>::operator=(_n);
(*_move) = *(_n._move);
}
// copy constructeur
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor<EOT, Fitness>::operator=(_n);
(*move) = *(_n.getMove());
}
// assignment operator
virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor <EOT, Fitness>::operator=(_n);
(*_move) = *(_n._move);
std::cout << moNeighbor<EOT, Fitness>::fitness() << " , " << _n.fitness() << std::endl;
(*move) = *(_n.getMove());
return *this ;
}
/*
* make the evaluation of the current neighbor and update the information on this neighbor
* the evaluation could be increamental
*/
virtual void eval(EOT & solution){
fitness((*_incrEval)(*_move, solution));
}
/*
* move the solution
*/
virtual void move(EOT & solution){
(*_move)(solution);
virtual void move(EOT & _solution){
(*move)(_solution);
}
/** Return the class id.
@ -58,51 +52,18 @@ public:
*/
virtual std::string className() const { return "moMoveNeighbor"; }
static void setIncrEval(moMoveIncrEval<M, Fitness>& increm) {
_incrEval = & increm ;
void setMove(M* _move){
move=_move;
}
/**
* Read object.\ \
* Calls base class, just in case that one had something to do.
* The read and print methods should be compatible and have the same format.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read.
*/
/* virtual void readFrom(std::istream& _is) {
std::string fitness_str;
int pos = _is.tellg();
_is >> fitness_str;
M* getMove(){
return move;
}
if (fitness_str == "INVALID")
{
throw std::runtime_error("invalid fitness");
}
else
{
_is.seekg(pos); // rewind
_is >> repFitness;
}
}
*/
/**
* Write object. Called printOn since it prints the object _on_ a stream.
* @param _os A std::ostream.
*/
/*virtual void printOn(std::ostream& _os) const {
_os << repFitness << ' ' ;
}*/
M* _move;
private:
static moMoveIncrEval<M, Fitness>* _incrEval;
M* move;
};
template< class M , class Fitness >
moMoveIncrEval<M, Fitness> * moMoveNeighbor<M, Fitness>::_incrEval = NULL;
#endif

View file

@ -28,31 +28,19 @@ public:
return *this ;
}
/*
* make the evaluation of the current neighbor and update the information on this neighbor
* the evaluation could be increamental
*/
virtual void eval(EOT & solution) = 0 ;
/*
* move the solution
*/
virtual void move(EOT & solution) = 0 ;
// true if the this is better than the neighbor __neighbor
// virtual bool betterThan(const moNeighbor<EOT,Fitness> & __neighbor) = 0 ;
virtual bool betterThan(const moNeighbor<EOT,Fitness> & __neighbor) {
return (*neighborComparator)(*this, __neighbor) ;
} ;
/// Return fitness value.
const Fitness& fitness() const {
return repFitness;
return repFitness;
}
/// Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
Fitness& fitnessReference() {
return repFitness;
return repFitness;
}
/** Set fitness. At the same time, validates it.
@ -74,22 +62,9 @@ public:
* The read and print methods should be compatible and have the same format.
* In principle, format is "plain": they just print a number
* @param _is a std::istream.
* @throw runtime_std::exception If a valid object can't be read.
*/
virtual void readFrom(std::istream& _is) {
std::string fitness_str;
int pos = _is.tellg();
_is >> fitness_str;
if (fitness_str == "INVALID")
{
throw std::runtime_error("invalid fitness");
}
else
{
_is.seekg(pos); // rewind
_is >> repFitness;
}
}
/**
@ -100,35 +75,10 @@ public:
_os << repFitness << ' ' ;
}
static void setNeighborComparator(const moNeighborComparator< moNeighbor<EOType, Fitness> > & comparator) {
neighborComparator = & comparator ;
}
static const moNeighborComparator< moNeighbor<EOType, Fitness> > & getNeighborComparator() {
return *neighborComparator ;
}
private:
// minimal information on the neighbor : fitness
Fitness repFitness ;
// the comparator of neighbors
static moNeighborComparator<moNeighbor<EOType, Fitness> > * neighborComparator ;
};
// static default comparor
template<class EOT, class Fitness>
moNeighborComparator<moNeighbor<EOT, Fitness> > * moNeighbor<EOT, Fitness>::neighborComparator = new moNeighborComparator<moNeighbor<EOT, Fitness> >();
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -33,14 +33,4 @@ public:
virtual std::string className() const { return "moNeighborhood"; }
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End: