12#ifndef BELFEM_CL_DNA_HPP
13#define BELFEM_CL_DNA_HPP
27 template <
size_t B,
size_t N >
52 for(
size_t i=0; i<N; ++i )
54 real tValue = aValues( i );
55 real tMin = mMinVals( i );
56 real tMax = mMaxVals( i );
64 if ( mTypes.test( i ) )
66 tValue = std::log( tValue );
67 tMin = std::log( tMin );
68 tMax = std::log( tMax );
72 tValue = std::max( std::min( tValue, tMax ), tMin );
75 tValue = ( tValue - tMin ) / ( tMax - tMin );
78 encode( i, std::round( tValue * ( ( 1u << B ) - 1 ) ) );
85 for(
size_t i=0; i<N; ++i )
88 real tMin = mMinVals( i );
89 real tMax = mMaxVals( i );
98 uint tBits = decode( i );
106 if ( mTypes.test( i ) )
108 tMin = std::log( tMin );
109 tMax = std::log( tMax );
111 tValue = std::exp( tMin + tValue * ( tMax - tMin ) );
116 tValue = tMin + tValue * ( tMax - tMin );
124 aValues( i ) = std::max( std::min( tValue, mMaxVals( i ) ),
133 for(
size_t i=0; i<N; ++i )
135 real tMin = mMinVals( i );
136 real tMax = mMaxVals( i );
144 if ( mTypes.test( i ) )
146 tMin = std::log( tMin );
147 tMax = std::log( tMax );
151 real tMean = 0.5 * ( tMin + tMax );
152 real tStdDev = ( tMax - tMin ) / 6.0;
161 real tZ = std::sqrt( -2.0 * std::log( u1 ) ) * std::cos( 2.0 *
constant::pi * u2 );
163 real tValue = tMean + tStdDev * tZ ;
166 tValue = std::max( std::min( tValue, tMax ), tMin );
169 tValue = ( tValue - tMin ) / ( tMax - tMin );
172 encode( i, std::round( tValue * ( ( 1u << B ) - 1 ) ) );
180 size_t tNumBits = N * B;
192 for(
size_t k=0; k<tSplit; ++k )
194 if( aMom->mDNA.
test( k ) )
201 for(
size_t k=tSplit; k<tNumBits; ++k )
203 if( aDad->mDNA.
test( k ) )
210 mDNA.flip( tMutate );
241 decode(
const size_t aIndex )
const
247 size_t tCount = aIndex * B ;
248 for(
size_t i=0; i<B; ++i )
250 if ( mDNA.
test( tCount++ ) )
260 encode(
const size_t aIndex,
uint aValue )
262 size_t tCount = aIndex *
B;
263 for(
size_t i=0;
i<
B; ++
i)
270 mDNA.reset(tCount++);
277 template <
size_t B,
size_t N >
Compile-time fixed-size bitset.
Definition cl_Bitset.hpp:32
bool test(const index_t aIndex) const
test if a bit is set
Definition cl_Bitset.hpp:138
Definition cl_Genome.hpp:29
void kill()
Definition cl_Genome.hpp:226
void set_fitness(const real aFitness)
Definition cl_Genome.hpp:220
void randomize()
Definition cl_Genome.hpp:130
Genome(const Vector< real > &aMinVals, const Vector< real > &aMaxVals, const Bitset< N > &aTypes)
Definition cl_Genome.hpp:38
void set_values(const Vector< real > &aValues)
Definition cl_Genome.hpp:49
real fitness() const
Definition cl_Genome.hpp:214
void inherit(const Genome *aMom, const Genome *aDad)
Definition cl_Genome.hpp:177
void get_values(Vector< real > &aValues) const
Definition cl_Genome.hpp:83
bool is_alive() const
Definition cl_Genome.hpp:233
const real pi
circle number
Definition constants.hpp:41
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
constexpr real BELFEM_EPSILON
Definition typedefs.hpp:90
double real
Definition typedefs.hpp:36
size_t size_t
Definition typedefs.hpp:25
real rand()
a random number between 0 and 1 must call seed first
Definition random.hpp:86
B
Definition test_twist_crosscheck.py:30
Definition cl_Genome.hpp:279
bool operator()(const Genome< B, N > *aA, const Genome< B, N > *aB)
Definition cl_Genome.hpp:281
#define BELFEM_REAL_MAX
Definition typedefs.hpp:81