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 generate_with_len<R: Rng>(rng: &mut R, len: usize) -> Self
pub fn generate_with_len<R: Rng>(rng: &mut R, len: usize) -> Self
Generate a random bit string of an explicit length.
This is the honest constructor for random generation: unlike
EvolutionaryGenome::generate,
which overloads MultiBounds and only reads its dimension count, this
takes the number of bits directly.
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.
§Panics
Panics if the two bit strings have different lengths (an invariant
violation). Use try_hamming_distance for
a fallible variant.
Sourcepub fn try_hamming_distance(&self, other: &Self) -> Result<usize, GenomeError>
pub fn try_hamming_distance(&self, other: &Self) -> Result<usize, GenomeError>
Fallible Hamming distance: returns Err(GenomeError::DimensionMismatch)
when the two bit strings differ in length instead of silently truncating
to the shorter one.
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
Source§fn count_zeros(&self) -> usize
fn count_zeros(&self) -> usize
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>,
impl Eq for BitString
Source§impl EvolutionaryGenome for BitString
impl EvolutionaryGenome for BitString
Source§fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
Generate a random bit string.
Only bounds.dimension() is consulted — it is the number of bits — and
the per-dimension min/max values are ignored. Prefer
BitString::generate_with_len to make the length explicit.
Source§fn as_mut_slice(&mut self) -> Option<&mut [bool]>
fn as_mut_slice(&mut self) -> Option<&mut [bool]>
Source§fn try_distance(&self, other: &Self) -> Result<f64, GenomeError>
fn try_distance(&self, other: &Self) -> Result<f64, GenomeError>
Source§impl IntoIterator for BitString
impl IntoIterator for BitString
Source§impl<'a> IntoIterator for &'a BitString
impl<'a> IntoIterator for &'a BitString
Source§impl MutationOperator<BitString> for BitFlipMutation
impl MutationOperator<BitString> for BitFlipMutation
Source§impl MutationOperator<BitString> for SwapMutation
impl MutationOperator<BitString> for SwapMutation
Source§impl MutationOperator<BitString> for ScrambleMutation
impl MutationOperator<BitString> for ScrambleMutation
impl StructuralPartialEq for BitString
Source§impl TraceGenome for BitString
Available on crate feature ppl only.
impl TraceGenome for BitString
ppl only.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.
A missing address terminates the scan (normal end of the sequence),
but an address that is present with the wrong value type is a corrupt
trace and yields GenomeError::TypeMismatch rather than silently
truncating.
Source§fn trace_prefix() -> &'static str
fn trace_prefix() -> &'static str
"gene").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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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<T> Scalar 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>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.