Created
June 29, 2014 21:39
-
-
Save thiagopnts/0006854c5984702b9796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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