git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2068 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
boufaras 2011-01-11 16:20:09 +00:00
commit ee10f48842
6 changed files with 129 additions and 0 deletions

View file

@ -0,0 +1 @@
ADD_SUBDIRECTORY(application)

View 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;
}
}

View 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

View 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

View 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