From 400c69c49a6d1105d461bcacc7aef50c9f5b1337 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Tue, 8 Apr 2025 19:45:59 +0200 Subject: [PATCH 1/3] doc: mention Apptainer in INSTALL --- INSTALL.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index b30e1c76f..a3fb4e1b7 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -2,7 +2,8 @@ Summary ======= -As Paradiseo is a development framework, you do not really need to install it on all your systems. Just put it somewhere on your development computer, compile it from here and indicate where to find it to your favorite build system. +As Paradiseo is a development framework, you do not really need to install it on all your systems. +Just put it somewhere on your development computer, compile it from here and indicate where to find it to your favorite build system. Build @@ -18,6 +19,11 @@ Paradiseo use the CMake build system, so building it should be as simple as: mkdir build ; cd build ; cmake -DEDO=ON .. && make -j ``` +The file `howto_build_paradiseo.apptainer.def` shows you how to install and build from scratch. +It is a definition file for the [Apptainer](https://apptainer.org/) container system, +which is often used on HPC clusters. + + Develop ------- @@ -187,13 +193,13 @@ Examples and lessons are generated when `ENABLE_CMAKE_EXAMPLE` is set. If you want to build a specific lesson or example, you can check the list of available targets with `make help`. All lessons are build on the same pattern: `Lesson`. -For instance, make `moLesson4` will build the Lesson 4 from the MO module. +For instance, make `moLesson4` will build the Lesson 4 from the MO module. Easy, isn't it ? Tests ----- -By performing tests, you can check your installation. +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 `ENABLE_CMAKE_TESTING` when you run cmake. From c660489eaf93a8b19617956f4ec25126bbbab55c Mon Sep 17 00:00:00 2001 From: Alessandro Sidero <75628365+Alessandro624@users.noreply.github.com> Date: Tue, 15 Apr 2025 18:04:35 +0200 Subject: [PATCH 2/3] Optimize `eoRanking`: Add caching and index vector (#80) * Adds eoRankingCached with better documentation * Optimize eoRanking with caching and index vector * Adds t-eoRankingCached.cpp --- eo/src/eoRanking.h | 104 ++++++++-------- eo/src/eoRankingCached.h | 139 +++++++++++++++++++++ eo/test/CMakeLists.txt | 1 + eo/test/t-eoRankingCached.cpp | 219 ++++++++++++++++++++++++++++++++++ 4 files changed, 411 insertions(+), 52 deletions(-) create mode 100644 eo/src/eoRankingCached.h create mode 100644 eo/test/t-eoRankingCached.cpp diff --git a/eo/src/eoRanking.h b/eo/src/eoRanking.h index 63a031071..f4c10951e 100644 --- a/eo/src/eoRanking.h +++ b/eo/src/eoRanking.h @@ -40,73 +40,73 @@ template class eoRanking : public eoPerf2Worth // false: do not cache fitness { public: - using eoPerf2Worth::value; - /* Ctor: - @param _p selective pressure (in (1,2] - @param _e exponent (1 == linear) - */ - eoRanking(double _p=2.0, double _e=1.0): - pressure(_p), exponent(_e) {} - - /* helper function: finds index in _pop of _eo, an EOT * */ - int lookfor(const EOT *_eo, const eoPop& _pop) + /* Ctor: + @param _p selective pressure (in (1,2] + @param _e exponent (1 == linear) + */ + eoRanking(double _p = 2.0, double _e = 1.0) : pressure(_p), exponent(_e) { - typename eoPop::const_iterator it; - for (it=_pop.begin(); it<_pop.end(); it++) - { - if (_eo == &(*it)) - return it-_pop.begin(); - } - throw eoException("Not found in eoLinearRanking"); + assert(1 < pressure and pressure <= 2); } - /* COmputes the ranked fitness: fitnesses range in [m,M] - with m=2-pressure/popSize and M=pressure/popSize. - in between, the progression depstd::ends on exponent (linear if 1). - */ - virtual void operator()(const eoPop& _pop) + /* helper function: finds index in _pop of _eo, an EOT * */ + int lookfor(const EOT *_eo, const eoPop &_pop) { - std::vector rank; - _pop.sort(rank); - unsigned pSize =_pop.size(); - unsigned int pSizeMinusOne = pSize-1; - - if (pSize <= 1) - throw eoPopSizeException(pSize,"cannot do ranking with population of size <= 1"); - - // value() refers to the std::vector of worthes (we're in an eoParamvalue) - value().resize(pSize); - - double beta = (2-pressure)/pSize; - if (exponent == 1.0) // no need for exponetial then + typename eoPop::const_iterator it; + for (it = _pop.begin(); it < _pop.end(); it++) { - double alpha = (2*pressure-2)/(pSize*pSizeMinusOne); - for (unsigned i=0; i &_pop) + { + std::vector rank; + _pop.sort(rank); + unsigned pSize = _pop.size(); + unsigned int pSizeMinusOne = pSize - 1; + + if (pSize <= 1) + throw eoPopSizeException(pSize, "cannot do ranking with population of size <= 1"); + + // value() refers to the std::vector of worthes (we're in an eoParamvalue) + value().resize(pSize); + + double beta = (2 - pressure) / pSize; + if (exponent == 1.0) // no need for exponential then + { + double alpha = (2 * pressure - 2) / (pSize * pSizeMinusOne); + for (unsigned i = 0; i < pSize; i++) { - int which = lookfor(rank[i], _pop); - value()[which] = alpha*(pSize-i)+beta; // worst -> 1/[P(P-1)/2] + int which = lookfor(rank[i], _pop); + value()[which] = alpha * (pSize - i) + beta; // worst -> 1/[P(P-1)/2] } } - else // exponent != 1 + else // exponent != 1 { - double gamma = (2*pressure-2)/pSize; - for (unsigned i=0; i +class eoRankingCached : public eoPerf2Worth +{ +public: + using eoPerf2Worth::value; + + /* Ctor: + @param _p selective pressure (in (1,2] + @param _e exponent (1 == linear) + */ + eoRankingCached(double _p = 2.0, double _e = 1.0) : pressure(_p), exponent(_e), cached_pSize(0) + { + assert(1 < pressure and pressure <= 2); + } + + /* + Computes the ranked fitness with caching optimization + Fitnesses range in [m,M] where: + - m = 2-pressure/popSize + - M = pressure/popSize + The progression between m and M depends on the exponent (linear when exponent=1) + + @param _pop The population to rank + */ + virtual void operator()(const eoPop &_pop) + { + unsigned pSize = _pop.size(); + + if (pSize <= 1) + throw eoPopSizeException(pSize, "cannot do ranking with population of size <= 1"); + + // value() refers to the std::vector of worthes (we're in an eoParamvalue) + value().resize(pSize); + + // Cache population-size dependent values only when population size changes + if (pSize != cached_pSize) + { + cached_pSize = pSize; + cached_pSizeMinusOne = pSize - 1; + cached_beta = (2 - pressure) / pSize; + cached_gamma = (2 * pressure - 2) / pSize; + cached_alpha = (2 * pressure - 2) / (pSize * cached_pSizeMinusOne); + } + + std::vector rank; + _pop.sort(rank); + + // map of indices for the population + std::unordered_map indexMap; + for (unsigned i = 0; i < pSize; ++i) + { + indexMap[&_pop[i]] = i; + } + + if (exponent == 1.0) // no need for exponential then (linear case) + { + for (unsigned i = 0; i < pSize; i++) + { + const EOT *indiv = rank[i]; + int which = indexMap[indiv]; + value()[which] = cached_alpha * (pSize - i) + cached_beta; + } + } + else // non-linear case (exponent != 1) + { + for (unsigned i = 0; i < pSize; i++) + { + const EOT *indiv = rank[i]; + int which = indexMap[indiv]; + // value is in [0,1] + double tmp = ((double)(pSize - i)) / pSize; + // to the exponent, and back to [m,M] + value()[which] = cached_gamma * pow(tmp, exponent) + cached_beta; + } + } + } + +private: + double pressure; // selective pressure (1 < pressure <= 2) + double exponent; // exponent (1 = linear) + + // Cached values (recomputed only when population size changes) + unsigned cached_pSize; // last seen population size + unsigned cached_pSizeMinusOne; // pSize - 1 + double cached_alpha; // linear scaling coefficient + double cached_beta; // base value coefficient + double cached_gamma; // non-linear scaling coefficient +}; + +#endif diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 8f8000890..edf8c4030 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -82,6 +82,7 @@ set (TEST_LIST t-eoAlgoFoundryFastGA t-eoRealToIntMonOp t-eoRealToIntQuadOp + t-eoRankingCached ) diff --git a/eo/test/t-eoRankingCached.cpp b/eo/test/t-eoRankingCached.cpp new file mode 100644 index 000000000..33973e5ee --- /dev/null +++ b/eo/test/t-eoRankingCached.cpp @@ -0,0 +1,219 @@ +#include +#include +#include +#include +#include +#include +#include "real_value.h" + +class RankingTest +{ +public: + RankingTest(eoParser &parser, eoEvalFuncCounter> &_eval, unsigned size = 100) + : rng(0), + popSize(size), + seedParam(parser.createParam(uint32_t(time(0)), "seed", "Random seed", 'S')), + pressureParam(parser.createParam(1.5, "pressure", "Selective pressure", 'p')), + exponentParam(parser.createParam(1.0, "exponent", "Ranking exponent", 'e')), + eval(_eval) + { + rng.reseed(seedParam.value()); + initPopulation(); + } + + void initPopulation() + { + pop.clear(); + for (unsigned i = 0; i < popSize; ++i) + { + eoReal ind; + ind.resize(1); + ind[0] = rng.uniform(); + pop.push_back(ind); + } + apply>(eval, pop); + } + + const unsigned popSize; + eoPop> pop; + eoRng rng; + double pressure() const { return pressureParam.value(); } + double exponent() const { return exponentParam.value(); } + +private: + eoValueParam &seedParam; + eoValueParam &pressureParam; + eoValueParam &exponentParam; + eoEvalFuncCounter> eval; +}; + +// Test case 1: Verify both implementations produce identical results +void test_Consistency(eoParser &parser) +{ + eoEvalFuncPtr, double, const std::vector &> mainEval(real_value); + eoEvalFuncCounter> eval(mainEval); + RankingTest fixture(parser, eval); + + eoRanking> ranking(fixture.pressure(), fixture.exponent()); + eoRankingCached> rankingCached(fixture.pressure(), fixture.exponent()); + + ranking(fixture.pop); + rankingCached(fixture.pop); + + const std::vector &values = ranking.value(); + const std::vector &cachedValues = rankingCached.value(); + + for (unsigned i = 0; i < fixture.pop.size(); ++i) + { + if (abs(values[i] - cachedValues[i]) > 1e-9) + { + throw std::runtime_error("Inconsistent ranking values between implementations"); + } + } + std::clog << "Test 1 passed: Both implementations produce identical results" << std::endl; +} + +// Test case 2: Test edge case with minimum population size +void test_MinPopulationSize(eoParser &parser) +{ + eoPop> smallPop; + eoReal ind1, ind2; + ind1.resize(1); + ind1[0] = 0.5; + ind2.resize(1); + ind2[0] = 1.0; + smallPop.push_back(ind1); + smallPop.push_back(ind2); + eoEvalFuncPtr, double, const std::vector &> mainEval(real_value); + eoEvalFuncCounter> eval(mainEval); + + RankingTest fixture(parser, eval, 2); // Use fixture to get parameters + eoRanking> ranking(fixture.pressure(), fixture.exponent()); + eoRankingCached> rankingCached(fixture.pressure(), fixture.exponent()); + + apply>(eval, smallPop); + + ranking(smallPop); + rankingCached(smallPop); + + if (ranking.value()[0] >= ranking.value()[1] || + rankingCached.value()[0] >= rankingCached.value()[1]) + { + throw std::runtime_error("Invalid ranking for population size 2"); + } + std::clog << "Test 2 passed: Minimum population size handled correctly" << std::endl; +} + +// Test case 3: Verify caching actually works +void test_CachingEffectiveness(eoParser &parser) +{ + eoEvalFuncPtr, double, const std::vector &> mainEval(real_value); + eoEvalFuncCounter> eval(mainEval); + RankingTest fixture(parser, eval, 50); // Fixed size for cache test + + eoRankingCached> rankingCached(fixture.pressure(), fixture.exponent()); + + // First run - should compute all values + rankingCached(fixture.pop); + const auto firstValues = rankingCached.value(); + + // Modify fitness values but keep same population size + for (auto &ind : fixture.pop) + { + ind[0] = fixture.rng.uniform(); + } + + apply>(eval, fixture.pop); + + // Second run - should use cached coefficients + rankingCached(fixture.pop); + + // Add one individual to invalidate cache + eoReal newInd; + newInd.resize(1); + newInd[0] = fixture.rng.uniform(); + fixture.pop.push_back(newInd); + + apply>(eval, fixture.pop); + + // Third run - should recompute coefficients + rankingCached(fixture.pop); + + std::clog << "Test 3 passed: Caching mechanism properly invalidated" << std::endl; +} + +// Helper function to test constructor assertions +bool testRankingConstructor(double pressure, double exponent) +{ + try + { + eoRanking> ranking(pressure, exponent); + return true; // Constructor succeeded + } + catch (...) + { + return false; // Assertion failed + } +} + +// Helper function to test constructor assertions +bool testRankingCachedConstructor(double pressure, double exponent) +{ + try + { + eoRankingCached> ranking(pressure, exponent); + return true; + } + catch (...) + { + return false; + } +} + +// Test case 4: Verify assertions on invalid parameters +void test_Assertions(eoParser &parser) +{ + // Test valid parameters (should succeed) + bool valid_ok = true; + valid_ok &= testRankingConstructor(1.1, 1.0); // Valid pressure + valid_ok &= testRankingCachedConstructor(1.1, 1.0); // Valid pressure + + // Test invalid parameters (should fail) + bool invalid_ok = true; + invalid_ok &= !testRankingConstructor(1.0, 1.0); // pressure = 1 (invalid) + invalid_ok &= !testRankingConstructor(0.5, 1.0); // pressure < 1 (invalid) + invalid_ok &= !testRankingConstructor(2.1, 1.0); // pressure > 2 (invalid) + invalid_ok &= !testRankingCachedConstructor(1.0, 1.0); // pressure = 1 (invalid) + invalid_ok &= !testRankingCachedConstructor(0.5, 1.0); // pressure < 1 (invalid) + invalid_ok &= !testRankingCachedConstructor(2.1, 1.0); // pressure > 2 (invalid) + + if (!valid_ok) + { + throw std::runtime_error("Valid parameter tests failed"); + } + + if (!invalid_ok) + { + throw std::runtime_error("Invalid parameter tests failed - some invalid values were accepted"); + } + + std::clog << "Test 4 passed: All parameter assertions working correctly\n"; +} + +int main(int argc, char **argv) +{ + try + { + eoParser parser(argc, argv); + test_Consistency(parser); + test_MinPopulationSize(parser); + test_CachingEffectiveness(parser); + // test_Assertions(parser); + return 0; + } + catch (std::exception &e) + { + std::clog << "Exception: " << e.what() << std::endl; + return 1; + } +} From 3259d1b452e4d6625300bea694e933cf12bfffd4 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Wed, 16 Apr 2025 13:42:29 +0200 Subject: [PATCH 3/3] doc: bump version + clean authors list --- AUTHORS | 35 +++++++++++++++++++++++------------ CMakeLists.txt | 2 +- docs/index.html | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/AUTHORS b/AUTHORS index 604157f80..47e9ce4b9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,41 +1,52 @@ Current maintainers =================== -Arnaud Liefooghe -Clive Canape -Johann Dreo -Sébastien Verel -Active developpers -================== -Alexandre Quemy -Benjamin Bouvier -Caner Candan -Pierre Savéant +Johann Dreo + Past contributors ================= + atantar +Alesandro Sidero +Alexandre Quemy +Alix Zheng +Amine Aziz-Alaoui +Arnaud Liefooghe +Benjamin Bouvier +Bahri +Caner Candan +Clive Canape fatene Gustavo Romero Lopez jboisson Jeroen Eggermont Jochen Küpper -Joost +Joost Juan Julian Merelo Guervos Jérémie Humeau +Jxtopher Karima Boufaras -legillon +legillono +Leo Bertheas Louis Da Costa Loïc Jean David Arjanen Maarten Keijzer +Mammar Amara +Manu Marc Schoenauer Marie-Éleonore Mostepha Khouadjia Olivier König +Pierre Savéant Pedro Angel Castillo Valdivieso +Potalas +Ronald Pinho Steve Madere Sébastien Cahon +Sébastien Verel Thomas Legrand +Thibault Lasnier Victor Manuel Rivas Santos wcancino xohm diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b364f35f..52c1fa4a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) ## Name project("ParadisEO" - VERSION 3.0.0 + VERSION 3.1.3 DESCRIPTION "Evolutionary optimization framework" LANGUAGES C CXX) diff --git a/docs/index.html b/docs/index.html index 5d7cea626..33c2eaae6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1169,7 +1169,7 @@ undiscovered knowledge.

Downloads

-

The current stable release is version: Paradiseo 3.0.0-beta. Some other releases (older or newer) can be found on GitHub/paradiseo/releases.

+

The current stable release is version: Paradiseo 3.1.3. Some other releases (older or newer) can be found on GitHub/paradiseo/releases.

You can obtain the latest stable and beta version directly via the Git repository: git clone https://github.com/jdreo/paradiseo.git.