13 #ifndef EMP_EVO_NK_CONST_H 14 #define EMP_EVO_NK_CONST_H 18 #include "../base/assert.h" 19 #include "../tools/BitSet.h" 20 #include "../tools/math.h" 21 #include "../tools/Random.h" 45 template <
size_t N,
size_t K>
48 static constexpr
size_t state_count() {
return emp::IntPow<size_t>(2,K+1); }
49 static constexpr
size_t total_count() {
return N * state_count(); }
50 std::array< std::array<double, state_count()>, N > landscape;
57 for ( std::array<
double, state_count()> & ltable : landscape) {
58 for (
double & pos : ltable) {
68 constexpr
size_t GetN()
const {
return N; }
70 constexpr
size_t GetK()
const {
return K; }
80 emp_assert(state < state_count(), state, state_count());
82 return landscape[n][state];
86 double GetFitness( std::array<size_t, N> states )
const {
87 double total = landscape[0][states[0]];
88 for (
size_t i = 1; i < N; i++) total +=
GetFitness(i,states[i]);
95 BitSet<N*2> genome2( genome.template Export<N*2>() );
96 genome2 |= (genome2 << N);
99 constexpr
size_t mask = emp::MaskLow<size_t>(K+1);
100 for (
size_t i = 0; i < N; i++) {
101 const size_t cur_val = (genome2 >> (int)i).
GetUInt(0) & mask;
102 const double cur_fit =
GetFitness(i, cur_val);
A versatile and non-patterned pseudo-random-number generator (Mersenne Twister).
Definition: ce_random.h:52
double GetFitness(size_t n, size_t state) const
Definition: NK-const.h:79
constexpr size_t GetN() const
Returns N.
Definition: NK-const.h:68
uint32_t GetUInt(size_t index) const
Get the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id) ...
Definition: BitSet.h:280
double GetFitness(std::array< size_t, N > states) const
Get the fitness of a whole bitstring.
Definition: NK-const.h:86
~NKLandscapeConst()
Definition: NK-const.h:64
NKLandscapeConst()=delete
Definition: NK-const.h:46
constexpr size_t GetTotalCount() const
Definition: NK-const.h:75
constexpr size_t GetStateCount() const
Get the number of posssible states for a given site.
Definition: NK-const.h:72
constexpr double GetDouble()
Definition: ce_random.h:166
constexpr size_t GetK() const
Returns K.
Definition: NK-const.h:70
NKLandscapeConst(emp::Random &random)
Build a new NKLandscapeConst using the random number generator [random].
Definition: NK-const.h:56
double GetFitness(const BitSet< N > &genome) const
Get the fitness of a whole bitstring.
Definition: NK-const.h:93
If we are in emscripten, make sure to include the header.
Definition: array.h:37
NKLandscapeConst & operator=(const NKLandscapeConst &)=delete
#define emp_assert(...)
Definition: assert.h:199