petri

Crates.iopetri
lib.rspetri
version0.0.4
sourcesrc
created_at2017-10-19 23:08:57.627064
updated_at2017-11-03 14:50:27.584034
descriptionEvolutionary computing toolkit
homepage
repositoryhttps://github.com/wbjohnston/petri.git
max_upload_size
id36262
size36,338
Will Johnston (wbjohnston)

documentation

README

Petri: Evolutionary Computing Toolkit

Tools for running evolutionary algorithms

Please read the API documentation

Note: This project is currently a work in progress. If somehow you stumble upon this library: you should not use this library as its incomplete and the API is not stable.

Travis Status codecov Crates.io badge License: MIT

Usage

// Import what algorithms we're going to use
use petri::algo::{Simple, EvolutionaryAlgorithm};
use petri::ops::select::Tournament;
use petri::ops::crossover::TwoPoint;
use petri::ops::mutate::FlipBit;

use rand::thread_rng;

// Create the fitness function to evaluate a genome with
fn fitness_fn(genome: &Vec<bool>) -> u32
{
    let mut ones = 0;
    for c in genome {
        if c {
            ones += 1;
        }
    }

    ones
}

// Create the runner
let mut gen_runner = Simple::new(
    Tournament::with_size(3),
    TwoPoint::default(),
    FlipBit::with_pb(0.02),
    fitness_fn,
    0.01,
    0.05,
    300,
    thread_rng()
);

// Initialize population
gen_runner.initialize(300, || vec![false; 100]);

// run the algorithm
while !gen_runner.is_done() {
    let _ = gen_runner.next();
}

// View our final population
println!("{:?}", gen_runner.population());

Contributing

Please see CONTRIBUTING.md

License

Dual-licensed to be compatible with the Rust project.

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.

Commit count: 104

cargo fmt