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:
parent
25c45dd1fa
commit
e13fd250d1
34 changed files with 1946 additions and 48 deletions
34
branches/newMo/tutorial/oneMax/src/bitMove.h
Normal file
34
branches/newMo/tutorial/oneMax/src/bitMove.h
Normal 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
|
||||
27
branches/newMo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal file
27
branches/newMo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal 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
|
||||
21
branches/newMo/tutorial/oneMax/src/bitMove_init.h
Normal file
21
branches/newMo/tutorial/oneMax/src/bitMove_init.h
Normal 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
|
||||
33
branches/newMo/tutorial/oneMax/src/bitMove_next.h
Normal file
33
branches/newMo/tutorial/oneMax/src/bitMove_next.h
Normal 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
|
||||
33
branches/newMo/tutorial/oneMax/src/funcOneMax.h
Normal file
33
branches/newMo/tutorial/oneMax/src/funcOneMax.h
Normal 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
|
||||
38
branches/newMo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal file
38
branches/newMo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal 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:
|
||||
Loading…
Add table
Add a link
Reference in a new issue