Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "neat"
description = "Crate for working with NEAT in rust"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["Inflectrix"]
repository = "https://github.com/inflectrix/neat"
Expand All @@ -26,7 +26,7 @@ serde = ["dep:serde", "dep:serde-big-array"]


[dependencies]
genetic-rs = "0.3"
genetic-rs = { version = "0.4", features = ["derive"] }
rand = "0.8.5"
rayon = { version = "1.8.1", optional = true }
serde = { version = "1.0.197", features = ["derive"], optional = true }
Expand Down
22 changes: 3 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Implementation of the NEAT algorithm using `genetic-rs`
### Features
- rayon - Uses parallelization on the `NeuralNetwork` struct and adds the `rayon` feature to the `genetic-rs` re-export.
- serde - Adds the NNTSerde struct and allows for serialization of `NeuralNetworkTopology`
- crossover - Implements the `CrossoverReproduction` trait on `NeuralNetworkTopology`
- crossover - Implements the `CrossoverReproduction` trait on `NeuralNetworkTopology` and adds the `crossover` feature to the `genetic-rs re-export.

### How To Use
When working with this crate, you'll want to use the `NeuralNetworkTopology` struct in your agent's DNA and
Expand All @@ -18,28 +18,12 @@ Here's an example of how one might use this crate:
```rust
use neat::*;

#[derive(Clone)]
#[derive(Clone, RandomlyMutable, DivisionReproduction)]
struct MyAgentDNA {
network: NeuralNetworkTopology<1, 2>,
other_stuff: Foo,
}

impl RandomlyMutable for MyAgentDNA {
fn mutate(&mut self, rate: f32, rng: &mut impl rand::Rng) {
self.network.mutate(rate, rng);
self.other_stuff.mutate(rate, rng);
}
}

impl DivisionReproduction for MyAgentDNA {
fn spawn_child(&self, rng: &mut impl rand::Rng) -> Self {
Self {
network: self.network.spawn_child(rng),
// ...
}
}
}

impl GenerateRandom for MyAgentDNA {
fn gen_random(rng: &mut impl rand::Rng) -> Self {
Self {
Expand Down Expand Up @@ -83,4 +67,4 @@ fn main() {
```

### License
This crate falls under the `MIT` license
This crate falls under the `MIT` license
26 changes: 2 additions & 24 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,14 @@
use neat::*;
use rand::prelude::*;

#[derive(PartialEq, Clone, Debug)]
#[derive(PartialEq, Clone, Debug, DivisionReproduction, RandomlyMutable)]
#[cfg_attr(feature = "crossover", derive(CrossoverReproduction))]
struct AgentDNA {
network: NeuralNetworkTopology<2, 4>,
}

impl RandomlyMutable for AgentDNA {
fn mutate(&mut self, rate: f32, rng: &mut impl Rng) {
self.network.mutate(rate, rng);
}
}

impl Prunable for AgentDNA {}

impl DivisionReproduction for AgentDNA {
fn divide(&self, rng: &mut impl Rng) -> Self {
let mut child = self.clone();
child.mutate(self.network.mutation_rate, rng);
child
}
}

#[cfg(feature = "crossover")]
impl CrossoverReproduction for AgentDNA {
fn crossover(&self, other: &Self, rng: &mut impl Rng) -> Self {
Self {
network: self.network.crossover(&other.network, rng),
}
}
}

impl GenerateRandom for AgentDNA {
fn gen_random(rng: &mut impl rand::Rng) -> Self {
Self {
Expand Down