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:
fatene 2009-03-05 11:02:24 +00:00
commit a28c5452ef
142 changed files with 8144 additions and 5695 deletions

View file

@ -56,10 +56,7 @@ LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib)
### 3) Define your target(s): just an executable here
######################################################################################
ADD_EXECUTABLE(pso3 mainPSO.cpp)
ADD_DEPENDENCIES(pso3 peo rmc_mpi)
ADD_EXECUTABLE(ea3 mainEA.cpp)
ADD_DEPENDENCIES(ea3 peo rmc_mpi)
ADD_EXECUTABLE(popEval main.cpp)
######################################################################################
@ -68,8 +65,8 @@ ADD_DEPENDENCIES(ea3 peo rmc_mpi)
######################################################################################
SET(LESSON3_VERSION ${GLOBAL_VERSION})
SET_TARGET_PROPERTIES(pso3 PROPERTIES VERSION "${LESSON3_VERSION}")
SET_TARGET_PROPERTIES(ea3 PROPERTIES VERSION "${LESSON3_VERSION}")
SET_TARGET_PROPERTIES(popEval PROPERTIES VERSION "${LESSON3_VERSION}")
######################################################################################
@ -77,8 +74,7 @@ SET_TARGET_PROPERTIES(ea3 PROPERTIES VERSION "${LESSON3_VERSION}")
### 5) Link the librairies
######################################################################################
TARGET_LINK_LIBRARIES(pso3 ${XML2_LIBS} peo rmc_mpi eo eoutils peo)
TARGET_LINK_LIBRARIES(ea3 ${XML2_LIBS} peo rmc_mpi eo eoutils peo)
TARGET_LINK_LIBRARIES(popEval eo ga es ${XML2_LIBS} peo rmc_mpi eoutils peo)
######################################################################################

View file

@ -0,0 +1,203 @@
/*
<Move.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
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 MOVE_H
#define MOVE_H
#include <mo.h>
#include <eo>
#include "QAP.h"
#endif
class ProblemEval : public eoEvalFunc <Problem> {
public:
void operator() (Problem & _problem){
//cout << "eoEvalFunc()"<< endl;
_problem.fitness(_problem.evaluate());
}
};
class Move : public moMove <Problem>, public std :: pair <unsigned, unsigned> {
public :
void operator () (Problem & _problem) {
// transformer une solution en une autre connaissant le meilleur mouvement
//cout << "MOVE() " << endl;
int temp = _problem.solution[first];
_problem.solution[first] = _problem.solution[second];
_problem.solution[second] = temp;
}
};
class MoveInit : public moMoveInit <Move> {
public:
void operator () (Move & _move, const Problem& _problem) {
//cout << "MoveInit " << endl;
_move.first = 0;
_move.second = 1;
}
};
class MoveNext : public moNextMove <Move>{
public:
bool operator() (Move & _move, const Problem & _problem) {
//cout << "MoveNext" << endl;
//cout << _move.first << " , " << _move.second << endl;
if (_move.first < n-2){
if (_move.second < n-1){
_move.second++;
}
else {
_move.first++;
_move.second = _move.first + 1;
}
return true;
}
return false;
}
};
class MoveIncrEval : public moMoveIncrEval <Move>
{
public:
int compute_delta(int n, int** a, int** b,
int* p, int i, int j)
{
int d; int k;
d = (a[i][i]-a[j][j])*(b[p[j]][p[j]]-b[p[i]][p[i]]) +
(a[i][j]-a[j][i])*(b[p[j]][p[i]]-b[p[i]][p[j]]);
for (k = 0; k < n; k = k + 1) if (k!=i && k!=j)
d = d + (a[k][i]-a[k][j])*(b[p[k]][p[j]]-b[p[k]][p[i]]) +
(a[i][k]-a[j][k])*(b[p[j]][p[k]]-b[p[i]][p[k]]);
return(d);
}
eoMinimizingFitness operator() (const Move & _move, const Problem & _problem){
double cost;
cost=0;
// for calculing delta difference
int* p = new int[n];
for (int i = 0 ; i < n ; i++)
p[i] = _problem.solution[i];
cost = _problem.fitness() + compute_delta(n,a,b,p,_move.first, _move.second);
delete[] p;
return cost;
}
};
class MoveRand : public moRandMove <Move>{
public:
void operator() (Move & _move){
_move.first = rand()%n;
do{
_move.second = rand()%n;
} while (_move.first == _move.second);
}
};
//for ILS
/*
class Perturbation : public eoMonOp <Problem>{
public:
bool operator() (Problem & _problem){
int r1,r2,temp;
int mu = 1 + rand()%n;
for (int k = 1 ; k <= mu; k++){
r1 = rand()%n;
for(;;){
r2 = rand()%n;
if (r1 != r2)
break;
}
temp = _problem.solution[r1];
_problem.solution[r1] = _problem.solution[r2];
_problem.solution[r2] = temp;
}
_problem.invalidate();
}
};
*/

