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
impl BitString
Sourcepub fn from_u64(value: u64, length: usize) -> Self
pub fn from_u64(value: u64, length: usize) -> Self
Create a bit string from a u64 with the given length
Sourcepub fn complement(&self) -> Self
pub fn complement(&self) -> Self
Get the complement (all bits flipped)
Sourcepub fn hamming_distance(&self, other: &Self) -> usize
pub fn hamming_distance(&self, other: &Self) -> usize
Hamming distance to another bit string
Sourcepub fn and(&self, other: &Self) -> Result<Self, GenomeError>
pub fn and(&self, other: &Self) -> Result<Self, GenomeError>
Bitwise AND with another bit string
Sourcepub fn or(&self, other: &Self) -> Result<Self, GenomeError>
pub fn or(&self, other: &Self) -> Result<Self, GenomeError>
Bitwise OR with another bit string
Sourcepub fn xor(&self, other: &Self) -> Result<Self, GenomeError>
pub fn xor(&self, other: &Self) -> Result<Self, GenomeError>
Bitwise XOR with another bit string
Trait Implementations§
Source§impl BinaryGenome for BitString
impl BinaryGenome for BitString
Source§fn count_ones(&self) -> usize
fn count_ones(&self) -> usize
Count the number of true bits (ones)
Source§fn count_zeros(&self) -> usize
fn count_zeros(&self) -> usize
Count the number of false bits (zeros)
Source§impl<'de> Deserialize<'de> for BitString
impl<'de> Deserialize<'de> for BitString
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 EvolutionaryGenome for BitString
impl EvolutionaryGenome for BitString
Source§fn to_trace(&self) -> Trace
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>
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§fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
Generate a random genome within the given bounds
Source§fn as_mut_slice(&mut self) -> Option<&mut [bool]>
fn as_mut_slice(&mut self) -> Option<&mut [bool]>
Get the genome’s genes as a mutable slice (for numeric genomes)
Source§fn trace_prefix() -> &'static str
fn trace_prefix() -> &'static str
Get the address prefix used for trace storage (default: “gene”)
Source§impl<'a> IntoIterator for &'a BitString
impl<'a> IntoIterator for &'a BitString
Source§impl IntoIterator for BitString
impl IntoIterator for BitString
Source§impl MutationOperator<BitString> for BitFlipMutation
impl MutationOperator<BitString> for BitFlipMutation
Source§impl MutationOperator<BitString> for ScrambleMutation
impl MutationOperator<BitString> for ScrambleMutation
Source§impl MutationOperator<BitString> for SwapMutation
impl MutationOperator<BitString> for SwapMutation
impl Eq for BitString
impl StructuralPartialEq for BitString
Auto Trait Implementations§
impl Freeze for BitString
impl RefUnwindSafe for BitString
impl Send for BitString
impl Sync for BitString
impl Unpin for BitString
impl UnsafeUnpin for BitString
impl UnwindSafe for BitString
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
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
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.