Migration from SVN

This commit is contained in:
quemy 2012-08-30 11:30:11 +02:00
commit 8cd56f37db
29069 changed files with 0 additions and 4096888 deletions

View file

@ -0,0 +1,5 @@
######################################################################################
### 0) Include lessons subdirectories
######################################################################################
add_subdirectory(Lesson1)

View file

@ -0,0 +1,29 @@
# Lesson 1
######################################################################################
### 0) Define files
######################################################################################
set(files
lesson1_eoEasyEA
)
######################################################################################
### 1) Create the lesson
######################################################################################
add_lesson(smp Lesson1 "${files}")
######################################################################################
### 2) Include dependencies
######################################################################################
include_directories(${EO_SRC_DIR}/src
${SMP_SRC_DIR}/src
${PROBLEMS_SRC_DIR})
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_SOURCE_DIR}/lesson1_data.dat
${CMAKE_CURRENT_BINARY_DIR}/lesson1_data.dat)

118
smp/tutorial/Lesson1/QAP.h Executable file
View 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

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, (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)
{
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

View file

@ -0,0 +1,27 @@
12 224416
0 27 85 2 1 15 11 35 11 20 21 61
27 0 80 58 21 76 72 44 85 94 90 51
85 80 0 3 48 29 90 66 41 15 83 96
2 58 3 0 74 45 65 40 54 83 14 71
1 21 48 74 0 77 36 53 37 26 87 76
15 76 29 45 77 0 91 13 29 11 77 32
11 72 90 65 36 91 0 87 67 94 79 2
35 44 66 40 53 13 87 0 10 99 56 70
11 85 41 54 37 29 67 10 0 99 60 4
20 94 15 83 26 11 94 99 99 0 56 2
21 90 83 14 87 77 79 56 60 56 0 60
61 51 96 71 76 32 2 70 4 2 60 0
0 21 95 82 56 41 6 25 10 4 63 6
21 0 44 40 75 79 0 89 35 9 1 85
95 44 0 84 12 0 26 91 11 35 82 26
82 40 84 0 69 56 86 45 91 59 18 76
56 75 12 69 0 39 18 57 36 61 36 21
41 79 0 56 39 0 71 11 29 82 82 6
6 0 26 86 18 71 0 71 8 77 74 30
25 89 91 45 57 11 71 0 89 76 76 40
10 35 11 91 36 29 8 89 0 93 56 1
4 9 35 59 61 82 77 76 93 0 50 4
63 1 82 18 36 82 74 76 56 50 0 36
6 85 26 76 21 6 30 40 1 4 36 0

View file

@ -0,0 +1,136 @@
/*
<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 QAP,
* redefinition of the crossover, mutation, initialisation of solution.
*
*/
#include <smp>
#include "QAP.h"
#include "QAPGA.h"
#include <string>
using namespace std;
using namespace paradiseo::smp;
/** 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
int main(int argc, char **argv)
{
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);
// Reading the a and b matrices of the QAP problem
loadInstances(param.inst.c_str(), n, bkv, a, b);
// Declaration of class wrapping the evaluation function of the QAP
ProblemEvalFunc plainEval;
eoEvalFuncCounter<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
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
try
{
// Create the algorithm
MWModel<eoEasyEA,Problem> mw(genCont, plainEval, select, transform, replace);
// Start a parallel evaluation on the population
mw.evaluate(pop);
std::cout << "Initial population :" << std::endl;
pop.sort();
std::cout << pop << std::endl;
// Start the algorithm on the population
mw(pop);
std::cout << "Final population :" << std::endl;
pop.sort();
std::cout << pop << std::endl;
}
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

@ -0,0 +1,37 @@
###### General ######
# --help=0 # -h : Prints this message
# --stopOnUnknownParam=1 # Stop if unkown param entered
# --seed=1104133126 # -S : Random number seed
###### 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=lesson1_data.dat # -i
--schema=schema.xml # -s
###### Stopping criterion ######
--maxGen=10 # -G : Maximum number of generations () = none)
--minGen=1 # -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,49 @@
/*
<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;
};

126
smp/tutorial/Lesson1/utils.h Executable file
View file

@ -0,0 +1,126 @@
/*
<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(10), "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();
// 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