Skip to content

Commit

Permalink
fix(jssp): invalid value passed as duration to zero & sink ops (#430)
Browse files Browse the repository at this point in the history
- Improve op printing in main
- Fix typo:
- Format & clippy fixes
- Fix invalid operation intialization

<!-- 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 Oct 9, 2023
1 parent 069bed1 commit ff0a0cf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
7 changes: 5 additions & 2 deletions examples/jssp/logging.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{path::{Path, PathBuf}, collections::HashMap};
use std::{
collections::HashMap,
path::{Path, PathBuf},
};

use log4rs::{
append::{console::ConsoleAppender, file::FileAppender},
Expand Down Expand Up @@ -35,7 +38,7 @@ pub fn init_logging(log_files: &HashMap<String, PathBuf>) -> Result<log4rs::Hand
Logger::builder()
.appender(event_name)
.additive(false)
.build(event_name, log::LevelFilter::Info)
.build(event_name, log::LevelFilter::Info),
);
}
}
Expand Down
8 changes: 5 additions & 3 deletions examples/jssp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn run_with_ecrs(instance: JsspInstance, _args: Args) {

fn run() {
let args = cli::parse_args();

util::assert_dir_exists(args.output_dir.as_ref());
let event_map = util::create_event_map(args.output_dir.as_ref());
if let Err(err) = logging::init_logging(&event_map) {
Expand All @@ -67,8 +67,10 @@ fn run() {

// Existance of input file is asserted during cli args parsing
let instance = JsspInstance::try_from(&args.input_file).unwrap();
for op in instance.jobs.iter() {
info!("{op:?}");
for job in instance.jobs.iter() {
for op in job {
info!("{op:?}");
}
}
run_with_ecrs(instance, args)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/jssp/problem/population.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ impl JsspPopProvider {

// Prepare mock operations
// TODO: Shouldn't the duration be set to 0?
let mut zero_op = Operation::new(0, usize::MAX, 0, None, Vec::new());
let sink_op = Operation::new(dim + 1, usize::MAX, 0, None, Vec::from_iter(0..=dim));
let mut zero_op = Operation::new(0, 0, 0, None, Vec::new());
let sink_op = Operation::new(dim + 1, 0, 0, None, Vec::from_iter(0..=dim));

// Shift all ids by 1 && and job 0 & n + 1
instance.jobs.iter_mut().for_each(|job| {
Expand Down
1 change: 1 addition & 0 deletions examples/jssp/problem/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl JsspProbe {
Self {}
}

#[allow(dead_code)]
// TODO: This has either been not working as expected or the solver runs so bad.
// TODO: Verify whether the diversity is better on other problems
fn estimate_pop_diversity(population: &[JsspIndividual]) -> f64 {
Expand Down
12 changes: 8 additions & 4 deletions examples/jssp/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![allow(dead_code)]

use std::{collections::{HashSet, HashMap, hash_map}, fmt::Display, path::{PathBuf, Path}};
use std::{
collections::{hash_map, HashMap, HashSet},
fmt::Display,
path::{Path, PathBuf},
};

pub fn print_hash_set<T: Display>(set: &HashSet<T>) {
for elem in set {
Expand All @@ -23,7 +27,7 @@ pub fn create_event_map(base_dir: &Path) -> HashMap<String, PathBuf> {
("newbest".to_owned(), base_dir.join("event_newbest.csv")),
("bestingen".to_owned(), base_dir.join("event_bestingen.csv")),
("popgentime".to_owned(), base_dir.join("event_popgentime.csv")),
("iterinfo".to_owned(), base_dir.join("event_iterinfo.csv"))
("iterinfo".to_owned(), base_dir.join("event_iterinfo.csv")),
])
}

Expand All @@ -33,7 +37,7 @@ pub fn assert_dir_exists(dir: &Path) {
}

match std::fs::create_dir_all(dir) {
Ok(()) => return,
Err(err) => panic!("Failed to create outuput directory with error {err}"),
Ok(()) => (),
Err(err) => panic!("Failed to create output directory with error {err}"),
};
}

0 comments on commit ff0a0cf

Please sign in to comment.