Minwei Kong commited on
Commit
a1fffe1
·
verified ·
1 Parent(s): 458d1ad

Fix delage2022 closed-ended and knife-dependent variants

Browse files
delage2022/feasibility_check.py ADDED
@@ -0,0 +1,530 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Feasibility checker for the three paper-supported CSCP variants.
4
+
5
+ Checks all hard constraints from the mathematical formulation (equations 16-23)
6
+ in Pérez Martínez, Adulyasak, and Jans (2022).
7
+
8
+ Constraints are numbered 1-8 counting top to bottom from the formulation:
9
+ Constraint 1 (eq 16): sum_{i in T} l_i * a_{ij} <= L * s_j, forall j in P
10
+ Constraint 2 (eq 17): z_j <= M * s_j, forall j in P
11
+ Constraint 3 (eq 18): q_{ij} = a_{ij} * z_j, forall i in T, j in P
12
+ Constraint 4 (eq 19): sum_j q_{ij} + x_i >= d_i, forall i in T
13
+ Constraint 5 (eq 20): sum_j z_j >= sum_i x_i
14
+ Constraint 6 (eq 21): z_{j-1} >= z_j, forall j in P, j > 1
15
+ Constraint 7 (eq 22): s_j in {0,1}, a_{ij} in Z_+, forall i,j
16
+ Constraint 8 (eq 23): x_i >= 0, z_j in Z_+, q_{ij} >= 0, forall i,j
17
+ Constraint 9 (eq 15): objective consistency -- the reported objective_value
18
+ must equal the recomputed total time
19
+ C_s * sum_j s_j + C_r * sum_j z_j, plus the
20
+ knife-dependent setup term when applicable.
21
+
22
+ Constraint 9 is a Tier-C anti-gaming check: the eval pipeline otherwise trusts
23
+ the program's self-reported objective_value. Every variable the objective
24
+ (eq 15) depends on -- the pattern setup flags s_j and the repetition counts
25
+ z_j -- is present in the solution, so a full recompute is possible and exact.
26
+ """
27
+
28
+ import argparse
29
+ import json
30
+ import math
31
+
32
+ # FRONTIEROR_RELEASE_CONTRACT_V2
33
+ _FRONTIEROR_REQUIRED_SOLUTION_FIELDS = ('extra_pieces', 'objective_value', 'patterns', 'production_quantities')
34
+ _FRONTIEROR_NONEMPTY_SOLUTION_FIELDS = ()
35
+ _FRONTIEROR_DERIVED_FIELD_RULES = ()
36
+ _FRONTIEROR_CONDITIONAL_FIELD_RULES = ()
37
+
38
+
39
+ def _frontieror_validate_solution_contract(solution):
40
+ """Return a structured rejection when the public solution contract is absent."""
41
+ violations = []
42
+ if not isinstance(solution, dict):
43
+ violations.append("solution must be a JSON object")
44
+ else:
45
+ missing = [
46
+ field
47
+ for field in _FRONTIEROR_REQUIRED_SOLUTION_FIELDS
48
+ if field not in solution or solution[field] is None
49
+ ]
50
+ if missing:
51
+ violations.append(
52
+ "missing required solution field(s): " + ", ".join(missing)
53
+ )
54
+
55
+ for discriminator, expected_value, fields in _FRONTIEROR_CONDITIONAL_FIELD_RULES:
56
+ if solution.get(discriminator) != expected_value:
57
+ continue
58
+ conditional_missing = [
59
+ field
60
+ for field in fields
61
+ if field not in solution or solution[field] is None
62
+ ]
63
+ if conditional_missing:
64
+ violations.append(
65
+ "missing conditionally required solution field(s): "
66
+ + ", ".join(conditional_missing)
67
+ )
68
+
69
+ empty = [
70
+ field
71
+ for field in _FRONTIEROR_NONEMPTY_SOLUTION_FIELDS
72
+ if field in solution and solution[field] in (None, [], {})
73
+ ]
74
+ if empty:
75
+ violations.append(
76
+ "empty required decision witness field(s): " + ", ".join(empty)
77
+ )
78
+
79
+ for target, operation, source, source_key in _FRONTIEROR_DERIVED_FIELD_RULES:
80
+ try:
81
+ reported = float(solution[target])
82
+ if operation == "length":
83
+ expected = float(len(solution[source]))
84
+ elif operation == "mapping_value":
85
+ expected = float(solution[source][source_key])
86
+ else:
87
+ raise ValueError("unknown derived-field operation")
88
+ except (KeyError, TypeError, ValueError, OverflowError):
89
+ violations.append(
90
+ f"cannot derive {target} from decision witness field {source}"
91
+ )
92
+ continue
93
+ if (
94
+ reported != reported
95
+ or expected != expected
96
+ or reported in (float("inf"), float("-inf"))
97
+ or expected in (float("inf"), float("-inf"))
98
+ or abs(reported - expected) > 1e-6
99
+ ):
100
+ violations.append(
101
+ f"{target}={reported} does not match the decision-derived "
102
+ f"value {expected}"
103
+ )
104
+
105
+ if "objective_value" in _FRONTIEROR_REQUIRED_SOLUTION_FIELDS:
106
+ objective = solution.get("objective_value")
107
+ if (
108
+ isinstance(objective, bool)
109
+ or not isinstance(objective, (int, float))
110
+ or objective != objective
111
+ or objective in (float("inf"), float("-inf"))
112
+ ):
113
+ violations.append("objective_value must be a finite JSON number")
114
+
115
+ if not violations:
116
+ return None
117
+ return {
118
+ "feasible": False,
119
+ "violated_constraints": ["solution_schema"],
120
+ "violations": violations,
121
+ "violation_magnitudes": [],
122
+ }
123
+
124
+
125
+ def _frontieror_write_unexpected_rejection(error):
126
+ """Turn malformed candidate/checker exceptions into a normal rejection."""
127
+ import json as _frontieror_json
128
+ import sys as _frontieror_sys
129
+
130
+ result_path = None
131
+ for index, argument in enumerate(_frontieror_sys.argv):
132
+ if argument == "--result_path" and index + 1 < len(_frontieror_sys.argv):
133
+ result_path = _frontieror_sys.argv[index + 1]
134
+ break
135
+ if argument.startswith("--result_path="):
136
+ result_path = argument.split("=", 1)[1]
137
+ break
138
+ if not result_path:
139
+ return False
140
+ try:
141
+ with open(result_path, "w") as result_handle:
142
+ _frontieror_json.dump(
143
+ {
144
+ "feasible": False,
145
+ "violated_constraints": ["malformed_solution"],
146
+ "violations": [
147
+ "checker rejected malformed candidate: "
148
+ + type(error).__name__
149
+ + ": "
150
+ + str(error)[:500]
151
+ ],
152
+ "violation_magnitudes": [],
153
+ },
154
+ result_handle,
155
+ indent=2,
156
+ )
157
+ except Exception:
158
+ return False
159
+ return True
160
+
161
+
162
+
163
+ def main():
164
+ parser = argparse.ArgumentParser(
165
+ description="Feasibility checker for CSCP variants"
166
+ )
167
+ parser.add_argument("--instance_path", type=str, required=True,
168
+ help="Path to the JSON instance file")
169
+ parser.add_argument("--solution_path", type=str, required=True,
170
+ help="Path to the JSON solution file")
171
+ parser.add_argument("--result_path", type=str, required=True,
172
+ help="Path to write the feasibility result JSON")
173
+ args = parser.parse_args()
174
+
175
+ with open(args.instance_path, "r") as f:
176
+ instance = json.load(f)
177
+ with open(args.solution_path, "r") as f:
178
+ solution = json.load(f)
179
+ _frontieror_contract_result = _frontieror_validate_solution_contract(solution)
180
+ if _frontieror_contract_result is not None:
181
+ with open(args.result_path, "w") as _frontieror_result_handle:
182
+ json.dump(
183
+ _frontieror_contract_result,
184
+ _frontieror_result_handle,
185
+ indent=2,
186
+ )
187
+ return
188
+
189
+ result = check_feasibility(instance, solution)
190
+
191
+ with open(args.result_path, "w") as f:
192
+ json.dump(result, f, indent=2)
193
+
194
+ print(f"Feasibility result written to {args.result_path}")
195
+ print(f"Feasible: {result['feasible']}")
196
+ if not result["feasible"]:
197
+ print(f"Violated constraints: {result['violated_constraints']}")
198
+ for v in result["violations"]:
199
+ print(f" - {v}")
200
+
201
+
202
+ def check_feasibility(instance, solution):
203
+ tol = 1e-5
204
+ eps = 1e-5
205
+
206
+ # --- Parse instance data ---
207
+ products = instance["products"]
208
+ num_products = instance["num_products"]
209
+ num_patterns = instance["num_patterns"]
210
+ L = instance["machine_length"]
211
+ M_val = instance["M"]
212
+ problem_type = instance.get("problem_type", "open_ended_cscp")
213
+ supported_types = {
214
+ "open_ended_cscp",
215
+ "closed_ended_cscp",
216
+ "cscp_with_knife_dependent_setups",
217
+ }
218
+ if problem_type not in supported_types:
219
+ raise ValueError(f"Unsupported problem_type: {problem_type}")
220
+ is_closed_ended = problem_type == "closed_ended_cscp"
221
+ is_knife_dependent = problem_type == "cscp_with_knife_dependent_setups"
222
+
223
+ T = list(range(num_products)) # 0-indexed
224
+ P = list(range(num_patterns)) # 0-indexed
225
+
226
+ d = {i: products[i]["demand"] for i in T}
227
+ l = {i: products[i]["length"] for i in T}
228
+ product_ids = {i: products[i]["id"] for i in T}
229
+ # Reverse map: product_id (int) -> 0-indexed
230
+ id_to_idx = {products[i]["id"]: i for i in T}
231
+
232
+ # --- Parse solution ---
233
+ patterns = solution["patterns"]
234
+ extra_pieces = solution["extra_pieces"]
235
+
236
+ # s_j: whether pattern j is used
237
+ s = {}
238
+ # z_j: repetitions of pattern j
239
+ z = {}
240
+ # a[i][j]: pieces of product i in pattern j
241
+ a = {}
242
+ knife_counts = {}
243
+ for j in P:
244
+ pdata = patterns[str(j)]
245
+ s[j] = 1 if pdata["used"] else 0
246
+ z[j] = pdata["repetitions"]
247
+ for i in T:
248
+ pid_str = str(product_ids[i])
249
+ a[(i, j)] = pdata["pieces"].get(pid_str, 0)
250
+ if is_knife_dependent:
251
+ if "knife_count" not in pdata:
252
+ raise ValueError(
253
+ f"pattern {j} missing knife_count for knife-dependent instance"
254
+ )
255
+ knife_counts[j] = pdata["knife_count"]
256
+
257
+ # x_i: extra pieces
258
+ x = {}
259
+ for i in T:
260
+ pid_str = str(product_ids[i])
261
+ x[i] = extra_pieces.get(pid_str, 0.0)
262
+
263
+ # q_{ij} = a_{ij} * z_j (computed from solution, this IS the production quantity)
264
+ q = {}
265
+ for i in T:
266
+ for j in P:
267
+ q[(i, j)] = a[(i, j)] * z[j]
268
+
269
+ # If the solution provides explicit production_quantities, use those for
270
+ # checking constraint 3 (eq 18) mismatch
271
+ q_reported = None
272
+ if "production_quantities" in solution:
273
+ q_reported = {}
274
+ for i in T:
275
+ for j in P:
276
+ key = f"product_{product_ids[i]}_pattern_{j}"
277
+ q_reported[(i, j)] = solution["production_quantities"].get(key, 0.0)
278
+
279
+ # --- Check constraints ---
280
+ violated_constraints = set()
281
+ violations = []
282
+ violation_magnitudes = []
283
+
284
+ def record_violation(constraint_idx, msg, lhs, rhs, violation_amount):
285
+ violated_constraints.add(constraint_idx)
286
+ violations.append(msg)
287
+ normalizer = max(abs(rhs), eps)
288
+ violation_magnitudes.append({
289
+ "constraint": constraint_idx,
290
+ "lhs": float(lhs),
291
+ "rhs": float(rhs),
292
+ "raw_excess": float(violation_amount),
293
+ "normalizer": float(normalizer),
294
+ "ratio": float(violation_amount / normalizer)
295
+ })
296
+
297
+ # ---- Constraint 1 (eq 16): sum_{i in T} l_i * a_{ij} <= L * s_j ----
298
+ for j in P:
299
+ lhs = sum(l[i] * a[(i, j)] for i in T)
300
+ rhs = L * s[j]
301
+ violation_amount = lhs - rhs
302
+ if violation_amount > tol:
303
+ record_violation(
304
+ 1,
305
+ f"Constraint 1 (eq 16) violated for pattern {j}: "
306
+ f"sum of piece lengths = {lhs}, but L*s_j = {rhs}",
307
+ lhs, rhs, violation_amount
308
+ )
309
+
310
+ # ---- Constraint 2 (eq 17): z_j <= M * s_j ----
311
+ for j in P:
312
+ lhs = z[j]
313
+ rhs = M_val * s[j]
314
+ violation_amount = lhs - rhs
315
+ if violation_amount > tol:
316
+ record_violation(
317
+ 2,
318
+ f"Constraint 2 (eq 17) violated for pattern {j}: "
319
+ f"z_j = {lhs}, but M*s_j = {rhs}",
320
+ lhs, rhs, violation_amount
321
+ )
322
+
323
+ # ---- Constraint 3 (eq 18): q_{ij} = a_{ij} * z_j ----
324
+ # If solution reports explicit q values, check they match a_{ij}*z_j
325
+ if q_reported is not None:
326
+ for i in T:
327
+ for j in P:
328
+ lhs = q_reported[(i, j)]
329
+ rhs = a[(i, j)] * z[j]
330
+ violation_amount = abs(lhs - rhs)
331
+ if violation_amount > tol:
332
+ record_violation(
333
+ 3,
334
+ f"Constraint 3 (eq 18) violated for product {product_ids[i]}, "
335
+ f"pattern {j}: q_reported = {lhs}, a*z = {rhs}",
336
+ lhs, rhs, violation_amount
337
+ )
338
+
339
+ # ---- Constraint 4 (eq 19): sum_j q_{ij} + x_i >= d_i ----
340
+ for i in T:
341
+ total_q = sum(q[(i, j)] for j in P)
342
+ lhs = total_q + x[i]
343
+ rhs = d[i]
344
+ violation_amount = rhs - lhs # >= constraint: RHS exceeds LHS
345
+ if violation_amount > tol:
346
+ record_violation(
347
+ 4,
348
+ f"Constraint 4 (eq 19) violated for product {product_ids[i]}: "
349
+ f"total production + extra = {lhs}, demand = {rhs}",
350
+ lhs, rhs, violation_amount
351
+ )
352
+
353
+ # ---- Constraint 5 (eq 20): sum_j z_j >= sum_i x_i ----
354
+ lhs_5 = sum(z[j] for j in P)
355
+ rhs_5 = sum(x[i] for i in T)
356
+ violation_amount_5 = rhs_5 - lhs_5 # >= constraint
357
+ if violation_amount_5 > tol:
358
+ record_violation(
359
+ 5,
360
+ f"Constraint 5 (eq 20) violated: "
361
+ f"sum(z_j) = {lhs_5}, sum(x_i) = {rhs_5}",
362
+ lhs_5, rhs_5, violation_amount_5
363
+ )
364
+
365
+ # ---- Constraint 6 (eq 21): z_{j-1} >= z_j, for j > 0 ----
366
+ for j in P:
367
+ if j > 0:
368
+ lhs = z[j - 1]
369
+ rhs = z[j]
370
+ violation_amount = rhs - lhs # >= constraint: z_{j-1} >= z_j
371
+ if violation_amount > tol:
372
+ record_violation(
373
+ 6,
374
+ f"Constraint 6 (eq 21) violated: "
375
+ f"z_{j-1} = {lhs} < z_{j} = {rhs}",
376
+ lhs, rhs, violation_amount
377
+ )
378
+
379
+ # ---- Constraint 7 (eq 22): s_j in {0,1}, a_{ij} in Z_+ ----
380
+ for j in P:
381
+ val = s[j]
382
+ if val not in (0, 1):
383
+ record_violation(
384
+ 7,
385
+ f"Constraint 7 (eq 22) violated: s_{j} = {val} not in {{0,1}}",
386
+ val, 0, 1.0
387
+ )
388
+ for i in T:
389
+ val_a = a[(i, j)]
390
+ if not isinstance(val_a, int) or val_a < 0:
391
+ if isinstance(val_a, float) and abs(val_a - round(val_a)) < tol and val_a >= -tol:
392
+ pass # close enough to non-negative integer
393
+ else:
394
+ violation_amount = abs(val_a - round(val_a)) if val_a >= 0 else abs(val_a)
395
+ record_violation(
396
+ 7,
397
+ f"Constraint 7 (eq 22) violated: a_{product_ids[i]},{j} = {val_a} "
398
+ f"not a non-negative integer",
399
+ val_a, round(max(val_a, 0)), violation_amount
400
+ )
401
+
402
+ # ---- Constraint 8 (eq 23): x_i >= 0, z_j in Z_+, q_{ij} >= 0 ----
403
+ for i in T:
404
+ if x[i] < -tol:
405
+ record_violation(
406
+ 8,
407
+ f"Constraint 8 (eq 23) violated: x_{product_ids[i]} = {x[i]} < 0",
408
+ x[i], 0.0, abs(x[i])
409
+ )
410
+
411
+ if is_closed_ended and abs(x[i]) > tol:
412
+ record_violation(
413
+ 10,
414
+ f"Closed-ended constraint violated: x_{product_ids[i]} = "
415
+ f"{x[i]}, expected 0",
416
+ x[i], 0.0, abs(x[i])
417
+ )
418
+
419
+ for j in P:
420
+ val_z = z[j]
421
+ if isinstance(val_z, float):
422
+ if abs(val_z - round(val_z)) > tol or val_z < -tol:
423
+ violation_amount = abs(val_z - round(val_z)) if val_z >= 0 else abs(val_z)
424
+ record_violation(
425
+ 8,
426
+ f"Constraint 8 (eq 23) violated: z_{j} = {val_z} "
427
+ f"not a non-negative integer",
428
+ val_z, round(max(val_z, 0)), violation_amount
429
+ )
430
+ elif isinstance(val_z, int):
431
+ if val_z < 0:
432
+ record_violation(
433
+ 8,
434
+ f"Constraint 8 (eq 23) violated: z_{j} = {val_z} < 0",
435
+ val_z, 0, abs(val_z)
436
+ )
437
+
438
+ for i in T:
439
+ for j in P:
440
+ if q[(i, j)] < -tol:
441
+ record_violation(
442
+ 8,
443
+ f"Constraint 8 (eq 23) violated: q_{product_ids[i]},{j} = {q[(i,j)]} < 0",
444
+ q[(i, j)], 0.0, abs(q[(i, j)])
445
+ )
446
+
447
+ # ---- Constraint 11: knife_count_j equals pieces cut per pass ----
448
+ if is_knife_dependent:
449
+ for j in P:
450
+ reported_knives = knife_counts[j]
451
+ expected_knives = sum(a[(i, j)] for i in T)
452
+ valid_numeric = (
453
+ not isinstance(reported_knives, bool)
454
+ and isinstance(reported_knives, (int, float))
455
+ and math.isfinite(float(reported_knives))
456
+ )
457
+ if not valid_numeric:
458
+ record_violation(
459
+ 11,
460
+ f"Knife-count constraint violated for pattern {j}: "
461
+ f"reported {reported_knives!r}, expected a finite integer",
462
+ 0.0, expected_knives, abs(expected_knives)
463
+ )
464
+ elif (
465
+ isinstance(reported_knives, bool)
466
+ or reported_knives < -tol
467
+ or abs(reported_knives - round(reported_knives)) > tol
468
+ or abs(reported_knives - expected_knives) > tol
469
+ ):
470
+ record_violation(
471
+ 11,
472
+ f"Knife-count constraint violated for pattern {j}: "
473
+ f"reported {reported_knives}, expected {expected_knives}",
474
+ reported_knives, expected_knives,
475
+ abs(reported_knives - expected_knives)
476
+ )
477
+
478
+ # ---- Constraint 9 (eq 15): objective consistency ----
479
+ # Tier-C anti-gaming check. The objective (eq 15) is
480
+ # C_s * sum_j s_j + C_r * sum_j z_j
481
+ # and every term -- the setup flags s_j and repetition counts z_j -- is
482
+ # present in the solution, so this is an exact full recompute. Reject the
483
+ # solution when the reported objective_value disagrees.
484
+ reported_obj = solution.get("objective_value")
485
+ if reported_obj is not None:
486
+ try:
487
+ reported = float(reported_obj)
488
+ except (TypeError, ValueError):
489
+ reported = None
490
+ if reported is not None:
491
+ C_s = instance["cost_setup_pattern"]
492
+ C_r = instance["cost_repetition"]
493
+ true_obj = float(C_s * sum(s[j] for j in P)
494
+ + C_r * sum(z[j] for j in P))
495
+ if is_knife_dependent:
496
+ C_k = instance["cost_knife_setup"]
497
+ true_obj += float(C_k * sum(knife_counts[j] for j in P))
498
+ abs_diff = abs(reported - true_obj)
499
+ # The objective is an integer count (C_s, C_r, s_j, z_j all
500
+ # integral); a 0.5 absolute floor fires on any integer mismatch,
501
+ # with a tiny relative term for large-magnitude safety.
502
+ obj_tol = max(0.5, 1e-6 * abs(true_obj))
503
+ if abs_diff > obj_tol:
504
+ record_violation(
505
+ 9,
506
+ f"Constraint 9 (eq 15) violated: reported objective_value "
507
+ f"= {reported} differs from recomputed "
508
+ f"variant-specific objective = {true_obj} "
509
+ f"(|diff| = {abs_diff:.6g}, tol = {obj_tol:.6g})",
510
+ reported, true_obj, abs_diff
511
+ )
512
+
513
+ # --- Build output ---
514
+ feasible = len(violated_constraints) == 0
515
+ return {
516
+ "feasible": feasible,
517
+ "violated_constraints": sorted(violated_constraints),
518
+ "violations": violations,
519
+ "violation_magnitudes": violation_magnitudes
520
+ }
521
+
522
+
523
+ if __name__ == "__main__":
524
+ try:
525
+ main()
526
+ except Exception as _frontieror_unexpected_error:
527
+ if not _frontieror_write_unexpected_rejection(
528
+ _frontieror_unexpected_error
529
+ ):
530
+ raise
delage2022/gurobi_code.py ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Gurobi-based MIP solver for the three paper-supported CSCP variants.
4
+
5
+ Source: Pérez Martínez, Adulyasak, and Jans (2022),
6
+ "Logic-Based Benders Decomposition for Integrated Process Configuration
7
+ and Production Planning Problems," INFORMS Journal on Computing, 34(4), pp. 2177-2191.
8
+
9
+ The OP has a nonlinear constraint q_{ij} = a_{ij} * z_j (eq. 18).
10
+ This is linearized via:
11
+ 1. Binary substitution (eq. 24): a_{ij} = sum_{k in K_i} b_k * w_{ijk},
12
+ where b_k = 2^{k-1}, K_i = {1, ..., n_i}, n_i = ceil(log2(N_i+1)).
13
+ 2. McCormick linearization: u_{ijk} = w_{ijk} * z_j (binary x integer):
14
+ u_{ijk} >= 0
15
+ u_{ijk} <= M * w_{ijk}
16
+ u_{ijk} <= z_j
17
+ u_{ijk} >= z_j - M * (1 - w_{ijk})
18
+ Then q_{ij} = sum_{k in K_i} b_k * u_{ijk} (exact, linear).
19
+ """
20
+
21
+ import argparse
22
+ import json
23
+ import math
24
+
25
+ import gurobipy as gp
26
+ from gurobipy import GRB
27
+ import os as _os, sys as _sys
28
+ import time
29
+ # Walk up from this file's directory to find repo root (containing scripts/).
30
+ _GUROBI_CODE_START_TIME = time.time()
31
+ _repo = _os.path.dirname(_os.path.abspath(__file__))
32
+ while _repo != _os.path.dirname(_repo) and not _os.path.isdir(_os.path.join(_repo, 'scripts', 'utils')):
33
+ _repo = _os.path.dirname(_repo)
34
+ if _os.path.isdir(_os.path.join(_repo, 'scripts', 'utils')):
35
+ _sys.path.insert(0, _repo)
36
+ try:
37
+ from scripts.utils.gurobi_log_helper import install_gurobi_logger
38
+ except ImportError:
39
+ def install_gurobi_logger(log_path): # no-op fallback when scripts/ unavailable
40
+ pass
41
+
42
+
43
+ def main():
44
+ parser = argparse.ArgumentParser(
45
+ description="Solve Open-Ended CSCP using Gurobi (linearized MIP)"
46
+ )
47
+ parser.add_argument("--instance_path", type=str, required=True,
48
+ help="Path to the JSON instance file")
49
+ parser.add_argument("--solution_path", type=str, required=True,
50
+ help="Path to write the solution JSON file")
51
+ parser.add_argument("--time_limit", type=int, required=True,
52
+ help="Maximum solver runtime in seconds")
53
+ parser.add_argument("--log_path", type=str, default=None, help="Path to log incumbent solutions")
54
+ args = parser.parse_args()
55
+ install_gurobi_logger(args.log_path)
56
+
57
+ # ------------------------------------------------------------------
58
+ # Load instance
59
+ # ------------------------------------------------------------------
60
+ with open(args.instance_path, "r") as f:
61
+ instance = json.load(f)
62
+
63
+ products = instance["products"]
64
+ num_products = instance["num_products"]
65
+ num_patterns = instance["num_patterns"]
66
+ L = instance["machine_length"]
67
+ C_s = instance["cost_setup_pattern"]
68
+ C_r = instance["cost_repetition"]
69
+ M = instance["M"] # M = max_{i in T} {d_i} (large number, eq. defined in paper)
70
+ problem_type = instance.get("problem_type", "open_ended_cscp")
71
+ supported_types = {
72
+ "open_ended_cscp",
73
+ "closed_ended_cscp",
74
+ "cscp_with_knife_dependent_setups",
75
+ }
76
+ if problem_type not in supported_types:
77
+ raise ValueError(f"Unsupported problem_type: {problem_type}")
78
+ is_closed_ended = problem_type == "closed_ended_cscp"
79
+ is_knife_dependent = problem_type == "cscp_with_knife_dependent_setups"
80
+ C_k = instance.get("cost_knife_setup", 0)
81
+ if is_closed_ended and not instance.get("x_i_forced_zero", False):
82
+ raise ValueError("closed_ended_cscp requires x_i_forced_zero=true")
83
+ if is_knife_dependent and C_k < 0:
84
+ raise ValueError("cost_knife_setup must be nonnegative")
85
+
86
+ T = list(range(num_products)) # 0-indexed product indices
87
+ P = list(range(num_patterns)) # 0-indexed pattern indices
88
+
89
+ d = [products[i]["demand"] for i in T]
90
+ l = [products[i]["length"] for i in T]
91
+ N_i = [products[i]["N_i"] for i in T] # floor(L / l_i)
92
+
93
+ # ------------------------------------------------------------------
94
+ # Binary substitution parameters (eq. 24)
95
+ # n_i = minimum number of bits to represent N_i
96
+ # K_i = {1, ..., n_i} (1-indexed)
97
+ # b_k = 2^{k-1}
98
+ # ------------------------------------------------------------------
99
+ def get_n_bits(Ni):
100
+ if Ni == 0:
101
+ return 1
102
+ return max(1, math.ceil(math.log2(Ni + 1)))
103
+
104
+ n_bits = [get_n_bits(N_i[i]) for i in T]
105
+ K_i = [list(range(1, n_bits[i] + 1)) for i in T] # 1-indexed
106
+
107
+ def bk(k):
108
+ return 2 ** (k - 1) # b_k = 2^{k-1}
109
+
110
+ # ------------------------------------------------------------------
111
+ # Build Gurobi model
112
+ # ------------------------------------------------------------------
113
+ model = gp.Model(f"CSCP_Linearized_{problem_type}")
114
+ model.setParam("Seed", 0)
115
+ model.setParam("MIPGap", 1e-4)
116
+ model.setParam("NumericFocus", 0)
117
+ model.setParam("Threads", 1)
118
+ model.setParam("TimeLimit", args.time_limit)
119
+ model.setParam("OutputFlag", 1)
120
+
121
+ # --- Variables ---
122
+
123
+ # s_j in {0,1}: 1 if pattern j is used (eq. 22)
124
+ s = model.addVars(P, vtype=GRB.BINARY, name="s")
125
+
126
+ # w_{ijk} in {0,1}: bit k of a_{ij} (binary substitution, eq. 24)
127
+ w = {}
128
+ for i in T:
129
+ for j in P:
130
+ for k in K_i[i]:
131
+ w[i, j, k] = model.addVar(vtype=GRB.BINARY, name=f"w_{i}_{j}_{k}")
132
+
133
+ # z_j in Z_+: number of repetitions of pattern j (eq. 23)
134
+ z = model.addVars(P, vtype=GRB.INTEGER, lb=0, ub=M, name="z")
135
+
136
+ # x_i >= 0: extra pieces of product i.
137
+ # INFERRED ASSUMPTION: declared continuous (x_i >= 0 per eq. 23, in R_+ component
138
+ # of y-vector). Physically integer, but relaxed here for faithfulness to OP form.
139
+ x = model.addVars(T, lb=0.0, ub=0.0 if is_closed_ended else GRB.INFINITY, name="x")
140
+
141
+ # n_j: number of knives in pattern j for the knife-dependent variant.
142
+ knife_count = None
143
+ if is_knife_dependent:
144
+ knife_count = model.addVars(P, lb=0.0, name="knife_count")
145
+
146
+ # u_{ijk} = w_{ijk} * z_j (McCormick linearization auxiliary)
147
+ u = {}
148
+ for i in T:
149
+ for j in P:
150
+ for k in K_i[i]:
151
+ u[i, j, k] = model.addVar(lb=0.0, ub=float(M), name=f"u_{i}_{j}_{k}")
152
+
153
+ # q_{ij} >= 0: production quantity (eq. 23), defined by linearization below
154
+ q = {}
155
+ for i in T:
156
+ for j in P:
157
+ q[i, j] = model.addVar(lb=0.0, name=f"q_{i}_{j}")
158
+
159
+ # --- Objective (eq. 15) ---
160
+ objective = (
161
+ C_s * gp.quicksum(s[j] for j in P)
162
+ + C_r * gp.quicksum(z[j] for j in P)
163
+ )
164
+ if is_knife_dependent:
165
+ objective += C_k * gp.quicksum(knife_count[j] for j in P)
166
+ model.setObjective(objective, GRB.MINIMIZE)
167
+
168
+ # --- Constraints ---
169
+
170
+ # (16)/(25) Configuration constraints:
171
+ # sum_{i in T} l_i * sum_{k in K_i} b_k * w_{ijk} <= L * s_j for all j in P
172
+ for j in P:
173
+ model.addConstr(
174
+ gp.quicksum(
175
+ l[i] * gp.quicksum(bk(k) * w[i, j, k] for k in K_i[i])
176
+ for i in T
177
+ ) <= L * s[j],
178
+ name=f"config_{j}"
179
+ )
180
+
181
+ # (17) Linking constraints: z_j <= M * s_j for all j in P
182
+ for j in P:
183
+ model.addConstr(z[j] <= M * s[j], name=f"link_{j}")
184
+
185
+ # Online supplement, Section 1.1.2: the knife setup is proportional to
186
+ # the number of pieces cut simultaneously by each used pattern.
187
+ if is_knife_dependent:
188
+ for j in P:
189
+ model.addConstr(
190
+ knife_count[j]
191
+ >= gp.quicksum(
192
+ bk(k) * w[i, j, k] for i in T for k in K_i[i]
193
+ ) + M * (s[j] - 1),
194
+ name=f"knife_count_{j}",
195
+ )
196
+
197
+ # McCormick linearization of u_{ijk} = w_{ijk} * z_j
198
+ # (w_{ijk} binary, z_j integer with upper bound M)
199
+ for i in T:
200
+ for j in P:
201
+ for k in K_i[i]:
202
+ model.addConstr(u[i, j, k] <= M * w[i, j, k], name=f"mck_a_{i}_{j}_{k}")
203
+ model.addConstr(u[i, j, k] <= z[j], name=f"mck_b_{i}_{j}_{k}")
204
+ model.addConstr(u[i, j, k] >= z[j] - M * (1 - w[i, j, k]), name=f"mck_c_{i}_{j}_{k}")
205
+
206
+ # q_{ij} = sum_{k in K_i} b_k * u_{ijk} (exact linearization of a_{ij} * z_j)
207
+ for i in T:
208
+ for j in P:
209
+ model.addConstr(
210
+ q[i, j] == gp.quicksum(bk(k) * u[i, j, k] for k in K_i[i]),
211
+ name=f"q_def_{i}_{j}"
212
+ )
213
+
214
+ # (19) Demand fulfillment: sum_j q_{ij} + x_i >= d_i for all i in T
215
+ for i in T:
216
+ model.addConstr(
217
+ gp.quicksum(q[i, j] for j in P) + x[i] >= d[i],
218
+ name=f"demand_{i}"
219
+ )
220
+
221
+ # (20) Extra pieces bound: sum_j z_j >= sum_i x_i
222
+ model.addConstr(
223
+ gp.quicksum(z[j] for j in P) >= gp.quicksum(x[i] for i in T),
224
+ name="extra_bound"
225
+ )
226
+
227
+ # (21) Symmetry-breaking: z_{j-1} >= z_j for all j in P, j > 1
228
+ for j in P:
229
+ if j > 0:
230
+ model.addConstr(z[j - 1] >= z[j], name=f"sym_{j}")
231
+
232
+ # ------------------------------------------------------------------
233
+ # Solve
234
+ # ------------------------------------------------------------------
235
+ model.optimize()
236
+
237
+ # ------------------------------------------------------------------
238
+ # Extract solution
239
+ # ------------------------------------------------------------------
240
+ if model.SolCount > 0:
241
+ obj_val = model.ObjVal
242
+ s_sol = {j: int(round(s[j].X)) for j in P}
243
+ z_sol = {j: int(round(z[j].X)) for j in P}
244
+ x_sol = {i: x[i].X for i in T}
245
+ a_sol = {
246
+ (i, j): int(sum(bk(k) * round(w[i, j, k].X) for k in K_i[i]))
247
+ for i in T for j in P
248
+ }
249
+ q_sol = {(i, j): q[i, j].X for i in T for j in P}
250
+
251
+ solution = {
252
+ "objective_value": obj_val,
253
+ "status": "optimal" if model.status == GRB.OPTIMAL else "feasible_time_limit",
254
+ "patterns": {
255
+ str(j): {
256
+ "used": bool(s_sol[j]),
257
+ "repetitions": z_sol[j],
258
+ "pieces": {
259
+ str(products[i]["id"]): a_sol[i, j]
260
+ for i in T
261
+ },
262
+ **(
263
+ {"knife_count": int(round(knife_count[j].X))}
264
+ if is_knife_dependent
265
+ else {}
266
+ ),
267
+ }
268
+ for j in P
269
+ },
270
+ "extra_pieces": {str(products[i]["id"]): x_sol[i] for i in T},
271
+ "production_quantities": {
272
+ f"product_{products[i]['id']}_pattern_{j}": q_sol[i, j]
273
+ for i in T for j in P
274
+ }
275
+ }
276
+ else:
277
+ solution = {
278
+ "objective_value": None,
279
+ "status": "no_feasible_solution_found"
280
+ }
281
+
282
+ with open(args.solution_path, "w") as f:
283
+ solution["runtime"] = time.time() - _GUROBI_CODE_START_TIME
284
+ json.dump(solution, f, indent=2)
285
+
286
+ print(f"Solution written to {args.solution_path}")
287
+ if solution.get("objective_value") is not None:
288
+ print(f"Objective value: {solution['objective_value']}")
289
+ print(f"Status: {solution['status']}")
290
+
291
+
292
+ if __name__ == "__main__":
293
+ main()
delage2022/gurobi_feasi_result/large_feasi_result_2.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
3
+ size 102
delage2022/gurobi_feasi_result/large_feasi_result_3.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3269392edcbb7720882e77caadb88b4a9cf2fda04cf482cebd23baace4a531fd
3
+ size 102
delage2022/gurobi_solution/large_solution_2.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca2a08633cf0381fffec239e04157a2dbbb0b806d4c64efb9b382d99f2aa81f2
3
+ size 48398
delage2022/gurobi_solution/large_solution_3.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a2dcf57cdc80ba3e212d35b4a390d71f64182a353b71ef57de6743a3e8edd1ad
3
+ size 49093
delage2022/gurobi_solution_log/large_log_2.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b31a38adf20041e7a521203de4a4faf27dd129e77ef3efd398663d55dfa6bc76
3
+ size 1367
delage2022/gurobi_solution_log/large_log_3.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3832e4e6dfc64b0d0acfffc68563846669db95a1d094762f76a827302b76d21b
3
+ size 702
delage2022/instance_schema.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "problem_type": "<str> One of 'open_ended_cscp', 'closed_ended_cscp', or 'cscp_with_knife_dependent_setups'.",
3
+ "machine_length": "<int> Length of the cutting machine in which patterns are configured.",
4
+ "num_products": "<int> Number of distinct product types to be cut.",
5
+ "num_patterns": "<int> Number of available cutting pattern slots.",
6
+ "num_groups": "<int> Number of product groups, where products sharing the same maximum pieces per pattern belong to the same group.",
7
+ "cost_setup_pattern": "<int> Time cost incurred once for each cutting pattern that is used.",
8
+ "cost_repetition": "<int> Time cost incurred for each repetition of any cutting pattern.",
9
+ "cost_knife_setup": "<number, optional> Additional setup time per knife; required only for cscp_with_knife_dependent_setups.",
10
+ "x_i_forced_zero": "<bool, optional> True for closed_ended_cscp, where all extra-piece quantities must be zero.",
11
+ "M": "<int> Upper bound on the number of repetitions any single pattern may have, equal to the maximum demand among all products.",
12
+ "products": [
13
+ {
14
+ "id": "<int> Unique identifier of the product type.",
15
+ "length": "<int> Length of one piece of this product type.",
16
+ "demand": "<int> Number of pieces of this product type that must be produced.",
17
+ "N_i": "<int> Maximum number of pieces of this product type that can fit within a single cutting pattern."
18
+ }
19
+ ],
20
+ "groups": "<dict, key: '{N_i_value}'> List of product IDs that share the same maximum pieces per pattern value, grouping products with identical fitting capacity."
21
+ }
delage2022/mathematical_formulation.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Original Formulation: Open-Ended Continuous Stock Cutting Problem (Open-Ended CSCP)
2
+
3
+ *Source: Logic-Based Benders Decomposition for Integrated Process Configuration and Production Planning Problems, Karim Pérez Martı́nez, Yossiri Adulyasak, and Raf Jans, 2022 (original OP formulation of Hajizadeh and Lee, 2007).*
4
+
5
+ ## Sets and Parameters
6
+
7
+ - $T$: set of product types, indexed by $i$.
8
+
9
+ - $P$: set of cutting patterns, indexed by $j$.
10
+
11
+ - $C_r$: time required for a single pattern use (cutting time per repetition).
12
+
13
+ - $C_s$: setup time for a used pattern.
14
+
15
+ - $d_i$: demand for product $i$.
16
+
17
+ - $l_i$: length of product $i$.
18
+
19
+ - $L$: length of the cutting machine.
20
+
21
+ - $M$: large number, defined as $M = \max_{i \in T}\{d_i\}$.
22
+
23
+ ## Decision Variables
24
+
25
+ - $s_j \in \{0,1\}$, $\forall j \in P$: 1 if pattern $j$ is used, 0 otherwise (configuration decision, part of $\mathbf{x}$).
26
+
27
+ - $a_{ij} \in \mathbb{Z}_+$, $\forall i \in T, j \in P$: number of pieces of product $i$ in pattern $j$ (configuration decision, part of $\mathbf{x}$).
28
+
29
+ - $z_j \in \mathbb{R}_+$, $\forall j \in P$: number of repetitions (uses) of pattern $j$ (production planning decision, part of $\mathbf{y}$).
30
+
31
+ - $x_i \in \mathbb{R}_+$, $\forall i \in T$: units of product $i$ produced as extra pieces (production planning decision, part of $\mathbf{y}$).
32
+
33
+ - $q_{ij} \in \mathbb{R}_+$, $\forall i \in T, j \in P$: units of product $i$ produced by pattern $j$ (production quantities).
34
+
35
+ ## Objective
36
+
37
+ $$\begin{align}
38
+ \text{OP:} \quad \min \quad \mathbf{c}^{\mathsf{T}}\mathbf{x} + \mathbf{d}^{\mathsf{T}}\mathbf{y} \;:\;
39
+ \min \quad & C_s \sum_{j \in P} s_j + C_r \sum_{j \in P} z_j \tag{15}
40
+ \end{align}$$
41
+
42
+ ## Constraints
43
+
44
+ $$\begin{align}
45
+ \mathbf{Ax} \ge \mathbf{a}: \quad & \sum_{i \in T} l_i\, a_{ij} \le L\, s_j,
46
+ & \forall j \in P, \tag{16}\\
47
+ \mathbf{Bx} + \mathbf{Cy} \ge \mathbf{b}: \quad & z_j \le M\, s_j,
48
+ & \forall j \in P, \tag{17}\\
49
+ \mathbf{q} = f(\mathbf{x},\mathbf{y}): \quad & q_{ij} = a_{ij}\, z_j,
50
+ & \forall i \in T,\; j \in P, \tag{18}\\
51
+ \mathbf{Dy} + \mathbf{Eq} \ge \mathbf{e}: \quad & \sum_{j \in P} q_{ij} + x_i \ge d_i,
52
+ & \forall i \in T, \tag{19}\\
53
+ & \sum_{j \in P} z_j \ge \sum_{i \in T} x_i, \tag{20}\\
54
+ & z_{j-1} \ge z_j,
55
+ & \forall j \in P : j > 1, \tag{21}\\
56
+ \mathbf{x} &\in \mathbb{B}^{|\mathcal{A}|} :\; s_j \in \{0,1\},\; a_{ij} \in \mathbb{Z}_+,
57
+ & \forall i \in T,\; j \in P, \tag{22}\\
58
+ \mathbf{y} \in \mathbb{R}_+^{|\mathcal{B}|} \times \mathbb{Z}_+^{|\mathcal{C}|};\;
59
+ \mathbf{q} &\in \mathbb{R}_+^{|\mathcal{D}|} :\; x_i \ge 0,\; z_j \in \mathbb{Z}_+;\; q_{ij} \ge 0,
60
+ & \forall i \in T,\; j \in P. \tag{23}
61
+ \end{align}$$
62
+
63
+ The objective (15) minimizes the total setup and cutting time. Constraints (16) are the configuration (machine length) constraints, which ensure that the total length of the pieces in a used pattern does not exceed the machine length. Constraints (17) link the pattern-use indicator $s_j$ with the number of pattern repetitions $z_j$. **Constraints (18) are the nonlinear (bilinear) production quantity constraints**: the amount of product $i$ produced by pattern $j$ equals the product of the configuration variable $a_{ij}$ (pieces of $i$ per pattern $j$) and the production level $z_j$ (number of repetitions). Constraints (19) ensure demand fulfillment, allowing demand to be met jointly by patterns and extra pieces. Constraints (20) limit the total number of extra pieces by the total number of pattern repetitions. Symmetry-breaking inequalities (21) order the used patterns by the number of repetitions. Constraints (22)–(23) define the variable domains.
64
+
65
+ ## Paper-Supported Variants
66
+
67
+ The closed-ended CSCP is the special case of (15)-(23) in which no extra pieces can be produced:
68
+
69
+ $$x_i = 0, \qquad \forall i \in T.$$
70
+
71
+ The open-ended CSCP with knife-dependent setups adds parameter $C_k$, the setup time per knife, and variable $n_j \ge 0$, the number of knives in pattern $j$. Its objective is
72
+
73
+ $$\min\; C_s\sum_{j\in P}s_j + C_r\sum_{j\in P}z_j + C_k\sum_{j\in P}n_j,$$
74
+
75
+ with the additional constraint from Section 1.1.2 of the online supplement,
76
+
77
+ $$n_j \ge \sum_{i\in T}a_{ij} + M(s_j-1), \qquad \forall j\in P.$$
78
+
79
+ Because $n_j$ has a positive objective coefficient, it equals the number of pieces cut simultaneously by each used pattern at optimum. All remaining open-ended constraints, including the extra-piece constraints, continue to apply to this variant.
delage2022/problem_description.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # Problem Description
2
+
3
+ A steel tube manufacturer operates a cutting machine that slices a continuous steel tube into smaller pieces of various product types. The machine has a fixed length, and it is configured using cutting patterns, each of which specifies how many pieces of each product type are cut simultaneously in a single pass. The machine may use multiple distinct patterns, and each pattern may be repeated multiple times. The input field `problem_type` selects one of three machine variants. In the open-ended variant, each repetition can additionally produce one extra piece of any product type beyond the configured pattern. In the closed-ended variant, the end wall prevents all such extra pieces. In the open-ended variant with knife-dependent setups, extra pieces are allowed, but setting up a used pattern incurs an additional cost proportional to the number of knives in that pattern. The number of knives equals the total number of pieces cut simultaneously by the pattern.
4
+
5
+ The input data consists of a set of products and a set of available patterns. Each product has a known length and a known demand (the number of pieces required). The cutting machine has a known total length. Two time-cost parameters are always given: a fixed setup time incurred once for each pattern that is used, and a cutting time incurred once per repetition of any pattern. Knife-dependent instances additionally provide the setup cost per knife. Closed-ended instances explicitly indicate that extra-piece variables are forced to zero. A large number, equal to the maximum demand among all products, caps the number of repetitions any single pattern may have. For each product, the maximum number of pieces of that product that can fit within a single pattern is also given.
6
+
7
+ The manufacturer must decide which patterns to use, how many pieces of each product type to include in each pattern, how many times to repeat each pattern, and, when the machine is open-ended, how many extra pieces of each product type to produce. The total number of units of each product produced by a given pattern equals the number of pieces of that product specified in that pattern multiplied by the number of repetitions of that pattern. If a pattern is not used, no pieces may be assigned to it. If a pattern is used, the sum of the lengths of all pieces assigned to it must not exceed the machine length. A pattern may have repetitions only if it has been set up for use, and its repetition count is limited by the large number described above. For every product, the total production from all patterns plus any permitted extra pieces must meet or exceed demand. In open-ended variants, the total number of extra pieces across all products must not exceed the total number of pattern repetitions. In the closed-ended variant, every extra-piece quantity must be zero. To avoid interchangeable orderings, patterns are ordered so that each repetition count is at least as large as the next. Piece counts and repetition counts must be nonnegative integers. Extra-piece quantities must be nonnegative. For a knife-dependent instance, the solution must also report each pattern's knife count, equal to the sum of its per-product piece counts.
8
+
9
+ The goal is to minimize total time: fixed setup times for used patterns plus cutting times for all pattern repetitions. For a knife-dependent instance, the objective also includes the setup cost per knife multiplied by the total number of knives across all patterns.
delage2022/solution_schema.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "objective_value": "<float> Total time required, equal to fixed setup times plus repetition times and, for knife-dependent instances, knife setup times.",
3
+ "patterns": {
4
+ "<key: '{pattern_index}'>": {
5
+ "used": "<bool> Whether this pattern is selected for use on the cutting machine.",
6
+ "repetitions": "<int> Number of times this pattern is repeated on the cutting machine.",
7
+ "pieces": "<dict, key: '{product_id}'> Number of pieces of each product cut in a single pass of this pattern.",
8
+ "knife_count": "<int, conditionally required> For cscp_with_knife_dependent_setups, the total number of pieces cut in one pass of this pattern; omit for other variants."
9
+ }
10
+ },
11
+ "extra_pieces": "<dict, key: '{product_id}'> Number of extra pieces of each product produced via the open end; every value must be zero for closed_ended_cscp.",
12
+ "production_quantities": "<dict, key: 'product_{product_id}_pattern_{pattern_index}'> Total number of pieces of each product produced by each pattern, equal to the pieces per pass multiplied by the number of repetitions."
13
+ }