Struct revonet::ga::GA
[−]
[src]
pub struct GA<'a, P: Problem + 'a> { /* fields omitted */ }
Baseline structure for Genetic Algorithm
Example: Running GA to solve minimization problem:
extern crate rand; extern crate revonet; use revonet::ea::*; use revonet::ga::*; use revonet::problem::*; use revonet::settings::*; fn main() { let pop_size = 20u32; let problem_dim = 10u32; let problem = SphereProblem{}; let gen_count = 10u32; let settings = EASettings::new(pop_size, gen_count, problem_dim); let mut ga: GA<SphereProblem> = GA::new(&problem); let res = ga.run(settings).expect("Error during GA run"); println!("\n\nGA results: {:?}", res); }
Methods
impl<'a, P: Problem> GA<'a, P>
[src]
Trait Implementations
impl<'a, P: Problem> EA<'a, P> for GA<'a, P>
[src]
type IndType = RealCodedIndividual
fn breed(
&self,
ctx: &mut EAContext<Self::IndType>,
sel_inds: &Vec<usize>,
children: &mut Vec<Self::IndType>
)
&self,
ctx: &mut EAContext<Self::IndType>,
sel_inds: &Vec<usize>,
children: &mut Vec<Self::IndType>
)
Function to create children individuals using current context and selected individuals. Read more
fn run(&mut self, settings: EASettings) -> Result<&EAResult<Self::IndType>, ()>
Run evolutionary algorithm and return EAResult
object. Read more
fn run_multiple(
&mut self,
settings: EASettings,
run_num: u32
) -> Result<EAResultMultiple<Self::IndType>, ()>
&mut self,
settings: EASettings,
run_num: u32
) -> Result<EAResultMultiple<Self::IndType>, ()>
fn run_with_context(
&self,
ctx: &mut EAContext<Self::IndType>,
problem: &P,
gen_count: u32
)
&self,
ctx: &mut EAContext<Self::IndType>,
problem: &P,
gen_count: u32
)
"Main" function for the EA which runs a cycle for an evolutionary search. Read more
fn evaluate(&self, ctx: &mut EAContext<Self::IndType>, problem: &P)
Function to evaluate current population for the given problem
. In result of evaluation fitness for every individual is updated as well as statistics regarding mean, min, max fitness values. Read more
fn select(&self, ctx: &mut EAContext<Self::IndType>) -> Vec<usize>
Function to select individuals for breeding. Updates given ctx
. Read more
fn next_generation(
&self,
ctx: &mut EAContext<Self::IndType>,
children: &Vec<Self::IndType>
)
&self,
ctx: &mut EAContext<Self::IndType>,
children: &Vec<Self::IndType>
)
Function to prepare population for the next generation. By default copies children obtained in result of breed
to the ctx.population
. Read more