Skip to content

Commit

Permalink
create progress bar for plotting example
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperCodec committed May 15, 2024
1 parent d150af4 commit 44b7fdb
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
69 changes: 69 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ serde = ["dep:serde", "dep:serde-big-array"]
[dependencies]
bitflags = "2.5.0"
genetic-rs = { version = "0.5.1", features = ["derive"] }

lazy_static = "1.4.0"
rand = "0.8.5"
rayon = { version = "1.8.1", optional = true }
Expand All @@ -37,4 +38,5 @@ serde-big-array = { version = "0.5.1", optional = true }
[dev-dependencies]
bincode = "1.3.3"
serde_json = "1.0.114"
plotters = "0.3.5"
plotters = "0.3.5"
indicatif = "0.17.8"
14 changes: 12 additions & 2 deletions examples/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
use neat::*;
use plotters::prelude::*;
use rand::prelude::*;
use indicatif::{ProgressBar, ProgressStyle};

#[derive(RandomlyMutable, DivisionReproduction, Clone)]
struct AgentDNA {
Expand Down Expand Up @@ -73,7 +74,7 @@ struct PerformanceStats {
}

const OUTPUT_FILE_NAME: &'static str = "fitness-plot.svg";
const GENS: usize = 100;
const GENS: usize = 1000;

fn main() -> Result<(), Box<dyn Error>> {
#[cfg(not(feature = "rayon"))]
Expand All @@ -94,12 +95,21 @@ fn main() -> Result<(), Box<dyn Error>> {
ng,
);

let pb = ProgressBar::new(GENS as u64)
.with_style(ProgressStyle::with_template("[{elapsed_precise}] {bar:40.cyan/blue} | {msg} {pos}/{len}")
.unwrap())
.with_message("gen");

println!("Training...");

for _ in 0..GENS {
sim.next_generation();

pb.inc(1);
}

pb.finish();

// prevent `Arc::into_inner` from failing
drop(sim);

Expand All @@ -116,7 +126,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.margin(5)
.x_label_area_size(30)
.y_label_area_size(30)
.build_cartesian_2d(0usize..100, 0f32..200.0)?;
.build_cartesian_2d(0usize..GENS, 0f32..1000.0)?;

chart.configure_mesh().draw()?;

Expand Down

0 comments on commit 44b7fdb

Please sign in to comment.