From 712098a5cd7448812b9b243563ab10101642cb27 Mon Sep 17 00:00:00 2001 From: nojhan Date: Thu, 22 Sep 2011 11:57:31 +0200 Subject: [PATCH] more asserts in RepairerDispatcher and BounderUniform --- edo/src/edoBounderUniform.h | 10 +++++++--- edo/src/edoRepairerDispatcher.h | 17 +++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/edo/src/edoBounderUniform.h b/edo/src/edoBounderUniform.h index 7637d833..c90317c7 100644 --- a/edo/src/edoBounderUniform.h +++ b/edo/src/edoBounderUniform.h @@ -40,13 +40,17 @@ class edoBounderUniform : public edoBounder< EOT > public: edoBounderUniform( EOT min, EOT max ) : edoBounder< EOT >( min, max ) - {} + { + } void operator()( EOT& sol ) { - unsigned int size = sol.size(); - assert(size > 0); + assert( this->min().size() > 0 ); + assert( this->max().size() > 0 ); + assert( sol.size() > 0); + + unsigned int size = sol.size(); for (unsigned int d = 0; d < size; ++d) { if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) { diff --git a/edo/src/edoRepairerDispatcher.h b/edo/src/edoRepairerDispatcher.h index 3f873ec7..96c07da5 100644 --- a/edo/src/edoRepairerDispatcher.h +++ b/edo/src/edoRepairerDispatcher.h @@ -75,35 +75,40 @@ public: //! Add more indexes set and their corresponding repairer operator address to the list void add( std::set idx, edoRepairer* op ) { + assert( idx.size() > 0 ); + assert( op != NULL ); + this->push_back( std::make_pair(idx, op) ); } //! Repair a solution by calling several repair operator on subset of indexes virtual void operator()( EOT& sol ) { - // i is an iterator that points on a pair - for( typename edoRepairerDispatcher::iterator i = this->begin(); i != this->end(); ++i ) { + // ipair is an iterator that points on a pair + for( typename edoRepairerDispatcher::iterator ipair = this->begin(); ipair != this->end(); ++ipair ) { // a partial copy of the sol EOT partsol; // j is an iterator that points on an uint - for( std::set< unsigned int >::iterator j = i->first.begin(); j != i->first.end(); ++j ) { + for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { partsol.push_back( sol.at(*j) ); } // for j + assert( partsol.size() > 0 ); + // apply the repairer on the partial copy // the repairer is a functor, thus second is callable - (*(i->second))( partsol ); + (*(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) unsigned int k=0; - for( std::set< unsigned int >::iterator j = i->first.begin(); j != i->first.end(); ++j ) { + for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) { sol[ *j ] = partsol[ k ]; k++; } // for j } // context for k - } // for i + } // for ipair } };