Trait revonet::ea::EA
[−]
[src]
pub trait EA<'a, P> where
P: Problem, { type IndType: Individual + Clone + Serialize + DeserializeOwned; fn breed(
&self,
ctx: &mut EAContext<Self::IndType>,
sel_inds: &Vec<usize>,
children: &mut Vec<Self::IndType>
); fn run(
&mut self,
settings: EASettings
) -> Result<&EAResult<Self::IndType>, ()>; fn run_multiple(
&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
) { ... } fn evaluate(&self, ctx: &mut EAContext<Self::IndType>, problem: &P) { ... } fn select(&self, ctx: &mut EAContext<Self::IndType>) -> Vec<usize> { ... } fn next_generation(
&self,
ctx: &mut EAContext<Self::IndType>,
children: &Vec<Self::IndType>
) { ... } }
Trait for an evolutionary algorithm.
Defines functions which are typical for running a common EA.
To implement a trait a function breed
should be implemented.
Associated Types
type IndType: Individual + Clone + Serialize + DeserializeOwned
Required Methods
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.
Arguments:
ctx
-EAContext
object containing information regarding current EA run.sel_inds
- vector of indices of individuals fromctx.population
selected for breeding.children
- reference to the container to store resulting children individuals.
fn run(&mut self, settings: EASettings) -> Result<&EAResult<Self::IndType>, ()>
Provided Methods
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.
Arguments:
ctx
-EAContext
object containing information regarding current EA run.problem
- reference to theProblem
trait which specifies an objective function.gen_count
- number of generations (iterations) for search.
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.
Arguments:
ctx
-EAContext
object containing information regarding current EA run.problem
- reference to theProblem
trait which specifies an objective function.
fn select(&self, ctx: &mut EAContext<Self::IndType>) -> Vec<usize>
Function to select individuals for breeding. Updates given ctx
.
Arguments:
ctx
-EAContext
object containing information regarding current EA run.
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
.
Arguments:
ctx
-EAContext
object containing information regarding current EA run.children
- reference to the vector of children individuals which should get to the next generation.