diff --git a/examples/jssp/config.rs b/examples/jssp/config.rs index e670118..a22b9d7 100644 --- a/examples/jssp/config.rs +++ b/examples/jssp/config.rs @@ -83,7 +83,7 @@ impl TryFrom for Config { n_gen: partial_cfg.n_gen, pop_size: partial_cfg.pop_size, delay_const_factor: partial_cfg.delay_const_factor, - perform_randomsearch: partial_cfg.perform_randomsearch.unwrap_or(false) + perform_randomsearch: partial_cfg.perform_randomsearch.unwrap_or(false), }) } } diff --git a/examples/jssp/main.rs b/examples/jssp/main.rs index 27e2330..e54d65f 100644 --- a/examples/jssp/main.rs +++ b/examples/jssp/main.rs @@ -33,6 +33,8 @@ use problem::replacement::JsspReplacement; use crate::problem::{JsspConfig, JsspInstance}; fn run_randomsearch(instance: JsspInstance, config: Config) { + info!("Running jssp solver with random search"); + let pop_size = if let Some(ps) = config.pop_size { // Overrided by user ps @@ -49,18 +51,18 @@ fn run_randomsearch(instance: JsspInstance, config: Config) { 400 }; - let probe = AggregatedProbe::new() - .add_probe(JsspProbe::new()) - .add_probe(PolicyDrivenProbe::new( - ElapsedTime::new(Duration::from_millis(1000), Duration::from_millis(0)), - StdoutProbe::new(), - )); + // let probe = AggregatedProbe::new() + // .add_probe(JsspProbe::new()) + // .add_probe(PolicyDrivenProbe::new( + // ElapsedTime::new(Duration::from_millis(1000), Duration::from_millis(0)), + // StdoutProbe::new(), + // )); // Only for debugging purposes. TODO: Remove it - let population_provider = JsspPopProvider::new(instance.clone()); - for op in population_provider.operations.iter() { - info!("{op:?}"); - } + // let population_provider = JsspPopProvider::new(instance.clone()); + // for op in population_provider.operations.iter() { + // info!("{op:?}"); + // } ga::Builder::new() .set_population_generator(JsspPopProvider::new(instance.clone())) @@ -68,8 +70,10 @@ fn run_randomsearch(instance: JsspInstance, config: Config) { .set_selection_operator(problem::selection::EmptySelection::new()) .set_crossover_operator(problem::crossover::NoopCrossover::new()) .set_mutation_operator(mutation::Identity::new()) - .set_replacement_operator(problem::replacement::ReplaceWithRandomPopulation::new(JsspPopProvider::new(instance.clone()))) - .set_probe(probe) + .set_replacement_operator(problem::replacement::ReplaceWithRandomPopulation::new( + JsspPopProvider::new(instance), + )) + .set_probe(JsspProbe::new()) .set_max_generation_count(n_gen) .set_population_size(pop_size) .build() @@ -77,6 +81,8 @@ fn run_randomsearch(instance: JsspInstance, config: Config) { } fn run_jssp_solver(instance: JsspInstance, config: Config) { + info!("Running JSSP solver"); + let pop_size = if let Some(ps) = config.pop_size { // Overrided by user ps @@ -93,19 +99,18 @@ fn run_jssp_solver(instance: JsspInstance, config: Config) { 400 }; - let probe = AggregatedProbe::new() - .add_probe(JsspProbe::new()) - .add_probe(PolicyDrivenProbe::new( - ElapsedTime::new(Duration::from_millis(1000), Duration::from_millis(0)), - StdoutProbe::new(), - )); + // let probe = AggregatedProbe::new() + // .add_probe(JsspProbe::new()) + // .add_probe(PolicyDrivenProbe::new( + // ElapsedTime::new(Duration::from_millis(1000), Duration::from_millis(0)), + // StdoutProbe::new(), + // )); // Only for debugging purposes. TODO: Remove it - let population_provider = JsspPopProvider::new(instance.clone()); - for op in population_provider.operations.iter() { - info!("{op:?}"); - } - + // let population_provider = JsspPopProvider::new(instance.clone()); + // for op in population_provider.operations.iter() { + // info!("{op:?}"); + // } ga::Builder::new() .set_selection_operator(selection::Rank::new()) @@ -114,7 +119,7 @@ fn run_jssp_solver(instance: JsspInstance, config: Config) { .set_population_generator(JsspPopProvider::new(instance.clone())) .set_replacement_operator(JsspReplacement::new(JsspPopProvider::new(instance), 0.1, 0.2)) .set_fitness(JsspFitness::new(1.5)) - .set_probe(probe) + .set_probe(JsspProbe::new()) // .set_max_duration(std::time::Duration::from_secs(30)) .set_max_generation_count(n_gen) .set_population_size(pop_size) @@ -141,7 +146,7 @@ fn run() { match config.perform_randomsearch { true => run_randomsearch(instance, config), - false => run_jssp_solver(instance, config) + false => run_jssp_solver(instance, config), } } diff --git a/examples/jssp/problem/crossover.rs b/examples/jssp/problem/crossover.rs index 082908d..fdbaef7 100644 --- a/examples/jssp/problem/crossover.rs +++ b/examples/jssp/problem/crossover.rs @@ -58,7 +58,11 @@ impl NoopCrossover { } impl CrossoverOperator for NoopCrossover { - fn apply(&mut self, parent_1: &JsspIndividual, parent_2: &JsspIndividual) -> (JsspIndividual, JsspIndividual) { + fn apply( + &mut self, + parent_1: &JsspIndividual, + parent_2: &JsspIndividual, + ) -> (JsspIndividual, JsspIndividual) { (parent_1.clone(), parent_2.clone()) } } diff --git a/examples/jssp/problem/replacement.rs b/examples/jssp/problem/replacement.rs index b71e713..c67f254 100644 --- a/examples/jssp/problem/replacement.rs +++ b/examples/jssp/problem/replacement.rs @@ -64,19 +64,21 @@ impl ReplacementOperator for JsspReplacement { } pub struct ReplaceWithRandomPopulation { - pop_gen: JsspPopProvider + pop_gen: JsspPopProvider, } impl ReplaceWithRandomPopulation { pub fn new(pop_gen: JsspPopProvider) -> Self { - Self { - pop_gen - } + Self { pop_gen } } } impl ReplacementOperator for ReplaceWithRandomPopulation { - fn apply(&mut self, population: Vec, _children: Vec) -> Vec { + fn apply( + &mut self, + population: Vec, + _children: Vec, + ) -> Vec { self.pop_gen.generate(population.len()) } diff --git a/examples/jssp/util.rs b/examples/jssp/util.rs index 8df0100..a356ec3 100644 --- a/examples/jssp/util.rs +++ b/examples/jssp/util.rs @@ -6,7 +6,6 @@ use std::{ path::{Path, PathBuf}, }; - pub fn print_hash_set(set: &HashSet) { for elem in set { print!("{elem}, ");