Skip to main content

FitnessValue

Trait FitnessValue 

Source
pub trait FitnessValue:
    PartialOrd
    + Clone
    + Send
    + Sync
    + Debug
    + Serialize
    + DeserializeOwned
    + 'static {
    // Required methods
    fn to_f64(&self) -> f64;
    fn is_better_than(&self, other: &Self) -> bool;

    // Provided methods
    fn is_worse_than(&self, other: &Self) -> bool { ... }
    fn cmp_by_quality(&self, other: &Self) -> Ordering { ... }
}
Expand description

Trait bound for fitness values

Fitness values must be comparable and convertible to f64 for probabilistic selection operations. They must also be serializable for checkpointing.

Required Methods§

Source

fn to_f64(&self) -> f64

Convert fitness to f64 for probabilistic operations

Source

fn is_better_than(&self, other: &Self) -> bool

Check if this fitness is better than another

Provided Methods§

Source

fn is_worse_than(&self, other: &Self) -> bool

Check if this fitness is worse than another

Source

fn cmp_by_quality(&self, other: &Self) -> Ordering

Total ordering by quality, where Ordering::Greater means self is the better individual.

This delegates to is_better_than for the quality comparison (never to a to_f64()-derived scalar, which can disagree with the true ordering — see the ParetoFitness case where infinite crowding distances collapse every rank to +inf). Any value whose to_f64() is NaN is ranked strictly worst, so the result is a genuine total order usable with max_by/min_by/sort_by even if a NaN fitness slips past Individual::set_fitness’s guard (defense in depth).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FitnessValue for f32

Source§

fn to_f64(&self) -> f64

Source§

fn is_better_than(&self, other: &Self) -> bool

Source§

impl FitnessValue for f64

Source§

fn to_f64(&self) -> f64

Source§

fn is_better_than(&self, other: &Self) -> bool

Source§

impl FitnessValue for i32

Source§

fn to_f64(&self) -> f64

Source§

fn is_better_than(&self, other: &Self) -> bool

Source§

impl FitnessValue for i64

Source§

fn to_f64(&self) -> f64

Source§

fn is_better_than(&self, other: &Self) -> bool

Source§

impl FitnessValue for usize

Source§

fn to_f64(&self) -> f64

Source§

fn is_better_than(&self, other: &Self) -> bool

Implementors§