pub struct BitCodec<T = ()> { /* private fields */ }
Expand description
A Codec for a Genotype
of BitGenes
. The encode
function creates a Genotype
with num_chromosomes
chromosomes
and num_genes
genes per chromosome. The decode
function creates a Vec<Vec<bool>>
from the Genotype
where the inner Vec
contains the alleles of the BitGenes
in the chromosome - the bool
values.
§Example
// In traditional genetic algorithms, a `BitCodec` would be used to create a `Genotype` of `BitGenes`, or a bit string.
// This would simply be created by the following:
use radiate_core::*;
// The number of bits (`BitGenes`) in the bit string
let length = 10;
// Create a new matrix `BitCodec` with a single chromosome and `length` genes
let codec = BitCodec::matrix(1, length);
// Create a new `Genotype` of `BitGenes` with a single chromosome and `length` genes
let genotype = codec.encode();
// Decode the `Genotype` to a `Vec<Vec<bool>>`, then get the first chromosome
let bit_string: Vec<bool> = codec.decode(&genotype)[0].clone();
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for BitCodec<T>
impl<T> RefUnwindSafe for BitCodec<T>where
T: RefUnwindSafe,
impl<T> Send for BitCodec<T>where
T: Send,
impl<T> Sync for BitCodec<T>where
T: Sync,
impl<T> Unpin for BitCodec<T>where
T: Unpin,
impl<T> UnwindSafe for BitCodec<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more