imrproved PSO topology/velocity tests
This commit is contained in:
parent
49d3df2cc4
commit
a1ee120589
4 changed files with 42 additions and 37 deletions
|
|
@ -2,8 +2,9 @@
|
|||
// t-eoSwapMutation.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eo>
|
||||
#include <set>
|
||||
|
||||
#include <eo>
|
||||
#include <eoInt.h>
|
||||
#include <eoSwapMutation.h>
|
||||
|
||||
|
|
@ -22,20 +23,21 @@ double real_value(const Chrom & _chrom)
|
|||
return sum/_chrom.size();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// 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-eoSwapMutation");
|
||||
throw std::runtime_error( s );
|
||||
}
|
||||
return true;
|
||||
bool check_permutation(const Chrom& _chrom){
|
||||
unsigned size= _chrom.size();
|
||||
std::set<unsigned> 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Reference in a new issue