View file

@ -0,0 +1,119 @@
/*
<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
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>
using namespace std;
/* 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 = rng.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

View file

@ -0,0 +1,128 @@
/*
<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
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)
{
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 = rng.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=rng.rand()%n;
do
j = rng.rand()%n;
while (i == j);
// swap
temp = _problem.solution[i];
_problem.solution[i] = _problem.solution[j];
_problem.solution[j] = temp;
return true;
}
};
#endif

View file

@ -0,0 +1,193 @@
/*
<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
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 QAP,
* redefinition of the crossover, mutation, initialisation of solution.
*
*/
#include <mo>
#include <peo>
#include <string>
#include "QAP.h"
#include "QAPGA.h"
#include "Move.h"
#include "qapPackUnpack.h"
/** 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
*/
// Global variables
int n; // problem size
int** a;
int** b; // a and matrices
int bkv; //best known value
void main_function(int argc, char **argv)
{
if (argc < 2){
cout << "Please give a param file" << endl;
exit(1);
}
// Declaration of useful variables to parse the parameters file and then
// its elements into a structure
eoParser parser(argc, argv);
parameters param;
parseFile(parser, param);
string s (argv[1]);
if ( (s.compare("-h") == 0) || (s.compare("--help") == 0 ) )
;//make help
// Reading the a and b matrices of the QAP problem
else
loadInstances(param.inst.c_str(), n, bkv, a, b);
rng.reseed(param.seed);
// Declaration of class wrapping the evaluation function of the QAP
ProblemEvalFunc plainEval;
peoPopEval<Problem> eval(plainEval);
// Class involving a simple call to the function of initialisation of a solution
ProblemInit chromInit;
eoPop<Problem> pop(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
MoveInit move_init;
ProblemEval problem_eval;
MoveNext move_next;
MoveIncrEval move_incr_eval;
moSimpleMoveTabuList<Move> tabulist(param.tabuListSize);
moImprBestFitAspirCrit<Move> aspiration_criterion;
moGenSolContinue<Problem> continu (param.TSmaxIter);
moTS <Move> tabu_search (move_init, move_next, move_incr_eval,
tabulist, aspiration_criterion, continu, problem_eval );
// The operators are encapsulated into an eoTRansform object
eoSGATransform<Problem> transform(Xover, param.pCross, tabu_search, param.pMut);
// REPLACE
eoPlusReplacement<Problem> replace;
eoGenContinue<Problem> genCont(param.maxGen); // generation continuation
eoEasyEA<Problem> gga(genCont, plainEval, select, transform, replace);
// PEO ADD
peo :: init( argc, argv );
peoWrapper parallelEA( gga, pop);
eval.setOwner(parallelEA);
if (getNodeRank()==1)
{
for (int i=0;i<pop.size();i++)
problem_eval(pop[i]);
pop.sort();
std::cout << "Initial population :\n" << pop << std::endl;
// GENERAL
}
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
cout << "Instance size = " << n << endl;
cout << "Best known value in the litterature = " << bkv << endl;
pop.sort();
std::cout << "Final population :\n" << pop << std::endl;
cout << "Best solution found" << endl;
pop[0].printSolution();
cout << pop[0] << endl;
// GENERAL
}
}
// 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';
}
// desallocate memory
for (int i=0; i<n; i++){
delete[] a[i];
delete[] b[i];
}
delete[] a;
delete[] b;
return 1;
}

View file

