Module genotype::mutation[][src]

Gene mutation operators.

Examples

struct TotallyRandomGen;

impl MutationGen for TotallyRandomGen {
    fn gen(&mut self) -> Param {
        0.4
    }
}

// as seen before
struct Weight(Param);

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

struct Human {
    weight: Weight,
}

impl ParamHolder for Human {
    // ...
}

let human = Rc::new(RefCell::new(
    Human { weight: Weight(0.1) }
));
// unscaled value is initially 0.1
assert!((human.borrow().weight.get_scaled() - 46.0) < 0.00001);

let mut gen = TotallyRandomGen{};
mutate(human.clone(), &mut gen);

// unscaled value has mutated to 0.5
assert!((human.borrow().weight.get_scaled() - 70.0) < 0.00001);

Traits

MutationGen

Produces values to add to an unscaled gene value.

Functions

mutate

Mutates the given ParamHolder with the given MutationGen by iterating through all genes and adding to each the result of calling the mutation generator.