GPU -> branches
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2178 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
842e7f83ad
commit
a786ffb8dc
158 changed files with 0 additions and 0 deletions
178
branches/ParadisEO-GPU/src/problems/data/PPPData.h
Normal file
178
branches/ParadisEO-GPU/src/problems/data/PPPData.h
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
<PPPData.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Boufaras Karima, Thé Van Luong
|
||||
|
||||
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 _PPPData_H_
|
||||
#define _PPPData_H_
|
||||
|
||||
#include <memory/moCudaSpecificData.h>
|
||||
|
||||
template<class ElemType>
|
||||
class PPPData: public moCudaSpecificData {
|
||||
|
||||
public:
|
||||
|
||||
using moCudaSpecificData::cudaObject;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
|
||||
PPPData() :
|
||||
moCudaSpecificData() {
|
||||
|
||||
(*this).load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor by copy
|
||||
* @param _pppData the specific data of PPP
|
||||
*/
|
||||
|
||||
PPPData(const PPPData & _pppData) {
|
||||
|
||||
a_h = new int[Md * Nd];
|
||||
H_h = new int[Nd + 1];
|
||||
|
||||
for (int i = 0; i < Md; i++)
|
||||
for (int j = 0; j < Nd; j++) {
|
||||
a_h[i * Nd + j] = _pppData.a_h[i * Nd + j];
|
||||
}
|
||||
for (int k = 0; k <= Nd; k++) {
|
||||
H_h[k] = _pppData.H_h[k];
|
||||
}
|
||||
|
||||
cudaObject.memCopy(a_d, a_h, Nd * Md);
|
||||
cudaObject.memCopy(H_d, H_h, Nd + 1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignement operator
|
||||
* @param _pppData the specific data of PPP
|
||||
* @return a PPP Data
|
||||
*/
|
||||
|
||||
PPPData & operator=(const PPPData & _pppData) {
|
||||
|
||||
a_h = new int[Md * Nd];
|
||||
H_h = new int[Nd + 1];
|
||||
for (int i = 0; i < Md; i++)
|
||||
for (int j = 0; j < Nd; j++) {
|
||||
a_h[i * Nd + j] = _pppData.a_h[i * Nd + j];
|
||||
}
|
||||
for (int k = 0; k <= Nd; k++) {
|
||||
H_h[k] = _pppData.H_h[k];
|
||||
}
|
||||
|
||||
cudaObject.memCopy(a_d, a_h, Nd * Md);
|
||||
cudaObject.memCopy(H_d, H_h, Nd + 1);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~PPPData() {
|
||||
cudaObject.memFree(a_d);
|
||||
cudaObject.memFree(H_d);
|
||||
delete[] a_h;
|
||||
delete[] H_h;
|
||||
}
|
||||
|
||||
/*
|
||||
*Load PPP data
|
||||
*/
|
||||
|
||||
void load(char * _fileName) {
|
||||
}
|
||||
|
||||
void load() {
|
||||
|
||||
int *v = new int[Nd];
|
||||
int *s = new int[Md];
|
||||
a_h = new int[Md * Nd];
|
||||
H_h = new int[Nd + 1];
|
||||
for (int i = 0; i < Md; i++) {
|
||||
for (int j = 0; j < Nd; j++) {
|
||||
if (rng.rand() % 2)
|
||||
a_h[i * Nd + j] = 1;
|
||||
else
|
||||
a_h[i * Nd + j] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Nd; i++) {
|
||||
if (rng.rand() % 2)
|
||||
v[i] = 1;
|
||||
else
|
||||
v[i] = -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Md; i++) {
|
||||
s[i] = 0;
|
||||
for (int j = 0; j < Nd; j++)
|
||||
s[i] += a_h[i * Nd + j] * v[j];
|
||||
if (s[i] < 0) {
|
||||
for (int k = 0; k < Nd; k++)
|
||||
a_h[i * Nd + k] = -a_h[i * Nd + k];
|
||||
s[i] = -s[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= Nd; i++)
|
||||
H_h[i] = 0;
|
||||
for (int i = 0; i < Md; i++)
|
||||
H_h[s[i]]++;
|
||||
|
||||
//Allocate and copy QAP data from CPU memory to GPU global memory
|
||||
cudaObject.memCopy(a_d, a_h, Nd * Md);
|
||||
cudaObject.memCopy(H_d, H_h, Nd + 1);
|
||||
|
||||
delete[] v;
|
||||
delete[] s;
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ElemType* a_h;
|
||||
ElemType* H_h;
|
||||
ElemType* a_d;
|
||||
ElemType* H_d;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
167
branches/ParadisEO-GPU/src/problems/data/QAPData.h
Normal file
167
branches/ParadisEO-GPU/src/problems/data/QAPData.h
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
<QAPData.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Boufaras Karima, Thé Van Luong
|
||||
|
||||
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 _QAPData_H_
|
||||
#define _QAPData_H_
|
||||
|
||||
#include <memory/moCudaSpecificData.h>
|
||||
|
||||
template<class ElemType>
|
||||
class QAPData: public moCudaSpecificData {
|
||||
|
||||
public:
|
||||
|
||||
using moCudaSpecificData::sizeData;
|
||||
using moCudaSpecificData::cudaObject;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
|
||||
QAPData() :
|
||||
moCudaSpecificData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _fileName the data file name
|
||||
*/
|
||||
|
||||
QAPData(char* _fileName) {
|
||||
|
||||
(*this).load(_fileName);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor by copy
|
||||
* @param _qapData the specific data of QAP
|
||||
*/
|
||||
|
||||
QAPData(const QAPData & _qapData) {
|
||||
|
||||
sizeData = _qapData.sizeData;
|
||||
a_h = new int[sizeData * sizeData];
|
||||
b_h = new int[sizeData * sizeData];
|
||||
for (int i = 0; i < sizeData; i++)
|
||||
|
||||
for (int j = 0; j < sizeData; j++) {
|
||||
|
||||
a_h[i * sizeData + j] = _qapData.a_h[i * sizeData + j];
|
||||
b_h[i * sizeData + j] = _qapData.b_h[i * sizeData + j];
|
||||
|
||||
}
|
||||
|
||||
cudaObject.memCopy(a_d, a_h, sizeData * sizeData);
|
||||
cudaObject.memCopy(b_d, b_h, sizeData * sizeData);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignement operator
|
||||
* @param _qapData the specific data of QAP
|
||||
* @return a QAP Data
|
||||
*/
|
||||
|
||||
QAPData & operator=(const QAPData & _qapData) {
|
||||
|
||||
sizeData = _qapData.sizeData;
|
||||
a_h = new int[sizeData * sizeData];
|
||||
b_h = new int[sizeData * sizeData];
|
||||
|
||||
for (int i = 0; i < sizeData; i++)
|
||||
for (int j = 0; j < sizeData; j++) {
|
||||
|
||||
a_h[i * sizeData + j] = _qapData.a_h[i * sizeData + j];
|
||||
b_h[i * sizeData + j] = _qapData.b_h[i * sizeData + j];
|
||||
|
||||
}
|
||||
cudaObject.memCopy(a_d, a_h, sizeData * sizeData);
|
||||
cudaObject.memCopy(b_d, b_h, sizeData * sizeData);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~QAPData() {
|
||||
cudaObject.memFree(a_d);
|
||||
cudaObject.memFree(b_d);
|
||||
delete[] a_h;
|
||||
delete[] b_h;
|
||||
}
|
||||
|
||||
/*
|
||||
*Load QAP data from file name
|
||||
*@param _fileName the data file name to load
|
||||
*/
|
||||
|
||||
void load(char* _fileName) {
|
||||
|
||||
fstream file(_fileName, ios::in);
|
||||
if (!file) {
|
||||
|
||||
string str = "QAPData: Could not open file [" + (string) _fileName
|
||||
+ "].";
|
||||
throw runtime_error(str);
|
||||
}
|
||||
|
||||
unsigned i, j;
|
||||
file >> sizeData;
|
||||
a_h = new ElemType[sizeData * sizeData];
|
||||
b_h = new ElemType[sizeData * sizeData];
|
||||
|
||||
for (i = 0; i < sizeData; i++)
|
||||
for (j = 0; j < sizeData; j++)
|
||||
file >> a_h[i * sizeData + j];
|
||||
for (i = 0; i < sizeData; i++)
|
||||
for (j = 0; j < sizeData; j++)
|
||||
file >> b_h[i * sizeData + j];
|
||||
|
||||
//Allocate and copy QAP data from CPU memory to GPU global memory
|
||||
cudaObject.memCopy(a_d, a_h, sizeData * sizeData);
|
||||
cudaObject.memCopy(b_d, b_h, sizeData * sizeData);
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
ElemType* a_h;
|
||||
ElemType* b_h;
|
||||
ElemType* a_d;
|
||||
ElemType* b_d;
|
||||
|
||||
};
|
||||
#endif
|
||||
79
branches/ParadisEO-GPU/src/problems/eval/EvalOneMax.h
Normal file
79
branches/ParadisEO-GPU/src/problems/eval/EvalOneMax.h
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
<EvalOneMax.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Karima Boufaras, Thé Van LUONG
|
||||
|
||||
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 __EvalOneMax
|
||||
#define __EvalOneMax
|
||||
|
||||
/**
|
||||
* Full Evaluation of the solution
|
||||
*/
|
||||
|
||||
template<class EOT>
|
||||
class EvalOneMax: public eoEvalFunc<EOT> {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
EvalOneMax() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~EvalOneMax(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Full evaluation of the solution
|
||||
* @param _bitVector the solution to evaluate
|
||||
*/
|
||||
|
||||
void operator()(EOT & _bitVector) {
|
||||
|
||||
unsigned sum = 0;
|
||||
|
||||
for (unsigned i = 0; i < _bitVector.size(); i++)
|
||||
sum += _bitVector[i];
|
||||
|
||||
//set the solution fitness
|
||||
_bitVector.fitness(sum);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
90
branches/ParadisEO-GPU/src/problems/eval/OneMaxIncrEval.h
Normal file
90
branches/ParadisEO-GPU/src/problems/eval/OneMaxIncrEval.h
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
<OneMaxIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Karima Boufaras, Thé Van LUONG
|
||||
|
||||
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 __OneMaxIncrEval_H
|
||||
#define __OneMaxIncrEval_H
|
||||
|
||||
#include <eval/moCudaEvalFunc.h>
|
||||
|
||||
/**
|
||||
* Incremental Evaluation of OneMax
|
||||
*/
|
||||
|
||||
template<class Neighbor>
|
||||
class OneMaxIncrEval: public moCudaEvalFunc<Neighbor> {
|
||||
|
||||
public:
|
||||
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
OneMaxIncrEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~OneMaxIncrEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Incremental evaluation of the solution(function inline can be called from host or device)
|
||||
* @param _bitVector the solution to evaluate
|
||||
* @param _fitness the fitness of the current solution
|
||||
* @param _index the index of solution neighbor
|
||||
*/
|
||||
|
||||
inline __host__ __device__ Fitness operator() (EOT & _bitVector,Fitness _fitness, unsigned int * _index) {
|
||||
|
||||
Fitness tmp;
|
||||
|
||||
if (_bitVector[_index[0]] == 0)
|
||||
|
||||
tmp= _fitness+1;
|
||||
|
||||
else
|
||||
|
||||
tmp= _fitness-1;
|
||||
|
||||
return tmp;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
104
branches/ParadisEO-GPU/src/problems/eval/PPPEval.h
Normal file
104
branches/ParadisEO-GPU/src/problems/eval/PPPEval.h
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
<PPPEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Boufaras Karima, Thé Van Luong
|
||||
|
||||
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 __PPPEval
|
||||
#define __PPPEval
|
||||
|
||||
#include <problems/data/PPPData.h>
|
||||
|
||||
template<class EOT, class ElemType = typename EOT::ElemType>
|
||||
class PPPEval: public eoEvalFunc<EOT> {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _qapData the specific data problem useful to evalute solution(flow & distance matrices of QAP problem)
|
||||
*/
|
||||
|
||||
PPPEval(PPPData<ElemType> & _pppData) {
|
||||
pppData = _pppData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~PPPEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Full evaluation of the solution
|
||||
* @param _sol the solution to evaluate
|
||||
*/
|
||||
|
||||
void operator()(EOT & _sol) {
|
||||
|
||||
int *H;
|
||||
int *S;
|
||||
int tmp_1=0;
|
||||
int tmp_2=0;
|
||||
|
||||
H=new int[Nd+1];
|
||||
S=new int[Md];
|
||||
|
||||
for (int i=0; i<Md; i++){
|
||||
S[i]=0;
|
||||
for (int j=0; j<Nd; j++){
|
||||
S[i]+=pppData.a_h[i*Nd+j]*_sol[j];
|
||||
}
|
||||
|
||||
tmp_1+=abs(S[i])-S[i];
|
||||
if(S[i]>=0)
|
||||
H[S[i]]++;
|
||||
}
|
||||
|
||||
for (int j=0; j<=Nd; j++){
|
||||
tmp_2+=abs(pppData.H_h[j]-H[j]);
|
||||
}
|
||||
|
||||
_sol.fitness(ca*tmp_1+cb*tmp_2);
|
||||
|
||||
delete[] H;
|
||||
delete[] S;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
PPPData<ElemType> pppData;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
105
branches/ParadisEO-GPU/src/problems/eval/PPPIncrEval.h
Normal file
105
branches/ParadisEO-GPU/src/problems/eval/PPPIncrEval.h
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
<PPPIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Karima Boufaras, Thé Van LUONG
|
||||
|
||||
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 __PPPIncrEval_H
|
||||
#define __PPPIncrEval_H
|
||||
|
||||
#include <eval/moCudaEvalFunc.h>
|
||||
|
||||
/**
|
||||
* Incremental Evaluation of PPP
|
||||
*/
|
||||
|
||||
template<class Neighbor>
|
||||
class PPPIncrEval: public moCudaEvalFunc<Neighbor> {
|
||||
|
||||
public:
|
||||
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
PPPIncrEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~PPPIncrEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* functor of incremental evaluation of the solution(function inline can be called from host or device)
|
||||
* @param _sol the solution to evaluate
|
||||
* @param _fitness the fitness of the current solution
|
||||
* @param _index the set of information to compute fitness neighbor
|
||||
*/
|
||||
|
||||
inline __host__ __device__ Fitness operator() (EOT & _sol,Fitness _fitness, unsigned int *_index) {
|
||||
|
||||
int H[Nd+1];
|
||||
int S[Md];
|
||||
int tmp_1=0;
|
||||
int tmp_2=0;
|
||||
|
||||
for (int i=0; i<Md; i++){
|
||||
S[i]=0;
|
||||
for (int j=0; j<Nd; j++){
|
||||
if(_sol[j])
|
||||
S[i]=S[i]+dev_a[i*Nd+j];
|
||||
else
|
||||
S[i]=S[i]-dev_a[i*Nd+j];
|
||||
}
|
||||
|
||||
tmp_1=tmp_1+abs(S[i])-S[i];
|
||||
if(S[i]>=0)
|
||||
H[S[i]]=H[S[i]]+1;
|
||||
}
|
||||
|
||||
for (int j=0; j<=Nd; j++){
|
||||
tmp_2=tmp_2+abs(dev_h[j]-H[j]);
|
||||
}
|
||||
|
||||
return ca*tmp_1+cb*tmp_2;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
84
branches/ParadisEO-GPU/src/problems/eval/QAPEval.h
Normal file
84
branches/ParadisEO-GPU/src/problems/eval/QAPEval.h
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
<QAPEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Boufaras Karima, Thé Van Luong
|
||||
|
||||
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 __QAPEval
|
||||
#define __QAPEval
|
||||
|
||||
#include <problems/data/QAPData.h>
|
||||
|
||||
template<class EOT, class ElemType = typename EOT::ElemType>
|
||||
class QAPEval: public eoEvalFunc<EOT> {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _qapData the specific data problem useful to evalute solution(flow & distance matrices of QAP problem)
|
||||
*/
|
||||
|
||||
QAPEval(QAPData<ElemType> & _qapData) {
|
||||
qapData = _qapData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~QAPEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Full evaluation of the solution
|
||||
* @param _sol the solution to evaluate
|
||||
*/
|
||||
|
||||
void operator()(EOT & _sol) {
|
||||
int cost = 0;
|
||||
unsigned int size = qapData.getSize();
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
for (unsigned int j = 0; j < size; j++) {
|
||||
cost += qapData.a_h[i * size + j] * qapData.b_h[_sol[i] * size
|
||||
+ _sol[j]];
|
||||
}
|
||||
|
||||
_sol.fitness(cost);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
QAPData<ElemType> qapData;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
121
branches/ParadisEO-GPU/src/problems/eval/QAPIncrEval.h
Normal file
121
branches/ParadisEO-GPU/src/problems/eval/QAPIncrEval.h
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
<QAPIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Karima Boufaras, Thé Van LUONG
|
||||
|
||||
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 __QAPIncrEval_H
|
||||
#define __QAPIncrEval_H
|
||||
|
||||
#include <eval/moCudaEvalFunc.h>
|
||||
|
||||
/**
|
||||
* Incremental Evaluation of QAP
|
||||
*/
|
||||
|
||||
template<class Neighbor>
|
||||
class QAPIncrEval: public moCudaEvalFunc<Neighbor> {
|
||||
|
||||
public:
|
||||
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
QAPIncrEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
|
||||
~QAPIncrEval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* functor of incremental evaluation of the solution(function inline can be called from host or device)
|
||||
* @param _sol the solution to evaluate
|
||||
* @param _fitness the fitness of the current solution
|
||||
* @param _index the set of information to compute fitness neighbor
|
||||
*/
|
||||
|
||||
inline __host__ __device__ Fitness operator() (EOT & _sol,Fitness _fitness, unsigned int *_index) {
|
||||
|
||||
Fitness tmp;
|
||||
|
||||
/**
|
||||
* dev_a & dev_b are global device variable, data specific to QAP problem (flow & distance matices)
|
||||
* _index[0] the first position of swap
|
||||
* _index[1] the second position of swap
|
||||
* _index[2] the solution size
|
||||
* _index[3] the id of neighbor
|
||||
*/
|
||||
|
||||
tmp=_fitness+compute_delta(dev_a,dev_b,_sol,_index[0],_index[1],_index[2],_index[3]);
|
||||
return tmp;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* compute the new fitness of the solution after permutation of pair(i,j)(function inline called from host device)
|
||||
* @param _a the flow matrix of size*size (specific data of QAP problem must be declared as global device variable)
|
||||
* @param _b the distance matrix of size*size (specific data of QAP problem must be declared as global device variable)
|
||||
* @param _sol the solution to evaluate
|
||||
* @param _i the first position of swap
|
||||
* @param _j the second position of swap
|
||||
* @param _size the id of neighbor
|
||||
* @param _id the neighbor identifier
|
||||
*/
|
||||
|
||||
inline __host__ __device__ int compute_delta(int * _a,int * _b,EOT & _sol, int _i, int _j,int _size, int _id){
|
||||
|
||||
int d;
|
||||
int k;
|
||||
|
||||
d = (_a[_i*_size+_i]-_a[_j*_size+_j])*(_b[_sol[_j+_id*_size]*_size+_sol[_j+_id*_size]]-_b[_sol[_i+_id*_size]*_size+_sol[_i+_id*_size]]) +
|
||||
(_a[_i*_size+_j]-_a[_j*_size+_i])*(_b[_sol[_j+_id*_size]*_size+_sol[_i+_id*_size]]-_b[_sol[_i+_id*_size]*_size+_sol[_j+_id*_size]]);
|
||||
|
||||
|
||||
for (k = 0; k < _size; k=k+1)
|
||||
if (k!=_i && k!=_j)
|
||||
|
||||
d = d + (_a[k*_size+_i]-_a[k*_size+_j])*(_b[_sol[k+_id*_size]*_size+_sol[_j+_id*_size]]-_b[_sol[k+_id*_size]*_size+_sol[_i+_id*_size]]) +
|
||||
(_a[_i*_size+k]-_a[_j*_size+k])*(_b[_sol[_j+_id*_size]*_size+_sol[k+_id*_size]]-_b[_sol[_i+_id*_size]*_size+_sol[k+_id*_size]]);
|
||||
|
||||
return(d);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
103
branches/ParadisEO-GPU/src/problems/neighborhood/PPPNeighbor.h
Normal file
103
branches/ParadisEO-GPU/src/problems/neighborhood/PPPNeighbor.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
<PPPNeighbor.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Boufaras Karima, Thé Van Luong
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
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".
|
||||
|
||||
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 _PPPNeighbor_h
|
||||
#define _PPPNeighbor_h
|
||||
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
#include <neighborhood/moIndexSwapNeighbor.h>
|
||||
|
||||
/**
|
||||
* PPP Neighbor
|
||||
*/
|
||||
|
||||
template<class EOT, class Fitness = typename EOT::Fitness>
|
||||
class PPPNeighbor: public moBackableNeighbor<EOT> ,
|
||||
public moIndexSwapNeighbor<EOT> {
|
||||
public:
|
||||
|
||||
using moIndexSwapNeighbor<EOT>::indices;
|
||||
using moIndexSwapNeighbor<EOT>::Kswap;
|
||||
using moIndexSwapNeighbor<EOT>::size;
|
||||
|
||||
/**
|
||||
*Default Constructor
|
||||
*/
|
||||
|
||||
PPPNeighbor() :
|
||||
moIndexSwapNeighbor<EOT> () {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _Kflip the number of bit to flip
|
||||
*/
|
||||
|
||||
PPPNeighbor(unsigned int _Kflip) :
|
||||
moIndexSwapNeighbor<EOT> (_Kflip) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the K-Flip in solution
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
|
||||
virtual void move(EOT& _solution) {
|
||||
size = _solution.size();
|
||||
if (!Kswap) {
|
||||
_solution[indices[Kswap]] = -_solution[indices[Kswap]];
|
||||
} else {
|
||||
for (unsigned int i = 0; i <= Kswap; i++) {
|
||||
_solution[indices[i]] = -_solution[indices[i]];
|
||||
}
|
||||
}
|
||||
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* apply the K-Flip to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
move(_solution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class name.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "PPPNeighbor";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
109
branches/ParadisEO-GPU/src/problems/types/PPPSolution.h
Normal file
109
branches/ParadisEO-GPU/src/problems/types/PPPSolution.h
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
<PPPSolution.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Karima Boufaras, Thé Van LUONG
|
||||
|
||||
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 _PPPSolution_H_
|
||||
#define _PPPSolution_H_
|
||||
|
||||
#include <cudaType/moCudaVector.h>
|
||||
|
||||
/**
|
||||
* Implementation of PPP vector representation on CUDA.
|
||||
*/
|
||||
|
||||
template<class Fitness>
|
||||
|
||||
class PPPSolution: public moCudaVector<int, Fitness> {
|
||||
|
||||
public:
|
||||
|
||||
using moCudaVector<int, Fitness>::vect;
|
||||
using moCudaVector<int, Fitness>::N;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
||||
PPPSolution() :
|
||||
moCudaVector<int, Fitness> () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*Constructor.
|
||||
*@param _size The neighborhood size.
|
||||
*/
|
||||
|
||||
PPPSolution(unsigned _size) {
|
||||
|
||||
N = _size;
|
||||
|
||||
vect = new int[_size];
|
||||
|
||||
create();
|
||||
}
|
||||
|
||||
/**
|
||||
*Assignment operator
|
||||
*@param _vector The vector passed to the function determine the new content.
|
||||
*@return a new vector.
|
||||
*/
|
||||
|
||||
PPPSolution& operator=(const PPPSolution & _vector) {
|
||||
|
||||
N = _vector.N;
|
||||
vect = new int[N];
|
||||
for (unsigned i = 0; i < N; i++)
|
||||
vect[i] = _vector.vect[i];
|
||||
fitness(_vector.fitness());
|
||||
return (*this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*Initializer of random PPP vector.
|
||||
*/
|
||||
void create() {
|
||||
|
||||
for (int i = 0; i <N; i++){
|
||||
if((rng.rand()%2)==0)
|
||||
vect[i] = -1;
|
||||
else
|
||||
vect[i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue