@@ -98,30 +98,6 @@ columngenerationsolver::Model get_model(
98
98
{
99
99
columngenerationsolver::Model model;
100
100
101
- Profit maximum_bin_type_cost = 0 ;
102
- for (BinTypeId bin_type_id = 0 ;
103
- bin_type_id < instance.number_of_bin_types ();
104
- ++bin_type_id) {
105
- if (maximum_bin_type_cost < instance.bin_type (bin_type_id).cost )
106
- maximum_bin_type_cost = instance.bin_type (bin_type_id).cost ;
107
- }
108
-
109
- ItemPos maximum_item_type_demand = 0 ;
110
- for (ItemTypeId item_type_id = 0 ;
111
- item_type_id < instance.number_of_item_types ();
112
- ++item_type_id) {
113
- if (maximum_item_type_demand < instance.item_type (item_type_id).copies )
114
- maximum_item_type_demand = instance.item_type (item_type_id).copies ;
115
- }
116
-
117
- Profit maximum_item_profit = 0 ;
118
- for (ItemTypeId item_type_id = 0 ;
119
- item_type_id < instance.number_of_item_types ();
120
- ++item_type_id) {
121
- if (maximum_item_profit < instance.item_type (item_type_id).profit )
122
- maximum_item_profit = instance.item_type (item_type_id).profit ;
123
- }
124
-
125
101
if (instance.objective () == Objective::VariableSizedBinPacking
126
102
|| instance.objective () == Objective::BinPacking) {
127
103
model.objective_sense = optimizationtools::ObjectiveDirection::Minimize;
@@ -196,33 +172,36 @@ std::vector<std::shared_ptr<const Column>> ColumnGenerationPricingSolver<Instanc
196
172
}
197
173
198
174
template <typename Solution>
199
- std::vector<std::shared_ptr<const Column>> solution2column (
175
+ std::vector<std::shared_ptr<const Column>> solution_to_columns (
200
176
const Solution& solution)
201
177
{
178
+ const auto & instance = solution.instance ();
179
+ double multiplier_cost = largest_power_of_two_lesser_or_equal (instance.largest_bin_cost ());
180
+ double multiplier_profit = largest_power_of_two_lesser_or_equal (instance.largest_item_profit ());
202
181
std::vector<std::shared_ptr<const Column>> columns;
203
182
for (BinPos bin_pos = 0 ;
204
183
bin_pos < solution.number_of_different_bins ();
205
184
++bin_pos) {
206
185
BinTypeId bin_type_id = solution.bin (bin_pos).bin_type_id ;
207
- Solution extra_solution (solution. instance () );
186
+ Solution extra_solution (instance);
208
187
extra_solution.append (solution, bin_pos, 1 );
209
188
Column column;
210
- if (solution. instance () .objective () == Objective::VariableSizedBinPacking
211
- || solution. instance () .objective () == Objective::BinPacking) {
212
- column.objective_coefficient = extra_solution.cost ();
213
- } else if (solution. instance () .objective () == Objective::Knapsack) {
214
- column.objective_coefficient = extra_solution.profit ();
189
+ if (instance.objective () == Objective::VariableSizedBinPacking
190
+ || instance.objective () == Objective::BinPacking) {
191
+ column.objective_coefficient = extra_solution.cost () / multiplier_cost ;
192
+ } else if (instance.objective () == Objective::Knapsack) {
193
+ column.objective_coefficient = extra_solution.profit () / multiplier_profit ;
215
194
}
216
195
columngenerationsolver::LinearTerm element;
217
196
element.row = bin_type_id;
218
197
element.coefficient = 1 ;
219
198
column.elements .push_back (element);
220
199
for (ItemTypeId item_type_id = 0 ;
221
- item_type_id < solution. instance () .number_of_item_types ();
200
+ item_type_id < instance.number_of_item_types ();
222
201
++item_type_id) {
223
202
if (extra_solution.item_copies (item_type_id) > 0 ) {
224
203
columngenerationsolver::LinearTerm element;
225
- element.row = solution. instance () .number_of_bin_types () + item_type_id;
204
+ element.row = instance.number_of_bin_types () + item_type_id;
226
205
element.coefficient = extra_solution.item_copies (item_type_id);
227
206
column.elements .push_back (element);
228
207
}
@@ -237,6 +216,9 @@ template <typename Instance, typename InstanceBuilder, typename Solution>
237
216
PricingOutput ColumnGenerationPricingSolver<Instance, InstanceBuilder, Solution>::solve_pricing(
238
217
const std::vector<Value>& duals)
239
218
{
219
+ double multiplier_cost = largest_power_of_two_lesser_or_equal (instance_.largest_bin_cost ());
220
+ double multiplier_profit = largest_power_of_two_lesser_or_equal (instance_.largest_item_profit ());
221
+
240
222
// std::cout << "solve_pricing" << std::endl;
241
223
PricingOutput output;
242
224
Value reduced_cost_bound = 0.0 ;
@@ -257,7 +239,8 @@ PricingOutput ColumnGenerationPricingSolver<Instance, InstanceBuilder, Solution>
257
239
for (ItemTypeId item_type_id = 0 ;
258
240
item_type_id < instance_.number_of_item_types ();
259
241
++item_type_id) {
260
- ItemPos copies = instance_.item_type (item_type_id).copies - filled_demands_[item_type_id];
242
+ const auto & item_type = instance_.item_type (item_type_id);
243
+ ItemPos copies = item_type.copies - filled_demands_[item_type_id];
261
244
if (copies == 0 )
262
245
continue ;
263
246
@@ -266,15 +249,16 @@ PricingOutput ColumnGenerationPricingSolver<Instance, InstanceBuilder, Solution>
266
249
|| instance_.objective () == Objective::BinPacking) {
267
250
profit = duals[instance_.number_of_bin_types () + item_type_id];
268
251
} else if (instance_.objective () == Objective::Knapsack) {
269
- profit = instance_.item_type (item_type_id).profit
270
- - duals[instance_.number_of_bin_types () + item_type_id];
252
+ profit = item_type.profit
253
+ - duals[instance_.number_of_bin_types () + item_type_id]
254
+ * multiplier_profit;
271
255
}
272
256
273
257
// std::cout << "j " << j << " profit " << profit << std::endl;
274
258
if (profit <= 0 )
275
259
continue ;
276
260
kp_instance_builder.add_item_type (
277
- instance_. item_type (item_type_id) ,
261
+ item_type,
278
262
profit,
279
263
copies);
280
264
kp2vbpp.push_back (item_type_id);
@@ -304,9 +288,9 @@ PricingOutput ColumnGenerationPricingSolver<Instance, InstanceBuilder, Solution>
304
288
305
289
if (instance_.objective () == Objective::VariableSizedBinPacking
306
290
|| instance_.objective () == Objective::BinPacking) {
307
- column.objective_coefficient = extra_solution.cost ();
291
+ column.objective_coefficient = extra_solution.cost () / multiplier_cost ;
308
292
} else if (instance_.objective () == Objective::Knapsack) {
309
- column.objective_coefficient = extra_solution.profit ();
293
+ column.objective_coefficient = extra_solution.profit () / multiplier_profit ;
310
294
}
311
295
312
296
columngenerationsolver::LinearTerm element;
@@ -332,11 +316,11 @@ PricingOutput ColumnGenerationPricingSolver<Instance, InstanceBuilder, Solution>
332
316
|| instance_.objective () == Objective::BinPacking) {
333
317
reduced_cost_bound = (std::min)(
334
318
reduced_cost_bound,
335
- bin_type.cost - duals[bin_type_id] - kp_output.knapsack_bound );
319
+ bin_type.cost / multiplier_cost - duals[bin_type_id] - kp_output.knapsack_bound );
336
320
} else if (instance_.objective () == Objective::Knapsack) {
337
321
reduced_cost_bound = (std::max)(
338
322
reduced_cost_bound,
339
- kp_output.knapsack_bound - duals[bin_type_id]);
323
+ kp_output.knapsack_bound / multiplier_profit - duals[bin_type_id]);
340
324
}
341
325
}
342
326
}
0 commit comments