Add a new file format in ubqpEval.h
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1953 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
142b69b4f4
commit
8857d9649b
1 changed files with 39 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
<ubqpval.h>
|
<ubqpEval.h>
|
||||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
Sebastien Verel
|
Sebastien Verel
|
||||||
|
|
@ -34,7 +34,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full evaluation Function for unconstrainted binary quadratic programming problem
|
* Full evaluation Function
|
||||||
|
* for unconstrainted binary quadratic programming problem
|
||||||
*/
|
*/
|
||||||
template< class EOT >
|
template< class EOT >
|
||||||
class UbqpEval : public eoEvalFunc<EOT>
|
class UbqpEval : public eoEvalFunc<EOT>
|
||||||
|
|
@ -43,18 +44,24 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* instance is given in the ORLIB format:
|
* instance is given in the ORLIB format (0) or matrix format (1):
|
||||||
* The format of these data files is:
|
* The format of these data files is:
|
||||||
* number of test problem in the serie
|
* number of test problem in the serie
|
||||||
* for each test problem in turn:
|
* for each test problem in turn:
|
||||||
* number of variables (n), number of non-zero elements in the q(i,j) matrix
|
* - Format 0:
|
||||||
* for each non-zero element in turn:
|
* number of variables (n), number of non-zero elements in the q(i,j) matrix
|
||||||
* i, j, q(i,j) {=q(j,i) as the matrix is symmetric}
|
* for each non-zero element in turn:
|
||||||
*
|
* i, j, q(i,j) {=q(j,i) as the matrix is symmetric}
|
||||||
|
* - Format 1:
|
||||||
|
* number of variables (n)
|
||||||
|
* for each line i
|
||||||
|
* for each columm j
|
||||||
|
* q(i,j)
|
||||||
* @param _fileName file name of the instance in ORLIB format
|
* @param _fileName file name of the instance in ORLIB format
|
||||||
|
* @param format id of the file format (0 or 1)
|
||||||
* @param _numInstance the number of the given instance to solve
|
* @param _numInstance the number of the given instance to solve
|
||||||
*/
|
*/
|
||||||
UbqpEval(std::string & _fileName, unsigned int _numInstance = 0) {
|
UbqpEval(std::string & _fileName, unsigned format = 0, unsigned int _numInstance = 0) {
|
||||||
std::fstream file(_fileName.c_str(), std::ios::in);
|
std::fstream file(_fileName.c_str(), std::ios::in);
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
|
@ -65,17 +72,27 @@ public:
|
||||||
unsigned int nbInstances;
|
unsigned int nbInstances;
|
||||||
file >> nbInstances;
|
file >> nbInstances;
|
||||||
|
|
||||||
|
// number of non zero in the matrix
|
||||||
|
unsigned int nbNonZero = 0;
|
||||||
|
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
int v;
|
int v;
|
||||||
|
|
||||||
for(unsigned k = 0; k < _numInstance; k++) {
|
for(unsigned k = 0; k < _numInstance; k++) {
|
||||||
file >> nbVar >> nbNonZero;
|
if (format == 0)
|
||||||
|
file >> nbVar >> nbNonZero ;
|
||||||
|
else
|
||||||
|
file >> nbVar ;
|
||||||
|
|
||||||
for(unsigned kk = 0; kk < nbNonZero; kk++)
|
for(unsigned kk = 0; kk < nbNonZero; kk++)
|
||||||
file >> i >> j >> v;
|
file >> i >> j >> v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the chosen instance
|
// the chosen instance
|
||||||
file >> nbVar >> nbNonZero;
|
if (format == 0)
|
||||||
|
file >> nbVar >> nbNonZero ;
|
||||||
|
else
|
||||||
|
file >> nbVar ;
|
||||||
|
|
||||||
// creation of the matrix
|
// creation of the matrix
|
||||||
Q = new int*[nbVar];
|
Q = new int*[nbVar];
|
||||||
|
|
@ -87,9 +104,18 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the matrix
|
// read the matrix
|
||||||
for(unsigned int k = 0; k < nbNonZero; k++) {
|
if (format == 0) {
|
||||||
file >> i >> j >> v;
|
for(unsigned int k = 0; k < nbNonZero; k++) {
|
||||||
Q[i][j] = v;
|
file >> i >> j >> v;
|
||||||
|
Q[i][j] = v;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(unsigned int i = 0; i < nbVar; i++) {
|
||||||
|
for(unsigned int j = 0; j < nbVar; j++) {
|
||||||
|
file >> v;
|
||||||
|
Q[i][j] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
@ -159,9 +185,6 @@ private:
|
||||||
// number of variable
|
// number of variable
|
||||||
unsigned int nbVar;
|
unsigned int nbVar;
|
||||||
|
|
||||||
// number of non zero in the matrix
|
|
||||||
unsigned int nbNonZero;
|
|
||||||
|
|
||||||
// matrix of flux:
|
// matrix of flux:
|
||||||
// the matrix is put in lower triangular form: for i<j Q[i][j] = 0
|
// the matrix is put in lower triangular form: for i<j Q[i][j] = 0
|
||||||
int ** Q;
|
int ** Q;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue