Turned bonary_value into the onemax (not pow that exploded for even only
moderately small size of genome!) Turned it into a double (it was a float) as floats are dead and should dissappear
This commit is contained in:
parent
f41cd957c0
commit
d686b37c1f
4 changed files with 11 additions and 19 deletions
|
|
@ -1,25 +1,16 @@
|
|||
#include <eo>
|
||||
#include <algorithm>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Just a simple function that takes binary value of a chromosome and sets
|
||||
/** Just the simple function that takes binary value of a chromosome and sets
|
||||
the fitnes.
|
||||
@param _chrom A binary chromosome
|
||||
*/
|
||||
|
||||
template <class Chrom> float binary_value(const Chrom& _chrom)
|
||||
template <class Chrom> double binary_value(const Chrom& _chrom)
|
||||
{
|
||||
float sum = 0;
|
||||
for (unsigned i = 0; i < _chrom.size(); i++)
|
||||
if (_chrom[i])
|
||||
sum += pow(2, _chrom.size() - i - 1);
|
||||
return sum;
|
||||
double sum = 0.0;
|
||||
for (unsigned i=0; i<_chrom.size(); i++)
|
||||
sum += _chrom[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
struct BinaryValue
|
||||
{
|
||||
template <class Chrom> void operator()(Chrom& _chrom)
|
||||
{
|
||||
_chrom.fitness(binary_value(_chrom));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Reference in a new issue