From 9d3c848dfbf9ac99afdadc9597b5ced46f38f1c3 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 28 Apr 2020 17:41:50 +0200 Subject: [PATCH] fix even more warnings and reduce some tests runtimes tested under gcc and clang --- edo/src/edoEstimatorAdaptiveEdit.h | 2 +- edo/test/t-mean-distance.cpp | 4 ++-- eo/src/eoNeighborhood.h | 6 +++--- eo/src/eoSocialNeighborhood.h | 6 +++--- eo/src/utils/eoRndGenerators.h | 6 ++++-- eo/src/utils/eoState.cpp | 4 ++-- eo/test/t-algo-forged-search.cpp | 6 +++--- eo/test/t-eoRandom.cpp | 19 ++++++++++--------- eo/test/t-eoRingTopology.cpp | 2 +- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/edo/src/edoEstimatorAdaptiveEdit.h b/edo/src/edoEstimatorAdaptiveEdit.h index 191e536b3..e99128daa 100644 --- a/edo/src/edoEstimatorAdaptiveEdit.h +++ b/edo/src/edoEstimatorAdaptiveEdit.h @@ -54,7 +54,7 @@ public: * distrib.mean, pop.best_element); * @endcode */ - edoEstimatorAdaptiveEdit( + edoEstimatorAdaptiveEdit( D& distrib, std::function getter, std::function setter diff --git a/edo/test/t-mean-distance.cpp b/edo/test/t-mean-distance.cpp index 8c79bc037..fb3eb07e3 100644 --- a/edo/test/t-mean-distance.cpp +++ b/edo/test/t-mean-distance.cpp @@ -65,9 +65,9 @@ int main(int ac, char** av) std::string section("Algorithm parameters"); - unsigned int r_max = parser.createParam((unsigned int)100, "run-number", "Number of run", 'r', section).value(); // r + unsigned int r_max = parser.createParam((unsigned int)10, "run-number", "Number of run", 'r', section).value(); // r unsigned int p_min = parser.createParam((unsigned int)10, "population-min", "Population min", 'p', section).value(); // p - unsigned int p_max = parser.createParam((unsigned int)1000, "population-max", "Population max", 'P', section).value(); // P + unsigned int p_max = parser.createParam((unsigned int)100, "population-max", "Population max", 'P', section).value(); // P unsigned int p_step = parser.createParam((unsigned int)50, "population-step", "Population step", 't', section).value(); // t unsigned int s_size = parser.createParam((unsigned int)2, "dimension-size", "Dimension size", 'd', section).value(); // d diff --git a/eo/src/eoNeighborhood.h b/eo/src/eoNeighborhood.h index 804dc1075..eea620f38 100644 --- a/eo/src/eoNeighborhood.h +++ b/eo/src/eoNeighborhood.h @@ -38,11 +38,11 @@ public: virtual void put(unsigned _oneIndice)=0; - virtual bool contains(unsigned _oneIndice)=0; + virtual bool contains(unsigned _oneIndice) const =0; - virtual unsigned size()=0; + virtual unsigned size() const =0; - virtual unsigned get(unsigned _index)=0; + virtual unsigned get(unsigned _index) const =0; virtual POT & best()=0; diff --git a/eo/src/eoSocialNeighborhood.h b/eo/src/eoSocialNeighborhood.h index 315d105e8..a9a10cbf8 100644 --- a/eo/src/eoSocialNeighborhood.h +++ b/eo/src/eoSocialNeighborhood.h @@ -56,7 +56,7 @@ public: * particle whose indice is _oneIndice") * @param _oneIndice - The indice of the particle in its population. */ - bool contains(unsigned _oneIndice) + bool contains(unsigned _oneIndice) const { for (unsigned i=0;i< indicesList.size();i++) { @@ -77,7 +77,7 @@ public: /** * Return the size of the neighborhood. */ - unsigned size() + unsigned size() const { return indicesList.size(); @@ -87,7 +87,7 @@ public: * Return the "_index-th" particle of the neighborhood. * Throw an exception if its not contained in the neighborhood. */ - unsigned get(unsigned _index) + unsigned get(unsigned _index) const { if (_index < size()) return indicesList[_index]; diff --git a/eo/src/utils/eoRndGenerators.h b/eo/src/utils/eoRndGenerators.h index d70143ff6..14cb8f822 100644 --- a/eo/src/utils/eoRndGenerators.h +++ b/eo/src/utils/eoRndGenerators.h @@ -28,11 +28,12 @@ #ifndef eoRndGenerators_h #define eoRndGenerators_h +#include +#include #include "../eoExceptions.h" #include "eoRNG.h" #include "../eoFunctor.h" -#include /** @defgroup Random Random number generation * @@ -80,7 +81,8 @@ template class eoUniformGenerator : public eoRndGenerator eoUniformGenerator(T _min, T _max, eoRng& _rng = rng) : minim(_min), range(_max-_min), uniform(_rng) { - if (_min>_max) + assert(_min < _max); + if (_min > _max) throw eoException("Min is greater than Max in uniform_generator"); } diff --git a/eo/src/utils/eoState.cpp b/eo/src/utils/eoState.cpp index 8359c65d9..6a46dc6eb 100644 --- a/eo/src/utils/eoState.cpp +++ b/eo/src/utils/eoState.cpp @@ -131,8 +131,8 @@ void eoState::load(std::istream& is) if (is_section(str, name)) break; - removeComment(str, getCommentString()); - fullstring += str + "\n"; + removeComment(str, getCommentString()); + fullstring += str + "\n"; } std::istringstream the_stream(fullstring); object->readFrom(the_stream); diff --git a/eo/test/t-algo-forged-search.cpp b/eo/test/t-algo-forged-search.cpp index 88b2e05b5..95de15520 100644 --- a/eo/test/t-algo-forged-search.cpp +++ b/eo/test/t-algo-forged-search.cpp @@ -71,7 +71,7 @@ std::pair< eoAlgo*, eoPop* > auto& random_pos = store.pack< eoInitFixedLength >(dim, gen_pos); auto pop = new eoPop(); - pop->append(100, random_pos); // pop size + pop->append(10, random_pos); // pop size auto& gen_minus = store.pack< eoUniformGenerator >(-0.05, 0.05); auto& random_velo = store.pack< eoVelocityInitFixedLength >(dim, gen_minus); @@ -89,7 +89,7 @@ std::pair< eoAlgo*, eoPop* > auto& flight = store.pack< eoStandardFlight >(); - auto& cont_gen = store.pack< eoGenContinue >(50); + auto& cont_gen = store.pack< eoGenContinue >(10); auto& cont = store.pack< eoCombinedContinue >(cont_gen); auto& checkpoint = store.pack< eoCheckPoint >(cont); @@ -122,7 +122,7 @@ int main(int /*argc*/, char** /*argv*/) // Evaluation of a forged algo on the sub-problem eoBooleanGenerator gen(0.5); - eoInitFixedLength onemax_init(/*bitstring size=*/500, gen); + eoInitFixedLength onemax_init(/*bitstring size=*/50, gen); eoEvalFoundryEA eval_foundry(foundry, onemax_init, /*pop_size=*/ 10, onemax_eval, /*penalization=*/ 0); diff --git a/eo/test/t-eoRandom.cpp b/eo/test/t-eoRandom.cpp index 30da63e30..2f39f0c0d 100644 --- a/eo/test/t-eoRandom.cpp +++ b/eo/test/t-eoRandom.cpp @@ -42,15 +42,16 @@ int main() { eoUniformGenerator u2(0.003, 0.05 ); eoUniformGenerator u3( 10000U, 10000000U); - try - { // throws an error - eoUniformGenerator utest( 10000000U, 10000U); - throw; // if this succeeds something is wrong, make sure that that is noticed - } - catch (std::logic_error& e) - { - std::cout << e.what() << std::endl; - } + // Test replaced by an assert + // try + // { // throws an error + // eoUniformGenerator utest( 10000000U, 10000U); + // throw; // if this succeeds something is wrong, make sure that that is noticed + // } + // catch (std::logic_error& e) + // { + // std::cout << e.what() << std::endl; + // } std::ofstream os("t-eoRandom.out"); diff --git a/eo/test/t-eoRingTopology.cpp b/eo/test/t-eoRingTopology.cpp index b309f33f1..f45df024b 100644 --- a/eo/test/t-eoRingTopology.cpp +++ b/eo/test/t-eoRingTopology.cpp @@ -40,7 +40,7 @@ int main_function(int /*argc*/, char **/*argv*/) topology.setup(pop); std::cout<<"\n\n\nPopulation :\n\n"<