Brand new documentation for ParadisEO-PEO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1475 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
8f499ab64e
commit
a28c5452ef
142 changed files with 8144 additions and 5695 deletions
|
|
@ -56,8 +56,7 @@ LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib)
|
|||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(ea5 main.cpp)
|
||||
ADD_DEPENDENCIES(ea5 peo rmc_mpi)
|
||||
ADD_EXECUTABLE(island main.cpp)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
@ -67,7 +66,7 @@ ADD_DEPENDENCIES(ea5 peo rmc_mpi)
|
|||
######################################################################################
|
||||
|
||||
SET(Lesson5_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(ea5 PROPERTIES VERSION "${Lesson5_VERSION}")
|
||||
SET_TARGET_PROPERTIES(island PROPERTIES VERSION "${Lesson5_VERSION}")
|
||||
######################################################################################
|
||||
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ SET_TARGET_PROPERTIES(ea5 PROPERTIES VERSION "${Lesson5_VERSION}")
|
|||
### 5) Link the librairies
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(ea5 ${XML2_LIBS} peo rmc_mpi eo eoutils peo)
|
||||
TARGET_LINK_LIBRARIES(island eo ga es ${XML2_LIBS} peo rmc_mpi eoutils peo)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
|
|
|||
118
trunk/paradiseo-peo/tutorial/Lesson5/QAP.h
Executable file
118
trunk/paradiseo-peo/tutorial/Lesson5/QAP.h
Executable file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
<QAP.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QAP_H
|
||||
#define QAP_H
|
||||
|
||||
#include <eo>
|
||||
|
||||
/* global variables */
|
||||
extern int n; // size
|
||||
extern int** a; // matrix A
|
||||
extern int** b; // matrix B
|
||||
|
||||
class Problem : public EO<eoMinimizingFitness> {
|
||||
|
||||
public:
|
||||
|
||||
int* solution;
|
||||
|
||||
Problem () {
|
||||
solution = new int[n];
|
||||
create();
|
||||
}
|
||||
|
||||
Problem (const Problem & _problem){ // copy constructor
|
||||
solution = new int[n];
|
||||
for (int i = 0; i < n ; i++){
|
||||
solution[i] = _problem.solution[i];
|
||||
}
|
||||
if (!_problem.invalid()) // if the solution has already been evaluated
|
||||
fitness(_problem.fitness()); // copy the fitness
|
||||
}
|
||||
|
||||
~Problem(){ // destructor
|
||||
delete[] solution;
|
||||
}
|
||||
|
||||
void operator= (const Problem & _problem){ // copy assignment operator
|
||||
for (int i = 0; i < n ; i++){
|
||||
solution[i] = _problem.solution[i];
|
||||
}
|
||||
fitness(_problem.fitness()); // copy the fitness
|
||||
}
|
||||
|
||||
int& operator[] (unsigned i)
|
||||
{
|
||||
return solution[i];
|
||||
}
|
||||
|
||||
|
||||
void create(){ // create and initialize a solution
|
||||
int random, temp;
|
||||
for (int i=0; i< n; i++)
|
||||
solution[i]=i;
|
||||
|
||||
// we want a random permutation so we shuffle
|
||||
for (int i = 0; i < n; i++){
|
||||
random = rand()%(n-i) + i;
|
||||
temp = solution[i];
|
||||
solution[i] = solution[random];
|
||||
solution[random] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
int evaluate() { // evaluate the solution
|
||||
int cost=0;
|
||||
for (int i=0; i<n; i++)
|
||||
for (int j=0; j<n; j++)
|
||||
cost += a[i][j] * b[solution[i]][solution[j]];
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
|
||||
void printSolution() {
|
||||
for (int i = 0; i < n ; i++)
|
||||
std::cout << solution[i] << " " ;
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
148
trunk/paradiseo-peo/tutorial/Lesson5/QAPGA.h
Normal file
148
trunk/paradiseo-peo/tutorial/Lesson5/QAPGA.h
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
<QAPGA.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _QAPGA_h
|
||||
#define _QAPGA_h
|
||||
|
||||
class ProblemInit : public eoInit<Problem>
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(Problem & _problem)
|
||||
{
|
||||
_problem.create();
|
||||
}
|
||||
};
|
||||
|
||||
class ProblemEvalFunc : public eoEvalFunc<Problem>
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(Problem & _problem)
|
||||
{
|
||||
_problem.fitness(_problem.evaluate());
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class ProblemXover : public eoQuadOp<Problem> {
|
||||
public:
|
||||
|
||||
/* The two parameters in input are the parents.
|
||||
The first parameter is also the output ie the child
|
||||
*/
|
||||
bool operator()(Problem & _problem1, Problem & _problem2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ProblemSwapMutation: public eoMonOp<Problem> {
|
||||
public:
|
||||
|
||||
bool operator()(Problem& _problem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
class ProblemXover : public eoQuadOp<Problem> {
|
||||
public:
|
||||
|
||||
// The two parameters in input are the parents.
|
||||
// The first parameter is also the output ie the child
|
||||
|
||||
bool operator()(Problem & _problem1, Problem & _problem2)
|
||||
{
|
||||
int i;
|
||||
int random, temp;
|
||||
int unassigned_positions[n];
|
||||
int remaining_items[n];
|
||||
int j = 0;
|
||||
|
||||
// 1) find the items assigned in different positions for the 2 parents
|
||||
for (i = 0 ; i < n ; i++){
|
||||
if (_problem1.solution[i] != _problem2.solution[i]){
|
||||
unassigned_positions[j] = i;
|
||||
remaining_items[j] = _problem1.solution[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
// 2) shuffle the remaining items to ensure that remaining items
|
||||
will be assigned at random positions
|
||||
for (i = 0; i < j; i++){
|
||||
random = rand()%(j-i) + i;
|
||||
temp = remaining_items[i];
|
||||
remaining_items[i] = remaining_items[random];
|
||||
remaining_items[random] = temp;
|
||||
}
|
||||
|
||||
// 3) copy the shuffled remaining items at unassigned positions
|
||||
for (i = 0; i < j ; i++)
|
||||
_problem1.solution[unassigned_positions[i]] = remaining_items[i];
|
||||
|
||||
// crossover in our case is always possible
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ProblemSwapMutation: public eoMonOp<Problem> {
|
||||
public:
|
||||
|
||||
bool operator()(Problem& _problem) {
|
||||
int i,j;
|
||||
int temp;
|
||||
|
||||
// generate two different indices
|
||||
i=rand()%n;
|
||||
do
|
||||
j = rand()%n;
|
||||
while (i == j);
|
||||
|
||||
// swap
|
||||
temp = _problem.solution[i];
|
||||
_problem.solution[i] = _problem.solution[j];
|
||||
_problem.solution[j] = temp;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
#endif
|
||||
524
trunk/paradiseo-peo/tutorial/Lesson5/main.cpp
Normal file → Executable file
524
trunk/paradiseo-peo/tutorial/Lesson5/main.cpp
Normal file → Executable file
|
|
@ -1,313 +1,255 @@
|
|||
/*
|
||||
* <main.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
* (C) OPAC Team, INRIA, 2008
|
||||
*
|
||||
* Clive Canape
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*
|
||||
* ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
* Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*
|
||||
<main.cpp>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
/**
|
||||
* Declaration of the necessary headers: In these are defined the class Problem,
|
||||
* redefinition of the crossover, mutation, initialisation of solution.
|
||||
*
|
||||
*/
|
||||
#include <peo>
|
||||
#include "QAP.h"
|
||||
#include "QAPGA.h"
|
||||
#include "qapPackUnpack.h"
|
||||
#include <string>
|
||||
using namespace std;
|
||||
//typedef Problem Problem;
|
||||
/** Set of parameters wrapped into a structure. We pass then the structure
|
||||
* to a function which parses the parameters file. Doing so helps cleaning
|
||||
* the code from the parts of reading the inputs.
|
||||
*/
|
||||
#include "parserStruct.h"
|
||||
#include "utils.h"
|
||||
/** The actual reading and parameters parsing is done inside this class utilities
|
||||
*/
|
||||
|
||||
#define SIZE 10
|
||||
#define DEF_DOMAIN 100
|
||||
#define POP_SIZE 100
|
||||
#define SELECT_RATE 0.8
|
||||
#define NB_GEN 1
|
||||
#define XOVER_P 0.75
|
||||
#define MUT_P 0.05
|
||||
#define MIGRATIONS_AT_N_GENERATIONS 5
|
||||
#define NUMBER_OF_MIGRANTS 10
|
||||
// Global variables
|
||||
int n; // Problem size
|
||||
int** a;
|
||||
int** b; // a and matrices
|
||||
|
||||
struct Representation : public eoVector< eoMinimizingFitness, double >
|
||||
{
|
||||
int bkv; //best known value
|
||||
|
||||
Representation()
|
||||
{
|
||||
resize( SIZE );
|
||||
}
|
||||
};
|
||||
|
||||
struct Init : public eoInit< Representation >
|
||||
{
|
||||
|
||||
void operator()( Representation& rep )
|
||||
{
|
||||
|
||||
for ( int i = 0; i < SIZE; i++ )
|
||||
{
|
||||
rep[ i ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct Eval : public eoEvalFunc< Representation >
|
||||
{
|
||||
|
||||
void operator()( Representation& rep )
|
||||
{
|
||||
|
||||
double fitnessValue = 0.0;
|
||||
for ( int i = 0; i < SIZE; i++ )
|
||||
{
|
||||
|
||||
fitnessValue += pow( rep[ i ], 2.0 );
|
||||
}
|
||||
|
||||
rep.fitness( fitnessValue );
|
||||
}
|
||||
};
|
||||
|
||||
struct MutationOp : public eoMonOp< Representation >
|
||||
{
|
||||
|
||||
bool operator()( Representation& rep )
|
||||
{
|
||||
|
||||
unsigned int pos = (unsigned int)( rng.uniform() * SIZE );
|
||||
rep[ pos ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
||||
|
||||
rep.invalidate();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct XoverOp : public eoQuadOp< Representation >
|
||||
{
|
||||
|
||||
bool operator()( Representation& repA, Representation& repB )
|
||||
{
|
||||
|
||||
static Representation offA, offB;
|
||||
double lambda = rng.uniform();
|
||||
|
||||
for ( int i = 0; i < SIZE; i++ )
|
||||
{
|
||||
|
||||
offA[ i ] = lambda * repA[ i ] + ( 1.0 - lambda ) * repB[ i ];
|
||||
offB[ i ] = lambda * repB[ i ] + ( 1.0 - lambda ) * repA[ i ];
|
||||
}
|
||||
|
||||
repA = offA;
|
||||
repB = offB;
|
||||
|
||||
repA.invalidate();
|
||||
repB.invalidate();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void pack( const Representation& rep )
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
// Declaration of useful variables to parse the parameters file and then
|
||||
// its elements into a structure
|
||||
if (argc < 2){
|
||||
cout << "Please give a param file" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
eoParser parser(argc, argv);
|
||||
parameters param;
|
||||
parseFile(parser, param);
|
||||
rng.reseed(param.seed);
|
||||
|
||||
|
||||
string s (argv[1]);
|
||||
|
||||
if ( rep.invalid() ) ::pack( (unsigned int)0 );
|
||||
if ( (s.compare("-h") == 0) || (s.compare("--help") == 0 ) )
|
||||
;//make help
|
||||
|
||||
// Reading the a and b matrices of the Problem Problem
|
||||
else
|
||||
{
|
||||
::pack( (unsigned int)1 );
|
||||
::pack( (double)(rep.fitness()) );
|
||||
}
|
||||
loadInstances(param.inst.c_str(), n, bkv, a, b);
|
||||
|
||||
// Declaration of class wrapping the evaluation function of the Problem
|
||||
ProblemEvalFunc plainEval;
|
||||
eoEvalFuncCounter<Problem> eval(plainEval);
|
||||
|
||||
// Class involving a simple call to the function of initialisation of a solution
|
||||
ProblemInit chromInit;
|
||||
|
||||
|
||||
eoPop<Problem> pop_1(param.popSize, chromInit); // Initialise the population
|
||||
eoPop<Problem> pop_2(param.popSize, chromInit); // Initialise the population
|
||||
eoPop<Problem> pop_3(param.popSize, chromInit); // Initialise the population
|
||||
|
||||
// The robust tournament selection
|
||||
eoDetTournamentSelect<Problem> selectOne(param.tSize);
|
||||
|
||||
// is now encapsulated in a eoSelectPerc (entage)
|
||||
eoSelectPerc<Problem> select(selectOne);// by default rate==1
|
||||
|
||||
ProblemXover Xover; // CROSSOVER
|
||||
ProblemSwapMutation mutationSwap; // MUTATION
|
||||
|
||||
// The operators are encapsulated into an eoTRansform object
|
||||
eoSGATransform<Problem> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
|
||||
// REPLACE
|
||||
eoPlusReplacement<Problem> replace;
|
||||
|
||||
eoGenContinue<Problem> genCont(param.maxGen); // generation continuation
|
||||
|
||||
eoCheckPoint< Problem > checkpoint_1( genCont );
|
||||
eoCheckPoint< Problem > checkpoint_2( genCont );
|
||||
eoCheckPoint< Problem > checkpoint_3( genCont );
|
||||
|
||||
eoEasyEA<Problem> gga_1(checkpoint_1, plainEval, select, transform, replace);
|
||||
eoEasyEA<Problem> gga_2(checkpoint_2, plainEval, select, transform, replace);
|
||||
eoEasyEA<Problem> gga_3(checkpoint_3, plainEval, select, transform, replace);
|
||||
|
||||
peo :: init (argc, argv);
|
||||
initDebugging();
|
||||
setDebugMode(true);
|
||||
|
||||
// Start the parallel EA
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
apply<Problem>(eval, pop_1);
|
||||
pop_1.sort();
|
||||
cout << "Initial Population 1\n" << pop_1 << endl;
|
||||
}
|
||||
|
||||
if (getNodeRank()==2)
|
||||
{
|
||||
apply<Problem>(eval, pop_2);
|
||||
pop_2.sort();
|
||||
cout << "Initial Population 2\n" << pop_2 << endl;
|
||||
}
|
||||
|
||||
if (getNodeRank()==3)
|
||||
{
|
||||
apply<Problem>(eval, pop_3);
|
||||
pop_3.sort();
|
||||
cout << "Initial Population 3\n" << pop_3 << endl;
|
||||
}
|
||||
|
||||
//Topolgy
|
||||
RingTopology ring,topology;
|
||||
|
||||
eoPeriodicContinue< Problem > mig_conti_1( param.manGeneration );
|
||||
eoContinuator<Problem> mig_cont_1(mig_conti_1,pop_1);
|
||||
eoRandomSelect<Problem> mig_select_one_1;
|
||||
eoSelector <Problem, eoPop<Problem> > mig_select_1 (mig_select_one_1,param.nbMigrants,pop_1);
|
||||
eoPlusReplacement<Problem> replace_one_1;
|
||||
eoReplace <Problem, eoPop<Problem> > mig_replace_1 (replace_one_1,pop_1);
|
||||
peoAsyncIslandMig< eoPop< Problem >, eoPop< Problem > > mig_1 (mig_cont_1,mig_select_1,mig_replace_1,topology);
|
||||
checkpoint_1.add( mig_1 );
|
||||
|
||||
eoPeriodicContinue< Problem > mig_conti_2( param.manGeneration );
|
||||
eoContinuator<Problem> mig_cont_2(mig_conti_2,pop_2);
|
||||
eoRandomSelect<Problem> mig_select_one_2;
|
||||
eoSelector <Problem, eoPop<Problem> > mig_select_2 (mig_select_one_2,param.nbMigrants,pop_2);
|
||||
eoPlusReplacement<Problem> replace_one_2;
|
||||
eoReplace <Problem, eoPop<Problem> > mig_replace_2 (replace_one_2,pop_2);
|
||||
peoAsyncIslandMig< eoPop< Problem >, eoPop< Problem > > mig_2 (mig_cont_2,mig_select_2,mig_replace_2,topology);
|
||||
checkpoint_2.add( mig_2 );
|
||||
|
||||
eoPeriodicContinue< Problem > mig_conti_3( param.manGeneration );
|
||||
eoContinuator<Problem> mig_cont_3(mig_conti_3,pop_3);
|
||||
eoRandomSelect<Problem> mig_select_one_3;
|
||||
eoSelector <Problem, eoPop<Problem> > mig_select_3 (mig_select_one_3,param.nbMigrants,pop_3);
|
||||
eoPlusReplacement<Problem> replace_one_3;
|
||||
eoReplace <Problem, eoPop<Problem> > mig_replace_3 (replace_one_3,pop_3);
|
||||
peoAsyncIslandMig< eoPop< Problem >, eoPop< Problem > > mig_3 (mig_cont_3,mig_select_3,mig_replace_3,topology);
|
||||
checkpoint_3.add( mig_3 );
|
||||
|
||||
peoWrapper parallelEA_1( gga_1, pop_1 );
|
||||
mig_1.setOwner( parallelEA_1 );
|
||||
|
||||
peoWrapper parallelEA_2( gga_2, pop_2 );
|
||||
mig_2.setOwner( parallelEA_2 );
|
||||
|
||||
peoWrapper parallelEA_3( gga_3, pop_3 );
|
||||
mig_3.setOwner( parallelEA_3 );
|
||||
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
endDebugging();
|
||||
// Print (sorted) intial population
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop_1.sort();
|
||||
cout << "FINAL Population 1\n" << pop_1 << endl;
|
||||
cout << "Best solution found\t" << pop_1[0].fitness() << endl;
|
||||
}
|
||||
|
||||
if (getNodeRank()==2)
|
||||
{
|
||||
pop_2.sort();
|
||||
cout << "FINAL Population 2\n" << pop_2 << endl;
|
||||
cout << "Best solution found\t" << pop_2[0].fitness() << endl;
|
||||
}
|
||||
|
||||
if (getNodeRank()==3)
|
||||
{
|
||||
pop_3.sort();
|
||||
cout << "FINAL Population 3\n" << pop_3 << endl;
|
||||
cout << "Best solution found\t" << pop_3[0].fitness() << endl;
|
||||
}
|
||||
|
||||
if (getNodeRank()==0)
|
||||
{
|
||||
cout << "\nInstance size = " << n << endl;
|
||||
cout << "Best known value in the litterature = " << bkv <<"\n"<< endl;
|
||||
}
|
||||
// GENERAL
|
||||
|
||||
|
||||
for ( unsigned int index = 0; index < SIZE; index++ )
|
||||
{
|
||||
::pack( (double)rep[ index ] );
|
||||
}
|
||||
}
|
||||
|
||||
void unpack( Representation& rep )
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
eoScalarFitness<double, std::greater<double> > fitness;
|
||||
unsigned int validFitness;
|
||||
|
||||
unpack( validFitness );
|
||||
if ( validFitness )
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
|
||||
double fitnessValue;
|
||||
::unpack( fitnessValue );
|
||||
rep.fitness( fitnessValue );
|
||||
}
|
||||
else
|
||||
catch(exception& e)
|
||||
{
|
||||
rep.invalidate();
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
double value;
|
||||
for ( unsigned int index = 0; index < SIZE; index++ )
|
||||
{
|
||||
::unpack( value );
|
||||
rep[ index ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int main( int __argc, char** __argv )
|
||||
{
|
||||
|
||||
|
||||
rng.reseed( time( NULL ) );
|
||||
srand( time( NULL ) );
|
||||
|
||||
peo::init( __argc, __argv );
|
||||
|
||||
|
||||
eoParser parser ( __argc, __argv );
|
||||
|
||||
eoValueParam < unsigned int > nbGenerations( NB_GEN, "maxGen");
|
||||
parser.processParam ( nbGenerations );
|
||||
|
||||
eoValueParam < double > selectionRate( SELECT_RATE, "select");
|
||||
parser.processParam ( selectionRate );
|
||||
|
||||
|
||||
RingTopology ring,topo;
|
||||
unsigned int dataA, dataB, dataC;
|
||||
|
||||
dataA = 1;
|
||||
dataB = 5;
|
||||
dataC = 10;
|
||||
|
||||
peoSyncDataTransfer dataTransfer( dataA, ring );
|
||||
peoSyncDataTransfer dataTransferb( dataB, ring );
|
||||
peoSyncDataTransfer dataTransferc( dataC, ring );
|
||||
|
||||
|
||||
Init init;
|
||||
Eval eval;
|
||||
eoPop< Representation > pop( POP_SIZE, init );
|
||||
MutationOp mut;
|
||||
XoverOp xover;
|
||||
eoSGATransform< Representation > transform( xover, XOVER_P, mut, MUT_P );
|
||||
eoStochTournamentSelect< Representation > select;
|
||||
eoSelectMany< Representation > selectN( select, selectionRate.value() );
|
||||
eoSSGAStochTournamentReplacement< Representation > replace( 1.0 );
|
||||
eoWeakElitistReplacement< Representation > elitReplace( replace );
|
||||
eoGenContinue< Representation > cont( nbGenerations.value() );
|
||||
eoCheckPoint< Representation > checkpoint( cont );
|
||||
eoEasyEA< Representation > algo( checkpoint, eval, selectN, transform, elitReplace );
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
// MIGRATION CONTEXT DEFINITION
|
||||
|
||||
eoPeriodicContinue< Representation > mig_conti( MIGRATIONS_AT_N_GENERATIONS );
|
||||
eoContinuator<Representation> mig_cont(mig_conti,pop);
|
||||
eoRandomSelect<Representation> mig_select_one;
|
||||
eoSelector <Representation, eoPop<Representation> > mig_select (mig_select_one,NUMBER_OF_MIGRANTS,pop);
|
||||
eoPlusReplacement<Representation> replace_one;
|
||||
eoReplace <Representation, eoPop<Representation> > mig_replace (replace_one,pop);
|
||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig(MIGRATIONS_AT_N_GENERATIONS,mig_select,mig_replace,topo);
|
||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig(mig_cont,mig_select,mig_replace,topo);
|
||||
checkpoint.add( mig );
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
eoPop< Representation > pop2( POP_SIZE, init );
|
||||
eoSGATransform< Representation > transform2( xover, XOVER_P, mut, MUT_P );
|
||||
eoStochTournamentSelect< Representation > select2;
|
||||
eoSelectMany< Representation > selectN2( select2, selectionRate.value() );
|
||||
eoSSGAStochTournamentReplacement< Representation > replace2( 1.0 );
|
||||
eoWeakElitistReplacement< Representation > elitReplace2( replace2 );
|
||||
eoGenContinue< Representation > cont2( nbGenerations.value() );
|
||||
eoCheckPoint< Representation > checkpoint2( cont2 );
|
||||
eoEasyEA< Representation > algo2( checkpoint2, eval, selectN2, transform2, elitReplace2 );
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
// MIGRATION CONTEXT DEFINITION
|
||||
|
||||
eoPeriodicContinue< Representation > mig_conti2( MIGRATIONS_AT_N_GENERATIONS );
|
||||
eoContinuator<Representation> mig_cont2(mig_conti2,pop2);
|
||||
eoRandomSelect<Representation> mig_select_one2;
|
||||
eoSelector <Representation, eoPop<Representation> > mig_select2 (mig_select_one2,NUMBER_OF_MIGRANTS,pop2);
|
||||
eoPlusReplacement<Representation> replace_one2;
|
||||
eoReplace <Representation, eoPop<Representation> > mig_replace2 (replace_one2,pop2);
|
||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig2(MIGRATIONS_AT_N_GENERATIONS,mig_select2,mig_replace2,topo);
|
||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig2(mig_cont2,mig_select2,mig_replace2,topo);
|
||||
checkpoint2.add( mig2 );
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
eoPop< Representation > pop3( POP_SIZE, init );
|
||||
eoSGATransform< Representation > transform3( xover, XOVER_P, mut, MUT_P );
|
||||
eoStochTournamentSelect< Representation > select3;
|
||||
eoSelectMany< Representation > selectN3( select3, selectionRate.value() );
|
||||
eoSSGAStochTournamentReplacement< Representation > replace3( 1.0 );
|
||||
eoWeakElitistReplacement< Representation > elitReplace3( replace3 );
|
||||
eoGenContinue< Representation > cont3( nbGenerations.value() );
|
||||
eoCheckPoint< Representation > checkpoint3( cont3 );
|
||||
eoEasyEA< Representation > algo3( checkpoint3, eval, selectN3, transform3, elitReplace3 );
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
// MIGRATION CONTEXT DEFINITION
|
||||
|
||||
eoPeriodicContinue< Representation > mig_conti3( MIGRATIONS_AT_N_GENERATIONS );
|
||||
eoContinuator<Representation> mig_cont3(mig_conti3,pop3);
|
||||
eoRandomSelect<Representation> mig_select_one3;
|
||||
eoSelector <Representation, eoPop<Representation> > mig_select3 (mig_select_one3,NUMBER_OF_MIGRANTS,pop3);
|
||||
eoPlusReplacement<Representation> replace_one3;
|
||||
eoReplace <Representation, eoPop<Representation> > mig_replace3 (replace_one3,pop3);
|
||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(MIGRATIONS_AT_N_GENERATIONS,mig_select3,mig_replace3,topo);
|
||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(mig_cont3,mig_select3,mig_replace3,topo);
|
||||
|
||||
checkpoint3.add( mig3 );
|
||||
//-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
peoWrapper algoPar( algo, pop );
|
||||
mig.setOwner( algoPar );
|
||||
checkpoint.add( dataTransfer );
|
||||
dataTransfer.setOwner( algoPar );
|
||||
|
||||
|
||||
peoWrapper algoPar2( algo2, pop2 );
|
||||
mig2.setOwner( algoPar2 );
|
||||
checkpoint2.add( dataTransferb );
|
||||
dataTransferb.setOwner( algoPar2 );
|
||||
|
||||
|
||||
peoWrapper algoPar3( algo3, pop3 );
|
||||
mig3.setOwner( algoPar3 );
|
||||
checkpoint3.add( dataTransferc );
|
||||
dataTransferc.setOwner( algoPar3 );
|
||||
|
||||
peo::run();
|
||||
peo::finalize();
|
||||
|
||||
if ( getNodeRank() == 1 )
|
||||
std::cout << "A: " << dataA << std::endl;
|
||||
if ( getNodeRank() == 2 )
|
||||
std::cout << "B: " << dataB << std::endl;
|
||||
if ( getNodeRank() == 3 )
|
||||
std::cout << "C: " << dataC << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
// desallocate memory
|
||||
for (int i=0; i<n; i++){
|
||||
delete[] a[i];
|
||||
delete[] b[i];
|
||||
}
|
||||
|
||||
delete[] a;
|
||||
delete[] b;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
48
trunk/paradiseo-peo/tutorial/Lesson5/param
Normal file → Executable file
48
trunk/paradiseo-peo/tutorial/Lesson5/param
Normal file → Executable file
|
|
@ -1,13 +1,41 @@
|
|||
###### Param ######
|
||||
--maxGen=1
|
||||
--select=0.8
|
||||
###### General ######
|
||||
# --help=0 # -h : Prints this message
|
||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||
# --seed=1104133126 # -S : Random number seed
|
||||
|
||||
## miscallenous parameters
|
||||
|
||||
--debug=false
|
||||
|
||||
## deployment schema
|
||||
|
||||
--schema=schema.xml
|
||||
###### Evolution Engine ######
|
||||
--popSize=10 # -P : Population Size
|
||||
--tSize=2 #tournament size
|
||||
|
||||
|
||||
###### Output ######
|
||||
# --useEval=1 # Use nb of eval. as counter (vs nb of gen.)
|
||||
# --useTime=1 # Display time (s) every generation
|
||||
# --printBestStat=1 # Print Best/avg/stdev every gen.
|
||||
# --printPop=0 # Print sorted pop. every gen.
|
||||
|
||||
###### Output - Disk ######
|
||||
# --resDir=Res # Directory to store DISK outputs
|
||||
# --eraseDir=1 # erase files in dirName if any
|
||||
# --fileBestStat=0 # Output bes/avg/std to file
|
||||
|
||||
###### Output - Graphical ######
|
||||
# --plotBestStat=0 # Plot Best/avg Stat
|
||||
# --plotHisto=0 # Plot histogram of fitnesses
|
||||
|
||||
###### Persistence ######
|
||||
# --Load=L # -L : A save file to restart from
|
||||
--inst=../benchs/tai12a.dat # -i
|
||||
--schema=schema.xml # -s
|
||||
|
||||
###### Stopping criterion ######
|
||||
--maxGen=100 # -G : Maximum number of generations () = none)
|
||||
--minGen=10 # -g : Minimum number of generations
|
||||
|
||||
###### Variation Operators ######
|
||||
--pCross=0.7 # -C : Probability of Crossover
|
||||
--pMut=0.8 # -M : Probability of Mutation
|
||||
|
||||
###### Migration Policy ######
|
||||
--nbMigrants=10 # -n : Number of migrants
|
||||
--manGeneration=5 # -N : Migration at N generations
|
||||
|
|
|
|||
51
trunk/paradiseo-peo/tutorial/Lesson5/parserStruct.h
Normal file
51
trunk/paradiseo-peo/tutorial/Lesson5/parserStruct.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
<parserStruct.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
struct parameters
|
||||
{
|
||||
unsigned seed ;
|
||||
int popSize;
|
||||
int tSize;
|
||||
string inst;
|
||||
string loadName;
|
||||
string schema;
|
||||
double pCross;
|
||||
double pMut;
|
||||
int minGen;
|
||||
int maxGen;
|
||||
int nbMigrants;
|
||||
int manGeneration;
|
||||
};
|
||||
81
trunk/paradiseo-peo/tutorial/Lesson5/qapPackUnpack.h
Normal file
81
trunk/paradiseo-peo/tutorial/Lesson5/qapPackUnpack.h
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
<qapPackUnpack.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
/**
|
||||
* Since you define your own class, you need to tell ParadisEO how to pack
|
||||
* and unpack your own data.
|
||||
* This example show you how we pack and unpack a QAP class. In our case, it is
|
||||
* just packing and unpacking an array of integers. In your case, it will depend
|
||||
* on the representation of your class.
|
||||
*/
|
||||
|
||||
void pack( const Problem& _problem )
|
||||
{
|
||||
|
||||
if ( _problem.invalid() )
|
||||
pack( (unsigned int)0 );
|
||||
else
|
||||
{
|
||||
pack( (unsigned int)1 );
|
||||
pack(_problem.fitness());
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++ )
|
||||
{
|
||||
pack( _problem.solution[i] );
|
||||
}
|
||||
}
|
||||
|
||||
void unpack( Problem& _problem )
|
||||
{
|
||||
unsigned int validFitness;
|
||||
|
||||
unpack( validFitness );
|
||||
if ( validFitness )
|
||||
{
|
||||
double fitnessValue;
|
||||
unpack( fitnessValue );
|
||||
_problem.fitness( fitnessValue );
|
||||
}
|
||||
else
|
||||
{
|
||||
_problem.invalidate();
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++ )
|
||||
{
|
||||
unpack(_problem[i]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<schema>
|
||||
<group scheduler="0">
|
||||
<node name="0" num_workers="0">
|
||||
</node>
|
||||
|
||||
<node name="1" num_workers="0">
|
||||
<runner>1</runner>
|
||||
|
||||
<group scheduler="0">
|
||||
<node name="0" num_workers="0">
|
||||
</node>
|
||||
<node name="1" num_workers="0">
|
||||
<runner>1</runner>
|
||||
</node>
|
||||
<node name="2" num_workers="1">
|
||||
<runner>2</runner>
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
<runner>3</runner>
|
||||
</node>
|
||||
</group>
|
||||
|
||||
|
||||
</node>
|
||||
|
||||
<node name="2" num_workers="1">
|
||||
<runner>2</runner>
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
<runner>3</runner>
|
||||
</node>
|
||||
|
||||
</group>
|
||||
</schema>
|
||||
|
||||
|
|
|
|||
129
trunk/paradiseo-peo/tutorial/Lesson5/utils.h
Executable file
129
trunk/paradiseo-peo/tutorial/Lesson5/utils.h
Executable file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
<utils.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille Nord Europe, 2006-2009
|
||||
(C) OPAC Team, LIFL, 2002-2009
|
||||
|
||||
The Van LUONG, (The-Van.Luong@inria.fr)
|
||||
Mahmoud FATENE, (mahmoud.fatene@inria.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void parseFile(eoParser & parser, parameters & param)
|
||||
{
|
||||
|
||||
// For each parameter, you can in on single line
|
||||
// define the parameter, read it through the parser, and assign it
|
||||
|
||||
param.seed = parser.createParam(unsigned(time(0)), "seed", "Random number seed", 'S').value(); // will be in default section General
|
||||
|
||||
// init and stop
|
||||
param.loadName = parser.createParam(string(""), "Load","A save file to restart from",'L', "Persistence" ).value();
|
||||
|
||||
param.inst = parser.createParam(string(""), "inst","a dat file to read instances from",'i', "Persistence" ).value();
|
||||
|
||||
param.schema = parser.createParam(string(""), "schema","an xml file mapping process",'s', "Persistence" ).value();
|
||||
|
||||
param.popSize = parser.createParam(unsigned(15), "popSize", "Population size",'P', "Evolution engine" ).value();
|
||||
|
||||
param.tSize = parser.createParam(unsigned(2), "tSize", "Tournament size",'T', "Evolution Engine" ).value();
|
||||
|
||||
param.minGen = parser.createParam(unsigned(100), "minGen", "Minimum number of iterations",'g', "Stopping criterion" ).value();
|
||||
|
||||
param.maxGen = parser.createParam(unsigned(300), "maxGen", "Maximum number of iterations",'G', "Stopping criterion" ).value();
|
||||
|
||||
param.pCross = parser.createParam(double(0.6), "pCross", "Probability of Crossover", 'C', "Genetic Operators" ).value();
|
||||
|
||||
param.pMut = parser.createParam(double(0.1), "pMut", "Probability of Mutation", 'M', "Genetic Operators" ).value();
|
||||
|
||||
param.nbMigrants = parser.createParam(unsigned(6), "nbMigrants", "Number of migrants",'n', "Migration Policy" ).value();
|
||||
|
||||
param.manGeneration = parser.createParam(unsigned(5), "manGeneration", "Migration at N generations",'N', "Migration Policy" ).value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
string statusName = parser.createParam(str_status, "status","Status file",'S', "Persistence" ).value();
|
||||
|
||||
// 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 (statusName != "")
|
||||
{
|
||||
ofstream os(statusName.c_str());
|
||||
os << parser; // and you can use that file as parameter file
|
||||
}
|
||||
}
|
||||
|
||||
void loadInstances(const char* filename, int& n, int& bkv, int** & a, int** & b)
|
||||
{
|
||||
|
||||
ifstream data_file;
|
||||
int i, j;
|
||||
data_file.open(filename);
|
||||
if (! data_file.is_open())
|
||||
{
|
||||
cout << "\n Error while reading the file " << filename << ". Please check if it exists !" << endl;
|
||||
exit (1);
|
||||
}
|
||||
data_file >> n;
|
||||
data_file >> bkv; // best known value
|
||||
// ****************** dynamic memory allocation ****************** /
|
||||
a = new int* [n];
|
||||
b = new int* [n];
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
a[i] = new int[n];
|
||||
b[i] = new int[n];
|
||||
}
|
||||
|
||||
// ************** read flows and distanceMatrixs matrices ************** /
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = 0; j < n; j++)
|
||||
data_file >> a[i][j];
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
for (j = 0; j < n; j++)
|
||||
data_file >> b[i][j];
|
||||
|
||||
data_file.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue