Skip to content

Commit 8a286b1

Browse files
committed
Implement update_variable_sized_bin_packing_bound in irregular
1 parent fbc8254 commit 8a286b1

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

include/packingsolver/irregular/algorithm_formatter.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class AlgorithmFormatter
6060
void update_bin_packing_bound(
6161
BinPos number_of_bins);
6262

63+
/** Update the variable-sized bin packing bound. */
64+
void update_variable_sized_bin_packing_bound(
65+
Profit cost);
66+
6367
/** Method to call at the end of the algorithm. */
6468
void end();
6569

src/irregular/algorithm_formatter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ void AlgorithmFormatter::update_bin_packing_bound(
285285
mutex_.unlock();
286286
}
287287

288+
void AlgorithmFormatter::update_variable_sized_bin_packing_bound(
289+
Profit cost)
290+
{
291+
mutex_.lock();
292+
if (cost > output_.variable_sized_bin_packing_bound) {
293+
output_.variable_sized_bin_packing_bound = cost;
294+
output_.json["IntermediaryOutputs"].push_back(output_.to_json());
295+
parameters_.new_solution_callback(output_);
296+
297+
// Check optimality.
298+
if (output_.solution_pool.best().full()
299+
&& output_.variable_sized_bin_packing_bound == output_.solution_pool.best().number_of_bins()) {
300+
end_ = true;
301+
}
302+
}
303+
mutex_.unlock();
304+
}
305+
288306
void AlgorithmFormatter::end()
289307
{
290308
output_.time = parameters_.timer.elapsed_time();

src/irregular/optimize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ void optimize_onedimensional_bound(
6565
algorithm_formatter.update_knapsack_bound(
6666
onedim_output.knapsack_bound);
6767
break;
68-
//} case Objective::VariableSizedBinPacking: {
69-
// algorithm_formatter.update_variable_sized_bin_packing_bound(
70-
// onedim_output.variable_sized_bin_packing_bound);
71-
// break;
68+
} case Objective::VariableSizedBinPacking: {
69+
algorithm_formatter.update_variable_sized_bin_packing_bound(
70+
onedim_output.variable_sized_bin_packing_bound);
71+
break;
7272
} default: {
7373
std::stringstream ss;
7474
ss << FUNC_SIGNATURE << ": "

0 commit comments

Comments
 (0)