diff --git a/mo/src/continuator/moVectorMonitor.h b/mo/src/continuator/moVectorMonitor.h index cd2b6c4e0..853096448 100644 --- a/mo/src/continuator/moVectorMonitor.h +++ b/mo/src/continuator/moVectorMonitor.h @@ -53,7 +53,7 @@ public: * Constructor * @param _param the parameter of type double to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), intLongParam(NULL), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), intLongParam(NULL), intLongLongParam(NULL), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -63,7 +63,7 @@ public: * Default Constructor * @param _param the parameter of type unsigned int to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), intLongParam(NULL), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), intLongParam(NULL), intLongLongParam(NULL), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -73,7 +73,17 @@ public: * Default Constructor * @param _param the parameter of type unsigned int to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(&_param), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(&_param), intLongLongParam(NULL), eotParam(NULL) + { + // precision of the output by default + precisionOutput = std::cout.precision(); + } + + /** + * Default Constructor + * @param _param the parameter of type unsigned int to save in the vector + */ + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), intLongLongParam(&_param), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -83,7 +93,18 @@ public: * Default Constructor * @param _param the parameter of type EOT to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), eotParam(&_param) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), intLongLongParam(NULL), eotParam(&_param) + { + // precision of the output by default + precisionOutput = std::cout.precision(); + } + + /** + * Default Constructor + * @param _param the parameter of type eoScalarFitness to save in the vector + */ + template + moVectorMonitor(eoValueParam > & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), intLongLongParam(& (eoValueParam&)_param), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -94,7 +115,7 @@ public: * @param _param the parameter of type eoScalarFitness to save in the vector */ template - moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), intLongParam(NULL), eotParam(NULL) + moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), intLongParam(NULL), intLongLongParam(NULL), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -105,7 +126,7 @@ public: * @param _param unvalid Parameter */ template - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), intLongLongParam(NULL), eotParam(NULL) { std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl; } @@ -133,8 +154,11 @@ public: else if (intLongParam != NULL) valueVec.push_back((double) intLongParam->value()); - else - eotVec.push_back(eotParam->value()); + else + if (intLongLongParam != NULL) + valueVec.push_back((double) intLongLongParam->value()); + else + eotVec.push_back(eotParam->value()); return *this ; } @@ -189,7 +213,10 @@ public: if (intLongParam != NULL) return intLongParam->longName(); else - return eotParam->longName(); + if (intLongLongParam != NULL) + return intLongLongParam->longName(); + else + return eotParam->longName(); } /** @@ -259,6 +286,7 @@ protected: eoValueParam * doubleParam ; eoValueParam * intParam ; eoValueParam * intLongParam ; + eoValueParam * intLongLongParam ; eoValueParam * eotParam ; std::vector valueVec; diff --git a/mo/src/problems/eval/moQAPIncrEval.h b/mo/src/problems/eval/moQAPIncrEval.h index 5c47623d9..16494e4b0 100644 --- a/mo/src/problems/eval/moQAPIncrEval.h +++ b/mo/src/problems/eval/moQAPIncrEval.h @@ -35,8 +35,10 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Incremental evaluation Function for the QAP problem + * + * ElemType is the type of elements in the matrix. This type must be signed and not unsigned. */ -template< class Neighbor > +template< class Neighbor, typename ElemType = long int > class moQAPIncrEval : public moEval { public: @@ -46,7 +48,7 @@ public: * default constructor * @param _qapEval full evaluation of the QAP problem */ - moQAPIncrEval(QAPeval & _qapEval) { + moQAPIncrEval(QAPeval & _qapEval) { n = _qapEval.getNbVar(); A = _qapEval.getA(); B = _qapEval.getB(); @@ -58,7 +60,7 @@ public: * @param _neighbor the neighbor to consider (of type moSwapNeigbor) */ virtual void operator()(EOT & _solution, Neighbor & _neighbor) { - int d; + ElemType d; int k; unsigned i = _neighbor.first(); @@ -81,10 +83,10 @@ private: int n; // matrix A - int ** A; + ElemType ** A; // matrix B - int ** B; + ElemType ** B; }; diff --git a/problems/eval/nkLandscapesEval.h b/problems/eval/nkLandscapesEval.h index 070fb1b43..f2e243021 100644 --- a/problems/eval/nkLandscapesEval.h +++ b/problems/eval/nkLandscapesEval.h @@ -71,6 +71,8 @@ public: consecutiveTables(); else randomTables(); + + generateTables(); }; /** @@ -365,6 +367,20 @@ protected: } } + /** + * To generate the tables: + * The component function is random + * each contribution is independent from the others ones + * and drawn from the distribution given by contribution() + * + */ + virtual void generateTables() { + for(int i = 0; i < N; i++) { + for(int j = 0; j < (1<<(K+1)); j++) + tables[i][j] = contribution(); + } + } + /** * To generate a contribution in the table f_i * @@ -386,10 +402,6 @@ protected: for(int i = 0; i < N; i++) { // random links to the bit choose(i, tabTirage); - - // table of contribution with random numbers from [0,1) - for(int j = 0; j < (1<<(K+1)); j++) - tables[i][j] = contribution(); } } @@ -403,10 +415,6 @@ protected: for(int i = 0; i < N; i++) { // consecutive link to bit i consecutiveLinks(i); - - // table of contribution with random numbers from [0,1) - for(int j = 0; j < (1<<(K+1)); j++) - tables[i][j] = contribution(); } } diff --git a/problems/eval/nkpLandscapesEval.h b/problems/eval/nkpLandscapesEval.h index 9be4f47e2..5f2a5e932 100644 --- a/problems/eval/nkpLandscapesEval.h +++ b/problems/eval/nkpLandscapesEval.h @@ -53,6 +53,7 @@ public: using nkLandscapesEval::loadTables; using nkLandscapesEval::consecutiveTables; using nkLandscapesEval::randomTables; + using nkLandscapesEval::generateTables; // parameter p : probability to have the contribution to zero, otherwise random number from [0,1) double p; @@ -79,6 +80,8 @@ public: consecutiveTables(); else randomTables(); + + generateTables(); } /** diff --git a/problems/eval/nkqLandscapesEval.h b/problems/eval/nkqLandscapesEval.h index 720143566..d40bf3955 100644 --- a/problems/eval/nkqLandscapesEval.h +++ b/problems/eval/nkqLandscapesEval.h @@ -53,6 +53,7 @@ public: using nkLandscapesEval::loadTables; using nkLandscapesEval::consecutiveTables; using nkLandscapesEval::randomTables; + using nkLandscapesEval::generateTables; // parameter q : number of different integer values in the table: [0..q[ unsigned q; @@ -78,6 +79,8 @@ public: consecutiveTables(); else randomTables(); + + generateTables(); } /** diff --git a/problems/eval/qapEval.h b/problems/eval/qapEval.h index 3236dae60..40d763c9f 100644 --- a/problems/eval/qapEval.h +++ b/problems/eval/qapEval.h @@ -34,11 +34,14 @@ Contact: paradiseo-help@lists.gforge.inria.fr /** * Full evaluation Function for QAP problem + * + * ElemType is the type of elements in the matrix. This type must be signed and not unsigned. */ -template< class EOT > +template< class EOT, typename ElemType = long int > class QAPeval : public eoEvalFunc { public: + //typedef typename EOT::Fitness ElemType ; /* * Constructor from instance file @@ -56,18 +59,18 @@ public: unsigned i, j; file >> n; - A = new int *[n]; - B = new int *[n]; + A = new ElemType *[n]; + B = new ElemType *[n]; for(i = 0; i < n; i++) { - A[i] = new int[n]; + A[i] = new ElemType[n]; for(j = 0; j < n; j++) { file >> A[i][j]; } } for(i = 0; i < n; i++) { - B[i] = new int[n]; + B[i] = new ElemType[n]; for(j = 0; j < n; j++) file >> B[i][j]; } @@ -100,7 +103,7 @@ public: * @param _solution the solution to evaluate */ void operator()(EOT & _solution) { - int cost = 0; + ElemType cost = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) @@ -114,7 +117,7 @@ public: * * @return matrix A */ - int** getA() { + ElemType** getA() { return A; } @@ -123,7 +126,7 @@ public: * * @return matrix B */ - int** getB() { + ElemType** getB() { return B; } @@ -141,10 +144,10 @@ private: int n; // matrix A - int ** A; + ElemType ** A; // matrix B - int ** B; + ElemType ** B; };