add new dummy neighbor : XCHangeNeighborDummy

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2304 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
boufaras 2011-07-08 12:42:47 +00:00
commit 6c5a1b4e81

View file

@ -30,7 +30,7 @@
ParadisEO WebSite : http://paradiseo.gforge.inria.fr ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr Contact: paradiseo-help@lists.gforge.inria.fr
*/ */
#ifndef _moTestClass_h #ifndef _moTestClass_h
#define _moTestClass_h #define _moTestClass_h
@ -53,54 +53,91 @@
#include <utils/eoUpdater.h> #include <utils/eoUpdater.h>
#include <eoInit.h> #include <eoInit.h>
#include <neighborhood/moXChangeNeighbor.h>
typedef eoBit<eoMinimizingFitness> bitVector; typedef eoBit<eoMinimizingFitness> bitVector;
typedef moBitNeighbor<eoMinimizingFitness> bitNeighbor; typedef moBitNeighbor<eoMinimizingFitness> bitNeighbor;
class moDummyRndNeighborhood: public moOrderNeighborhood<bitNeighbor>, public moRndNeighborhood<bitNeighbor> { class moDummyRndNeighborhood: public moOrderNeighborhood<bitNeighbor> ,
public moRndNeighborhood<bitNeighbor> {
public: public:
moDummyRndNeighborhood(unsigned int a): moOrderNeighborhood<bitNeighbor>(a) {} moDummyRndNeighborhood(unsigned int a) :
moOrderNeighborhood<bitNeighbor> (a) {
}
}; };
typedef moDummyRndNeighborhood bitNeighborhood ; typedef moDummyRndNeighborhood bitNeighborhood;
typedef EO<int> Solution; typedef EO<int> Solution;
class moDummyNeighborTest : public moNeighbor<Solution> { class moDummyNeighborTest: public moNeighbor<Solution> {
public: public:
virtual void move(Solution & _solution) {} virtual void move(Solution & _solution) {
}
}; };
class moDummyBackableNeighbor : public moBackableNeighbor<Solution> { class moDummyBackableNeighbor: public moBackableNeighbor<Solution> {
public: public:
virtual void move(Solution & _solution) {} virtual void move(Solution & _solution) {
virtual void moveBack(Solution & _solution) {} }
virtual void moveBack(Solution & _solution) {
}
}; };
class moDummyNeighborhoodTest : public moNeighborhood<moDummyNeighborTest> { template < class EOT>
class XChangeNeighborDummy: public moXChangeNeighbor<EOT> {
public:
XChangeNeighborDummy() :
moXChangeNeighbor<EOT> () {
}
/**
* Constructor
* @param _xChange the number of x-change to do
*/
XChangeNeighborDummy(unsigned int _xChange) :
moXChangeNeighbor<EOT> (_xChange) {
}
/**
* Move a solution
* @param _solution the related solution
*/
void move(EOT & _solution) {
}
};
class moDummyNeighborhoodTest: public moNeighborhood<moDummyNeighborTest> {
public: public:
typedef moDummyNeighborTest Neighbor; typedef moDummyNeighborTest Neighbor;
moDummyNeighborhoodTest():i(0),j(0) {} moDummyNeighborhoodTest() :
i(0), j(0) {
}
virtual bool hasNeighbor(EOT & _solution) { virtual bool hasNeighbor(EOT & _solution) {
bool res; bool res;
if (i%3==0 || i==1) if (i % 3 == 0 || i == 1)
res=false; res = false;
else else
res=true; res = true;
i++; i++;
return res; return res;
} }
virtual void init(EOT & _solution, Neighbor & _current) {} virtual void init(EOT & _solution, Neighbor & _current) {
virtual void next(EOT & _solution, Neighbor & _current) {} }
virtual void next(EOT & _solution, Neighbor & _current) {
}
virtual bool cont(EOT & _solution) { virtual bool cont(EOT & _solution) {
j++; j++;
return (j%10!=0); return (j % 10 != 0);
} }
private: private:
int i,j; int i, j;
}; };
class moDummyEvalTest: public eoEvalFunc<Solution> { class moDummyEvalTest: public eoEvalFunc<Solution> {
@ -109,21 +146,25 @@ public:
if (_sol.invalid()) if (_sol.invalid())
_sol.fitness(100); _sol.fitness(100);
else else
_sol.fitness(_sol.fitness()+50); _sol.fitness(_sol.fitness() + 50);
} }
}; };
class evalOneMax : public moEval< bitNeighbor > class evalOneMax: public moEval<bitNeighbor> {
{
private: private:
unsigned size; unsigned size;
public: public:
evalOneMax(unsigned _size) : size(_size) {}; evalOneMax(unsigned _size) :
size(_size) {
}
;
~evalOneMax(void) {} ; ~evalOneMax(void) {
}
;
void operator() (bitVector& _sol, bitNeighbor& _n) { void operator()(bitVector& _sol, bitNeighbor& _n) {
unsigned int fit = _sol.fitness(); unsigned int fit = _sol.fitness();
if (_sol[_n.index()]) if (_sol[_n.index()])
fit--; fit--;
@ -133,27 +174,32 @@ public:
} }
}; };
class dummyEvalOneMax : public moEval< bitNeighbor > class dummyEvalOneMax: public moEval<bitNeighbor> {
{
private: private:
unsigned size; unsigned size;
public: public:
dummyEvalOneMax(unsigned _size) : size(_size) {}; dummyEvalOneMax(unsigned _size) :
size(_size) {
}
;
~dummyEvalOneMax(void) {} ; ~dummyEvalOneMax(void) {
}
;
void operator() (bitVector& _sol, bitNeighbor& _n) { void operator()(bitVector& _sol, bitNeighbor& _n) {
unsigned int fit = _sol.fitness(); unsigned int fit = _sol.fitness();
_n.fitness(fit); _n.fitness(fit);
} }
}; };
class monitor1 : public eoMonitor class monitor1: public eoMonitor {
{
public: public:
monitor1(unsigned int& _a): a(_a) {} monitor1(unsigned int& _a) :
a(_a) {
}
eoMonitor& operator()() { eoMonitor& operator()() {
a++; a++;
@ -168,11 +214,12 @@ private:
unsigned int& a; unsigned int& a;
}; };
class monitor2 : public eoMonitor class monitor2: public eoMonitor {
{
public: public:
monitor2(unsigned int& _a): a(_a) {} monitor2(unsigned int& _a) :
a(_a) {
}
eoMonitor& operator()() { eoMonitor& operator()() {
a++; a++;
@ -187,10 +234,11 @@ private:
unsigned int& a; unsigned int& a;
}; };
class updater1: public eoUpdater class updater1: public eoUpdater {
{
public: public:
updater1(unsigned int& _a): a(_a) {} updater1(unsigned int& _a) :
a(_a) {
}
void operator()() { void operator()() {
a++; a++;
@ -204,20 +252,22 @@ private:
unsigned int& a; unsigned int& a;
}; };
class dummyInit: public eoInit<bitVector>{ class dummyInit: public eoInit<bitVector> {
public: public:
void operator()(bitVector& sol){ void operator()(bitVector& sol) {
} }
}; };
class dummyInit2: public eoInit<bitVector>{ class dummyInit2: public eoInit<bitVector> {
public: public:
dummyInit2(unsigned int _size):size(_size){} dummyInit2(unsigned int _size) :
size(_size) {
}
void operator()(bitVector& sol){ void operator()(bitVector& sol) {
sol.resize(0); sol.resize(0);
for(unsigned int i=0; i< size; i++) for (unsigned int i = 0; i < size; i++)
sol.push_back(true); sol.push_back(true);
} }