From 0f6aa0581bb7792a6cf93886bb53f0d10e9a979d Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 7 Oct 2011 15:12:14 +0200 Subject: [PATCH 1/8] conditionnal compilation to __UNIX__ with warning on other systems --- eo/src/eoEvalUserTimeThrowException.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/eo/src/eoEvalUserTimeThrowException.h b/eo/src/eoEvalUserTimeThrowException.h index 5d1f4c8a..0da39e57 100644 --- a/eo/src/eoEvalUserTimeThrowException.h +++ b/eo/src/eoEvalUserTimeThrowException.h @@ -21,6 +21,13 @@ Authors: Johann Dréo */ +#ifndef __UNIX__ +#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX systems (defining 'rusage' in 'sys/resource.h'), contributions for other systems are welcomed." +#else + +#ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__ +#define __EOEVALUSERTIMETHROWEXCEPTION_H__ + #include #include @@ -60,3 +67,6 @@ protected: const long _max; struct rusage _usage; }; + +#endif // __EOEVALUSERTIMETHROWEXCEPTION_H__ +#endif // __UNIX__ From 5c7f3835f2036f021459d03514b0aa75082bea93 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 10 Oct 2011 21:11:03 +0200 Subject: [PATCH 2/8] be sure that we fill the line with space when saving the status file --- eo/src/utils/eoParser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index e97a2a2e..fc1068b3 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -289,7 +289,7 @@ void eoParser::printOn(ostream& os) const string str = "--" + param->longName() + "=" + param->getValue(); os.setf(ios_base::left, ios_base::adjustfield); - os << setw(40) << str; + os << setfill(' ') << setw(40) << str; os << setw(0) << " # "; if (param->shortName()) From ea17fb07ad325843b682656c86a3c39fd3330948 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 10 Oct 2011 21:15:19 +0200 Subject: [PATCH 3/8] useless assert --- edo/src/edoSamplerUniform.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/edo/src/edoSamplerUniform.h b/edo/src/edoSamplerUniform.h index 44a59ea8..396a0d08 100644 --- a/edo/src/edoSamplerUniform.h +++ b/edo/src/edoSamplerUniform.h @@ -58,12 +58,15 @@ public: // Sampling all dimensions for (unsigned int i = 0; i < size; ++i) - { + { double min = distrib.min()[i]; double max = distrib.max()[i]; double random = rng.uniform(min, max); + + assert( min < random && random < max); + solution.push_back(random); - } + } return solution; } From edc38e53943e62be2c07934e3d572286b1859a80 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 10 Oct 2011 22:20:39 +0200 Subject: [PATCH 4/8] it's __unix__, not __UNIX__ --- eo/src/eoEvalUserTimeThrowException.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/eoEvalUserTimeThrowException.h b/eo/src/eoEvalUserTimeThrowException.h index 0da39e57..87e47ac5 100644 --- a/eo/src/eoEvalUserTimeThrowException.h +++ b/eo/src/eoEvalUserTimeThrowException.h @@ -21,7 +21,7 @@ Authors: Johann Dréo */ -#ifndef __UNIX__ +#ifndef __unix__ #warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX systems (defining 'rusage' in 'sys/resource.h'), contributions for other systems are welcomed." #else From 0ec2cb51b033be85dd414b6d5c56fd525caddcb1 Mon Sep 17 00:00:00 2001 From: nojhan Date: Tue, 11 Oct 2011 18:46:26 +0200 Subject: [PATCH 5/8] more explanations about eoScalarFitness --- eo/src/eoScalarFitness.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/eo/src/eoScalarFitness.h b/eo/src/eoScalarFitness.h index f3a3a4bb..31a9dbff 100644 --- a/eo/src/eoScalarFitness.h +++ b/eo/src/eoScalarFitness.h @@ -34,11 +34,16 @@ */ /** - * eoScalarFitness >: * Wraps a scalar fitness values such as a double or int, with the option of * maximizing (using less) or minimizing (using greater) - - * It overrides operator<() to use the Compare template argument + * + * It overrides operator<() to use the Compare template argument. Thus, if you + * need to compare if an indiv1 is "better" than an indiv2, you can use: + * if( indiv1 > indiv2 ) { + * // indiv1 is better + * } else { + * // indiv2 is better + * } * * Suitable constructors and assignments and casts are defined to work * with this quantity as if it were a ScalarType. @@ -57,6 +62,13 @@ class eoScalarFitness eoScalarFitness& operator=(const ScalarType& v) { value = v; return *this; } + /** Conversion operator: it permits to use a fitness instance as its scalar + * type, if needed. For example, this is possible: + * eoScalarFitness > fit; + * double val = 1.0; + * fit = val; + * val = fit; + */ operator ScalarType(void) const { return value; } /// Comparison, using less by default @@ -83,13 +95,13 @@ class eoScalarFitness * */ + /** Typedefs for fitness comparison, Maximizing Fitness compares with less, and minimizing fitness compares with greater. This because we want ordinary fitness values (doubles) to be equivalent with Maximizing Fitness, and comparing with less is the default behaviour. */ - #if defined(__CUDACC__) typedef eoScalarFitness > eoMaximizingFitness; typedef eoScalarFitness > eoMinimizingFitness; From 99d1a08e7c0d417f1a2898fd4cc2463813953e18 Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 14 Oct 2011 10:34:33 +0200 Subject: [PATCH 6/8] repairer dispatcher may be used with an unordered vector of indexes, thus we use a vector and not a set --- edo/src/edoRepairerDispatcher.h | 17 ++++++++--------- edo/test/t-dispatcher-round.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/edo/src/edoRepairerDispatcher.h b/edo/src/edoRepairerDispatcher.h index 96c07da5..5c4aa7d8 100644 --- a/edo/src/edoRepairerDispatcher.h +++ b/edo/src/edoRepairerDispatcher.h @@ -29,7 +29,6 @@ Authors: #define _edoRepairerDispatcher_h #include -#include #include #include "edoRepairer.h" @@ -52,28 +51,28 @@ template < typename EOT > class edoRepairerDispatcher : public edoRepairer, std::vector< - std::pair< std::set< unsigned int >, edoRepairer< EOT >* > + std::pair< std::vector< unsigned int >, edoRepairer< EOT >* > > { public: //! Empty constructor edoRepairerDispatcher() : std::vector< - std::pair< std::set< unsigned int >, edoRepairer< EOT >* > + std::pair< std::vector< unsigned int >, edoRepairer< EOT >* > >() {} //! Constructor with a single index set and repairer operator - edoRepairerDispatcher( std::set idx, edoRepairer* op ) : + edoRepairerDispatcher( std::vector idx, edoRepairer* op ) : std::vector< - std::pair< std::set< unsigned int >, edoRepairer< EOT >* > + std::pair< std::vector< unsigned int >, edoRepairer< EOT >* > >() { this->add( idx, op ); } //! Add more indexes set and their corresponding repairer operator address to the list - void add( std::set idx, edoRepairer* op ) + void add( std::vector idx, edoRepairer* op ) { assert( idx.size() > 0 ); assert( op != NULL ); @@ -90,7 +89,7 @@ public: EOT partsol; // j is an iterator that points on an uint - for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { + for( std::vector< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { partsol.push_back( sol.at(*j) ); } // for j @@ -101,9 +100,9 @@ public: (*(ipair->second))( partsol ); { // copy back the repaired partial solution to sol - // browse partsol with uint k, and the idx set with an iterator (std::set is an associative tab) + // browse partsol with uint k, and the idx set with an iterator (std::vector is an associative tab) unsigned int k=0; - for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { + for( std::vector< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { sol[ *j ] = partsol[ k ]; k++; } // for j diff --git a/edo/test/t-dispatcher-round.cpp b/edo/test/t-dispatcher-round.cpp index 245a2e2c..89fc1644 100644 --- a/edo/test/t-dispatcher-round.cpp +++ b/edo/test/t-dispatcher-round.cpp @@ -43,13 +43,13 @@ int main(void) edoRepairer* rep1 = new edoRepairerFloor(); edoRepairer* rep2 = new edoRepairerCeil(); - std::set indexes1; - indexes1.insert(0); - indexes1.insert(2); + std::vector indexes1; + indexes1.push_back(0); + indexes1.push_back(2); - std::set indexes2; - indexes2.insert(1); - indexes2.insert(3); + std::vector indexes2; + indexes2.push_back(1); + indexes2.push_back(3); edoRepairerDispatcher repare( indexes1, rep1 ); repare.add( indexes2, rep2 ); From ea98e9b3f4f2254f221c9536961104ecc18066c4 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 17 Oct 2011 14:42:25 +0200 Subject: [PATCH 7/8] bugfix assert was too restrictive in the uniform sampler, when min==max, the number drawn can be <= max --- edo/src/edoSamplerUniform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edo/src/edoSamplerUniform.h b/edo/src/edoSamplerUniform.h index 396a0d08..6821e8fa 100644 --- a/edo/src/edoSamplerUniform.h +++ b/edo/src/edoSamplerUniform.h @@ -63,7 +63,7 @@ public: double max = distrib.max()[i]; double random = rng.uniform(min, max); - assert( min < random && random < max); + assert( min == random && random == max || min <= random && random < max); // random in [ min, max [ solution.push_back(random); } From c0ba29d4a3d52060e7a785b5f0a0ebfa60a19c1e Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 19 Oct 2011 11:32:20 +0200 Subject: [PATCH 8/8] explicit parenthesis for the assert in edoSamplerUniform --- edo/src/edoSamplerUniform.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/edo/src/edoSamplerUniform.h b/edo/src/edoSamplerUniform.h index 6821e8fa..4edf4323 100644 --- a/edo/src/edoSamplerUniform.h +++ b/edo/src/edoSamplerUniform.h @@ -37,6 +37,12 @@ Authors: * edoSamplerUniform * This class uses the Uniform distribution parameters (bounds) to return * a random position used for population sampling. + * + * Returns a random number in [min,max[ for each variable defined by the given + * distribution. + * + * Note: if the distribution given at call defines a min==max for one of the + * variable, the result will be the same number. */ template < typename EOT, class D = edoUniform > class edoSamplerUniform : public edoSampler< D > @@ -63,7 +69,7 @@ public: double max = distrib.max()[i]; double random = rng.uniform(min, max); - assert( min == random && random == max || min <= random && random < max); // random in [ min, max [ + assert( ( min == random && random == max ) || ( min <= random && random < max) ); // random in [ min, max [ solution.push_back(random); }