panga
Classes | Public Member Functions | List of all members
panga::Genome Class Reference

#include <Genome.h>

Classes

struct  Gene
 

Public Member Functions

 Genome (const Genome &rhs)=delete
 
 Genome (Genome &&rhs)=default
 
Genomeoperator= (const Genome &rhs)=delete
 
size_t AddGene (size_t bit_width, bool byte_align=false)
 
void SetBooleanGeneCount (size_t boolean_gene_count)
 
void AddBooleanGenes (size_t count)
 
size_t GetBooleanGeneCount () const
 
size_t GetGeneStartBitIndex (size_t gene_index) const
 
size_t GetGeneBitWitdh (size_t gene_index) const
 
size_t GetFirstBooleanGeneBitIndex () const
 
size_t GetFirstBooleanGeneIndex () const
 
size_t GetGeneCount () const
 
size_t BitsRequired () const
 

Detailed Description

Provides a representation of the genes which, taken together, represent a genome for members of a species.
Using the Genome, we may decode a block of binary data and extract the bits representing each gene from the data. (This is what Chromosome does).
The Genome data may be constructed by adding genes one-at-a-time via AddGene along with an optional number of boolean genes.
The genome is structured into two pieces:

  1. Genes with a bit width
  2. Boolean genes which have only one bit value
    For performance reasons, all of the boolean genes are located at the end of the Genome. It is preferable to add a boolean gene than add a gene with bit width of 1.
    See also
    AddGene
    Chromosome

Member Function Documentation

◆ AddBooleanGenes()

void panga::Genome::AddBooleanGenes ( size_t  count)

Add count boolean genes to the boolean gene count for this Genome.
Does not return the gene indices because adding more non-boolean genes to the Genome can change the boolean gene indices.

See also
GetFirstBooleanGeneIndex
GetFirstBooleanGeneBitIndex

◆ AddGene()

size_t panga::Genome::AddGene ( size_t  bit_width,
bool  byte_align = false 
)

Add a gene to the Genome.
The new gene will be added to the end of the Genome.
This can be very useful if you want to access the memory backing this gene later directly (via something like Chromosome::GetRawGene).

Parameters
bit_widthThe width of the gene we want to add.
byte_alignIf true, we will shift the starting offset and bit width such that this gene begins and ends on a byte-boundary.
See also
Chromosome::GetRawGene
Returns
The gene index of the newly-added gene.

◆ BitsRequired()

size_t panga::Genome::BitsRequired ( ) const

Get the number of bits needed to encode this Genome.

◆ GetBooleanGeneCount()

size_t panga::Genome::GetBooleanGeneCount ( ) const

Get the number of boolean Genes in the Genome.

◆ GetFirstBooleanGeneBitIndex()

size_t panga::Genome::GetFirstBooleanGeneBitIndex ( ) const

Get the bit index of the first boolean gene in the Genome.

◆ GetFirstBooleanGeneIndex()

size_t panga::Genome::GetFirstBooleanGeneIndex ( ) const

Get the gene index of the first boolean gene in the Genome.

◆ GetGeneBitWitdh()

size_t panga::Genome::GetGeneBitWitdh ( size_t  gene_index) const

Get the bit width for a gene.

Parameters
gene_indexIndex of the gene we should return the width for.
Returns
The width in bits of gene at index gene_index.

◆ GetGeneCount()

size_t panga::Genome::GetGeneCount ( ) const

Get the count of genes in the Genome.
Note: Includes the count of boolean genes.

◆ GetGeneStartBitIndex()

size_t panga::Genome::GetGeneStartBitIndex ( size_t  gene_index) const

Get the bit offset where a gene starts.

◆ SetBooleanGeneCount()

void panga::Genome::SetBooleanGeneCount ( size_t  boolean_gene_count)

Set the number of boolean genes in this Genome.
This overwrites any value currently in the boolean gene count.


The documentation for this class was generated from the following files: