Skip to main content

BitString

Struct BitString 

Source
pub struct BitString { /* private fields */ }
Expand description

Fixed-length bit string genome

This genome type represents binary optimization problems where solutions are vectors of boolean values.

Implementations§

Source§

impl BitString

Source

pub fn new(bits: Vec<bool>) -> Self

Create a new bit string with the given bits

Source

pub fn zeros(length: usize) -> Self

Create an all-zeros bit string of the given length

Source

pub fn ones(length: usize) -> Self

Create an all-ones bit string of the given length

Source

pub fn from_u64(value: u64, length: usize) -> Self

Create a bit string from a u64 with the given length

Source

pub fn to_u64(&self) -> Option<u64>

Convert to a u64 (only valid for length <= 64)

Source

pub fn len(&self) -> usize

Get the length of the bit string

Source

pub fn is_empty(&self) -> bool

Check if the bit string is empty

Source

pub fn get(&self, index: usize) -> Option<bool>

Get a specific bit

Source

pub fn set(&mut self, index: usize, value: bool)

Set a specific bit

Source

pub fn flip(&mut self, index: usize)

Flip a specific bit

Source

pub fn flip_all(&mut self)

Flip all bits

Source

pub fn complement(&self) -> Self

Get the complement (all bits flipped)

Source

pub fn hamming_distance(&self, other: &Self) -> usize

Hamming distance to another bit string

Source

pub fn and(&self, other: &Self) -> Result<Self, GenomeError>

Bitwise AND with another bit string

Source

pub fn or(&self, other: &Self) -> Result<Self, GenomeError>

Bitwise OR with another bit string

Source

pub fn xor(&self, other: &Self) -> Result<Self, GenomeError>

Bitwise XOR with another bit string

Trait Implementations§

Source§

impl BinaryGenome for BitString

Source§

fn bits(&self) -> &[bool]

Get the bits as a slice
Source§

fn bits_mut(&mut self) -> &mut [bool]

Get the bits as a mutable slice
Source§

fn from_bits(bits: Vec<bool>) -> Result<Self, GenomeError>

Create from a vector of bits
Source§

fn count_ones(&self) -> usize

Count the number of true bits (ones)
Source§

fn count_zeros(&self) -> usize

Count the number of false bits (zeros)
Source§

impl Clone for BitString

Source§

fn clone(&self) -> BitString

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 CrossoverOperator<BitString> for OnePointCrossover

Source§

fn crossover<R: Rng>( &self, parent1: &BitString, parent2: &BitString, rng: &mut R, ) -> OperatorResult<(BitString, BitString)>

Apply crossover to two parents and produce two offspring
Source§

fn crossover_probability(&self) -> f64

Get the probability of crossover being applied
Source§

impl CrossoverOperator<BitString> for TwoPointCrossover

Source§

fn crossover<R: Rng>( &self, parent1: &BitString, parent2: &BitString, rng: &mut R, ) -> OperatorResult<(BitString, BitString)>

Apply crossover to two parents and produce two offspring
Source§

fn crossover_probability(&self) -> f64

Get the probability of crossover being applied
Source§

impl CrossoverOperator<BitString> for UniformCrossover

Source§

fn crossover<R: Rng>( &self, parent1: &BitString, parent2: &BitString, rng: &mut R, ) -> OperatorResult<(BitString, BitString)>

Apply crossover to two parents and produce two offspring
Source§

fn crossover_probability(&self) -> f64

Get the probability of crossover being applied
Source§

impl Debug for BitString

Source§

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

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

impl<'de> Deserialize<'de> for BitString

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for BitString

Source§

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

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

impl EvolutionaryGenome for BitString

Source§

fn to_trace(&self) -> Trace

Convert BitString to Fugue trace.

Each bit is stored at address “bit#i” where i is the index.

Source§

fn from_trace(trace: &Trace) -> Result<Self, GenomeError>

Reconstruct BitString from Fugue trace.

Reads bits from addresses “bit#0”, “bit#1”, … until no more are found.

Source§

type Allele = bool

The allele type for individual genes
Source§

type Phenotype = Vec<bool>

The phenotype or decoded solution type
Source§

fn decode(&self) -> Self::Phenotype

Decode genome into phenotype for fitness evaluation
Source§

fn dimension(&self) -> usize

Compute dimensionality for adaptive operators
Source§

fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self

Generate a random genome within the given bounds
Source§

fn as_slice(&self) -> Option<&[bool]>

Get the genome’s genes as a slice (for numeric genomes)
Source§

fn as_mut_slice(&mut self) -> Option<&mut [bool]>

Get the genome’s genes as a mutable slice (for numeric genomes)
Source§

fn distance(&self, other: &Self) -> f64

Distance metric between two genomes (default: 0.0)
Source§

fn trace_prefix() -> &'static str

Get the address prefix used for trace storage (default: “gene”)
Source§

impl<const N: usize> From<[bool; N]> for BitString

Source§

fn from(arr: [bool; N]) -> Self

Converts to this type from the input type.
Source§

impl From<BitString> for Vec<bool>

Source§

fn from(genome: BitString) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<bool>> for BitString

Source§

fn from(bits: Vec<bool>) -> Self

Converts to this type from the input type.
Source§

impl Hash for BitString

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Index<usize> for BitString

Source§

type Output = bool

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a BitString

Source§

type Item = &'a bool

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, bool>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for BitString

Source§

type Item = bool

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<bool>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl MutationOperator<BitString> for BitFlipMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut BitString, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl MutationOperator<BitString> for ScrambleMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut BitString, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl MutationOperator<BitString> for SwapMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut BitString, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl PartialEq for BitString

Source§

fn eq(&self, other: &BitString) -> 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 Serialize for BitString

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for BitString

Source§

impl StructuralPartialEq for BitString

Auto Trait Implementations§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,