Skip to content

Commit

Permalink
feat(jssp): log on entering solver function (#462)
Browse files Browse the repository at this point in the history
<!-- If applicable - remember to add the PR to the EA Rust project (ONLY
IF THERE IS NO LINKED ISSUE) -->

## Description

<!-- Please describe the motivation & changes introduced by this PR -->

## Linked issues

<!-- Please use "Resolves #<issue_no> syntax in case this PR should be
linked to an issue -->

## Important implementation details

<!-- if any, optional section -->
  • Loading branch information
kkafar authored Nov 9, 2023
1 parent 010a5d3 commit 77cc30b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/jssp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl TryFrom<PartialConfig> 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),
})
}
}
Expand Down
55 changes: 30 additions & 25 deletions examples/jssp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,34 +51,38 @@ 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()))
.set_fitness(JsspFitness::new(1.5))
.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()
.run();
}

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
Expand All @@ -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())
Expand All @@ -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)
Expand All @@ -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),
}
}

Expand Down
6 changes: 5 additions & 1 deletion examples/jssp/problem/crossover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ impl NoopCrossover {
}

impl CrossoverOperator<JsspIndividual> 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())
}
}
12 changes: 7 additions & 5 deletions examples/jssp/problem/replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ impl ReplacementOperator<JsspIndividual> 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<JsspIndividual> for ReplaceWithRandomPopulation {
fn apply(&mut self, population: Vec<JsspIndividual>, _children: Vec<JsspIndividual>) -> Vec<JsspIndividual> {
fn apply(
&mut self,
population: Vec<JsspIndividual>,
_children: Vec<JsspIndividual>,
) -> Vec<JsspIndividual> {
self.pop_gen.generate(population.len())
}

Expand Down
1 change: 0 additions & 1 deletion examples/jssp/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
path::{Path, PathBuf},
};


pub fn print_hash_set<T: Display>(set: &HashSet<T>) {
for elem in set {
print!("{elem}, ");
Expand Down

0 comments on commit 77cc30b

Please sign in to comment.