Crates.io | optimigation |
lib.rs | optimigation |
version | 0.1.0 |
source | src |
created_at | 2022-04-09 09:20:21.301521 |
updated_at | 2022-04-09 09:20:21.301521 |
description | This is Rust tools for evolutionary computation, participate GA. |
homepage | |
repository | https://github.com/nima555/optimiGAtion |
max_upload_size | |
id | 564699 |
size | 23,107 |
This is Rust tools for evolutionary computation, participate GA. The tools focuses high level of versatility, so we can optimaze so much types of mutivariable problem via this.
GA(Genetic Algorithm) is one of the most basic theory of evolutionary computation, which is used for optimazation mutivariable problem in the situation of reserch, design, and so on. This logic mainly contains four steps to get the answer you want. This is below,
In general, the next generation of genomes is greater than the last one because weak genome would be exchanged to new child genome which is expected as strong. After many evolution of gneomes group, the most strong genome in the group is the values you want to know. Of couece, the evaluate function would be set by you.
If you want to use this tools, you should add optimiGAtion to dependencies in cargo.toml like
[dependencies]
optimiGAtion = "0.1.0"
Then, main.rs should be like this.
extern crate gene;
use gene::GenomeList;
use crate::gene::ga_algorithm::Generation;
use crate::gene::ga_algorithm::System;
fn sum(genome: &Vec<f32>) -> f32{
let mut a: f32 = 0.0;
for i in 0..genome.len(){
a += genome[i];
}
a
}
fn main() {
let c1: fn(&Vec<f32>) -> f32 = |x| {(sum(x)/x.len() as f32 - 10.0).abs()};
let mut functions = Vec::new();
functions.push(c1);
let mut world = GenomeList::new(1000, 10, 0.0, 10.0, &functions); // initiating group of genome.
GenomeList::ga_loop(&mut world, 200, 3, 0.05, 0.0, 10.0); // starting GA loop.
}
these are arguments of this function.
these are arguments of this function.
Especialy third argument, the correspondence table of key and way of crossover is
key | way of crossover |
---|---|
-1 | inherited average of parents component |
0 | inherited components in units of random |
n > 0 | inherited components in units of n |
The result of the above main.rs would be this.
Note : Creating first generation...
Note : GA loop start.
Result : Genome { dna: [9.99994, 9.9998865, 9.999953, 9.9998865, 9.999953, 9.9998865, 9.99994, 9.9998865, 9.999953, 9.9998865], eval: 8.2969666e-5 }
Generations : 13953.0
the all of theoritical values are 1.0, and GA can get quasi‐optimum solution.