@ -1,150 +0,0 @@
/*
* <mainEA.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/syncor 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
*
*/
#include <peo>
#include <es.h>
typedef eoReal<double> Indi;
double f (const Indi & _indi)
{
double sum;
sum=_indi[1]-pow(_indi[0],2);
sum=100*pow(sum,2);
sum+=pow((1-_indi[0]),2);
return (-sum);
}
int main (int __argc, char *__argv[])
{
peo :: init( __argc, __argv );
eoParser parser(__argc, __argv);
unsigned int POP_SIZE = parser.createParam((unsigned int)(20), "popSize", "Population size",'P',"Param").value();
unsigned int MAX_GEN = parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations",'G',"Param").value();
double EPSILON = parser.createParam(0.01, "mutEpsilon", "epsilon for mutation",'e',"Param").value();
double CROSS_RATE = parser.createParam(0.25, "pCross", "Crossover probability",'C',"Param").value();
double MUT_RATE = parser.createParam(0.35, "pMut", "Mutation probability",'M',"Param").value();
unsigned int VEC_SIZE = parser.createParam((unsigned int)(2), "vecSize", "Vector size",'V',"Param").value();
double INIT_POSITION_MIN = parser.createParam(-2.0, "pMin", "Init position min",'N',"Param").value();
double INIT_POSITION_MAX = parser.createParam(2.0, "pMax", "Init position max",'X',"Param").value();
unsigned int MIG_FREQ = parser.createParam((unsigned int)(10), "migFreq", "Migration frequency",'F',"Param").value();
unsigned int MIG_SIZE = parser.createParam((unsigned int)(5), "migSize", "Migration size",'S',"Param").value();
rng.reseed (time(0));
// Define the topology of your island model
RingTopology topology;
// First algorithm
/*****************************************************************************************/
eoGenContinue < Indi > genContPara (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara (genContPara);
eoCheckPoint<Indi> checkpoint(continuatorPara);
peoEvalFunc<Indi> mainEval( f );
peoPopEval <Indi> eval(mainEval);
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
eoRankingSelect<Indi> selectionStrategy;
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
eoSegmentCrossover<Indi> crossover;
eoUniformMutation<Indi> mutation(EPSILON);
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
eoPop < Indi > pop;
pop.append (POP_SIZE, random);
// Define a synchronous island
// Seclection
eoRandomSelect<Indi> mig_select_one;
eoSelector <Indi, eoPop<Indi> > mig_select (mig_select_one,MIG_SIZE,pop);
// Replacement
eoPlusReplacement<Indi> replace;
eoReplace <Indi, eoPop<Indi> > mig_replace (replace,pop);
// Island
peoSyncIslandMig<eoPop<Indi>, eoPop<Indi> > mig(MIG_FREQ,mig_select,mig_replace,topology);
checkpoint.add(mig);
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
peoWrapper parallelEA( eaAlg, pop);
eval.setOwner(parallelEA);
transform.setOwner(parallelEA);
// setOwner
mig.setOwner(parallelEA);
/*****************************************************************************************/
// Second algorithm (on the same model but with others names)
/*****************************************************************************************/
eoGenContinue < Indi > genContPara2 (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
peoEvalFunc<Indi> mainEval2( f );
peoPopEval <Indi> eval2(mainEval2);
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
eoRankingSelect<Indi> selectionStrategy2;
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
eoSegmentCrossover<Indi> crossover2;
eoUniformMutation<Indi> mutation2(EPSILON);
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
eoPop < Indi > pop2;
pop2.append (POP_SIZE, random2);
eoPlusReplacement<Indi> replace2;
eoRandomSelect<Indi> mig_select_one2;
eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_select_one2,MIG_SIZE,pop2);
eoReplace <Indi, eoPop<Indi> > mig_replace2 (replace2,pop2);
peoSyncIslandMig<eoPop<Indi>, eoPop<Indi> > mig2(MIG_FREQ,mig_select2,mig_replace2,topology);
checkpoint2.add(mig2);
eoEasyEA< Indi > eaAlg2( checkpoint2, eval2, select2, transform2, replace2 );
peoWrapper parallelEA2( eaAlg2, pop2);
eval2.setOwner(parallelEA2);
transform2.setOwner(parallelEA2);
mig2.setOwner(parallelEA2);
/*****************************************************************************************/
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
pop2.sort();
std::cout << "Final population 1 :\n" << pop << std::endl;
std::cout << "Final population 2 :\n" << pop2 << std::endl;
}
}

View file

