fn populate(&mut self) -> &mut Self
	{
		let mut rng = rand::thread_rng();
		let len = self.items.len();
		let missing = self.learn_params.0 as usize - len;
		
		for _ in 0..missing
		{
			//random two items to breed a new item
			let i1:usize = rng.gen::<usize>() % len;
			let i2:usize = rng.gen::<usize>() % len;
			let mut new_item = self.items[i1].0.breed(&self.items[i2].0);
			
			//mutate new item
			if rng.gen::<f64>() < self.learn_params.3
			{
				new_item.mutate();
			}
			
			self.items.push((new_item, 0.0, 0)); //add with score 0.0, will be evaluated soon
		}
		
		self
	}
/// Populate the population and randomly mutate new items
Populate the population and randomly mutate new items
Populate the population and randomly mutate new items
fn populate(&mut self) -> &mut Self
	{
		let mut rng = rand::thread_rng();
		let len = self.items.len();
		let missing = self.learn_params.0 as usize - len;
		for _ in 0..missing
		{
			//random two items to breed a new item
			let i1:usize = rng.gen::<usize>() % len;
			let i2:usize = rng.gen::<usize>() % len;
			let mut new_item = self.items[i1].0.breed(&self.items[i2].0);
			//mutate new item
			if rng.gen::<f64>() < self.learn_params.3
			{
				new_item.mutate();
			}
			self.items.push((new_item, 0.0, 0)); //add with score 0.0, will be evaluated soon
		}
		self
	}
fn populate ( & mut self ) -> & mut Self { let mut rng = rand :: thread_rng ( ) ; let len = self . items . len ( ) ; let missing = self . learn_params . 0 as usize - len ; for _ in 0 .. missing { //random two items to breed a new item let i1 : usize = rng . gen :: < usize > ( ) % len ; let i2 : usize = rng . gen :: < usize > ( ) % len ; let mut new_item = self . items [ i1 ] . 0 . breed ( & self . items [ i2 ] . 0 ) ; //mutate new item if rng . gen :: < f64 > ( ) < self . learn_params . 3 { new_item . mutate ( ) ; } self . items . push ( ( new_item , 0.0 , 0 ) ) ; //add with score 0.0, will be evaluated soon } self }
Populate the population and randomly mutate new items
Populate the population and randomly mutate new items
&mut self
&mut self