Skip to content

Commit a48e07e

Browse files
committed
bugfix for cases where the minimum matlimit is reached
1 parent d0b835a commit a48e07e

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/optimization/gdrr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ impl<'a> GDRR<'a> {
9494
} else {
9595
//Current local optimum is not better, add the best cost to the history queue
9696
for _ in 0..(self.config.history_length - lahc_history.len()) {
97-
lahc_history.push_back(lahc_history.back().unwrap().clone());
97+
let best = lahc_history.back().unwrap_or(&empty_problem_cost).clone();
98+
lahc_history.push_back(best);
9899
}
99100
}
100101
n_accepted += 1;
@@ -110,7 +111,7 @@ impl<'a> GDRR<'a> {
110111
}
111112
n_iterations += 1;
112113
if n_iterations % 100 == 0 {
113-
self.local_sol_collector.rx_sync();
114+
self.local_sol_collector.rx_sync()
114115
}
115116

116117
debug_assert!(lahc_history.len() <= self.config.history_length, "{}", lahc_history.len());

src/optimization/instance.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ impl Instance {
5757
}
5858
}
5959

60+
pub fn smallest_sheet_value(&self) -> u64 {
61+
self.sheets.iter().map(|(s, _)| s.area()).min().unwrap()
62+
}
63+
6064
pub fn total_part_area(&self) -> u64 {
6165
self.total_part_area
6266
}

src/optimization/sol_collectors/global_sol_collector.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ impl GlobalSolCollector {
8282
}
8383
}
8484
}
85+
if self.material_limit.unwrap_or(u64::MAX) == self._instance.smallest_sheet_value(){
86+
timed_println!("Minimum material limit reached");
87+
break;
88+
}
89+
8590
if gdrr_thread_handlers.iter().all(|h| h.is_finished()) {
8691
timed_println!("All GDRR threads have finished execution");
8792
break;

src/optimization/sol_collectors/local_sol_collector.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub struct LocalSolCollector<'a> {
2121
best_complete_transferred: bool,
2222
best_incomplete_transferred: bool,
2323
terminate: bool,
24-
2524
}
2625

2726

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

164-
165163
pub fn terminate(&self) -> bool {
166164
self.terminate
167165
}

0 commit comments

Comments
 (0)