Skip to content

Commit

Permalink
bugfix for cases where the minimum matlimit is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenGar committed Jan 11, 2023
1 parent d0b835a commit a48e07e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/optimization/gdrr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl<'a> GDRR<'a> {
} else {
//Current local optimum is not better, add the best cost to the history queue
for _ in 0..(self.config.history_length - lahc_history.len()) {
lahc_history.push_back(lahc_history.back().unwrap().clone());
let best = lahc_history.back().unwrap_or(&empty_problem_cost).clone();
lahc_history.push_back(best);
}
}
n_accepted += 1;
Expand All @@ -110,7 +111,7 @@ impl<'a> GDRR<'a> {
}
n_iterations += 1;
if n_iterations % 100 == 0 {
self.local_sol_collector.rx_sync();
self.local_sol_collector.rx_sync()
}

debug_assert!(lahc_history.len() <= self.config.history_length, "{}", lahc_history.len());
Expand Down
4 changes: 4 additions & 0 deletions src/optimization/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ impl Instance {
}
}

pub fn smallest_sheet_value(&self) -> u64 {
self.sheets.iter().map(|(s, _)| s.area()).min().unwrap()
}

pub fn total_part_area(&self) -> u64 {
self.total_part_area
}
Expand Down
5 changes: 5 additions & 0 deletions src/optimization/sol_collectors/global_sol_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ impl GlobalSolCollector {
}
}
}
if self.material_limit.unwrap_or(u64::MAX) == self._instance.smallest_sheet_value(){
timed_println!("Minimum material limit reached");
break;
}

if gdrr_thread_handlers.iter().all(|h| h.is_finished()) {
timed_println!("All GDRR threads have finished execution");
break;
Expand Down
2 changes: 0 additions & 2 deletions src/optimization/sol_collectors/local_sol_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct LocalSolCollector<'a> {
best_complete_transferred: bool,
best_incomplete_transferred: bool,
terminate: bool,

}


Expand Down Expand Up @@ -161,7 +160,6 @@ impl<'a> LocalSolCollector<'a> {
self.material_limit.unwrap_or(u64::MAX)
}


pub fn terminate(&self) -> bool {
self.terminate
}
Expand Down

0 comments on commit a48e07e

Please sign in to comment.