more asserts in RepairerDispatcher and BounderUniform

This commit is contained in:
nojhan 2011-09-22 11:57:31 +02:00
commit 712098a5cd
2 changed files with 18 additions and 9 deletions

View file

@ -40,13 +40,17 @@ class edoBounderUniform : public edoBounder< EOT >
public: public:
edoBounderUniform( EOT min, EOT max ) edoBounderUniform( EOT min, EOT max )
: edoBounder< EOT >( min, max ) : edoBounder< EOT >( min, max )
{} {
}
void operator()( EOT& sol ) void operator()( EOT& sol )
{ {
unsigned int size = sol.size(); assert( this->min().size() > 0 );
assert(size > 0); assert( this->max().size() > 0 );
assert( sol.size() > 0);
unsigned int size = sol.size();
for (unsigned int d = 0; d < size; ++d) { for (unsigned int d = 0; d < size; ++d) {
if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) { if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) {

View file

@ -75,35 +75,40 @@ public:
//! Add more indexes set and their corresponding repairer operator address to the list //! Add more indexes set and their corresponding repairer operator address to the list
void add( std::set<unsigned int> idx, edoRepairer<EOT>* op ) void add( std::set<unsigned int> idx, edoRepairer<EOT>* op )
{ {
assert( idx.size() > 0 );
assert( op != NULL );
this->push_back( std::make_pair(idx, op) ); this->push_back( std::make_pair(idx, op) );
} }
//! Repair a solution by calling several repair operator on subset of indexes //! Repair a solution by calling several repair operator on subset of indexes
virtual void operator()( EOT& sol ) virtual void operator()( EOT& sol )
{ {
// i is an iterator that points on a pair // ipair is an iterator that points on a pair
for( typename edoRepairerDispatcher<EOT>::iterator i = this->begin(); i != this->end(); ++i ) { for( typename edoRepairerDispatcher<EOT>::iterator ipair = this->begin(); ipair != this->end(); ++ipair ) {
// a partial copy of the sol // a partial copy of the sol
EOT partsol; EOT partsol;
// j is an iterator that points on an uint // 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) ); partsol.push_back( sol.at(*j) );
} // for j } // for j
assert( partsol.size() > 0 );
// apply the repairer on the partial copy // apply the repairer on the partial copy
// the repairer is a functor, thus second is callable // the repairer is a functor, thus second is callable
(*(i->second))( partsol ); (*(ipair->second))( partsol );
{ // copy back the repaired partial solution to sol { // 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::set is an associative tab)
unsigned int k=0; 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 ]; sol[ *j ] = partsol[ k ];
k++; k++;
} // for j } // for j
} // context for k } // context for k
} // for i } // for ipair
} }
}; };