diff --git a/INSTALL b/INSTALL index 9734fc95a..6f1d121a7 100644 --- a/INSTALL +++ b/INSTALL @@ -183,9 +183,9 @@ Easy, isn't it ? By performing tests, you can check your installation. Testing is disable by default, except if you build with the full install type. -To enable testing, define -DENABLE_TESTING when you launch cmake. +To enable testing, define -DENABLE_CMAKE_TESTING=true when you launch cmake. -To perform tests simply type ctest ou make test. +To perform tests simply type ctest or make test. ------------------------------------------------------------------------------------------ 5.2 REPORTING diff --git a/eo/src/CMakeLists.txt b/eo/src/CMakeLists.txt index d38543098..b2b445a93 100644 --- a/eo/src/CMakeLists.txt +++ b/eo/src/CMakeLists.txt @@ -47,7 +47,7 @@ install(DIRECTORY do es ga gp other utils add_subdirectory(es) add_subdirectory(ga) add_subdirectory(utils) -add_subdirectory(serial) +#add_subdirectory(serial) if(ENABLE_PYEO) add_subdirectory(pyeo) diff --git a/eo/src/utils/eoDistance.h b/eo/src/utils/eoDistance.h index b26f249d6..35ce9a109 100644 --- a/eo/src/utils/eoDistance.h +++ b/eo/src/utils/eoDistance.h @@ -62,13 +62,15 @@ public: }; /** + SV: from eoHammingDistance, it is in fact the L1 distance + This is a generic class for L1 distance computation: assumes the 2 things are std::vectors of something that is double-castable For bitstrings, this is the Hamming distance */ template< class EOT > -class eoHammingDistance : public eoDistance +class eoL1Distance : public eoDistance { public: double operator()(const EOT & _v1, const EOT & _v2) @@ -83,6 +85,27 @@ public: } }; +/** + SV: change to have the Hamming (number of differences) + + For bitstrings, this is the Hamming distance +*/ +template< class EOT > +class eoHammingDistance : public eoDistance +{ +public: + double operator()(const EOT & _v1, const EOT & _v2) + { + double sum=0.0; + for (unsigned i=0; i<_v1.size(); i++) + { + if (_v1[i] != _v2[i]) + sum++; + } + return sum; + } +}; + /* this distance measures the difference in fitness * I am not sure it can be of any use, though ... * except for some testing diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 15fd22464..4a0c74e43 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -69,6 +69,7 @@ set (TEST_LIST #t-openmp # does not work anymore since functions used in this test were removed from EO #t-eoDualFitness t-eoParser + t-eoPartiallyMappedXover ) diff --git a/mo/src/algo/moRandomWalk.h b/mo/src/algo/moRandomWalk.h index dafa3f277..6ccdbc107 100644 --- a/mo/src/algo/moRandomWalk.h +++ b/mo/src/algo/moRandomWalk.h @@ -60,7 +60,7 @@ public: */ moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc& _fullEval, moEval& _eval, unsigned _nbStepMax): moLocalSearch(explorer, iterCont, _fullEval), - iterCont(_nbStepMax), + iterCont(_nbStepMax, false), explorer(_neighborhood, _eval) {} diff --git a/mo/src/continuator/moVectorMonitor.h b/mo/src/continuator/moVectorMonitor.h index b04eb8adf..d6870bb80 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), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(&_param), intParam(NULL), intLongParam(NULL), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -63,7 +63,17 @@ public: * Default Constructor * @param _param the parameter of type unsigned int to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(&_param), intLongParam(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(&_param), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -73,7 +83,7 @@ public: * Default Constructor * @param _param the parameter of type EOT to save in the vector */ - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), eotParam(&_param) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -84,7 +94,7 @@ public: * @param _param the parameter of type eoScalarFitness to save in the vector */ template - moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), eotParam(NULL) + moVectorMonitor(eoValueParam > & _param) : doubleParam( & (eoValueParam&)_param), intParam(NULL), intLongParam(NULL), eotParam(NULL) { // precision of the output by default precisionOutput = std::cout.precision(); @@ -95,7 +105,7 @@ public: * @param _param unvalid Parameter */ template - moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL) + moVectorMonitor(eoValueParam & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), eotParam(NULL) { std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl; } @@ -120,8 +130,11 @@ public: else if (intParam != NULL) valueVec.push_back((double) intParam->value()); - else - eotVec.push_back(eotParam->value()); + else + if (intLongParam != NULL) + valueVec.push_back((double) intLongParam->value()); + else + eotVec.push_back(eotParam->value()); return *this ; } @@ -227,6 +240,7 @@ public: protected: eoValueParam * doubleParam ; eoValueParam * intParam ; + eoValueParam * intLongParam ; eoValueParam * eotParam ; std::vector valueVec; diff --git a/mo/src/mo.h b/mo/src/mo.h index 2a56a86a5..2ba411388 100755 --- a/mo/src/mo.h +++ b/mo/src/mo.h @@ -190,6 +190,7 @@ //#include //#include //#include +#include #include diff --git a/mo/src/neighborhood/moIndexNeighbor.h b/mo/src/neighborhood/moIndexNeighbor.h index 5ce17cdda..eaf302966 100644 --- a/mo/src/neighborhood/moIndexNeighbor.h +++ b/mo/src/neighborhood/moIndexNeighbor.h @@ -109,9 +109,9 @@ public: * @param _solution solution from which the neighborhood is visited * @param _key index of the IndexNeighbor */ - virtual void index(EOT & _solution, unsigned int _key) { - key = _key; - } + virtual void index(EOT & _solution, unsigned int _key) { + key = _key; + } /** * @param _neighbor a neighbor @@ -121,6 +121,22 @@ public: return (key == _neighbor.index()); } + /** + * Write object with its index + * @param _os A std::ostream. + */ + virtual void printOn(std::ostream& _os) const { + if (this->invalid()) { + _os << "INVALID "; + } + else + { + _os << this->fitness() << ' '; + } + + _os << key ; + } + protected: // key allowing to describe the neighbor unsigned int key; diff --git a/mo/src/neighborhood/moRndWithoutReplNeighborhood.h b/mo/src/neighborhood/moRndWithoutReplNeighborhood.h index 52113cc07..e51c6d6e7 100644 --- a/mo/src/neighborhood/moRndWithoutReplNeighborhood.h +++ b/mo/src/neighborhood/moRndWithoutReplNeighborhood.h @@ -130,7 +130,7 @@ public: return "moRndWithoutReplNeighborhood"; } -private: +protected: unsigned int maxIndex; std::vector indexVector; }; diff --git a/mo/src/problems/permutation/moIndexedSwapNeighbor.h b/mo/src/problems/permutation/moIndexedSwapNeighbor.h index d30305100..d3ddababf 100644 --- a/mo/src/problems/permutation/moIndexedSwapNeighbor.h +++ b/mo/src/problems/permutation/moIndexedSwapNeighbor.h @@ -46,6 +46,33 @@ public: using moIndexNeighbor::index; /** + * Default Constructor + */ + moIndexedSwapNeighbor() : moIndexNeighbor() { + } + + /** + * Copy Constructor + * @param _n the neighbor to copy + */ + moIndexedSwapNeighbor(const moIndexedSwapNeighbor & _n) : moIndexNeighbor(_n) + { + indices.first = _n.first(); + indices.second = _n.second(); + } + + /** + * Assignment operator + * @param _source the source neighbor + */ + moIndexedSwapNeighbor & operator=(const moIndexedSwapNeighbor & _source) { + moIndexNeighbor::operator=(_source); + indices.first = _source.first(); + indices.second = _source.second(); + return *this; + } + + /** * Apply the swap * @param _solution the solution to move */ @@ -111,7 +138,7 @@ public: * Getter of the firt location * @return first indice */ - unsigned int first() { + unsigned int first() const { return indices.first; } @@ -119,11 +146,11 @@ public: * Getter of the second location * @return second indice */ - unsigned int second() { + unsigned int second() const { return indices.second; } -private: +protected: std::pair indices; }; diff --git a/mo/test/CMakeLists.txt b/mo/test/CMakeLists.txt index 652b66be3..a27f97db9 100644 --- a/mo/test/CMakeLists.txt +++ b/mo/test/CMakeLists.txt @@ -18,6 +18,7 @@ set (TEST_LIST t-moOrderNeighborhood t-moFullEvalByCopy t-moFullEvalByModif + t-moNKlandscapesIncrEval t-moNeighborComparator t-moSolNeighborComparator t-moTrueContinuator diff --git a/mo/tutorial/Lesson6/adaptiveWalks.cpp b/mo/tutorial/Lesson6/adaptiveWalks.cpp index 36ab47ca0..1976f577b 100644 --- a/mo/tutorial/Lesson6/adaptiveWalks.cpp +++ b/mo/tutorial/Lesson6/adaptiveWalks.cpp @@ -85,6 +85,7 @@ void main_function(int argc, char **argv) string str_out = "out.dat"; // default value eoValueParam outParam(str_out.c_str(), "out", "Output file of the sampling", 'o'); parser.processParam(outParam, "Persistence" ); + str_out = outParam.value(); // the name of the "status" file where all actual parameter values will be saved string str_status = parser.ProgramName() + ".status"; // default value diff --git a/mo/tutorial/Lesson6/autocorrelation.cpp b/mo/tutorial/Lesson6/autocorrelation.cpp index 6f07d8ae7..f034efc43 100644 --- a/mo/tutorial/Lesson6/autocorrelation.cpp +++ b/mo/tutorial/Lesson6/autocorrelation.cpp @@ -89,6 +89,7 @@ void main_function(int argc, char **argv) string str_out = "out.dat"; // default value eoValueParam outParam(str_out.c_str(), "out", "Output file of the sampling", 'o'); parser.processParam(outParam, "Persistence" ); + str_out = outParam.value(); // the name of the "status" file where all actual parameter values will be saved string str_status = parser.ProgramName() + ".status"; // default value diff --git a/mo/tutorial/Lesson6/densityOfStates.cpp b/mo/tutorial/Lesson6/densityOfStates.cpp index a47323423..9e2eeddca 100644 --- a/mo/tutorial/Lesson6/densityOfStates.cpp +++ b/mo/tutorial/Lesson6/densityOfStates.cpp @@ -83,6 +83,7 @@ void main_function(int argc, char **argv) string str_out = "out.dat"; // default value eoValueParam outParam(str_out.c_str(), "out", "Output file of the sampling", 'o'); parser.processParam(outParam, "Persistence" ); + str_out = outParam.value(); // the name of the "status" file where all actual parameter values will be saved string str_status = parser.ProgramName() + ".status"; // default value diff --git a/moeo/src/metric/moeoHyperVolumeMetric.h b/moeo/src/metric/moeoHyperVolumeMetric.h index f59ba19a6..99f132131 100644 --- a/moeo/src/metric/moeoHyperVolumeMetric.h +++ b/moeo/src/metric/moeoHyperVolumeMetric.h @@ -83,7 +83,7 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d * @param _ref_point the reference point * @param _bounds bounds value */ - moeoHyperVolumeMetric(ObjectiveVector& _ref_point=NULL, std::vector < eoRealInterval >& _bounds=NULL): normalize(false), rho(0.0), ref_point(_ref_point), bounds(_bounds){} + moeoHyperVolumeMetric(ObjectiveVector& _ref_point, std::vector < eoRealInterval >& _bounds): normalize(false), rho(0.0), ref_point(_ref_point), bounds(_bounds){} /** * calculates and returns the HyperVolume value of a pareto front diff --git a/moeo/src/selection/moeoRouletteSelect.h b/moeo/src/selection/moeoRouletteSelect.h index b5adcb0c2..fb34259e7 100644 --- a/moeo/src/selection/moeoRouletteSelect.h +++ b/moeo/src/selection/moeoRouletteSelect.h @@ -80,7 +80,7 @@ class moeoRouletteSelect:public moeoSelectOne < MOEOT > protected: /** size */ - double & tSize; + unsigned int & tSize; }; diff --git a/problems/eval/nkLandscapesEval.h b/problems/eval/nkLandscapesEval.h index 29fd20d5f..070fb1b43 100644 --- a/problems/eval/nkLandscapesEval.h +++ b/problems/eval/nkLandscapesEval.h @@ -31,6 +31,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr #define __nkLandscapesEval_H #include +#include template< class EOT > class nkLandscapesEval : public eoEvalFunc { @@ -79,7 +80,7 @@ public: */ nkLandscapesEval(const char * _fileName) { - string fname(_fileName); + std::string fname(_fileName); load(fname); }; @@ -132,16 +133,16 @@ public: * * @param _fileName file name of the instance */ - virtual void load(const string _fileName) + virtual void load(const std::string _fileName) { - fstream file; - file.open(_fileName.c_str(), ios::in); + std::fstream file; + file.open(_fileName.c_str(), std::fstream::in); if (file.is_open()) { - string s; + std::string s; // Read the commentairies - string line; + std::string line; file >> s; while (s[0] == 'c') { getline(file,line,'\n'); @@ -150,14 +151,14 @@ public: // Read the parameters if (s[0] != 'p') { - string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ; + throw std::runtime_error(str); } file >> s; if (s != "NK") { - string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ; + throw std::runtime_error(str); } // read parameters N and K @@ -166,22 +167,22 @@ public: // read the links if (s[0] != 'p') { - string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ; + throw std::runtime_error(str); } file >> s; if (s == "links") { loadLinks(file); } else { - string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ; + throw std::runtime_error(str); } // lecture des tables if (s[0] != 'p') { - string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ; + throw std::runtime_error(str); } file >> s; @@ -189,14 +190,14 @@ public: if (s == "tables") { loadTables(file); } else { - string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ; + throw std::runtime_error(str); } file.close(); } else { - string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ; - throw runtime_error(str); + std::string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ; + throw std::runtime_error(str); } }; @@ -206,7 +207,7 @@ public: * * @param file the file to read */ - void loadLinks(fstream & file) { + void loadLinks(std::fstream & file) { for(int j = 0; j < K+1; j++) for(int i = 0; i < N; i++) { file >> links[i][j]; @@ -218,7 +219,7 @@ public: * * @param file the file to read */ - void loadTables(fstream & file) { + void loadTables(std::fstream & file) { for(int j = 0; j < (1<<(K+1)); j++) for(int i = 0; i < N; i++) file >> tables[i][j]; @@ -230,29 +231,29 @@ public: * @param _fileName the file name of instance */ virtual void save(const char * _fileName) { - fstream file; - file.open(_fileName, ios::out); + std::fstream file; + file.open(_fileName, std::fstream::out); if (file.is_open()) { - file << "c name of the file : " << _fileName << endl; - file << "p NK " << N << " " << K <