eoBitOp feat: access to preference, fix: use doubles and swap
- Makes the `preference` member protected instead of private, which may be used for algorithms managing their internal parameters during search. - Replace float parameter with double, used everywhere else in the framework. - use std::swap instead of handmade swap.
This commit is contained in:
parent
e64417f2a5
commit
87d4f08258
1 changed files with 11 additions and 9 deletions
|
|
@ -30,9 +30,10 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <algorithm> // swap_ranges
|
#include <algorithm> // swap_ranges
|
||||||
|
|
||||||
#include "../utils/eoRNG.h"
|
#include "../utils/eoRNG.h"
|
||||||
#include "../eoInit.h" // eoMonOp
|
#include "../eoInit.h" // eoMonOp
|
||||||
#include "eoBit.h"
|
#include "eoBit.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -187,7 +188,7 @@ template<class Chrom> class eoBitMutation: public eoMonOp<Chrom>
|
||||||
return changed_something;
|
return changed_something;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
double rate;
|
double rate;
|
||||||
bool normalize; // divide rate by chromSize
|
bool normalize; // divide rate by chromSize
|
||||||
};
|
};
|
||||||
|
|
@ -330,7 +331,7 @@ template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// (Default) Constructor.
|
/// (Default) Constructor.
|
||||||
eoUBitXover(const float& _preference = 0.5): preference(_preference)
|
eoUBitXover(const double& _preference = 0.5): preference(_preference)
|
||||||
{
|
{
|
||||||
if ( (_preference <= 0.0) || (_preference >= 1.0) )
|
if ( (_preference <= 0.0) || (_preference >= 1.0) )
|
||||||
std::runtime_error("UxOver --> invalid preference");
|
std::runtime_error("UxOver --> invalid preference");
|
||||||
|
|
@ -353,16 +354,17 @@ template<class Chrom> class eoUBitXover: public eoQuadOp<Chrom>
|
||||||
{
|
{
|
||||||
if (chrom1[i] != chrom2[i] && eo::rng.flip(preference))
|
if (chrom1[i] != chrom2[i] && eo::rng.flip(preference))
|
||||||
{
|
{
|
||||||
bool tmp = chrom1[i];
|
// bool tmp = chrom1[i];
|
||||||
chrom1[i]=chrom2[i];
|
// chrom1[i]=chrom2[i];
|
||||||
chrom2[i] = tmp;
|
// chrom2[i] = tmp;
|
||||||
|
std::swap(chrom1[i], chrom2[i]);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
private:
|
protected:
|
||||||
float preference;
|
double preference;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue