You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed-length string of bits for binary/discrete optimization.
Module
use fugue_evo::genome::bit_string::BitString;
Construction
// From vectorlet genome = BitString::new(vec![true,false,true,true]);// All zeroslet genome = BitString::zeros(10);// All oneslet genome = BitString::ones(10);// Randomlet genome = BitString::random(10,&mut rng);// Random with probabilitylet genome = BitString::random_with_probability(10,0.3,&mut rng);
Methods
Access
Method
Return
Description
bits()
&[bool]
Immutable bit access
bits_mut()
&mut [bool]
Mutable bit access
length()
usize
Number of bits
get(i)
Option<bool>
Get bit at index
Bit Operations
Method
Description
flip(i)
Flip bit at index
set(i, val)
Set bit to value
count_ones()
Number of true bits
count_zeros()
Number of false bits
Binary Operations
Method
Description
and(&other)
Bitwise AND
or(&other)
Bitwise OR
xor(&other)
Bitwise XOR
not()
Bitwise NOT
Distance
Method
Description
hamming_distance(&other)
Number of differing bits
Trace Representation
Bits stored as 0.0 or 1.0:
addr!("bit",0) → 0.0 or 1.0addr!("bit",1) → 0.0 or 1.0// ...
Recommended Operators
Crossover
// Uniform: each bit from random parentUniformCrossover::new()// One-point crossoverOnePointCrossover::new()// Two-point crossoverTwoPointCrossover::new()
Mutation
// Flip each bit with probabilityBitFlipMutation::new(0.01)// 1% per bit