Struct gas::fitness::color_count::ColorCount
source · [−]pub struct ColorCount<const N: usize, const NSYMS: usize> {
pub ncolors: usize,
pub chromosone_colors: Vec<usize>,
pub preferences: Vec<Vec<usize>>,
pub color_names: &'static [&'static str],
pub weight: f64,
}
Expand description
In a scheduling system, there are various types of shifts like overnight, weekend, holiday, etc. Each employee would like to have a certain number of each type of shift.
This type of fitness function is genericized here by assigning each chromosone location (aka shift) a “color” (aka shift type), and then for each symbol (aka employee), count how many of each color is in the chromosone. The negated absolute difference between each count and corresponding preference is a fitness score. (negated so that 0 is the highest score).
Parameters: chromosone_colors: the color of each locus in a corresponding chromosone preferences: the preferred count each symbol has for each color.
Fields
ncolors: usize
chromosone_colors: Vec<usize>
preferences: Vec<Vec<usize>>
color_names: &'static [&'static str]
weight: f64
Implementations
Trait Implementations
sourceimpl<const N: usize, const NSYMS: usize> FitnessFunction<N, NSYMS> for ColorCount<N, NSYMS>
impl<const N: usize, const NSYMS: usize> FitnessFunction<N, NSYMS> for ColorCount<N, NSYMS>
fn nscores(&self) -> usize
sourcefn weights(&self) -> Vec<f64>
fn weights(&self) -> Vec<f64>
not all games take weights into account, but some do. The vector must be [FitnessFunction.nscores] long. Scores with higher weights are worth weight
times as much as nominal scores. Note that the value of the score is irrelevant – scores are never compared with scores in a different position, scores are only compared with the same score on a different candidate. The weight signifies how valuable it is that this particular score on one candidate is higher or lower than the same score on a different candidate.
sourcefn run(&self, chromosone: &[Gene; N]) -> Vec<f64>
fn run(&self, chromosone: &[Gene; N]) -> Vec<f64>
returns a vector of floats where bigger numbers are better. If your fitness function optimizes to 0, remember that 0 is the biggest negative number. NaN is also a valid score, and means that the score cannot be compared and is considered a tie with any other number.
sourcefn names(&self) -> Vec<FitnessName>
fn names(&self) -> Vec<FitnessName>
provides an [FitnessFunction.nscores] length human readable name for the scores returned. Optional, but useful for debugging
Auto Trait Implementations
impl<const N: usize, const NSYMS: usize> RefUnwindSafe for ColorCount<N, NSYMS>
impl<const N: usize, const NSYMS: usize> Send for ColorCount<N, NSYMS>
impl<const N: usize, const NSYMS: usize> Sync for ColorCount<N, NSYMS>
impl<const N: usize, const NSYMS: usize> Unpin for ColorCount<N, NSYMS>
impl<const N: usize, const NSYMS: usize> UnwindSafe for ColorCount<N, NSYMS>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more