Skip to main content

FloatGene

Struct FloatGene 

Source
pub struct FloatGene<F: Float> { /* private fields */ }
Expand description

Minimum and maximum values for the FloatGene allele. This should be large enough to cover most practical use cases but small enough to avoid overflow or underflow issues in calculations. 1e18 = 1 quintillion A Gene that represents a floating point number. The allele is the in the case of the FloatGene a f32. The min and max values default to [MIN] and [MAX] respectively. The min and max values are used to generate a random number between the min and max values, which is the allele of the FloatGene. The upper_bound and lower_bound are used to set the bounds of the FloatGene when it is used in a BoundGene context (crossover or mutation). The upper_bound and lower_bound default to [MAX] and [MIN] respectively.

§Example

use radiate_core::*;

// Create a new FloatGene with a min value of 0 and a max value of 1 meaning the
// allele will be a random number between 0 and 1.
// The upper_bound and lower_bound are set to 0 and 1 respectively.
let gene = FloatGene::from(0_f32..1_f32);

// Create a new FloatGene with a min of 0 and a max of 1 and set the upper_bound
// and lower_bound to 0 and 100 respectively.
let gene = FloatGene::from((0_f32..1_f32, 0_f32..100_f32));

Implementations§

Source§

impl<F: Float> FloatGene<F>

Source

pub fn new(allele: F, value_range: Range<F>, bounds: Range<F>) -> Self

Creates a new FloatGene with the given allele, value_range, and bounds.

Trait Implementations§

Source§

impl<F: Float> Add for FloatGene<F>

Source§

type Output = FloatGene<F>

The resulting type after applying the + operator.
Source§

fn add(self, other: FloatGene<F>) -> FloatGene<F>

Performs the + operation. Read more
Source§

impl<F: Float> ArithmeticGene for FloatGene<F>

Source§

fn mean(&self, other: &FloatGene<F>) -> FloatGene<F>

Source§

impl<F: Float> BoundedGene for FloatGene<F>

Source§

fn min(&self) -> &Self::Allele

Source§

fn max(&self) -> &Self::Allele

Source§

fn bounds(&self) -> (&Self::Allele, &Self::Allele)

Source§

impl<F: Clone + Float> Clone for FloatGene<F>

Source§

fn clone(&self) -> FloatGene<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug + Float> Debug for FloatGene<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Float> Default for FloatGene<F>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<F: Float> Display for FloatGene<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Float> Div for FloatGene<F>

Source§

type Output = FloatGene<F>

The resulting type after applying the / operator.
Source§

fn div(self, other: FloatGene<F>) -> FloatGene<F>

Performs the / operation. Read more
Source§

impl<F: Float> From<(Range<F>, Range<F>)> for FloatGene<F>

Source§

fn from((value_range, bounds): (Range<F>, Range<F>)) -> Self

Converts to this type from the input type.
Source§

impl<F: Float> From<F> for FloatGene<F>

Source§

fn from(allele: F) -> Self

Converts to this type from the input type.
Source§

impl<F: Float> From<FloatGene<F>> for FloatChromosome<F>

Source§

fn from(gene: FloatGene<F>) -> Self

Converts to this type from the input type.
Source§

impl<F: Float> From<Range<F>> for FloatGene<F>

Source§

fn from(range: Range<F>) -> Self

Converts to this type from the input type.
Source§

impl<F: Float> FromIterator<FloatGene<F>> for FloatChromosome<F>

Source§

fn from_iter<I: IntoIterator<Item = FloatGene<F>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<F: Float> Gene for FloatGene<F>

Source§

type Allele = F

Source§

fn allele(&self) -> &F

Get the allele of the Gene. This is the value that the Gene represents or “expresses”.
Source§

fn allele_mut(&mut self) -> &mut F

Get a mutable reference to the allele of the Gene.
Source§

fn new_instance(&self) -> FloatGene<F>

Create a new instance of the Gene.
Source§

fn with_allele(&self, allele: &F) -> FloatGene<F>

Create a new Gene with the given allele.
Source§

impl<F: Float> Mul for FloatGene<F>

Source§

type Output = FloatGene<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: FloatGene<F>) -> FloatGene<F>

Performs the * operation. Read more
Source§

impl<F: PartialEq + Float> PartialEq for FloatGene<F>

Source§

fn eq(&self, other: &FloatGene<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Float> Sub for FloatGene<F>

Source§

type Output = FloatGene<F>

The resulting type after applying the - operator.
Source§

fn sub(self, other: FloatGene<F>) -> FloatGene<F>

Performs the - operation. Read more
Source§

impl<F: Float> Valid for FloatGene<F>

Implement the Valid trait for the FloatGene.

The is_valid method checks if the allele of the FloatGene is between the min and max values. The GeneticEngine will check the validity of the Chromosome and Phenotype and remove any invalid individuals from the population, replacing them with new individuals at the given generation.

Source§

fn is_valid(&self) -> bool

Source§

impl<F: Float> StructuralPartialEq for FloatGene<F>

Auto Trait Implementations§

§

impl<F> Freeze for FloatGene<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for FloatGene<F>
where F: RefUnwindSafe,

§

impl<F> Send for FloatGene<F>
where F: Send,

§

impl<F> Sync for FloatGene<F>
where F: Sync,

§

impl<F> Unpin for FloatGene<F>
where F: Unpin,

§

impl<F> UnsafeUnpin for FloatGene<F>
where F: UnsafeUnpin,

§

impl<F> UnwindSafe for FloatGene<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<G, T> NumericGene for G
where G: Gene<Allele = T>, T: NumericAllele,