pub struct RandomKeyChromosome {
pub keys: Vec<f64>,
/* private fields */
}Expand description
Random-key chromosome for BRKGA.
Each gene is a floating-point value in [0, 1) that represents a random key. The decoder interprets these keys to construct a solution.
Fields§
§keys: Vec<f64>Random keys in [0, 1).
Implementations§
Source§impl RandomKeyChromosome
impl RandomKeyChromosome
Sourcepub fn set_fitness(&mut self, fitness: f64)
pub fn set_fitness(&mut self, fitness: f64)
Sets the fitness value.
Sourcepub fn biased_crossover<R: Rng>(
&self,
other: &Self,
elite_bias: f64,
rng: &mut R,
) -> Self
pub fn biased_crossover<R: Rng>( &self, other: &Self, elite_bias: f64, rng: &mut R, ) -> Self
Biased crossover with another chromosome.
For each gene, there’s an elite_bias probability of inheriting
from self (the elite parent) and 1 - elite_bias from other.
Sourcepub fn decode_as_permutation(&self) -> Vec<usize>
pub fn decode_as_permutation(&self) -> Vec<usize>
Decodes the random keys into a permutation (sorted indices by key value).
This is the most common decoding: sort items by their random keys to get a placement order.
Sourcepub fn decode_as_discrete(&self, key_idx: usize, num_options: usize) -> usize
pub fn decode_as_discrete(&self, key_idx: usize, num_options: usize) -> usize
Decodes a subset of keys as discrete values in a range.
For example, to decode orientation (0-5), use:
decode_as_discrete(key_idx, 6) which maps [0, 1) to {0, 1, 2, 3, 4, 5}.
Sourcepub fn discrete_key(choice: usize, num_options: usize) -> f64
pub fn discrete_key(choice: usize, num_options: usize) -> f64
The key Self::decode_as_discrete reads as choice of num_options
– how a known solution is written into a chromosome.
decode_as_discrete maps the interval
[choice / num_options, (choice + 1) / num_options) to choice; this
is its midpoint, the furthest a key can be from either edge, so a
crossover that nudges it still decodes as the same choice.
Sourcepub fn permutation_keys(order: &[usize], num_items: usize) -> Vec<f64>
pub fn permutation_keys(order: &[usize], num_items: usize) -> Vec<f64>
The keys Self::decode_as_permutation reads back as order –
order[rank] is the item placed rank-th. Items order leaves out
keep key 0.
Trait Implementations§
Source§impl Clone for RandomKeyChromosome
impl Clone for RandomKeyChromosome
Auto Trait Implementations§
impl Freeze for RandomKeyChromosome
impl RefUnwindSafe for RandomKeyChromosome
impl Send for RandomKeyChromosome
impl Sync for RandomKeyChromosome
impl Unpin for RandomKeyChromosome
impl UnsafeUnpin for RandomKeyChromosome
impl UnwindSafe for RandomKeyChromosome
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,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.