Skip to content

Instantly share code, notes, and snippets.

@thiagopnts
Created June 29, 2014 21:39
Show Gist options
  • Save thiagopnts/0006854c5984702b9796 to your computer and use it in GitHub Desktop.
Save thiagopnts/0006854c5984702b9796 to your computer and use it in GitHub Desktop.
use std::vec::Vec;
use std::rand::random;
use super::individual::Individual;
pub struct Population<'ind> {
size: uint,
individuals: Vec<&'ind mut Individual>
}
// ???
// compiler error: wrong number of lifetime parameters: expected 1 but found 0
impl Population {
pub fn new(size: uint, genes_size: uint) -> Population {
Population {
size: size,
individuals: Vec::from_fn(size, |i| { Individual::new(genes_size) })
}
}
// I want to pick a random individual and modify it
pub fn pick(&self) -> &mut Individual {
self.individuals.get(random::<uint>() % self.individuals.len())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment