QAP evaluation
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1864 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
403afc9823
commit
7c7b6f331b
4 changed files with 254 additions and 1 deletions
|
|
@ -37,7 +37,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
/**
|
||||
* Continue until a maximum fixed number of neighbor evaluation is reached
|
||||
*
|
||||
* Becareful 1: The number of full evaluations considered is within the local search (not before it)
|
||||
* Becareful 1: The number of neighbor evaluations (for example incremental evaluations) considered is within the local search (not before it)
|
||||
* Becareful 2: Can not be used if the evaluation function is used in parallel
|
||||
*/
|
||||
template< class Neighbor >
|
||||
|
|
|
|||
92
trunk/paradiseo-mo/src/problems/eval/moQAPIncrEval.h
Normal file
92
trunk/paradiseo-mo/src/problems/eval/moQAPIncrEval.h
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
<moQAPIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie Humeau
|
||||
|
||||
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 _moQAPIncrEval_H
|
||||
#define _moQAPIncrEval_H
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <eval/QAPeval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the QAP problem
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moQAPIncrEval : public moEval<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
* @param _qapEval full evaluation of the QAP problem
|
||||
*/
|
||||
moQAPIncrEval(QAPeval<EOT> & _qapEval) {
|
||||
n = _qapEval.getNbVar();
|
||||
A = _qapEval.getA();
|
||||
B = _qapEval.getB();
|
||||
}
|
||||
|
||||
/*
|
||||
* incremental evaluation of the neighbor for the QAP problem
|
||||
* @param _solution the solution to move (permutation)
|
||||
* @param _neighbor the neighbor to consider (of type moSwapNeigbor)
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
int d;
|
||||
int k;
|
||||
|
||||
unsigned i, j;
|
||||
|
||||
_neighbor.getIndices(n, i, j);
|
||||
|
||||
d = (A[i][i]-A[j][j])*(B[_solution[j]][_solution[j]]-B[_solution[i]][_solution[i]]) +
|
||||
(A[i][j]-A[j][i])*(B[_solution[j]][_solution[i]]-B[_solution[i]][_solution[j]]);
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
if (k != i && k != j)
|
||||
d = d + (A[k][i]-A[k][j])*(B[_solution[k]][_solution[j]]-B[_solution[k]][_solution[i]]) +
|
||||
(A[i][k]-A[j][k])*(B[_solution[j]][_solution[k]]-B[_solution[i]][_solution[k]]);
|
||||
|
||||
_neighbor.fitness(_solution.fitness() + d);
|
||||
}
|
||||
|
||||
private:
|
||||
// number of variables
|
||||
int n;
|
||||
|
||||
// matrix A
|
||||
int ** A;
|
||||
|
||||
// matrix B
|
||||
int ** B;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -75,6 +75,16 @@ public:
|
|||
indices.second = _second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the two indexes to swap
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void getIndices(unsigned int & _first, unsigned int & _second) {
|
||||
_first = indices.first;
|
||||
_second = indices.second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the Neighbor
|
||||
*/
|
||||
|
|
|
|||
151
trunk/problems/eval/qapEval.h
Normal file
151
trunk/problems/eval/qapEval.h
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
<qapEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
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 _qapEval_h
|
||||
#define _qapEval_h
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
|
||||
/**
|
||||
* Full evaluation Function for QAP problem
|
||||
*/
|
||||
template< class EOT >
|
||||
class QAPeval : public eoEvalFunc<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
/*
|
||||
* Constructor from instance file
|
||||
*
|
||||
* @param _fileData the file name which contains the instance of QAP from QAPlib
|
||||
*/
|
||||
QAPeval(string & _fileData) {
|
||||
fstream file(_fileData.c_str(), ios::in);
|
||||
|
||||
if (!file) {
|
||||
string str = "QAPeval: Could not open file [" + _fileData + "]." ;
|
||||
throw runtime_error(str);
|
||||
}
|
||||
|
||||
unsigned i, j;
|
||||
|
||||
file >> n;
|
||||
A = new int *[n];
|
||||
B = new int *[n];
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
A[i] = new int[n];
|
||||
for(j = 0; j < n; j++) {
|
||||
file >> A[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < n; i++) {
|
||||
B[i] = new int[n];
|
||||
for(j = 0; j < n; j++)
|
||||
file >> B[i][j];
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* default destructor
|
||||
*/
|
||||
~QAPeval() {
|
||||
unsigned i;
|
||||
|
||||
if (A != NULL) {
|
||||
for(i = 0; i < n; i++)
|
||||
delete[] A[i];
|
||||
delete[] A;
|
||||
}
|
||||
|
||||
if (B != NULL) {
|
||||
for(i = 0; i < n; i++)
|
||||
delete[] B[i];
|
||||
delete[] B;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* full evaluation for QAP
|
||||
*
|
||||
* @param _solution the solution to evaluate
|
||||
*/
|
||||
void operator()(EOT & _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]];
|
||||
|
||||
_solution.fitness(cost);
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the matrix A
|
||||
*
|
||||
* @return matrix A
|
||||
*/
|
||||
int** getA() {
|
||||
return A;
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the matrix B
|
||||
*
|
||||
* @return matrix B
|
||||
*/
|
||||
int** getB() {
|
||||
return B;
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the number of objects, of variables
|
||||
*
|
||||
* @return number of objects
|
||||
*/
|
||||
int getNbVar() {
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
// number of variables
|
||||
int n;
|
||||
|
||||
// matrix A
|
||||
int ** A;
|
||||
|
||||
// matrix B
|
||||
int ** B;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue