Début du dev de newMo

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1639 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-01-15 10:45:55 +00:00
commit e13fd250d1
34 changed files with 1946 additions and 48 deletions

View file

@ -0,0 +1,34 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "bitMove.h"
#ifndef __bitMove
#define __bitMove
#include <utility>
#include <move/moMove.h>
template <class EOT>
class BitMove : public moMove <EOT> {
public :
typedef EOT EOType;
unsigned bit;
BitMove() {
bit = 0;
}
BitMove(unsigned _bit) : bit(_bit) { }
void operator () (EOT & chrom)
{
chrom[bit] = !chrom[bit];
};
} ;
#endif

View file

@ -0,0 +1,27 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "incrEval_funcNK.h"
#ifndef __incr_eval_funcNK_h
#define __incr_eval_funcNK_h
#include <move/moMoveIncrEval.h>
#include "bitMove.h"
template <class EOT>
class OneMaxIncrEval : public moMoveIncrEval < BitMove<EOT> > {
public :
OneMaxIncrEval(){ };
typename EOT::Fitness operator () (const BitMove<EOT> & move, const EOT & chrom) {
if(chrom[move.bit]==0){
return chrom.fitness()+1;
}
else{
return chrom.fitness()-1;
}
};
};
#endif

View file

@ -0,0 +1,21 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "bitMove_init.h"
#ifndef __bitMove_init
#define __bitMove_init
#include <move/moMoveInit.h>
#include "bitMove.h"
template <class EOT>
class BitMove_init : public moMoveInit < BitMove<EOT> > {
public :
void operator () (BitMove<EOT> & __move, const EOT & genome) {
__move.bit = 0 ;
};
} ;
#endif

View file

@ -0,0 +1,33 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "bitMove_next.h"
#ifndef __bitMove_next_h
#define __bitMove_next_h
#include <move/moNextMove.h>
#include "bitMove.h"
template <class EOT>
class BitMove_next : public moNextMove < BitMove<EOT> > {
public:
BitMove_next()
{
};
bool operator () (BitMove<EOT> & __move, const EOT & genome) {
if (__move.bit >= (genome.size() - 1)){
return false ;
}
else {
__move.bit++;
return true ;
}
};
} ;
#endif

View file

@ -0,0 +1,33 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// funcOneMax.h
// 25/11/2009 : copy from FuncU.h
//-----------------------------------------------------------------------------
#ifndef __FuncOneMax
#define __FuncOneMax
template< class EOT >
class FuncOneMax : public eoEvalFunc<EOT>
{
private:
unsigned N;
public:
FuncOneMax(unsigned n) : N(n) {};
~FuncOneMax(void) {} ;
void operator() (EOT & genome) {
unsigned sum = 0;
for (int i = 0; i < N; i++)
sum += genome[i];
genome.fitness(sum);
}
};
#endif

View file

@ -0,0 +1,38 @@
#ifndef _oneMaxBitNeighbor_h
#define _oneMaxBitNeighbor_h
#include <neighborhood/moBitNeighbor.h>
#include <ga.h>
/*
contener of the neighbor information
*/
template< class Fitness >
class OneMaxBitNeighbor : public moBitNeighbor<Fitness>
{
public:
typedef eoBit<Fitness> EOType ;
using moBitNeighbor<Fitness>::bit ;
/*
* incremental evaluation of the solution for the oneMax problem
*/
virtual void eval(EOType & solution) {
if (solution[bit] == 0)
fitness(solution.fitness() + 1);
else
fitness(solution.fitness() - 1);
};
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End: