imrproved PSO topology/velocity tests
This commit is contained in:
parent
49d3df2cc4
commit
a1ee120589
4 changed files with 42 additions and 37 deletions
|
|
@ -43,20 +43,20 @@ int main_function(int argc, char **argv)
|
||||||
eoExtendedVelocity <Particle> velocity (topology,1,1,1,1);
|
eoExtendedVelocity <Particle> velocity (topology,1,1,1,1);
|
||||||
|
|
||||||
// the test itself
|
// the test itself
|
||||||
for (unsigned int i = 0; i < POP_SIZE; ++i)
|
for (unsigned int i = 0; i < POP_SIZE; i++)
|
||||||
{
|
{
|
||||||
std::cout << " Initial particle n°" << i << " velocity: " << std::endl;
|
std::cout << " Initial particle n°" << i << " velocity: " << std::endl;
|
||||||
for (unsigned int j = 0; j < VEC_SIZE; ++j)
|
for (unsigned int j = 0; j < VEC_SIZE; j++)
|
||||||
std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
|
std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < POP_SIZE; ++i)
|
for (unsigned int i = 0; i < POP_SIZE; i++)
|
||||||
velocity (pop[i],i);
|
velocity (pop[i],i);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < POP_SIZE; ++i)
|
for (unsigned int i = 0; i < POP_SIZE; i++)
|
||||||
{
|
{
|
||||||
std::cout << " Final particle n°" << i << " velocity: " << std::endl;
|
std::cout << " Final particle n°" << i << " velocity: " << std::endl;
|
||||||
for (unsigned int j = 0; j < VEC_SIZE; ++j)
|
for (unsigned int j = 0; j < VEC_SIZE; j++)
|
||||||
std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
|
std::cout << " v" << j << "=" << pop[i].velocities[j] << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@
|
||||||
// t-eoOrderXover.cpp
|
// t-eoOrderXover.cpp
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eo>
|
#include <set>
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
#include <eoInt.h>
|
#include <eoInt.h>
|
||||||
#include <eoOrderXover.h>
|
#include <eoOrderXover.h>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -56,13 +57,13 @@ int main()
|
||||||
eoOrderXover<Chrom> cross;
|
eoOrderXover<Chrom> cross;
|
||||||
|
|
||||||
for (i = 0; i < POP_SIZE; ++i)
|
for (i = 0; i < POP_SIZE; ++i)
|
||||||
std::cout << " Initial chromosome n°" << i << " : " << pop[i] << "..." << std::endl;
|
std::cout << " Initial chromosome n<EFBFBD>" << i << " : " << pop[i] << "..." << std::endl;
|
||||||
|
|
||||||
cross(pop[0],pop[1]);
|
cross(pop[0],pop[1]);
|
||||||
cross(pop[1],pop[2]);
|
cross(pop[1],pop[2]);
|
||||||
|
|
||||||
for (i = 0; i < POP_SIZE; ++i) {
|
for (i = 0; i < POP_SIZE; ++i) {
|
||||||
std::cout << " Initial chromosome n°" << i << " becomes : " << pop[i] << " after orderXover" << std::endl;
|
std::cout << " Initial chromosome n<EFBFBD>" << i << " becomes : " << pop[i] << " after orderXover" << std::endl;
|
||||||
check_permutation(pop[i]);
|
check_permutation(pop[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@
|
||||||
// t-eoSwapMutation.cpp
|
// t-eoSwapMutation.cpp
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eo>
|
#include <set>
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
#include <eoInt.h>
|
#include <eoInt.h>
|
||||||
#include <eoSwapMutation.h>
|
#include <eoSwapMutation.h>
|
||||||
|
|
||||||
|
|
@ -22,20 +23,21 @@ double real_value(const Chrom & _chrom)
|
||||||
return sum/_chrom.size();
|
return sum/_chrom.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
// Return true if the given chromosome corresponds to a permutation
|
// 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){
|
||||||
bool check_permutation(const Chrom & _chrom)
|
unsigned size= _chrom.size();
|
||||||
{
|
std::set<unsigned> verif;
|
||||||
for (unsigned i = 0; i < _chrom.size(); ++i)
|
for(unsigned i=0; i< size; i++){
|
||||||
for (unsigned j = 0; j < _chrom.size(); ++j)
|
if(verif.insert(_chrom[i]).second==false){
|
||||||
if(i!=j)
|
std::cout << " Error: Wrong permutation !" << std::endl;
|
||||||
if(_chrom[i]==_chrom[j]){
|
std::string s;
|
||||||
std::cout << " Error: Wrong permutation !" << std::endl;
|
s.append( " Wrong permutation in t-eoShiftMutation");
|
||||||
std::string s;
|
throw std::runtime_error( s );
|
||||||
s.append( " Wrong permutation in t-eoSwapMutation");
|
return false;
|
||||||
throw std::runtime_error( s );
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,9 @@
|
||||||
// t-eoTwoOptMutation.cpp
|
// t-eoTwoOptMutation.cpp
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eo>
|
#include <set>
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
#include <eoInt.h>
|
#include <eoInt.h>
|
||||||
#include <eoTwoOptMutation.h>
|
#include <eoTwoOptMutation.h>
|
||||||
|
|
||||||
|
|
@ -22,20 +23,21 @@ double real_value(const Chrom & _chrom)
|
||||||
return sum/_chrom.size();
|
return sum/_chrom.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
// Return true if the given chromosome corresponds to a permutation
|
// 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){
|
||||||
bool check_permutation(const Chrom & _chrom)
|
unsigned size= _chrom.size();
|
||||||
{
|
std::set<unsigned> verif;
|
||||||
for (unsigned i = 0; i < _chrom.size(); ++i)
|
for(unsigned i=0; i< size; i++){
|
||||||
for (unsigned j = 0; j < _chrom.size(); ++j)
|
if(verif.insert(_chrom[i]).second==false){
|
||||||
if(i!=j)
|
std::cout << " Error: Wrong permutation !" << std::endl;
|
||||||
if(_chrom[i]==_chrom[j]){
|
std::string s;
|
||||||
std::cout << " Error: Wrong permutation !" << std::endl;
|
s.append( " Wrong permutation in t-eoShiftMutation");
|
||||||
std::string s;
|
throw std::runtime_error( s );
|
||||||
s.append( " Wrong permutation in t-eoTwoOptMutation");
|
return false;
|
||||||
throw std::runtime_error( s );
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue