|
panga
|
#include <Chromosome.h>


Public Member Functions | |
| Chromosome (const Genome &genome) | |
| Chromosome (const Chromosome &rhs)=delete | |
| Chromosome (Chromosome &&rhs)=default | |
| Chromosome & | operator= (const Chromosome &rhs)=delete |
| const Genome & | GetGenome () const |
| void | Randomize (RandomWrapper *random) |
| template<typename IntegerType = uint64_t, bool use_gray_encoding = true> | |
| IntegerType | DecodeIntegerGene (size_t gene_index, IntegerType min=0, IntegerType max=std::numeric_limits< IntegerType >::max()) const |
| template<typename IntegerType = uint64_t, bool use_gray_encoding = true> | |
| void | EncodeIntegerGene (size_t gene_index, IntegerType value) |
| template<typename FloatType = double, bool use_gray_encoding = true> | |
| FloatType | DecodeFloatGene (size_t gene_index, FloatType min, FloatType max) const |
| template<typename FloatType = double, bool use_gray_encoding = true> | |
| void | EncodeFloatGene (size_t gene_index, FloatType value, FloatType min, FloatType max) |
| bool | DecodeBooleanGene (size_t gene_index) const |
| void | EncodeBooleanGene (size_t gene_index, bool value) |
| std::byte * | GetRawGene (size_t gene_index, size_t *gene_bit_width) |
Public Member Functions inherited from panga::BitVector | |
| BitVector (size_t bit_count=0) | |
| BitVector (const BitVector &source) | |
| BitVector & | operator= (const BitVector &rhs) |
| bool | Equals (const BitVector &rhs, size_t bits_to_compare) const |
| bool | Equals (const BitVector &rhs) const |
| void | SetBitCount (size_t bit_count) |
| size_t | GetBitCount () const |
| void | Clip (size_t bit_count) |
| void | Clear () |
| void | Set (size_t index) |
| void | Unset (size_t index) |
| bool | Get (size_t index) const |
| void | Flip (size_t index) |
| template<typename IntegerType = uint64_t> | |
| IntegerType | GetInt (size_t bit_index, size_t bit_width) const |
| template<typename IntegerType = uint64_t> | |
| void | SetInt (IntegerType value, size_t bit_index, size_t bit_width) |
| void | SubVector (BitVector *destination, size_t destination_start_bit_offset, size_t source_start_bit_offset, size_t bits_to_copy) const |
| size_t | HammingDistance (const BitVector &rhs) const |
| size_t | ToString (char *buffer, size_t buffer_length) const |
| void | FromString (const char *buffer, size_t buffer_length) |
| size_t | ToStringHex (char *buffer, size_t buffer_length) const |
| void | FromStringHex (const char *buffer, size_t buffer_length) |
Static Public Member Functions | |
| template<typename IntegerType = uint64_t> | |
| static IntegerType | DecodeGray (IntegerType gray_value) |
| template<typename IntegerType = uint64_t> | |
| static IntegerType | EncodeGray (IntegerType binary_value) |
| template<typename FloatType = double, typename IntegerType = uint64_t> | |
| static FloatType | DecodeFloat (IntegerType int_value, size_t bit_width, FloatType min, FloatType max) |
| template<typename FloatType = double, typename IntegerType = uint64_t> | |
| static IntegerType | EncodeFloat (FloatType float_value, size_t bit_width, FloatType min, FloatType max) |
| static void | UniformCrossover (const Chromosome &parent1, const Chromosome &parent2, Chromosome *offspring, RandomWrapper *random, bool ignore_gene_boundaries=true) |
| static void | KPointCrossover (size_t k, const Chromosome &parent1, const Chromosome &parent2, Chromosome *offspring, RandomWrapper *random, bool ignore_gene_boundaries=true) |
| static void | FlipMutator (Chromosome *chromosome, double mutation_percentage, RandomWrapper *random) |
Additional Inherited Members | |
Static Public Attributes inherited from panga::BitVector | |
| static HexFormat_t | HexFormat |
Protected Member Functions inherited from panga::BitVector | |
| const std::vector< std::byte > & | GetBytes () const |
| std::vector< std::byte > & | GetBytesWritable () |
| void | Resize (size_t bit_count) |
| void | WriteToStream (std::ostream &out) const |
| void | WriteToStreamHex (std::ostream &out) const |
Static Protected Member Functions inherited from panga::BitVector | |
| template<typename IntegerType = uint64_t> | |
| static void | WriteInt (std::byte *bytes, size_t start_bit_index, size_t bits_to_copy, IntegerType value) |
| template<typename IntegerType = uint64_t> | |
| static IntegerType | ReadInt (const std::byte *bytes, size_t start_bit_index, size_t bits_to_copy) |
| static void | WriteBytes (const std::byte *source, size_t source_start_bit_offset, std::byte *destination, size_t destination_start_bit_offset, size_t bits_to_copy) |
| static bool | Compare (const std::byte *left, const std::byte *right, size_t bits_to_compare) |
The binary data acting as an instance of a Genome.
Length of Chromosome in bits will be the same as the bits required to encode the Genome.
With the Genome, we know where all the genes are located in our binary data and we can interpret the bits making up each gene.
| bool panga::Chromosome::DecodeBooleanGene | ( | size_t | gene_index | ) | const |
Return true if the gene at |gene_index| is set and false if the gene is not set.
Note: |gene_index| must be the index of a boolean gene and not a gene with a bit width - even if that bit width is 1.
|
inlinestatic |
Decode a floating point number from an integer representation.
| int_value | The integer representation we will decode. |
| bit_width | How many bits of int_value do we want to decode. |
| min | Min value for the float. |
| max | Max value for the float. |
|
inline |
Fetch the binary data representing a gene and interpret it as a floating point number scaled between min and max.
If use_gray_encoding is true, we will treat the gene data as a gray-coded number and decode it into a binary representation before scaling.
| gene_index | The index of the gene we should interpret. |
| min | The min value which the float could assume. |
| max | The max value which the float could assume. |
|
inlinestatic |
Decode a binary integer from a gray-encoded value.
| gray_value | Gray-encoded value |
|
inline |
Fetch the binary data representing a gene and interpret it as an integer scaled between min and max.
If use_gray_encoding is true, we will treat the gene data as a gray-coded number and decode it into a binary representation before scaling.
| gene_index | The index of the gene we should interpret. |
| min | The min value which the integer could assume. |
| max | The max value which the integer could assume. |
| void panga::Chromosome::EncodeBooleanGene | ( | size_t | gene_index, |
| bool | value | ||
| ) |
Set the bit value at |gene_index|.
Note: |gene_index| must be the index of a boolean gene and not a gene with a bit width - even if that bit width is 1.
| value | If true, the bit at |gene_index| is set. If false, the bit at |gene_index| is unset. |
|
inlinestatic |
Encode a floating point number into an integer representation.
| float_value | Float value to encode. |
| bit_width | How many bits should we limit the integer representation to. |
| min | Min value for the float. |
| max | Max value for the float. |
|
inline |
Take a floating point value and encode it into the binary data representing a gene in the Chromosome.
If use_gray_encoding is true, we will encode value into a gray-coded value before writing it into the gene data.
| gene_index | The index of the gene we should write to. |
| value | The floating point value we want to write into the Chromosome. |
|
inlinestatic |
Encode a binary integer value into a gray representation.
| binary_value | Binary integer value |
|
inline |
Take an integer value and encode it into the binary data representing a gene in the Chromosome.
If use_gray_encoding is true, we will encode the integer into a gray-coded value before writing it into the gene data.
| gene_index | The index of the gene we should write to. |
| value | The integer value we want to write into the Chromosome. |
|
static |
Perform flip mutation on |chromosome|.
Every bit in |chromosome| will have |mutation_percentage| chance of flipping.
| const Genome & panga::Chromosome::GetGenome | ( | ) | const |
Get a read-only reference to the Genome used by this Chromosome.
| std::byte * panga::Chromosome::GetRawGene | ( | size_t | gene_index, |
| size_t * | gene_bit_width | ||
| ) |
Get the raw binary data from the Chromosome where the gene at |gene_index| is located. Doesn't interpret the binary data.
| gene_bit_width | An out param which receives the bit width of the gene at |gene_index|. |
|
static |
Perform k-point crossover between |parent1| and |parent2| and store the result in |offspring|.
| ignore_gene_boundaries | If false, gene boundaries will be respected. Instead of some bits from a gene being copied from |parent1| and some from |parent2|, all of the bits containing the gene will be copied together from a single parent. Genes are copied in chunks according to the cut points. If true, gene boundaries are ignored and the chromosome is treated as a single chunk of bits which is split into chunks according to the cut points. |
| void panga::Chromosome::Randomize | ( | RandomWrapper * | random | ) |
Randomize all bits in the Chromosome.
|
static |
Perform uniform crossover between |parent1| and |parent2| and store the result in |offspring|.
| ignore_gene_boundaries | If false, gene boundaries will be respected. Instead of some bits from a gene being copied from |parent1| and some from |parent2|, all of the bits containing the gene will be copied together from a single parent. Each gene still has uniformly equal chance of being copied from either parent. If true, gene boundaries are ignored and every bit in the chromosome has an equal chance to be copied from either parent. |
1.8.17