git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2068 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
d9916bec0e
commit
ee10f48842
6 changed files with 129 additions and 0 deletions
1
ParadisEO-GPU/tutoriel/QAP_CPU/CMakeLists.txt
Normal file
1
ParadisEO-GPU/tutoriel/QAP_CPU/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ADD_SUBDIRECTORY(application)
|
||||||
0
ParadisEO-GPU/tutoriel/QAP_CPU/src/Init.h
Normal file
0
ParadisEO-GPU/tutoriel/QAP_CPU/src/Init.h
Normal file
37
ParadisEO-GPU/tutoriel/QAP_CPU/src/Problem.h
Normal file
37
ParadisEO-GPU/tutoriel/QAP_CPU/src/Problem.h
Normal file
|
|
@ -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<n;i++)
|
||||||
|
a[i]=new int[n];
|
||||||
|
b=new int*[n];
|
||||||
|
for(int i=0;i<n;i++)
|
||||||
|
b[i]=new int[n];
|
||||||
|
for (i=0;i<n;i++)
|
||||||
|
for(j=0;j<n;j++)
|
||||||
|
fscanf(f,"%d",&a[i][j]);
|
||||||
|
for (i=0;i<n;i++)
|
||||||
|
for(j=0;j<n;j++)
|
||||||
|
fscanf(f,"%d",&b[i][j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class EOT>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
27
ParadisEO-GPU/tutoriel/QAP_CPU/src/QapEval.h
Normal file
27
ParadisEO-GPU/tutoriel/QAP_CPU/src/QapEval.h
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef __QapEval
|
||||||
|
#define __QapEval
|
||||||
|
|
||||||
|
template <class EOT>
|
||||||
|
class QapEval : public eoEvalFunc<EOT>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
QapEval(){}
|
||||||
|
|
||||||
|
~QapEval(){}
|
||||||
|
|
||||||
|
void operator() (EOT & _sol) {
|
||||||
|
int cost=0;
|
||||||
|
for (int i=0; i<n; i++)
|
||||||
|
std::cout<<_sol[i]<<" ";
|
||||||
|
std::cout<<std::endl;
|
||||||
|
for (int i=0; i<n; i++)
|
||||||
|
for (int j=0; j<n; j++)
|
||||||
|
cost += a[i][j] * b[_sol[i]][_sol[j]];
|
||||||
|
_sol.fitness(cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
43
ParadisEO-GPU/tutoriel/QAP_CPU/src/QapIncrEval.h
Normal file
43
ParadisEO-GPU/tutoriel/QAP_CPU/src/QapIncrEval.h
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef __QapIncrEval
|
||||||
|
#define __QapIncrEval
|
||||||
|
|
||||||
|
#include <eval/moEval.h>
|
||||||
|
template <class Neighbor>
|
||||||
|
class QapIncrEval : public moEval<Neighbor>{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename moEval<Neighbor>::EOT EOT;
|
||||||
|
typedef typename moEval<Neighbor>::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
|
||||||
21
ParadisEO-GPU/tutoriel/QAP_CPU/src/Solution.h
Normal file
21
ParadisEO-GPU/tutoriel/QAP_CPU/src/Solution.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef _SOLUTION_H_
|
||||||
|
#define _SOLUTION_H_
|
||||||
|
|
||||||
|
#include <eo> // PARADISEO
|
||||||
|
|
||||||
|
class Solution:public EO <eoMinimizingFitness>{ // PARADISEO
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
int * solution;
|
||||||
|
|
||||||
|
Solution(int _taille){
|
||||||
|
solution=new int[_taille];
|
||||||
|
}
|
||||||
|
|
||||||
|
~Solution(){
|
||||||
|
delete[] solution;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue