Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samyhaff committed Apr 20, 2024
1 parent 89addc0 commit 07e6734
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
10 changes: 1 addition & 9 deletions src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ impl Benchmark {
}

fn pole_balancing(alg: &Algorithm) -> f64 {
let mut state = State::new(
0.,
0.,
vec![1., 0.1],
vec![0.017, 0.],
vec![0., 0.],
1.,
vec![0.5, 0.05],
);
let mut state = State::default();

let mut count = 0;

Expand Down
24 changes: 14 additions & 10 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ fn main() {
Problem::PoleBalancing => Benchmark::PoleBalancing,
};

if cli.problem == Problem::PoleBalancing {
panic!("Not implemented yet!");
}

match cli.algorithm {
AlgorithmType::Oneplusonena => {
match cli.continuous {
Expand Down Expand Up @@ -83,12 +79,20 @@ fn main() {

match cli.gui {
true => {
let state = State::new(alg, problem, N_ITERATIONS);
let mut conf_file = File::open("gui_conf.toml").unwrap();
let conf = conf::Conf::from_toml_file(&mut conf_file).unwrap();
let cb = ContextBuilder::new("Neuroevolution", "Samy Haffoudhi") .default_conf(conf);
let (ctx, event_loop) = cb.build().unwrap();
event::run(ctx, event_loop, state);
match problem {
Benchmark::PoleBalancing => {
panic!("Not implemented yet!");
}

_ => {
let state = State::new(alg, problem, N_ITERATIONS);
let mut conf_file = File::open("gui_conf.toml").unwrap();
let conf = conf::Conf::from_toml_file(&mut conf_file).unwrap();
let cb = ContextBuilder::new("Neuroevolution", "Samy Haffoudhi") .default_conf(conf);
let (ctx, event_loop) = cb.build().unwrap();
event::run(ctx, event_loop, state);
}
}
}
false => {
alg.optimize(&problem, cli.iterations);
Expand Down
11 changes: 2 additions & 9 deletions src/bin/pole_balancing_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ use neuroevolution::benchmarks::Benchmark;
use neuroevolution::pole_balancing_gui::State;

fn main() {
let pole_balancing_state = neuroevolution::pole_balancing::State::new(
0.,
0.,
vec![1., 0.1],
vec![0.017, 0.],
vec![0., 0.],
1.,
vec![0.5, 0.05],
);
let pole_balancing_state = neuroevolution::pole_balancing::State::default();

let config = Config {
population_size: 1000,
Expand All @@ -40,6 +32,7 @@ fn main() {
let neat = Neat::new(config);
let mut alg = Algorithm::Neat(neat);
let problem = Benchmark::PoleBalancing;
println!("Optimizing algorithm...");
alg.optimize(&problem, 20);
println!("Fitness: {}", problem.evaluate(&alg));

Expand Down
12 changes: 12 additions & 0 deletions src/pole_balancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ impl State {
}
}

pub fn default() -> Self {
Self::new(
0.,
0.,
vec![1., 0.1],
vec![0.017, 0.],
vec![0., 0.],
1.,
vec![0.5, 0.05],
)
}

pub fn get_cart_position(&self) -> f64 {
self.cart_position
}
Expand Down

0 comments on commit 07e6734

Please sign in to comment.