Skip to content

Commit

Permalink
Merge pull request #75 from HyperCodec/dev
Browse files Browse the repository at this point in the history
Update 0.5.4
  • Loading branch information
HyperCodec authored Oct 1, 2024
2 parents 1676db6 + 3fa9938 commit a92ff19
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["genetic-rs", "genetic-rs-common", "genetic-rs-macros"]
resolver = "2"

[workspace.package]
version = "0.5.3"
version = "0.5.4"
authors = ["HyperCodec"]
homepage = "https://github.com/hypercodec/genetic-rs"
repository = "https://github.com/hypercodec/genetic-rs"
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ fn main() {
);

// perform evolution (100 gens)
for _ in 0..100 {
// there might be some cases where you want to do something between calls.
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand Down
28 changes: 7 additions & 21 deletions genetic-rs-common/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,7 @@ mod tests {
scrambling_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand All @@ -403,9 +401,7 @@ mod tests {
fn r_scramble() {
let mut sim = GeneticSim::new(Vec::gen_random(1000), my_fitness_fn, scrambling_nextgen);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand All @@ -420,9 +416,7 @@ mod tests {
division_pruning_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand All @@ -438,9 +432,7 @@ mod tests {
crossover_pruning_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand All @@ -454,9 +446,7 @@ mod tests {
crossover_pruning_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand All @@ -472,9 +462,7 @@ mod tests {
speciated_crossover_pruning_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand All @@ -488,9 +476,7 @@ mod tests {
speciated_crossover_pruning_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand Down
14 changes: 14 additions & 0 deletions genetic-rs-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ where
self.next_gen.next_gen(rewards)
});
}

/// Calls [`next_generation`][GeneticSim::next_generation] `count` number of times.
pub fn perform_generations(&mut self, count: usize) {
for _ in 0..count {
self.next_generation();
}
}
}

#[cfg(feature = "rayon")]
Expand Down Expand Up @@ -191,6 +198,13 @@ where
self.next_gen.next_gen(rewards)
});
}

/// Calls [`next_generation`][GeneticSim::next_generation] `count` number of times.
pub fn perform_generations(&mut self, count: usize) {
for _ in 0..count {
self.next_generation();
}
}
}

#[cfg(feature = "genrand")]
Expand Down
4 changes: 1 addition & 3 deletions genetic-rs/examples/crossover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ fn main() {
crossover_pruning_nextgen,
);

for _ in 0..100 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes, magic_number);
}
Expand Down
4 changes: 1 addition & 3 deletions genetic-rs/examples/readme_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ fn main() {
);

// perform evolution (100 gens)
for _ in 0..100 {
sim.next_generation(); // in a genetic algorithm with state, such as a physics simulation, you'd want to do things with `sim.genomes` in between these calls
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand Down
4 changes: 1 addition & 3 deletions genetic-rs/examples/speciation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ fn main() {
);

// speciation tends to take more generations (not needed to this extent, but the crate is fast enough to where it isn't much of a compromise)
for _ in 0..1000 {
sim.next_generation();
}
sim.perform_generations(100);

dbg!(sim.genomes);
}
Expand Down

0 comments on commit a92ff19

Please sign in to comment.