From 4b844243cebb20dc68a26f9f00cfd3588fa45267 Mon Sep 17 00:00:00 2001 From: paradiseo Date: Thu, 17 Apr 2008 14:31:11 +0000 Subject: [PATCH] new implementation of the test --- eo/test/t-eoShiftMutation.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/eo/test/t-eoShiftMutation.cpp b/eo/test/t-eoShiftMutation.cpp index 928cdf30..afc27749 100644 --- a/eo/test/t-eoShiftMutation.cpp +++ b/eo/test/t-eoShiftMutation.cpp @@ -6,6 +6,7 @@ #include #include +#include //----------------------------------------------------------------------------- @@ -23,19 +24,19 @@ double real_value(const Chrom & _chrom) } // Return true if the given chromosome corresponds to a permutation -// There must be an nicer way to do it (set?) ... -bool check_permutation(const Chrom & _chrom) -{ - for (unsigned i = 0; i < _chrom.size(); ++i) - for (unsigned j = 0; j < _chrom.size(); ++j) - if(i!=j) - if(_chrom[i]==_chrom[j]){ - std::cout << " Error: Wrong permutation !" << std::endl; - std::string s; - s.append( " Wrong permutation in t-eoShiftMutation"); - throw std::runtime_error( s ); - } - return true; +bool check_permutation(const Chrom& _chrom){ + unsigned size= _chrom.size(); + std::set verif; + for(unsigned i=0; i< size; i++){ + if(verif.insert(_chrom[i]).second==false){ + std::cout << " Error: Wrong permutation !" << std::endl; + std::string s; + s.append( " Wrong permutation in t-eoShiftMutation"); + throw std::runtime_error( s ); + return false; + } + } + return true; }