Add PEO for the tag, and update main CMakeLists and findParadisEO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2726 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
aca78b998a
commit
009d0cda1f
188 changed files with 18942 additions and 9 deletions
79
trunk/peo/tutorial/Lesson6/CMakeLists.txt
Normal file
79
trunk/peo/tutorial/Lesson6/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
######################################################################################
|
||||
### 0) Set the compiler and define targets to easily run the lessons
|
||||
######################################################################################
|
||||
|
||||
SET (CMAKE_CXX_COMPILER mpicxx)
|
||||
|
||||
#ADD_CUSTOM_TARGET(install DEPENDS ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/param ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/schema.xml)
|
||||
|
||||
#ADD_CUSTOM_COMMAND(
|
||||
# TARGET install
|
||||
# POST_BUILD
|
||||
# COMMAND ${CMAKE_COMMAND}
|
||||
# ARGS -E copy_if_different
|
||||
# ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/param
|
||||
# ${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson6)
|
||||
#ADD_CUSTOM_COMMAND(
|
||||
# TARGET install
|
||||
# POST_BUILD
|
||||
# COMMAND ${CMAKE_COMMAND}
|
||||
# ARGS -E copy_if_different
|
||||
# ${ParadisEO-PEO_SOURCE_DIR}/tutorial/Lesson6/schema.xml
|
||||
# ${ParadisEO-PEO_BINARY_DIR}/tutorial/Lesson6)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/param
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/schema.xml
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 1) Include the sources
|
||||
######################################################################################
|
||||
|
||||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src ${MOEO_SRC_DIR}/src ${OLDMO_SRC_DIR}/src ${MO_SRC_DIR}/src ${ParadisEO-PEO_SOURCE_DIR}/src)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 2) Specify where CMake can find the libraries
|
||||
######################################################################################
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib ${ParadisEO-PEO_BINARY_DIR}/lib )
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 3) Define your target(s): just an executable here
|
||||
######################################################################################
|
||||
|
||||
ADD_EXECUTABLE(hybrid main.cpp)
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 4) Optionnal: define properties
|
||||
######################################################################################
|
||||
|
||||
SET(Lesson6_VERSION ${GLOBAL_VERSION})
|
||||
SET_TARGET_PROPERTIES(hybrid PROPERTIES VERSION "${Lesson6_VERSION}")
|
||||
######################################################################################
|
||||
|
||||
|
||||
######################################################################################
|
||||
### 5) Link the librairies
|
||||
######################################################################################
|
||||
|
||||
TARGET_LINK_LIBRARIES(hybrid eo ga es ${XML2_LIBS} peo rmc_mpi eoutils peo)
|
||||
|
||||
######################################################################################
|
||||
|
||||
200
trunk/peo/tutorial/Lesson6/Move.h
Executable file
200
trunk/peo/tutorial/Lesson6/Move.h
Executable file
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
<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, (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 MOVE_H
|
||||
#define MOVE_H
|
||||
|
||||
#include <oldmo.h>
|
||||
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
*/
|
||||
#endif
|
||||
118
trunk/peo/tutorial/Lesson6/QAP.h
Executable file
118
trunk/peo/tutorial/Lesson6/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
|
||||
128
trunk/peo/tutorial/Lesson6/QAPGA.h
Normal file
128
trunk/peo/tutorial/Lesson6/QAPGA.h
Normal 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
|
||||
195
trunk/peo/tutorial/Lesson6/main.cpp
Executable file
195
trunk/peo/tutorial/Lesson6/main.cpp
Executable file
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
<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
|
||||
*/
|
||||
|
||||
#include <oldmo>
|
||||
#include <peo>
|
||||
#include <time.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "QAP.h"
|
||||
#include "Move.h"
|
||||
#include "QAPGA.h"
|
||||
#include "qapPackUnpack.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** 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; // flows and distances 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
|
||||
// put 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);
|
||||
|
||||
MoveInit move_init;
|
||||
|
||||
ProblemEval problem_eval;
|
||||
|
||||
MoveNext move_next;
|
||||
|
||||
MoveIncrEval move_incr_eval;
|
||||
|
||||
moBestImprSelect<Move> move_select;
|
||||
|
||||
moSimpleMoveTabuList <Move> tabulist (param.tabuListSize);
|
||||
|
||||
//moNoAspirCrit<Move> aspiration_criterion;
|
||||
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 );
|
||||
|
||||
ProblemInit chromInit;
|
||||
|
||||
eoPop <Problem> pop (param.popSize, chromInit);
|
||||
eoDetTournamentSelect<Problem> selectOne(param.tSize);
|
||||
eoSelectPerc<Problem> select(selectOne);// by default rate==1
|
||||
ProblemXover Xover; // CROSSOVER
|
||||
ProblemSwapMutation mutationSwap; // MUTATION
|
||||
eoSGATransform<Problem> transform(Xover, param.pCross, mutationSwap, param.pMut);
|
||||
eoPlusReplacement<Problem> replace;
|
||||
eoGenContinue<Problem> genCont(param.maxGen); // generation continuation
|
||||
|
||||
eoEasyEA<Problem> gga(genCont, problem_eval, select, transform, replace);
|
||||
// Initialisation of the parallel environment
|
||||
peo :: init (argc, argv);
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult before the local search\n";
|
||||
//std :: cout << "size\t" << pop.size() << endl;
|
||||
for (int i=0;i<pop.size();i++)
|
||||
problem_eval(pop[i]);
|
||||
pop.sort();
|
||||
cout << pop;
|
||||
}
|
||||
|
||||
// The parallel EA
|
||||
|
||||
peoWrapper parallelEA( gga, pop);
|
||||
peo :: run ();
|
||||
peo :: finalize ();
|
||||
|
||||
// Local search
|
||||
peo :: init (argc, argv);
|
||||
peoMultiStart <Problem> initParallelTS (tabu_search);
|
||||
peoWrapper parallelTS (initParallelTS, pop);
|
||||
initParallelTS.setOwner(parallelTS);
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
cout << "\nInstance size = " << n << endl;
|
||||
cout << "Best known value in the litterature = " << bkv << endl;
|
||||
std :: cout << "\nResult after the local search\n";
|
||||
// sort and print the population
|
||||
pop.sort();
|
||||
cout << pop;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cout << endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
|
||||
// desallocate memory
|
||||
for (int i=0; i<n; i++){
|
||||
delete[] a[i];
|
||||
delete[] b[i];
|
||||
}
|
||||
|
||||
delete[] a;
|
||||
delete[] b;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
40
trunk/peo/tutorial/Lesson6/param
Executable file
40
trunk/peo/tutorial/Lesson6/param
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
###### 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
|
||||
|
||||
|
||||
###### 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
|
||||
|
||||
###### Tabu Search ######
|
||||
--TSmaxIter=100 # -t : Maximum number of iterations () = none)
|
||||
--tabuListSize=10 # -l : tabu list size () = none)
|
||||
|
||||
###### Stopping criterion ######
|
||||
--maxGen=1000 # -G : Maximum number of generations () = none)
|
||||
--minGen=100 # -g : Minimum number of generations
|
||||
|
||||
###### Variation Operators ######
|
||||
--pCross=0.7 # -C : Probability of Crossover
|
||||
--pMut=0.8 # -M : Probability of Mutation
|
||||
51
trunk/peo/tutorial/Lesson6/parserStruct.h
Normal file
51
trunk/peo/tutorial/Lesson6/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;
|
||||
string loadName;
|
||||
string inst;
|
||||
string schema;
|
||||
int TSmaxIter;
|
||||
int tabuListSize;
|
||||
int tSize;
|
||||
double pCross;
|
||||
double pMut;
|
||||
int maxGen;
|
||||
int minGen;
|
||||
};
|
||||
81
trunk/peo/tutorial/Lesson6/qapPackUnpack.h
Normal file
81
trunk/peo/tutorial/Lesson6/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]);
|
||||
}
|
||||
}
|
||||
19
trunk/peo/tutorial/Lesson6/schema.xml
Normal file
19
trunk/peo/tutorial/Lesson6/schema.xml
Normal file
|
|
@ -0,0 +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>
|
||||
</node>
|
||||
<node name="2" num_workers="1">
|
||||
</node>
|
||||
<node name="3" num_workers="1">
|
||||
</node>
|
||||
</group>
|
||||
|
||||
|
||||
</schema>
|
||||
|
||||
127
trunk/peo/tutorial/Lesson6/utils.h
Executable file
127
trunk/peo/tutorial/Lesson6/utils.h
Executable file
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
<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.popSize = parser.createParam(unsigned(15), "popSize", "Population size",'P', "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 data file to read instances from",'i', "Persistence" ).value();
|
||||
param.schema = parser.createParam(string(""), "schema","An xml file mapping processes",'s', "Persistence" ).value();
|
||||
|
||||
param.TSmaxIter = parser.createParam(unsigned(1000), "TSmaxIter", "Maximum number of iterations",'M', "Tabu Search" ).value();
|
||||
|
||||
param.tabuListSize = parser.createParam(unsigned(10), "tabuListSize", "Tabu List Size",'l', "Tabu Search" ).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
|
||||
Loading…
Add table
Add a link
Reference in a new issue