From fd6b84b3e497c028672a2117bfd613e448a3d882 Mon Sep 17 00:00:00 2001 From: Tristan Murphy <72839119+inflectrix@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:35:48 -0500 Subject: [PATCH 1/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 140a66c..67ad30a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -83,4 +83,4 @@ fn main() { ``` ### License -This crate falls under the `MIT` license \ No newline at end of file +This crate falls under the `MIT` license From ca76444db639e51978342a564e7ca038cc608bea Mon Sep 17 00:00:00 2001 From: Tristan Murphy <72839119+inflectrix@users.noreply.github.com> Date: Tue, 27 Feb 2024 15:42:03 +0000 Subject: [PATCH 2/3] change to use genetic-rs derive --- Cargo.lock | 32 +++++++++++++++++++++++++++----- Cargo.toml | 2 +- README.md | 18 +----------------- examples/basic.rs | 26 ++------------------------ 4 files changed, 31 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78fcb3c..e144559 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,15 +50,37 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "genetic-rs" -version = "0.3.0" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "355778de2b2da7f1c4c5db9b98bfa94058159ff732b941b01d552cc0004c8610" +dependencies = [ + "genetic-rs-common", + "genetic-rs-macros", +] + +[[package]] +name = "genetic-rs-common" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "694916cca5538e02a6f04a0fcb5deef9297b460c697520b9f88ea4b9c0a1a09c" +checksum = "4583c0a38736e3ae592a0409d341156c414d0385658810de348ceca2c333575b" dependencies = [ "rand", "rayon", "replace_with", ] +[[package]] +name = "genetic-rs-macros" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dffb2a3f48483f65dd474ffcee8f7d728c6d57c76b9a4279b26febafe5d9027" +dependencies = [ + "genetic-rs-common", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "getrandom" version = "0.2.12" @@ -78,7 +100,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "neat" -version = "0.2.1" +version = "0.3.0" dependencies = [ "bincode", "genetic-rs", @@ -199,9 +221,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.50" +version = "2.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" +checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 58f4808..efb7924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/README.md b/README.md index 67ad30a..2502fae 100644 --- a/README.md +++ b/README.md @@ -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 { diff --git a/examples/basic.rs b/examples/basic.rs index 93f5cf9..32e99e6 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -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 { From 9f4fa5341d3bddca88b2891a8ccca4e3c8778826 Mon Sep 17 00:00:00 2001 From: Tristan Murphy <72839119+inflectrix@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:02:52 +0000 Subject: [PATCH 3/3] change version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e144559..9980c49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,7 +100,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "neat" -version = "0.3.0" +version = "0.4.0" dependencies = [ "bincode", "genetic-rs", diff --git a/Cargo.toml b/Cargo.toml index efb7924..fa5f9bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"