NK-const.hpp
This file provides code to build NK landscapes, setup at compile time..
Knowing the size of N and K at compile time allow for slightly more optimized code, at the expense of flexibility.
-
template<size_t N, size_t K>
class NKLandscapeConst - #include <NK-const.hpp>
An NK Landscape is a popular tool for studying theoretical questions about evolutionary dynamics. It is a randomly generated fitness landscape on which bitstrings can evolve. NK Landscapes have two parameters: N (the length of the bitstrings) and K (epistasis). Since you have control over the amount of epistasis, NK Landscapes are often called “tunably rugged” - a useful feature, since the ruggedness of the fitness landscape is thought to be important to many evolutionary dynamics. For each possible value that a site and its K neighbors to the right can have, a random fitness contribution is chosen. These contributions are summed across the bitstring. So when K = 0, each site has a single optimal value, resulting in a single smooth fitness peak.
For more information, see Kauffman and Levin, 1987 (Towards a general theory of adaptive walks on rugged landscapes).
This object handles generating and maintaining an NK fitness landscape. Note: Overly large Ns and Ks currently trigger a seg-fault, caused by trying to build a table that is larger than will fit in memory. You can use larger values of N and K (for slightly reduced speed) of you use an NKLandscape object instead.
Public Functions
-
NKLandscapeConst() = delete
-
inline NKLandscapeConst(Random &random)
Build a new NKLandscapeConst using the random number generator [random].
-
NKLandscapeConst(const NKLandscapeConst&) = delete
-
inline ~NKLandscapeConst()
-
NKLandscapeConst &operator=(const NKLandscapeConst&) = delete
-
inline constexpr size_t GetN() const
Returns N.
-
inline constexpr size_t GetK() const
Returns K.
-
inline constexpr size_t GetStateCount() const
Get the number of posssible states for a given site.
-
inline constexpr size_t GetTotalCount() const
Get the total number of states possible in the landscape (i.e. the number of different fitness contributions in the table)
-
inline double GetFitness(size_t n, size_t state) const
Get the fitness contribution of position [n] when it (and its K neighbors) have the value [state]
Private Members
-
std::array<std::array<double, state_count()>, N> landscape
-
NKLandscapeConst() = delete