pub struct IntCodec<T: Integer<T>, D = T> { /* private fields */ }
Expand description
A Codec for a Genotype of IntGenes
. The encode
function creates a Genotype with num_chromosomes
chromosomes
and num_genes
genes per chromosome. The decode
function creates a Vec<Vec<T>>
from the Genotype where the inner Vec
contains the alleles of the IntGenes
in the chromosome. T
must implement the Integer
trait, meaning it must be one of
i8
, i16
, i32
, i64
, i128
, u8
, u16
, u32
, u64
, or u128
.
The lower and upper bounds of the IntGenes
can be set with the with_bounds
function.
The default bounds are equal to min
and max
.
Implementations§
Source§impl<T: Integer<T>, D> IntCodec<T, D>
impl<T: Integer<T>, D> IntCodec<T, D>
pub fn with_bounds(self, bounds: Range<T>) -> Self
Trait Implementations§
Source§impl<T: Integer<T>> Codec<IntChromosome<T>, T> for IntCodec<T, T>
impl<T: Integer<T>> Codec<IntChromosome<T>, T> for IntCodec<T, T>
§Example
use radiate_core::*;
// Create a new IntCodec with a single gene
// per chromosome - a single i32 value.
let codec = IntCodec::scalar(0..100);
let genotype: Genotype<IntChromosome<i32>> = codec.encode();
let decoded: i32 = codec.decode(&genotype);
fn encode(&self) -> Genotype<IntChromosome<T>>
fn decode(&self, genotype: &Genotype<IntChromosome<T>>) -> T
Source§impl<T: Integer<T>> Codec<IntChromosome<T>, Vec<T>> for IntCodec<T, Vec<T>>
impl<T: Integer<T>> Codec<IntChromosome<T>, Vec<T>> for IntCodec<T, Vec<T>>
§Example
use radiate_core::*;
// Create a new IntCodec with 10 genes
// per chromosome - a vector of i32 values.
let codec = IntCodec::vector(10, 0..100);
let genotype: Genotype<IntChromosome<i32>> = codec.encode();
let decoded: Vec<i32> = codec.decode(&genotype);
Source§impl<T: Integer<T>> Codec<IntChromosome<T>, Vec<Vec<T>>> for IntCodec<T, Vec<Vec<T>>>
impl<T: Integer<T>> Codec<IntChromosome<T>, Vec<Vec<T>>> for IntCodec<T, Vec<Vec<T>>>
§Example
use radiate_core::*;
// Create a new IntCodec with 10 chromosomes with 10 genes
// per chromosome - a matrix of i32 values.
let codec = IntCodec::matrix(10, 10, 0..100);
let genotype: Genotype<IntChromosome<i32>> = codec.encode();
let decoded: Vec<Vec<i32>> = codec.decode(&genotype);
Auto Trait Implementations§
impl<T, D> Freeze for IntCodec<T, D>where
T: Freeze,
impl<T, D> RefUnwindSafe for IntCodec<T, D>where
T: RefUnwindSafe,
D: RefUnwindSafe,
impl<T, D> Send for IntCodec<T, D>
impl<T, D> Sync for IntCodec<T, D>
impl<T, D> Unpin for IntCodec<T, D>
impl<T, D> UnwindSafe for IntCodec<T, D>where
T: UnwindSafe,
D: 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