git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1650 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
01feefce30
commit
0f370ac9e1
14 changed files with 269 additions and 185 deletions
|
|
@ -44,6 +44,9 @@ public:
|
||||||
|
|
||||||
searchExplorer.terminate(solution);
|
searchExplorer.terminate(solution);
|
||||||
|
|
||||||
|
//A CHANGER
|
||||||
|
return true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
34
branches/newMo/src/comparator/moComparator.h
Normal file
34
branches/newMo/src/comparator/moComparator.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef _moNeighborComparator_h
|
||||||
|
#define _moNeighborComparator_h
|
||||||
|
|
||||||
|
#include <neighborhood/moNeighbor.h>
|
||||||
|
|
||||||
|
template< class Neigh >
|
||||||
|
class moNeighborComparator : public eoBF<const Neigh & , const Neigh & , bool>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/*
|
||||||
|
* true if the neighbor1 is better than neighbor2
|
||||||
|
*/
|
||||||
|
virtual bool operator()(const Neigh & neighbor1, const Neigh & neighbor2) {
|
||||||
|
return (neighbor1.fitness() > neighbor2.fitness());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return the class id.
|
||||||
|
* @return the class name as a std::string
|
||||||
|
*/
|
||||||
|
virtual std::string className() const { return "moNeighborComparator"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// coding: iso-8859-1
|
||||||
|
// mode: C++
|
||||||
|
// c-file-offsets: ((c . 0))
|
||||||
|
// c-file-style: "Stroustrup"
|
||||||
|
// fill-column: 80
|
||||||
|
// End:
|
||||||
|
|
@ -3,22 +3,35 @@
|
||||||
|
|
||||||
#include <neighborhood/moNeighbor.h>
|
#include <neighborhood/moNeighbor.h>
|
||||||
|
|
||||||
template< class Neigh >
|
|
||||||
class moNeighborComparator : public eoBF<const Neigh & , const Neigh & , bool>
|
|
||||||
|
// moComparator => comparer deux solutions
|
||||||
|
// idée :
|
||||||
|
// - eoComparator
|
||||||
|
// - moComparator qui hérite de eoComparator ?
|
||||||
|
// - moeoComparator qui hérite de eoComparator
|
||||||
|
// idée J :
|
||||||
|
// - eoComparator<TYPE> : eoBF <const TYPE & , const TYPE & , bool>
|
||||||
|
// - eoSolComparator : eoComparator<EOT> ?
|
||||||
|
// - moNeighborCompartor : : eoComparator<Neighbor>
|
||||||
|
//
|
||||||
|
// une instantiation possible !!
|
||||||
|
template< class EOT >
|
||||||
|
class moComparator : public eoBF<const EOT & , const EOT & , bool>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* true if the neighbor1 is better than neighbor2
|
* true if the _sol1 is better than _sol2
|
||||||
*/
|
*/
|
||||||
virtual bool operator()(const Neigh & neighbor1, const Neigh & neighbor2) {
|
virtual bool operator()(const EOT & _sol1, const EOT & _sol2) {
|
||||||
return (neighbor1.fitness() > neighbor2.fitness());
|
return (_sol1.fitness() > _sol2.fitness());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the class id.
|
/** Return the class id.
|
||||||
* @return the class name as a std::string
|
* @return the class name as a std::string
|
||||||
*/
|
*/
|
||||||
virtual std::string className() const { return "moNeighborComparator"; }
|
virtual std::string className() const { return "moComparator"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
14
branches/newMo/src/eval/moEval.h
Normal file
14
branches/newMo/src/eval/moEval.h
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef moEval_H
|
||||||
|
#define moEval_H
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
|
template<class Neighbor>
|
||||||
|
class moEval : public eoBF<typename Neighbor::EOType &, Neighbor&, void>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename Neighbor::EOType EOT;
|
||||||
|
typedef typename EOT::Fitness Fitness;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
45
branches/newMo/src/eval/moFullEvalByCopy.h
Normal file
45
branches/newMo/src/eval/moFullEvalByCopy.h
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef moFullEvalByCopy_H
|
||||||
|
#define moFullEvalByCopy_H
|
||||||
|
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <moEval.h>
|
||||||
|
|
||||||
|
template<class Neighbor>
|
||||||
|
class moFullEvalByCopy : public moEval<Neighbor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using moEval<Neighbor>::EOT EOT;
|
||||||
|
using moEval<Neighbor>::Fitness Fitness;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor
|
||||||
|
* @param _eval the full evaluation object
|
||||||
|
*/
|
||||||
|
moFullEvalByCopy(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full evaluation of the neighbor by copy
|
||||||
|
* @param _sol current solution
|
||||||
|
* @param _neighbor the neighbor to be evaluated
|
||||||
|
*/
|
||||||
|
void operator()(EOT & _sol, Neighbor & _neighbor)
|
||||||
|
{
|
||||||
|
// tmp solution
|
||||||
|
EOT tmp(_sol);
|
||||||
|
// move tmp solution wrt _neighbor
|
||||||
|
_neighbor.(tmp);
|
||||||
|
// eval copy
|
||||||
|
tmp.invalidate();
|
||||||
|
eval(tmp);
|
||||||
|
// set the fitness value to the neighbor
|
||||||
|
_neighbor.fitness(tmp.fitness());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** the full evaluation object */
|
||||||
|
eoEvalFunc<EOT> & eval;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
56
branches/newMo/src/eval/moFullEvalByModif.h
Normal file
56
branches/newMo/src/eval/moFullEvalByModif.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
#ifndef moFullEvalByModif_H
|
||||||
|
#define moFullEvalByModif_H
|
||||||
|
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <moEval.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Full evaluation to use with a moBackableNeighbor
|
||||||
|
*/
|
||||||
|
template<class BackableNeighbor>
|
||||||
|
class moFullEvalByModif : public moEval<BackableNeighbor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using moEval<BackableNeighbor>::EOT EOT;
|
||||||
|
using moEval<BackableNeighbor>::Fitness Fitness;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ctor
|
||||||
|
* @param _eval the full evaluation object
|
||||||
|
*/
|
||||||
|
moFullEvalByCopy(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full evaluation of the neighbor by copy
|
||||||
|
* @param _sol current solution
|
||||||
|
* @param _neighbor the neighbor to be evaluated
|
||||||
|
*/
|
||||||
|
void operator()(EOT & _sol, BackableNeighbor & _neighbor)
|
||||||
|
{
|
||||||
|
// tmp fitness value of the current solution
|
||||||
|
Fitness tmpFit;
|
||||||
|
|
||||||
|
// save current fitness value
|
||||||
|
tmpFit = _sol.fitness();
|
||||||
|
|
||||||
|
// move the current solution wrt _neighbor
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** the full evaluation object */
|
||||||
|
eoEvalFunc<EOT> & eval;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
34
branches/newMo/src/eval/moIncrEvalWrapper.h
Normal file
34
branches/newMo/src/eval/moIncrEvalWrapper.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef moIncrEvalWrapper_H
|
||||||
|
#define moIncrEvalWrapper_H
|
||||||
|
|
||||||
|
#include <eoEvalFunc.h>
|
||||||
|
#include <moEval.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (Old fashioned) Incremental evaluation to use with a moMoveNeighbor
|
||||||
|
* WARNING: Don't use this class unless you are an moMove user.
|
||||||
|
*/
|
||||||
|
template<class MoveNeighbor, class M>
|
||||||
|
class moIncrEvalWrapper : public moEval<MoveNeighbor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using moEval<BackableNeighbor>::EOT EOT;
|
||||||
|
using moEval<BackableNeighbor>::Fitness Fitness;
|
||||||
|
|
||||||
|
moIncrEvalWrapper(moIncrEval<M>& _incr):incr(_incr){}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* make the evaluation of the current neighbor and update the information on this neighbor
|
||||||
|
* the evaluation could be increamental
|
||||||
|
*/
|
||||||
|
virtual void eval(MoveNeighbor& _neighbor,EOT & _solution){
|
||||||
|
_neighbor.fitness(incrEval(*(_neighbor.getMove()), _solution));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** the full evaluation object */
|
||||||
|
moIncrEval<M> & incrEval;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -11,10 +11,14 @@ class moNeighborhoodExplorer : public eoUF<typename NH::EOT & , void>
|
||||||
public:
|
public:
|
||||||
typedef NH Neighborhood ;
|
typedef NH Neighborhood ;
|
||||||
typedef typename Neighborhood::EOT EOT ;
|
typedef typename Neighborhood::EOT EOT ;
|
||||||
|
typedef typename Neighborhood::Neighbor Neighbor ;
|
||||||
|
|
||||||
// empty constructor
|
// empty constructor
|
||||||
moNeighborhoodExplorer() { } ;
|
moNeighborhoodExplorer() { } ;
|
||||||
|
|
||||||
|
// empty constructor
|
||||||
|
moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):neighborhood(_neighborhood), eval(_eval) { } ;
|
||||||
|
|
||||||
virtual void initParam (EOT & solution) = 0 ;
|
virtual void initParam (EOT & solution) = 0 ;
|
||||||
|
|
||||||
virtual void updateParam (EOT & solution) = 0 ;
|
virtual void updateParam (EOT & solution) = 0 ;
|
||||||
|
|
@ -31,8 +35,14 @@ public:
|
||||||
* @return the class name as a std::string
|
* @return the class name as a std::string
|
||||||
*/
|
*/
|
||||||
virtual std::string className() const { return "moNeighborhoodExplorer"; }
|
virtual std::string className() const { return "moNeighborhoodExplorer"; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Neighborhood & neighborhood;
|
||||||
|
moEval<Neighbor>& eval;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,20 +27,20 @@ public:
|
||||||
//est qu'on peut initializer
|
//est qu'on peut initializer
|
||||||
|
|
||||||
if(neighborhood.hasNeighbor(solution)){
|
if(neighborhood.hasNeighbor(solution)){
|
||||||
neighborhood.init(solution, current);
|
neighborhood.init(solution, *current);
|
||||||
|
|
||||||
current.eval(solution);
|
(*current).eval(solution);
|
||||||
|
|
||||||
best = current;
|
best = ¤t;
|
||||||
|
|
||||||
while (neighborhood.cont(solution)) {
|
while (neighborhood.cont(solution)) {
|
||||||
neighborhood.next(solution, current);
|
neighborhood.next(solution, *current);
|
||||||
|
|
||||||
current.eval(solution);
|
(*current).eval(solution);
|
||||||
|
|
||||||
if (current.betterThan(best)) {
|
if (current.betterThan(best)) {
|
||||||
|
|
||||||
best = current;
|
best = ¤t;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,9 +72,9 @@ private:
|
||||||
Neighborhood & neighborhood;
|
Neighborhood & neighborhood;
|
||||||
|
|
||||||
// attention il faut que le constructeur vide existe
|
// attention il faut que le constructeur vide existe
|
||||||
Neighbor best ;
|
Neighbor* best;
|
||||||
|
|
||||||
Neighbor current ;
|
Neighbor* current;
|
||||||
|
|
||||||
// true if the move is accepted
|
// true if the move is accepted
|
||||||
bool isAccept ;
|
bool isAccept ;
|
||||||
|
|
|
||||||
20
branches/newMo/src/neighborhood/moBackableNeighbor.h
Normal file
20
branches/newMo/src/neighborhood/moBackableNeighbor.h
Normal 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
|
||||||
|
|
@ -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:
|
|
||||||
|
|
@ -19,38 +19,32 @@ public:
|
||||||
typedef typename M::EOType EOT;
|
typedef typename M::EOType EOT;
|
||||||
|
|
||||||
// empty constructor
|
// empty constructor
|
||||||
moMoveNeighbor() {_move=new M();};
|
moMoveNeighbor() {
|
||||||
|
move=new M();
|
||||||
|
};
|
||||||
|
|
||||||
~moMoveNeighbor() {delete _move;};
|
~moMoveNeighbor() {
|
||||||
|
delete move;
|
||||||
|
};
|
||||||
|
|
||||||
// copy constructeur
|
// copy constructeur
|
||||||
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
|
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
|
||||||
moNeighbor<EOT, Fitness>::operator=(_n);
|
moNeighbor<EOT, Fitness>::operator=(_n);
|
||||||
(*_move) = *(_n._move);
|
(*move) = *(_n.getMove());
|
||||||
}
|
}
|
||||||
|
|
||||||
// assignment operator
|
// assignment operator
|
||||||
virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) {
|
virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) {
|
||||||
moNeighbor <EOT, Fitness>::operator=(_n);
|
moNeighbor <EOT, Fitness>::operator=(_n);
|
||||||
(*_move) = *(_n._move);
|
(*move) = *(_n.getMove());
|
||||||
|
|
||||||
std::cout << moNeighbor<EOT, Fitness>::fitness() << " , " << _n.fitness() << std::endl;
|
|
||||||
return *this ;
|
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
|
* move the solution
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & solution){
|
virtual void move(EOT & _solution){
|
||||||
(*_move)(solution);
|
(*move)(_solution);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the class id.
|
/** Return the class id.
|
||||||
|
|
@ -58,51 +52,18 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual std::string className() const { return "moMoveNeighbor"; }
|
virtual std::string className() const { return "moMoveNeighbor"; }
|
||||||
|
|
||||||
static void setIncrEval(moMoveIncrEval<M, Fitness>& increm) {
|
void setMove(M* _move){
|
||||||
_incrEval = & increm ;
|
move=_move;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
M* getMove(){
|
||||||
* Read object.\ \
|
return move;
|
||||||
* 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;
|
|
||||||
|
|
||||||
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:
|
private:
|
||||||
|
M* move;
|
||||||
static moMoveIncrEval<M, Fitness>* _incrEval;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template< class M , class Fitness >
|
|
||||||
moMoveIncrEval<M, Fitness> * moMoveNeighbor<M, Fitness>::_incrEval = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -28,23 +28,11 @@ public:
|
||||||
return *this ;
|
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
|
* move the solution
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & solution) = 0 ;
|
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.
|
/// Return fitness value.
|
||||||
const Fitness& fitness() const {
|
const Fitness& fitness() const {
|
||||||
return repFitness;
|
return repFitness;
|
||||||
|
|
@ -74,23 +62,10 @@ public:
|
||||||
* The read and print methods should be compatible and have the same format.
|
* The read and print methods should be compatible and have the same format.
|
||||||
* In principle, format is "plain": they just print a number
|
* In principle, format is "plain": they just print a number
|
||||||
* @param _is a std::istream.
|
* @param _is a std::istream.
|
||||||
* @throw runtime_std::exception If a valid object can't be read.
|
|
||||||
*/
|
*/
|
||||||
virtual void readFrom(std::istream& _is) {
|
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;
|
_is >> repFitness;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
|
|
@ -100,35 +75,10 @@ public:
|
||||||
_os << repFitness << ' ' ;
|
_os << repFitness << ' ' ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setNeighborComparator(const moNeighborComparator< moNeighbor<EOType, Fitness> > & comparator) {
|
|
||||||
neighborComparator = & comparator ;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const moNeighborComparator< moNeighbor<EOType, Fitness> > & getNeighborComparator() {
|
|
||||||
return *neighborComparator ;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// minimal information on the neighbor : fitness
|
// minimal information on the neighbor : fitness
|
||||||
Fitness repFitness ;
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Local Variables:
|
|
||||||
// coding: iso-8859-1
|
|
||||||
// mode: C++
|
|
||||||
// c-file-offsets: ((c . 0))
|
|
||||||
// c-file-style: "Stroustrup"
|
|
||||||
// fill-column: 80
|
|
||||||
// End:
|
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,4 @@ public:
|
||||||
virtual std::string className() const { return "moNeighborhood"; }
|
virtual std::string className() const { return "moNeighborhood"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Local Variables:
|
|
||||||
// coding: iso-8859-1
|
|
||||||
// mode: C++
|
|
||||||
// c-file-offsets: ((c . 0))
|
|
||||||
// c-file-style: "Stroustrup"
|
|
||||||
// fill-column: 80
|
|
||||||
// End:
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue