diff --git a/ParadisEO-GPU/tutoriel/QAP_CPU/CMakeLists.txt b/ParadisEO-GPU/tutoriel/QAP_CPU/CMakeLists.txt new file mode 100644 index 000000000..8bf58768d --- /dev/null +++ b/ParadisEO-GPU/tutoriel/QAP_CPU/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(application) \ No newline at end of file diff --git a/ParadisEO-GPU/tutoriel/QAP_CPU/src/Init.h b/ParadisEO-GPU/tutoriel/QAP_CPU/src/Init.h new file mode 100644 index 000000000..e69de29bb diff --git a/ParadisEO-GPU/tutoriel/QAP_CPU/src/Problem.h b/ParadisEO-GPU/tutoriel/QAP_CPU/src/Problem.h new file mode 100644 index 000000000..fe88a53f8 --- /dev/null +++ b/ParadisEO-GPU/tutoriel/QAP_CPU/src/Problem.h @@ -0,0 +1,37 @@ +void load(char* _fileName){ + FILE *f; + int i,j; + //open the file in read mode + f=fopen(_fileName,"r" ); + //Verify if the file was open successfely + if (f != NULL) + fscanf(f,"%d",&n); + else + printf("Le Fichier est vide\n"); + a=new int*[n]; + for(int i=0;i +void create(EOT &_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; + } + } diff --git a/ParadisEO-GPU/tutoriel/QAP_CPU/src/QapEval.h b/ParadisEO-GPU/tutoriel/QAP_CPU/src/QapEval.h new file mode 100644 index 000000000..6d8d3c0ee --- /dev/null +++ b/ParadisEO-GPU/tutoriel/QAP_CPU/src/QapEval.h @@ -0,0 +1,27 @@ +#ifndef __QapEval +#define __QapEval + +template +class QapEval : public eoEvalFunc +{ + + public: + + QapEval(){} + + ~QapEval(){} + + void operator() (EOT & _sol) { + int cost=0; + for (int i=0; i +template +class QapIncrEval : public moEval{ + + public: + + typedef typename moEval::EOT EOT; + typedef typename moEval::Fitness Fitness; + + + QapIncrEval(){} + + + + ~QapIncrEval(){} + + void operator() (EOT & _sol, Neighbor & _neighbor){ + + int cost=0; + unsigned i,j; + int neighborhoodsize = (n * (n - 1)) / 2; + _neighbor.getIndices(i,j); + cost = _sol.fitness() +compute_delta(n,a,b,_sol,i,j); + _neighbor.fitness(cost); + } + + // specific to the QAP incremental evaluation (part of algorithmic) + int compute_delta(int n, int** a, int** b,EOT & _sol,int i,int j) + { + int d; int k; + d = (a[i][i]-a[j][j])*(b[_sol[j]][_sol[j]]-b[_sol[i]][_sol[i]]) + + (a[i][j]-a[j][i])*(b[_sol[j]][_sol[i]]-b[_sol[i]][_sol[j]]); + for (k = 0; k < n; k = k + 1) + if (k!=i && k!=j) + d = d + (a[k][i]-a[k][j])*(b[_sol[k]][_sol[j]]-b[_sol[k]][_sol[i]]) + + (a[i][k]-a[j][k])*(b[_sol[j]][_sol[k]]-b[_sol[i]][_sol[k]]); + return(d); + } +}; +#endif diff --git a/ParadisEO-GPU/tutoriel/QAP_CPU/src/Solution.h b/ParadisEO-GPU/tutoriel/QAP_CPU/src/Solution.h new file mode 100644 index 000000000..0fb39fb52 --- /dev/null +++ b/ParadisEO-GPU/tutoriel/QAP_CPU/src/Solution.h @@ -0,0 +1,21 @@ +#ifndef _SOLUTION_H_ +#define _SOLUTION_H_ + +#include // PARADISEO + +class Solution:public EO { // PARADISEO + + public: + + int * solution; + + Solution(int _taille){ + solution=new int[_taille]; + } + + ~Solution(){ + delete[] solution; + } +}; + +#endif