use crate::evolearn::Population;

use super::Evolver;

impl Evolver {
    /// Changes population size.
    pub fn pop(&mut self, size: usize) -> Result<(), String> {
        if size == 0 {
            return Err(String::from("Population size must be positive"));
        }

        let curr_size = self.population.len();

        if size < curr_size {
            self.population.truncate(size);
        } else if size > curr_size {
            self.population.add_inheritants(self.parameters.par_ratio, self.parameters.parents, self.parameters.par_sw_prob, self.parameters.mutat_prob, size - curr_size);
            self.evol(1)?;
            // Now population is sorted again
        }

        Ok(())
    }

}
