Skip to main content

FloatGene

Struct FloatGene 

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

A Gene that represents a floating point number. The allele is the in the case of the FloatGene is of type F - which is a floating point type. The min and max values default to F::MIN and F::MAX respectively. During evolution, the value_range is used to generate new allele values, while the bounds are used to ensure that the allele remains within a valid range. If no bounds are provided, they default to the same values as value_range.

§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> FloatGene<F>
where F: Float,

Source

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

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

Trait Implementations§

Source§

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

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> ArithmeticGene for FloatGene<F>
where F: Float,

Source§

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

Source§

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

Source§

fn min(&self) -> &<FloatGene<F> as Gene>::Allele

Source§

fn max(&self) -> &<FloatGene<F> as Gene>::Allele

Source§

fn bounds( &self, ) -> (&<FloatGene<F> as Gene>::Allele, &<FloatGene<F> as Gene>::Allele)

Source§

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

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

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

Source§

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

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

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

Source§

fn default() -> FloatGene<F>

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

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

Source§

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

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

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

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> From<(Range<F>, Range<F>)> for FloatGene<F>
where F: Float,

Source§

fn from(_: (Range<F>, Range<F>)) -> FloatGene<F>

Converts to this type from the input type.
Source§

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

Source§

fn from(allele: F) -> FloatGene<F>

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from_iter<I>(iter: I) -> FloatChromosome<F>
where I: IntoIterator<Item = FloatGene<F>>,

Creates a value from an iterator. Read more
Source§

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

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> Mul for FloatGene<F>
where F: Float,

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 for FloatGene<F>
where F: PartialEq + Float,

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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> StructuralPartialEq for FloatGene<F>
where F: PartialEq + Float,

Source§

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

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> Valid for FloatGene<F>
where F: Float,

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

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<G, T> NumericGene for G
where G: Gene<Allele = T>, T: NumericAllele,

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more