/// An epoch that allows units to breed and mutate without harsh culling.
/// It's important to sometimes allow 'weak' units to produce generations
/// that might escape local peaks in certain dimensions.
An epoch that allows units to breed and mutate without harsh culling.
It's important to sometimes allow 'weak' units to produce generations
that might escape local peaks in certain dimensions.
An epoch that allows units to breed and mutate without harsh culling . It ' s important to sometimes allow ' weak ' units to produce generations that might escape local peaks in certain dimensions .
fn epoch(&self, units: &mut Vec<LazyUnit<T>>, mut rng: StdRng) -> StdRng {
        assert!(units.len() > 0);
        // breed_factor dicates how large a percentage of the population will be
        // able to breed.
        let breed_up_to = (self.breed_factor * (units.len() as f64)) as usize;
        let mut breeders: Vec<LazyUnit<T>> = Vec::new();
        while let Some(unit) = units.pop() {
            breeders.push(unit);
            if breeders.len() == breed_up_to {
                break;
            }
        }
        units.clear();
        // The strongest half of our breeders will survive each epoch. Always at
        // least one.
        let surviving_parents = (breeders.len() as f64 * self.survival_factor).ceil() as usize;
        let pcnt_range = Range::new(0, breeders.len());
        for i in 0..self.max_size - surviving_parents {
            let rs = pcnt_range.ind_sample(&mut rng);
            units.push(LazyUnit::from(
                breeders[i % breeders.len()].unit.breed_with(
                    &breeders[rs].unit,
                ),
            ));
        }
        // Move our survivors into the new generation.
        units.append(&mut breeders.drain(0..surviving_parents).collect());
        rng
    }
fn epoch ( & self , units : & mut Vec < LazyUnit < T > > , mut rng : StdRng ) -> StdRng { assert ! ( units len ( ) 0 ) ; // breed_factor dicates how large a percentage of the population will be // able to breed. let breed_up_to = ( self . breed_factor * ( units . len ( ) as f64 ) ) as usize ; let mut breeders : Vec < LazyUnit < T > > = Vec :: new ( ) ; while let Some ( unit ) = units . pop ( ) { breeders . push ( unit ) ; if breeders . len ( ) == breed_up_to { break ; } } units . clear ( ) ; // The strongest half of our breeders will survive each epoch. Always at // least one. let surviving_parents = ( breeders . len ( ) as f64 * self . survival_factor ) . ceil ( ) as usize ; let pcnt_range = Range :: new ( 0 , breeders . len ( ) ) ; for i in 0 .. self . max_size - surviving_parents { let rs = pcnt_range . ind_sample ( & mut rng ) ; units . push ( LazyUnit :: from ( breeders [ i % breeders . len ( ) ] . unit . breed_with ( & breeders [ rs ] . unit , ) , ) ) ; } // Move our survivors into the new generation. units . append ( & mut breeders . drain ( 0 .. surviving_parents ) . collect ( ) ) ; rng }
An epoch that allows units to breed and mutate without harsh culling.
An epoch that allows units to breed and mutate without harsh culling .
&self
units
&mut Vec<LazyUnit<T>>
rng
StdRng