Encore du nettoyage
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1814 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
3d8057ac4d
commit
02e5cfb6c0
66 changed files with 987 additions and 1785 deletions
|
|
@ -23,7 +23,7 @@ using namespace std;
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include "../oneMax/src/funcRoyalRoad.h"
|
||||
#include <eval/royalRoadEval.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||
#include <problems/bitString/moBitNeighbor.h>
|
||||
|
|
@ -120,7 +120,7 @@ void main_function(int argc, char **argv)
|
|||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncRoyalRoad<Indi> eval(vecSize / blockSize, blockSize);
|
||||
RoyalRoadEval<Indi> eval(blockSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
ADD_SUBDIRECTORY(application)
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src
|
||||
${MO_SRC_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src)
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib)
|
||||
|
||||
ADD_EXECUTABLE(testSimpleHC testSimpleHC.cpp)
|
||||
ADD_EXECUTABLE(testFirstImpr testFirstImpr.cpp)
|
||||
ADD_EXECUTABLE(testRandomWalk testRandomWalk.cpp)
|
||||
ADD_EXECUTABLE(testRandomBestHC testRandomBestHC.cpp)
|
||||
ADD_EXECUTABLE(testHCneutral testHCneutral.cpp)
|
||||
ADD_EXECUTABLE(testMetropolisHasting testMetropolisHasting.cpp)
|
||||
#ADD_EXECUTABLE(testWithMove testWithMove.cpp)
|
||||
ADD_EXECUTABLE(testSimpleTS testSimpleTS.cpp)
|
||||
ADD_EXECUTABLE(testRandomNeutralWalk testRandomNeutralWalk.cpp)
|
||||
ADD_EXECUTABLE(testILS testILS.cpp)
|
||||
ADD_EXECUTABLE(testSimulatedAnnealing testSimulatedAnnealing.cpp)
|
||||
|
||||
TARGET_LINK_LIBRARIES(testSimpleHC eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testFirstImpr eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testRandomWalk eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testRandomBestHC eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testHCneutral eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testMetropolisHasting eoutils ga eo)
|
||||
#TARGET_LINK_LIBRARIES(testWithMove eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testSimpleTS eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testRandomNeutralWalk eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testILS eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testSimulatedAnnealing eoutils ga eo)
|
||||
|
||||
|
||||
|
|
@ -1,214 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHC.cpp
|
||||
*
|
||||
* SV - 12/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include "ga.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
|
||||
//#include <eoInt.h>
|
||||
//#include <moEmptyNeighbor.h>
|
||||
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
|
||||
// local search algorithm
|
||||
#include <algo/moLocalSearch.h>
|
||||
|
||||
// the simple HC explorer
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
// explore the neighborhood of a bit string in order
|
||||
#include <neighborhood/moMoveNeighborhood.h>
|
||||
|
||||
//#include <moFullEvalBitNeighbor.h>
|
||||
|
||||
#include <neighborhood/moMoveNeighbor.h>
|
||||
|
||||
#include <bitMove.h>
|
||||
#include <bitMove_init.h>
|
||||
#include <bitMoveIncrEval.h>
|
||||
#include <bitMove_next.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<unsigned> Indi;
|
||||
//typedef OneMaxBitNeighbor<unsigned> Neighbor ; // incremental evaluation
|
||||
typedef moMoveNeighbor<BitMove<Indi>, unsigned> Neighbor ; // full evaluation
|
||||
typedef moMoveNeighborhood<BitMove<Indi>, unsigned> Neighborhood ;
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
string fileOut("out.dat");
|
||||
eoValueParam<string> fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o');
|
||||
parser.processParam( fileStatParam, "Persistence" );
|
||||
fileOut = fileStatParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "")
|
||||
{
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser; // and you can use that file as parameter file
|
||||
}
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
OneMaxIncrEval<Indi> incrEval;
|
||||
Neighbor::setIncrEval(incrEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// no need if incremental evaluation with OneMaxBitNeighbor
|
||||
// Neighbor::setFullEvalFunc(eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
BitMove_init<Indi> init;
|
||||
BitMove_next<Indi> next;
|
||||
|
||||
|
||||
Neighborhood neighborhood(init, next);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorator solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHCexplorer<Neighborhood> explorer(neighborhood);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;
|
||||
|
||||
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// -*- 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
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// -*- 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
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// -*- 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
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// -*- 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
|
||||
|
|
@ -1,328 +0,0 @@
|
|||
#ifndef __funcNK
|
||||
#define __funcNK
|
||||
|
||||
#include <eo>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
template< class EOT >
|
||||
class FuncNK : public eoEvalFunc<EOT> {
|
||||
public:
|
||||
// tables des contributions
|
||||
double ** tables;
|
||||
|
||||
// liste des liens epistatiques en fonction du bit i
|
||||
// pour chaque contribution, donne la liste des variables consernés
|
||||
unsigned ** links;
|
||||
|
||||
// liste inverse
|
||||
// pour chaque variable, donne la liste indices des contributions
|
||||
vector<unsigned> * knils;
|
||||
|
||||
unsigned N;
|
||||
unsigned K;
|
||||
|
||||
// constructeur vide
|
||||
FuncNK() : N(0), K(0)
|
||||
{
|
||||
tables = NULL;
|
||||
links = NULL;
|
||||
};
|
||||
|
||||
FuncNK(unsigned _n) : N(_n), K(0)
|
||||
{
|
||||
tables = NULL;
|
||||
links = NULL;
|
||||
};
|
||||
|
||||
// construction de tables aléatoirement
|
||||
FuncNK(int n, int k, bool consecutive = false) : N(n), K(k)
|
||||
{
|
||||
if (consecutive)
|
||||
consecutiveTables();
|
||||
else
|
||||
randomTables();
|
||||
};
|
||||
|
||||
// construction à partir d'un fichier des tables et des liens
|
||||
FuncNK(const char * fichier = "")
|
||||
{
|
||||
load(fichier);
|
||||
};
|
||||
|
||||
~FuncNK()
|
||||
{
|
||||
deleteTables();
|
||||
};
|
||||
|
||||
void buildTables()
|
||||
{
|
||||
links = new unsigned*[N];
|
||||
knils = new vector<unsigned>[N];
|
||||
tables = new double*[N];
|
||||
for(unsigned i = 0; i < N; i++) {
|
||||
tables[i] = new double[1<<(K+1)];
|
||||
links[i] = new unsigned[K+1];
|
||||
knils[i].clear();
|
||||
}
|
||||
};
|
||||
|
||||
void deleteTables()
|
||||
{
|
||||
if (links != NULL) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
delete [] (links[i]);
|
||||
}
|
||||
delete [] links;
|
||||
links = NULL;
|
||||
}
|
||||
|
||||
if (knils != NULL) {
|
||||
/*
|
||||
for(int i = 0; i < N; i++) {
|
||||
knils[i].clear();
|
||||
}
|
||||
*/
|
||||
delete [] knils;
|
||||
knils = NULL;
|
||||
}
|
||||
|
||||
if (tables != NULL) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
delete [] (tables[i]);
|
||||
}
|
||||
delete [] tables;
|
||||
tables = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
virtual void load(const char * nomTables)
|
||||
{
|
||||
fstream file;
|
||||
file.open(nomTables, ios::in);
|
||||
|
||||
if (file.is_open()) {
|
||||
//cout <<"loadTables: chargement des tables " <<nomTables <<endl;
|
||||
string s;
|
||||
|
||||
// lecture des commentaires
|
||||
string line;
|
||||
file >> s;
|
||||
while (s[0] == 'c') {
|
||||
getline(file,line,'\n');
|
||||
file >> s;
|
||||
}
|
||||
|
||||
// lecture des parametres
|
||||
if (s[0] != 'p') {
|
||||
cerr <<"loadTables: erreur de lecture de paramètre pour " << nomTables <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file >> s;
|
||||
if (s != "NK") {
|
||||
cerr <<"erreur " <<nomTables << " n'est pas un fichier NK" <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// lecture des paramètres N et K
|
||||
file >> N >> K;
|
||||
buildTables();
|
||||
|
||||
// lecture des liens
|
||||
if (s[0] != 'p') {
|
||||
cerr <<"loadTables: erreur de lecture de paramètre 'links' pour " << nomTables <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file >> s;
|
||||
if (s == "links") {
|
||||
loadLinks(file);
|
||||
} else {
|
||||
cerr <<"loadTables: erreur de lecture de paramètre 'links' pour " << nomTables <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// lecture des tables
|
||||
if (s[0] != 'p') {
|
||||
cerr <<"loadTables: erreur de lecture de paramètre 'tables' pour " << nomTables <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file >> s;
|
||||
|
||||
if (s == "tables") {
|
||||
loadTables(file);
|
||||
} else {
|
||||
cerr << "loadTables: erreur de lecture de paramètre 'tables' pour " << nomTables <<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file.close();
|
||||
} else {
|
||||
cerr << "loadTables: impossible d'ouvrir " << nomTables << endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void loadLinks(fstream & file) {
|
||||
for(int j = 0; j < K+1; j++)
|
||||
for(int i = 0; i < N; i++) {
|
||||
file >> links[i][j];
|
||||
knils[links[i][j]].push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
void loadTables(fstream & file) {
|
||||
for(int j = 0; j < (1<<(K+1)); j++)
|
||||
for(int i = 0; i < N; i++)
|
||||
file >> tables[i][j];
|
||||
}
|
||||
|
||||
virtual void save(const char * nomTables)
|
||||
{
|
||||
// cout <<"saveTables: sauvegarde de la table " <<nomTables <<endl;
|
||||
fstream file;
|
||||
file.open(nomTables, ios::out);
|
||||
|
||||
if (file.is_open()) {
|
||||
file << "c name of file : " << nomTables << endl;
|
||||
file << "p NK " << N << " " << K <<endl;
|
||||
|
||||
file << "p links" << endl;
|
||||
for(int j=0; j<K+1; j++)
|
||||
for(int i=0; i<N; i++)
|
||||
file << links[i][j] << endl;
|
||||
|
||||
file << "p tables" << endl;
|
||||
for(int j=0; j<(1<<(K+1)); j++) {
|
||||
for(int i=0; i<N; i++)
|
||||
file << tables[i][j] << " ";
|
||||
file << endl;
|
||||
}
|
||||
file.close();
|
||||
} else {
|
||||
cerr <<"saveTables: impossible d'ouvrir " <<nomTables <<endl;
|
||||
}
|
||||
};
|
||||
|
||||
void affiche()
|
||||
{
|
||||
int j;
|
||||
for(int i=0; i<N; i++) {
|
||||
cout <<"link " <<i <<" : ";
|
||||
for(j = 0; j <= K; j++)
|
||||
cout <<links[i][j] <<" ";
|
||||
cout <<endl;
|
||||
}
|
||||
cout <<endl;
|
||||
|
||||
for(int i=0; i<N; i++) {
|
||||
cout <<"knils " <<i <<" : ";
|
||||
for(j=0; j<knils[i].size(); j++)
|
||||
cout <<knils[i][j] <<" ";
|
||||
cout <<endl;
|
||||
}
|
||||
cout <<endl;
|
||||
|
||||
for(int i=0; i<N; i++) {
|
||||
cout <<"table " <<i <<endl;
|
||||
for(j=0; j<(1<<(K+1)); j++)
|
||||
cout << tables[i][j] <<endl;
|
||||
}
|
||||
};
|
||||
|
||||
// calcul de la fitness
|
||||
virtual void operator() (EOT & genome)
|
||||
{
|
||||
double accu = 0.0;
|
||||
|
||||
for(int i = 0; i < N; i++)
|
||||
accu += tables[i][sigma(genome,i)];
|
||||
// double M = 0.05;
|
||||
// genome.fitness( M * ((unsigned) (accu / (N*M))) ); // affecte la fitness du genome
|
||||
genome.fitness( accu / (double) N ); // affecte la fitness du genome
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
void initTirage(int tabTirage[]) {
|
||||
for(int i = 0; i<N; i++)
|
||||
tabTirage[i] = i;
|
||||
};
|
||||
|
||||
void perm(int tabTirage[],int i, int j) {
|
||||
int k = tabTirage[i];
|
||||
tabTirage[i] = tabTirage[j];
|
||||
tabTirage[j] = k;
|
||||
};
|
||||
|
||||
void tire(int i,int tabTirage[]) {
|
||||
int t[K+1];
|
||||
for(int j=0; j<K+1; j++) {
|
||||
if (j==0) t[j]=i;
|
||||
else t[j] = rng.random(N-j);
|
||||
links[i][j] = tabTirage[t[j]];
|
||||
knils[tabTirage[t[j]]].push_back(i);
|
||||
perm(tabTirage, t[j], N-1-j);
|
||||
}
|
||||
for(int j=K; j>=0; j--)
|
||||
perm(tabTirage, t[j], N-1-j);
|
||||
};
|
||||
|
||||
void consecutiveLinks(int i) {
|
||||
for(int j=0; j<K+1; j++) {
|
||||
links[i][j] = (i + j) % N;
|
||||
knils[(i + j) % N].push_back(i);
|
||||
}
|
||||
};
|
||||
|
||||
// tables et liens aléatoires
|
||||
virtual void randomTables() {
|
||||
buildTables();
|
||||
|
||||
int tabTirage[N];
|
||||
initTirage(tabTirage);
|
||||
|
||||
for(int i = 0; i < N; i++) {
|
||||
// construit les loci epistatiquement liés au locus i
|
||||
tire(i, tabTirage);
|
||||
|
||||
// la table Fi
|
||||
for(int j = 0; j < (1<<(K+1)); j++)
|
||||
tables[i][j] = rng.uniform();
|
||||
}
|
||||
};
|
||||
|
||||
// tables et liens aléatoires
|
||||
virtual void consecutiveTables() {
|
||||
buildTables();
|
||||
|
||||
for(int i = 0; i < N; i++) {
|
||||
// construit les loci epistatiquement liés au locus i
|
||||
consecutiveLinks(i);
|
||||
|
||||
// la table Fi
|
||||
for(int j = 0; j < (1<<(K+1)); j++)
|
||||
tables[i][j] = rng.uniform();
|
||||
}
|
||||
};
|
||||
|
||||
// extrait les bits liés au bit n°i
|
||||
unsigned int sigma(EOT & genome, int i)
|
||||
{
|
||||
unsigned int n = 1;
|
||||
unsigned int accu = 0;
|
||||
for(int j=0; j<K+1; j++) {
|
||||
if (genome[links[i][j]] == 1)
|
||||
accu = accu | n;
|
||||
n = n<<1;
|
||||
}
|
||||
return accu;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// -*- 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 int N;
|
||||
|
||||
public:
|
||||
FuncOneMax(unsigned int n) : N(n) {};
|
||||
|
||||
~FuncOneMax(void) {} ;
|
||||
|
||||
void operator() (EOT & genome) {
|
||||
unsigned int sum = 0;
|
||||
|
||||
for (unsigned int i = 0; i < N; i++)
|
||||
sum += genome[i];
|
||||
|
||||
genome.fitness(sum);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
// -*- 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
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef _oneMaxBitNeighbor_h
|
||||
#define _oneMaxBitNeighbor_h
|
||||
|
||||
#include <problems/bitString/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