@ -1,166 +0,0 @@
/*
* <mainPSO.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
*
*/
#include <peo>
typedef eoRealParticle < double >Indi;
double f (const Indi & _indi)
{
double sum;
sum=_indi[1]-pow(_indi[0],2);
sum=100*pow(sum,2);
sum+=pow((1-_indi[0]),2);
return (-sum);
}
int main (int __argc, char *__argv[])
{
peo :: init( __argc, __argv );
eoParser parser(__argc, __argv);
unsigned int POP_SIZE = parser.createParam((unsigned int)(20), "popSize", "Population size",'P',"Param").value();
unsigned int MAX_GEN = parser.createParam((unsigned int)(100), "maxGen", "Maximum number of generations",'G',"Param").value();
unsigned int VEC_SIZE = parser.createParam((unsigned int)(2), "vecSize", "Vector size",'V',"Param").value();
double INIT_POSITION_MIN = parser.createParam(-2.0, "pMin", "Init position min",'N',"Param").value();
double INIT_POSITION_MAX = parser.createParam(2.0, "pMax", "Init position max",'X',"Param").value();
double INIT_VELOCITY_MIN = parser.createParam(-1.0, "vMin", "Init velocity min",'n',"Param").value();
double INIT_VELOCITY_MAX = parser.createParam(1.0, "vMax", "Init velocity max",'x',"Param").value();
double omega = parser.createParam(1.0, "weight", "Weight",'w',"Param").value();
double C1 = parser.createParam(0.5, "c1", "C1",'1',"Param").value();
double C2 = parser.createParam(2.0, "c2t", "C2",'2',"Param").value();
unsigned int NEIGHBORHOOD_SIZE = parser.createParam((unsigned int)(6), "neighSize", "Neighborhood size",'H',"Param").value();
unsigned int MIG_FREQ = parser.createParam((unsigned int)(10), "migFreq", "Migration frequency",'F',"Param").value();
rng.reseed (time(0));
// Island model
RingTopology topologyMig;
// First
eoGenContinue < Indi > genContPara (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara (genContPara);
eoCheckPoint<Indi> checkpoint(continuatorPara);
peoEvalFunc<Indi, double, const Indi& > plainEval(f);
peoPopEval< Indi > eval(plainEval);
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
eoFirstIsBestInit < Indi > localInit;
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
eoStandardFlight < Indi > flight(bndsFlight);
eoPop < Indi > pop;
pop.append (POP_SIZE, random);
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds);
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
// Island model
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
peoPSOSelect<Indi> mig_selec(topology);
peoWorstPositionReplacement<Indi> mig_replac;
// Specific implementation (peoData.h)
eoContinuator<Indi> cont(mig_cont, pop);
eoSelector <Indi, eoPop<Indi> > mig_select (mig_selec,1,pop);
eoReplace <Indi, eoPop<Indi> > mig_replace (mig_replac,pop);
// Second
eoGenContinue < Indi > genContPara2 (MAX_GEN);
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
peoEvalFunc<Indi, double, const Indi& > plainEval2(f);
peoPopEval< Indi > eval2(plainEval2);
eoUniformGenerator < double >uGen2 (INIT_POSITION_MIN, INIT_POSITION_MAX);
eoInitFixedLength < Indi > random2 (VEC_SIZE, uGen2);
eoUniformGenerator < double >sGen2 (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
eoVelocityInitFixedLength < Indi > veloRandom2 (VEC_SIZE, sGen2);
eoFirstIsBestInit < Indi > localInit2;
eoRealVectorBounds bndsFlight2(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
eoStandardFlight < Indi > flight2(bndsFlight2);
eoPop < Indi > pop2;
pop2.append (POP_SIZE, random2);
eoLinearTopology<Indi> topology2(NEIGHBORHOOD_SIZE);
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
eoStandardVelocity < Indi > velocity2 (topology2,omega,C1,C2,bnds2);
eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
// Island model
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
peoPSOSelect<Indi> mig_selec2(topology2);
peoWorstPositionReplacement<Indi> mig_replac2;
// Specific implementation (peoData.h)
eoContinuator<Indi> cont2(mig_cont2,pop2);
eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
eoReplace <Indi, eoPop<Indi> > mig_replace2 (mig_replac2,pop2);
// Asynchronous island
peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig);
checkpoint.add( mig );
peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig);
checkpoint2.add( mig2 );
// Parallel algorithm
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
peoWrapper parallelPSO( psa, pop);
eval.setOwner(parallelPSO);
mig.setOwner(parallelPSO);
eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2);
peoWrapper parallelPSO2( psa2, pop2);
eval2.setOwner(parallelPSO2);
mig2.setOwner(parallelPSO2);
peo :: run();
peo :: finalize();
if (getNodeRank()==1)
{
pop.sort();
pop2.sort();
std::cout << "Final population :\n" << pop << std::endl;
std::cout << "Final population :\n" << pop2 << std::endl;
}
}

