* indentations + whitespace cleanup

This commit is contained in:
Caner Candan 2011-05-05 16:54:00 +02:00
commit 56c6edab04
285 changed files with 6068 additions and 6223 deletions

View file

@ -10,7 +10,7 @@
#include <algorithm>
#include <utils/eoRNG.h>
#include <eoInit.h>
#include <eoInit.h>
/**
* apply orderXover on two chromosomes.
@ -26,65 +26,65 @@
template<class Chrom> class eoOrderXover: public eoQuadOp<Chrom>
{
public:
/// The class name.
virtual std::string className() const { return "eoOrderXover"; }
/// The class name.
virtual std::string className() const { return "eoOrderXover"; }
/**
* @return true if the chromosome has changed
* @param _chrom1 The first chromosome which will be crossed with chrom2.
* @param _chrom2 The second chromosome which will be crossed with chrom1.
*/
bool operator()(Chrom& _chrom1, Chrom& _chrom2){
char direction=eo::rng.flip()? 1 : -1;
unsigned cut2= 1 + eo::rng.random(_chrom1.size());
unsigned cut1= eo::rng.random(cut2);
Chrom tmp1= _chrom1;
Chrom tmp2= _chrom2;
cross(tmp1, tmp2, _chrom1, direction, cut1, cut2);
cross(tmp2, tmp1, _chrom2, direction, cut1, cut2);
_chrom1.invalidate();
_chrom2.invalidate();
return true;
}
/**
* @return true if the chromosome has changed
* @param _chrom1 The first chromosome which will be crossed with chrom2.
* @param _chrom2 The second chromosome which will be crossed with chrom1.
*/
bool operator()(Chrom& _chrom1, Chrom& _chrom2){
char direction=eo::rng.flip()? 1 : -1;
unsigned cut2= 1 + eo::rng.random(_chrom1.size());
unsigned cut1= eo::rng.random(cut2);
Chrom tmp1= _chrom1;
Chrom tmp2= _chrom2;
cross(tmp1, tmp2, _chrom1, direction, cut1, cut2);
cross(tmp2, tmp1, _chrom2, direction, cut1, cut2);
_chrom1.invalidate();
_chrom2.invalidate();
return true;
}
private:
/**
* @param _chrom1 The first parent chromosome.
* @param _chrom2 The second parent chromosome.
* @param _child The result chromosome.
* @param _direction The direction of the OrderXover (left: -1 or right: 1)
* @param _cut1 index of the first cut
* @param _cut2 index of the second cut
*/
void cross(Chrom& _chrom1, Chrom& _chrom2, Chrom& _child, char _direction, unsigned _cut1, unsigned _cut2){
unsigned size, id=0, from=0;
size= _chrom1.size();
std::vector<bool> verif(size, false);
for(unsigned i= _cut1; i<_cut2; i++){
_child[id++]= _chrom1[i];
verif[_chrom1[i] % size] = true;
}
while(_chrom2[from] != _child[_cut2 - 1])
from++;
for(unsigned i=0; i<size; i++){
unsigned j= (_direction*i + from + size) % size;
if(!verif[_chrom2[j] % size]){
_child[id++]=_chrom2[j];
verif[_chrom2[j]%size]=true;
}
}
}
/**
* @param _chrom1 The first parent chromosome.
* @param _chrom2 The second parent chromosome.
* @param _child The result chromosome.
* @param _direction The direction of the OrderXover (left: -1 or right: 1)
* @param _cut1 index of the first cut
* @param _cut2 index of the second cut
*/
void cross(Chrom& _chrom1, Chrom& _chrom2, Chrom& _child, char _direction, unsigned _cut1, unsigned _cut2){
unsigned size, id=0, from=0;
size= _chrom1.size();
std::vector<bool> verif(size, false);
for(unsigned i= _cut1; i<_cut2; i++){
_child[id++]= _chrom1[i];
verif[_chrom1[i] % size] = true;
}
while(_chrom2[from] != _child[_cut2 - 1])
from++;
for(unsigned i=0; i<size; i++){
unsigned j= (_direction*i + from + size) % size;
if(!verif[_chrom2[j] % size]){
_child[id++]=_chrom2[j];
verif[_chrom2[j]%size]=true;
}
}
}
};
/** @example t-eoOrderXover.cpp
*/