Trait genotype::ParamHolder[][src]

pub trait ParamHolder {
    fn param_count(&self) -> usize;
fn get_param(&mut self, index: usize) -> &mut RangedParam; }

An entity with multiple parameters, i.e. a chromosone.

Examples

struct Weight(Param);
struct Height(Param);

impl RangedParam for Weight {
    fn range(&self) -> (Param, Param) {
        (40.0, 100.0)
    }
    // ...
}

impl RangedParam for Height {
    fn range(&self) -> (Param, Param) {
        (140.0, 185.0)
    }
    // ...
}


struct Human {
    weight: Weight,
    height: Height,
}

impl ParamHolder for Human {
    fn param_count(&self) -> usize {
        2
    }

    fn get_param(&mut self, index: usize) -> &mut RangedParam {
        match index {
            0 => &mut self.weight,
            1 => &mut self.height,
            _ => panic!("Bad index"),
        }
    }
}

Required Methods

The number of parameters/genes on this chromosone.

Returns a mutable reference to the gene at the given index.

Panics

If index >= self.param_count()

Implementors