View file

@ -1,242 +0,0 @@
# Doxyfile 1.4.7
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = "ParadisEO-PEO Lesson3"
PROJECT_NUMBER = 0.1
OUTPUT_DIRECTORY = ../../../doc/html/lesson3
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF = "The $name class" \
"The $name widget" \
"The $name file" \
is \
provides \
specifies \
contains \
represents \
a \
an \
the
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = NO
STRIP_FROM_PATH =
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = YES
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
BUILTIN_STL_SUPPORT = NO
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = NO
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_CLASSES = YES
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = NO
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = NO
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = .
FILE_PATTERNS = *.cpp \
*.h \
NEWS \
README
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = NO
IMAGE_PATH = ../../docs/images
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 3
IGNORE_PREFIX = peo
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = NO
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = YES
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = YES
USE_PDFLATEX = YES
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = NO
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = NO
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = YES
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = NO
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES = ../../../paradiseo-mo/docs/eo.doxytag=../../../../../paradiseo-mo/docs/html \
../../../paradiseo-mo/docs/mo.doxytag=../../../../../paradiseo-mo/docs/html \
../../docs/paradiseo-peo.doxytag=../../ \
../shared/paradiseo-peo-lsn-shared.doxytag=../../lsnshared/html
GENERATE_TAGFILE = ../../docs/paradiseo-peo-lsn.doxytag
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = NO
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = NO
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = NO
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 0
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = NO
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = YES

58
trunk/paradiseo-peo/tutorial/Lesson3/param Normal file → Executable file
View file

@ -1,27 +1,37 @@
###### Param ######
--popSize=20 # -P : Population size
--maxGen=200 # -G : Maximum number of generations
--mutEpsilon=0.01 # -e : epsilon for mutation
--pCross=0.80 # -C : Crossover probability
--pMut=0.30 # -M : Mutation probability
--vecSize=2 # -V : Vector size
--pMin=-2.0 # -N : Init position min
--pMax=2.0 # -X : Init position max
--vMin=-1.0 # -n : Init velocity min
--vMax=1.0 # -x : Init velocity max
--neighSize=6 # -H : Neighborhood size
--weight=1.0 # -w : Weight
--c1=0.5 # -1 : C1
--c2=2.0 # -2 : C2
--migFreq=10 # -F : Migration frequency
--migSize=5 # -S : Migration size
###### 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=10 # -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

View 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
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 ;
unsigned popSize ;
unsigned tSize ;
string loadName ;
string inst ;
string schema ;
unsigned maxGen ;
unsigned minGen ;
double pCross ;
double pMut ;
int TSmaxIter ;
int tabuListSize;
};

View file

@ -0,0 +1,88 @@
/*
<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]);
}
}
/*
void unpack( eoMinimizingFitness& __fitness )
{
cout << " unpacking .... " << endl;
}
*/

View file

@ -1,20 +1,19 @@
<?xml version="1.0"?>
<schema>
<group scheduler="0">
<node name="0" num_workers="0">
</node>
<node name="1" num_workers="0">
<runner>1</runner>
<runner>2</runner>
</node>
<node name="2" num_workers="1">
</node>
<node name="3" num_workers="1">
</node>
</group>
<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">
</node>
<node name="3" num_workers="1">
</node>
</group>
</schema>

View file

@ -0,0 +1,131 @@
/*
<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
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
// parameters for evolution engine
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.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.maxGen = parser.createParam(unsigned(10), "maxGen", "Maximum number of generations",'G', "Stopping criterion" ).value();
param.minGen = parser.createParam(unsigned(10), "minGen", "Minimum number of generations",'g', "Stopping criterion" ).value();
// operators probabilities at the algorithm level
param.pCross = parser.createParam(double(0.6), "pCross", "Probability of Crossover", 'C', "Genetic Operators" ).value();
param.pMut = parser.createParam(double(0.3), "pMut", "Probability of Mutation", 'M', "Genetic Operators" ).value();
param.TSmaxIter = parser.createParam(unsigned(1000), "TSmaxIter", "Maximum number of iterations",'I', "Tabu Search" ).value();
param.tabuListSize = parser.createParam(unsigned(10), "tabuListSize", "Tabu List Size",'V', "Tabu Search" ).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