paradiseo new mo added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1712 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e2546ca8d5
commit
d7496cafff
116 changed files with 12034 additions and 0 deletions
34
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h
Normal file
34
trunk/paradiseo-mo/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
trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal file
27
trunk/paradiseo-mo/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
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h
Normal file
21
trunk/paradiseo-mo/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
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h
Normal file
33
trunk/paradiseo-mo/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
trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h
Normal file
33
trunk/paradiseo-mo/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
|
||||
40
trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h
Normal file
40
trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
#ifndef __funcRoyalRoad
|
||||
#define __funcRoyalRoad
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
|
||||
template< class EOT >
|
||||
class FuncRoyalRoad : public eoEvalFunc<EOT>
|
||||
{
|
||||
// number of blocks
|
||||
unsigned n;
|
||||
|
||||
// size of a block
|
||||
unsigned k;
|
||||
|
||||
public:
|
||||
FuncRoyalRoad(unsigned _n, unsigned _k) : n(_n), k(_k) {};
|
||||
|
||||
~FuncRoyalRoad(void) {} ;
|
||||
|
||||
virtual void operator() (EOT & _solution)
|
||||
{
|
||||
unsigned sum = 0;
|
||||
unsigned i, j;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
j = 0;
|
||||
while (_solution[i * n + j] && j < k) j++;
|
||||
|
||||
if (j == k)
|
||||
sum++;
|
||||
}
|
||||
|
||||
_solution.fitness(sum);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
38
trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal file
38
trunk/paradiseo-mo/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