pub struct Solutions { /* private fields */ }
Expand description
The Solution
is the container for your current pool of solution
’s.
Implementations§
Trait Implementations§
Source§impl Display for Solutions
Represent the Solution by displaying `Solutions([solution-1, solution-2]).
impl Display for Solutions
Represent the Solution by displaying `Solutions([solution-1, solution-2]).
Source§impl From<Vec<Solution>> for Solutions
impl From<Vec<Solution>> for Solutions
Source§fn from(solution: Vec<Solution>) -> Self
fn from(solution: Vec<Solution>) -> Self
Create a new Population from a vector of solutions.
§Arguments
solutions
- The solutions you collected so far and would like to put into your Solutions.
§Examples
use genetic_algorithm_fn::solutions;
use genetic_algorithm_fn::solution;
let my_solutions = solutions::Solutions::from(vec![
solution::Solution::new(vec![1.0, 2.0, 3.0]),
solution::Solution::new(vec![1.0, 2.0, 4.0])
]);
println!("Current solutions: {}", my_solutions);
Source§impl<'a> Population<'a> for Solutions
impl<'a> Population<'a> for Solutions
Source§fn get_fittest_population(&self, n: usize, function: &Function) -> Solutions
fn get_fittest_population(&self, n: usize, function: &Function) -> Solutions
Given your pool, compute the fitness of your individuals to solve the problem at hand.
§Arguments
n
- How many individuals to keep?function
- The distances between nodes that is neccessary to computes how well the route work in terms of the Function to maximize.
§Examples
use genetic_algorithm_fn::solutions;
use genetic_algorithm_fn::function;
use genetic_algorithm_traits::Population;
let function_to_optimize = function::Function::new(
|x| match x.len() {
3 => Ok(x[0] * x[1] * x[2]),
_ => Err(function::FunctionError::WrongNumberOfEntries {
actual_number_of_entries: x.len(),
expected_number_of_entries: 3,
}),
}
);
let all_solutions = solutions::Solutions::random(30, 1.0..10.0, 3);
println!("Best 5 solutions: {}", all_solutions.get_fittest_population(5, &function_to_optimize));
Source§fn evolve(&self, mutate_prob: f32) -> Solutions
fn evolve(&self, mutate_prob: f32) -> Solutions
Evolve your population.
The evolution process consists of the following stages:
crossover
between all 1,…,n solutions excluding the solution itself.mutate
is applied to all individuals.
§Arguments
mutate_prob
- The probabilty of an inviduals beeing mutated. Is applied viaindividuals.mutate
.
§Examples
use genetic_algorithm_fn::solutions;
use genetic_algorithm_traits::Population;
let all_solutions = solutions::Solutions::random(2, 1.0..10.0, 3);
println!("The evolved invdividuals are {}", all_solutions.evolve(0.5));
Source§fn iter(&'a self) -> Iter<'_, Solution>
fn iter(&'a self) -> Iter<'_, Solution>
Iterate over the individuals of your population.
§Examples
use genetic_algorithm_fn::solutions;
use genetic_algorithm_traits::Population;
let all_solutions = solutions::Solutions::random(5, 1.0..10.0, 3);
all_solutions.iter().map(|solution| println!("{}", solution));
Source§type Individual = Solution
type Individual = Solution
The Type of individuals your population should consist of.
Source§type IndividualCollection = Iter<'a, Solution>
type IndividualCollection = Iter<'a, Solution>
The iteratore type if you iterate over your individuals. It depends on the data container you use
to store individuals in your implementation of
Population
.Source§fn fitnesses(
&'a self,
cost_data: &'a <Self::Individual as Individual<'a>>::IndividualCost,
) -> Vec<(f64, &'a Self::Individual)>
fn fitnesses( &'a self, cost_data: &'a <Self::Individual as Individual<'a>>::IndividualCost, ) -> Vec<(f64, &'a Self::Individual)>
Given the pool of current individuals, compute the fitness of your individuals to solve the
problem at hand. Read more
Source§fn get_n_fittest(
&'a self,
n: usize,
cost_data: &'a <Self::Individual as Individual<'a>>::IndividualCost,
) -> Vec<Self::Individual>
fn get_n_fittest( &'a self, n: usize, cost_data: &'a <Self::Individual as Individual<'a>>::IndividualCost, ) -> Vec<Self::Individual>
Get the n fittest individuals in your population. Read more
Source§fn evolve_individuals(&'a self, mutate_prob: f32) -> Vec<Self::Individual>
fn evolve_individuals(&'a self, mutate_prob: f32) -> Vec<Self::Individual>
Evolve your population. Read more
impl StructuralPartialEq for Solutions
Auto Trait Implementations§
impl Freeze for Solutions
impl RefUnwindSafe for Solutions
impl Send for Solutions
impl Sync for Solutions
impl Unpin for Solutions
impl UnwindSafe for Solutions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more