diff --git a/data/irregular/tests/feasibility_poly1a_five_items.json b/data/irregular/tests/feasibility_poly1a_five_items.json
new file mode 100644
index 000000000..accbc85fa
--- /dev/null
+++ b/data/irregular/tests/feasibility_poly1a_five_items.json
@@ -0,0 +1,447 @@
+{
+ "bin_types": [
+ {
+ "copies": 1,
+ "copies_min": 0,
+ "cost": 204.49,
+ "elements": [
+ {
+ "end": {
+ "x": 14.3,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 14.3,
+ "y": 14.3
+ },
+ "start": {
+ "x": 14.3,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 14.3
+ },
+ "start": {
+ "x": 14.3,
+ "y": 14.3
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 14.3
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "item_bin_minimum_spacing": 0.0,
+ "type": "general"
+ }
+ ],
+ "item_types": [
+ {
+ "allowed_rotations": [
+ {
+ "end": 0.0,
+ "mirror": false,
+ "start": 0.0
+ }
+ ],
+ "copies": 1,
+ "profit": 23.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 10.0,
+ "y": 2.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 8.0,
+ "y": 5.0
+ },
+ "start": {
+ "x": 10.0,
+ "y": 2.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 4.0,
+ "y": 4.0
+ },
+ "start": {
+ "x": 8.0,
+ "y": 5.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 4.0,
+ "y": 4.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 0.0,
+ "mirror": false,
+ "start": 0.0
+ }
+ ],
+ "copies": 1,
+ "profit": 28.5,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 8.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 1.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 4.0,
+ "y": 3.0
+ },
+ "start": {
+ "x": 8.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 7.0,
+ "y": 6.0
+ },
+ "start": {
+ "x": 4.0,
+ "y": 3.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 5.0
+ },
+ "start": {
+ "x": 7.0,
+ "y": 6.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 1.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 5.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 0.0,
+ "mirror": false,
+ "start": 0.0
+ }
+ ],
+ "copies": 1,
+ "profit": 29.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 6.0,
+ "y": 2.0
+ },
+ "start": {
+ "x": 2.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 9.0,
+ "y": 1.0
+ },
+ "start": {
+ "x": 6.0,
+ "y": 2.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 7.0,
+ "y": 3.0
+ },
+ "start": {
+ "x": 9.0,
+ "y": 1.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 3.0,
+ "y": 5.0
+ },
+ "start": {
+ "x": 7.0,
+ "y": 3.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 5.0,
+ "y": 7.0
+ },
+ "start": {
+ "x": 3.0,
+ "y": 5.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 8.0
+ },
+ "start": {
+ "x": 5.0,
+ "y": 7.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 2.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 8.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 0.0,
+ "mirror": false,
+ "start": 0.0
+ }
+ ],
+ "copies": 1,
+ "profit": 25.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 10.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 9.0,
+ "y": 4.0
+ },
+ "start": {
+ "x": 10.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 4.0,
+ "y": 2.0
+ },
+ "start": {
+ "x": 9.0,
+ "y": 4.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 2.0,
+ "y": 3.0
+ },
+ "start": {
+ "x": 4.0,
+ "y": 2.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 2.0,
+ "y": 3.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 0.0,
+ "mirror": false,
+ "start": 0.0
+ }
+ ],
+ "copies": 1,
+ "profit": 22.5,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 5.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 3.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 7.0,
+ "y": 2.0
+ },
+ "start": {
+ "x": 5.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 8.0,
+ "y": 4.0
+ },
+ "start": {
+ "x": 7.0,
+ "y": 2.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 2.0,
+ "y": 5.0
+ },
+ "start": {
+ "x": 8.0,
+ "y": 4.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 3.0
+ },
+ "start": {
+ "x": 2.0,
+ "y": 5.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ }
+ ],
+ "objective": "feasibility",
+ "parameters": {
+ "item_item_minimum_spacing": 0.0,
+ "leftover_corner": "BottomLeft",
+ "open_dimension_xy_aspect_ratio": -1.0
+ }
+}
\ No newline at end of file
diff --git a/data/irregular/tests/feasibility_poly2a_five_items_feasible.json b/data/irregular/tests/feasibility_poly2a_five_items_feasible.json
new file mode 100644
index 000000000..bf3646a65
--- /dev/null
+++ b/data/irregular/tests/feasibility_poly2a_five_items_feasible.json
@@ -0,0 +1,489 @@
+{
+ "objective": "feasibility",
+ "parameters": {
+ "item_item_minimum_spacing": 0.0,
+ "leftover_corner": "BottomLeft",
+ "open_dimension_xy_aspect_ratio": -1.0
+ },
+ "bin_types": [
+ {
+ "copies": 1,
+ "copies_min": 0,
+ "cost": 2041755.2100000002,
+ "elements": [
+ {
+ "end": {
+ "x": 1428.9,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 1428.9,
+ "y": 1428.9
+ },
+ "start": {
+ "x": 1428.9,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 1428.9
+ },
+ "start": {
+ "x": 1428.9,
+ "y": 1428.9
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 1428.9
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "item_bin_minimum_spacing": 0.0,
+ "type": "general"
+ }
+ ],
+ "item_types": [
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 230400.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 1000.0,
+ "y": 199.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 800.0,
+ "y": 500.0
+ },
+ "start": {
+ "x": 1000.0,
+ "y": 199.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 400.0,
+ "y": 400.0
+ },
+ "start": {
+ "x": 800.0,
+ "y": 500.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 400.0,
+ "y": 400.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 245000.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 700.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 499.0,
+ "y": 700.0
+ },
+ "start": {
+ "x": 700.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 499.0,
+ "y": 700.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 309550.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 599.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 799.0,
+ "y": 200.0
+ },
+ "start": {
+ "x": 599.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 300.0,
+ "y": 700.0
+ },
+ "start": {
+ "x": 799.0,
+ "y": 200.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 300.0,
+ "y": 700.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 284649.5,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 800.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 99.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 399.0,
+ "y": 300.0
+ },
+ "start": {
+ "x": 800.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 700.0,
+ "y": 600.0
+ },
+ "start": {
+ "x": 399.0,
+ "y": 300.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 499.0
+ },
+ "start": {
+ "x": 700.0,
+ "y": 600.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 99.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 499.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 289000.5,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 599.0,
+ "y": 199.0
+ },
+ "start": {
+ "x": 200.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 899.0,
+ "y": 100.0
+ },
+ "start": {
+ "x": 599.0,
+ "y": 199.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 699.0,
+ "y": 299.0
+ },
+ "start": {
+ "x": 899.0,
+ "y": 100.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 299.0,
+ "y": 499.0
+ },
+ "start": {
+ "x": 699.0,
+ "y": 299.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 499.0,
+ "y": 699.0
+ },
+ "start": {
+ "x": 299.0,
+ "y": 499.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 799.0
+ },
+ "start": {
+ "x": 499.0,
+ "y": 699.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 200.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 799.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/data/irregular/tests/feasibility_poly2a_five_items_infeasible.json b/data/irregular/tests/feasibility_poly2a_five_items_infeasible.json
new file mode 100644
index 000000000..ba6635b81
--- /dev/null
+++ b/data/irregular/tests/feasibility_poly2a_five_items_infeasible.json
@@ -0,0 +1,456 @@
+{
+ "objective": "feasibility",
+ "parameters": {
+ "item_item_minimum_spacing": 0.0,
+ "leftover_corner": "BottomLeft",
+ "open_dimension_xy_aspect_ratio": -1.0
+ },
+ "bin_types": [
+ {
+ "copies": 1,
+ "copies_min": 0,
+ "cost": 2041755.2100000002,
+ "elements": [
+ {
+ "end": {
+ "x": 1428.9,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 1428.9,
+ "y": 1428.9
+ },
+ "start": {
+ "x": 1428.9,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 1428.9
+ },
+ "start": {
+ "x": 1428.9,
+ "y": 1428.9
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 1428.9
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "item_bin_minimum_spacing": 0.0,
+ "type": "general"
+ }
+ ],
+ "item_types": [
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 230400.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 1000.0,
+ "y": 199.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 800.0,
+ "y": 500.0
+ },
+ "start": {
+ "x": 1000.0,
+ "y": 199.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 400.0,
+ "y": 400.0
+ },
+ "start": {
+ "x": 800.0,
+ "y": 500.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 400.0,
+ "y": 400.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 245000.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 700.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 499.0,
+ "y": 700.0
+ },
+ "start": {
+ "x": 700.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 499.0,
+ "y": 700.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 370000.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 600.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 200.0,
+ "y": 300.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 700.0,
+ "y": 700.0
+ },
+ "start": {
+ "x": 600.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 1000.0
+ },
+ "start": {
+ "x": 700.0,
+ "y": 700.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 200.0,
+ "y": 300.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 1000.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 309550.0,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 599.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 799.0,
+ "y": 200.0
+ },
+ "start": {
+ "x": 599.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 300.0,
+ "y": 700.0
+ },
+ "start": {
+ "x": 799.0,
+ "y": 200.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 300.0,
+ "y": 700.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ },
+ {
+ "allowed_rotations": [
+ {
+ "end": 90.0,
+ "mirror": false,
+ "start": 90.0
+ },
+ {
+ "end": 180.0,
+ "mirror": false,
+ "start": 180.0
+ },
+ {
+ "end": 270.0,
+ "mirror": false,
+ "start": 270.0
+ },
+ {
+ "end": 360.0,
+ "mirror": false,
+ "start": 360.0
+ }
+ ],
+ "copies": 1,
+ "profit": 284649.5,
+ "shapes": [
+ {
+ "elements": [
+ {
+ "end": {
+ "x": 800.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 99.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 399.0,
+ "y": 300.0
+ },
+ "start": {
+ "x": 800.0,
+ "y": 0.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 700.0,
+ "y": 600.0
+ },
+ "start": {
+ "x": 399.0,
+ "y": 300.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 0.0,
+ "y": 499.0
+ },
+ "start": {
+ "x": 700.0,
+ "y": 600.0
+ },
+ "type": "LineSegment"
+ },
+ {
+ "end": {
+ "x": 99.0,
+ "y": 0.0
+ },
+ "start": {
+ "x": 0.0,
+ "y": 499.0
+ },
+ "type": "LineSegment"
+ }
+ ],
+ "is_path": false,
+ "type": "general"
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/doc/img/irregular_benders_decomposition_iteration.svg b/doc/img/irregular_benders_decomposition_iteration.svg
new file mode 100644
index 000000000..b96db38a6
--- /dev/null
+++ b/doc/img/irregular_benders_decomposition_iteration.svg
@@ -0,0 +1,35 @@
+
diff --git a/doc/img/irregular_milp_nfp_core_widening.svg b/doc/img/irregular_milp_nfp_core_widening.svg
new file mode 100644
index 000000000..ad881900b
--- /dev/null
+++ b/doc/img/irregular_milp_nfp_core_widening.svg
@@ -0,0 +1,20 @@
+
diff --git a/doc/img/irregular_milp_nfp_pieces.svg b/doc/img/irregular_milp_nfp_pieces.svg
new file mode 100644
index 000000000..3217ea401
--- /dev/null
+++ b/doc/img/irregular_milp_nfp_pieces.svg
@@ -0,0 +1,33 @@
+
diff --git a/doc/internals/algorithm_selection.rst b/doc/internals/algorithm_selection.rst
index f990690bc..16abf2d73 100644
--- a/doc/internals/algorithm_selection.rst
+++ b/doc/internals/algorithm_selection.rst
@@ -36,7 +36,7 @@ With a single bin, the problem is a single :code:`knapsack`, :code:`feasibility`
* :code:`rectangleguillotine`: depending on the number of stages, the cut type and the features used, the :ref:`tree search `, the :ref:`column generation strips `, the :ref:`tree search with maximal spaces `, or the :ref:`tree search hypergraph with infinite copies ` when the item types have many copies;
* :code:`box`: the tree search; for the :code:`knapsack` and :code:`feasibility` objectives, only in the directions in which few items fit in a section of the bin (at most 8 on average), or the :ref:`tree search with maximal spaces ` if there is no such direction;
* :code:`boxstacks`: the :ref:`sequential one-dimensional / rectangle ` algorithm;
-* :code:`irregular`: the tree search, or the :ref:`tree search with periodic packings ` when the instance is dominated by item types with many copies (together with the tree search if fewer than 64 items fit in the bin), and the :ref:`local search ` for the objectives it supports.
+* :code:`irregular`: the tree search, or the :ref:`tree search with periodic packings ` when the instance is dominated by item types with many copies (together with the tree search if fewer than 64 items fit in the bin), and the :ref:`local search ` for the objectives it supports; in the :code:`exact` mode, the :ref:`Benders decomposition ` for the :code:`knapsack` objective, and the :ref:`MILP NFP ` algorithm for the :code:`feasibility` objective.
Several bins
------------
diff --git a/doc/internals/generic_algorithms/column_generation.rst b/doc/internals/generic_algorithms/column_generation.rst
index 495cebb96..c3b3cd76f 100644
--- a/doc/internals/generic_algorithms/column_generation.rst
+++ b/doc/internals/generic_algorithms/column_generation.rst
@@ -79,7 +79,7 @@ The pricing problems are solved with the regular algorithms of the problem type,
**Bound.** The value of the restricted master problem is not a bound until no pattern of negative reduced cost remains, which a heuristic pricing can't prove. But the algorithms of the pricing problem also return a bound on the profit of the best pattern (for example the area of the bin, or a :ref:`dual feasible function ` bound), which bounds the best reduced cost :math:`\bar{r}` of a pattern of each bin type. Since a solution uses at most :math:`N` bins, the value of the linear relaxation is at least the value of the restricted master problem plus :math:`N \bar{r}`: this *Lagrangian bound* is valid at each iteration. :math:`N` is the number of items or of bins, whichever is smaller; for the :code:`bin-packing` objective, the number of bins of the best solution found; for the :code:`variable-sized-bin-packing` objective, the largest number of bins whose cost doesn't exceed the cost of the best solution found.
-**Exact pricing for rectangle.** For the rectangle problem type, once the column generation converges with the regular pricing, the pricing problems are solved once more with the :ref:`Benders decomposition ` (at most twice per column generation), which returns a much tighter bound on the best pattern, and proves the bound of the linear relaxation when it is exact. In the :code:`exact` mode, this Benders decomposition is itself run in :code:`exact` mode.
+**Exact pricing for rectangle and irregular.** For the rectangle and irregular problem types, once the column generation converges with the regular pricing, the pricing problems are solved once more with the Benders decomposition (:ref:`rectangle `, :ref:`irregular `, with the :ref:`MILP NFP ` algorithm in its subproblems) (at most twice per column generation), which returns a much tighter bound on the best pattern, and proves the bound of the linear relaxation when it is exact. In the :code:`exact` mode, this Benders decomposition is itself run in :code:`exact` mode.
Search
------
diff --git a/doc/internals/irregular.rst b/doc/internals/irregular.rst
index f9579ba1f..634e5ed81 100644
--- a/doc/internals/irregular.rst
+++ b/doc/internals/irregular.rst
@@ -74,6 +74,24 @@ It rasterizes the bins and the items onto a grid and solves the resulting placem
See :doc:`the detailed description `.
+Benders decomposition
+------------------------
+
+This algorithm solves the :code:`knapsack`, :code:`bin-packing` and :code:`variable-sized-bin-packing` objectives.
+
+Its master problem assigns the items to the bins considering only their areas, as a one-dimensional problem. For each bin of its solution, a subproblem checks whether the items actually fit; if not, no-good cuts forbidding infeasible subsets of them are added to the master problem, which is solved again. With the :ref:`MILP NFP ` algorithm in its subproblems, the cuts are proven, so the value of the master problem is a bound, and the algorithm is exact.
+
+See :doc:`the detailed description `.
+
+MILP NFP
+------------
+
+This algorithm solves the :code:`feasibility` objective with a single bin. Its main use is to prove that a set of items doesn't fit in a bin, in the subproblems of the Benders decomposition.
+
+For each combination of rotations of the items, the non-overlap of each pair of items is modeled with the convex pieces of the complement of their no-fit polygon, in a mixed-integer linear program. The items don't fit if every program is infeasible.
+
+See :doc:`the detailed description `.
+
One-dimensional bound
------------------------
@@ -90,3 +108,5 @@ Relaxes the instance to a one-dimensional problem (each bin and item type keeps
irregular/tree_search_maximal_spaces
irregular/local_search
irregular/milp_raster
+ irregular/benders_decomposition
+ irregular/milp_nfp
diff --git a/doc/internals/irregular/benders_decomposition.rst b/doc/internals/irregular/benders_decomposition.rst
new file mode 100644
index 000000000..ad8691b16
--- /dev/null
+++ b/doc/internals/irregular/benders_decomposition.rst
@@ -0,0 +1,112 @@
+.. _internals_irregular_benders_decomposition:
+
+Benders decomposition
+=====================
+
+Objectives
+----------
+
+This algorithm solves the :code:`knapsack` objective, with one or several bins, and the :code:`bin-packing` and :code:`variable-sized-bin-packing` objectives. It supports the resources of the bins.
+
+It is an exact method when its subproblems use the :ref:`MILP NFP ` algorithm: when it converges, the solution found is optimal, and before that, the value of its master problem is a bound.
+
+Principle
+---------
+
+It is the combinatorial Benders decomposition of the :ref:`rectangle Benders decomposition `, with the geometry of irregular items. The problem is split in two:
+
+* the *master problem* decides which items go in which bin, ignoring the geometry: it is a one-dimensional problem, where each item is reduced to its area and each bin to its area;
+* the *subproblems* check, for each bin of the solution of the master problem, whether its items actually fit together in the bin.
+
+When the items of a bin don't fit, *no-good cuts* are added to the master problem, forbidding infeasible subsets of them in a bin of this type, and the master problem is solved again. Since the master problem is a relaxation of the problem, the value of its optimal solution is a bound. The algorithm stops when the items of every bin fit, or when the solution of the master problem can't be better than the best solution found: the best solution found is then optimal.
+
+Unlike in the rectangle version, nothing is known about the geometry before the first iteration: two irregular items which don't fit side by side or one above the other may still fit together, interlocked or rotated, so there are no incompatible pairs or triplets, and no dual feasible function cuts. All the geometric information of the master problem comes from the subproblems.
+
+Master problem
+--------------
+
+The master problem is a :ref:`onedimensional ` instance, with the objective of the instance:
+
+* each bin type has its area, rounded up, as length, and keeps its copies, its cost and its resources;
+* each item type has its area, rounded down, as length, and keeps its copies and, for the :code:`knapsack` objective, its profit.
+
+The roundings keep the master problem a relaxation. It is solved with the :ref:`MILP assignment ` algorithm, in non-anytime mode, or in :code:`exact` mode in the :code:`exact` mode.
+
+The cuts are encoded as onedimensional *resources* on the bin types, as in the rectangle version: a cut forbidding :math:`n_i` copies of each item type :math:`i` of a set :math:`S`, with lifted item types :math:`L`, is the resource of capacity :math:`\sum_{i \in S} n_i - 1` where the copies of item type :math:`i \in S` consume :math:`(1, \ldots, 1, 0)` (:math:`n_i` ones) and the copies of item type :math:`j \in L` consume :math:`(1, 0)`. With the variables :math:`x_{i,t,k,c}` of the MILP assignment model (bin :math:`k` of type :math:`t` contains at least :math:`c` copies of item type :math:`i`), it is the constraint, for each bin :math:`(t, k)`:
+
+.. math::
+
+ \sum_{i \in S} \sum_{c \le n_i} x_{i,t,k,c} + \sum_{j \in L} x_{j,t,k,1} \le \sum_{i \in S} n_i - 1
+
+Iterations
+----------
+
+At each iteration, the master problem is solved, then the bins of its solution are checked. With the MILP NFP algorithm in the subproblems:
+
+.. image:: ../../img/irregular_benders_decomposition_iteration.svg
+ :align: center
+
+The steps are:
+
+1. **Master problem.** If all the cuts are proven (see below), the value of its solution is reported as a bound of the instance. If a solution has already been found, and the solution of the master problem can't be better (smaller profit for the :code:`knapsack` objective, as many bins or more for the :code:`bin-packing` objective, cost as large or larger for the :code:`variable-sized-bin-packing` objective), the algorithm stops.
+2. **Subproblems.** The selection of items of each bin of the solution of the master problem is checked (see below). A selection containing the items of a cut added earlier in the same iteration, for another bin, is known to be infeasible and is skipped. The bins whose items fit are assembled into a solution, which is reported if it is better than the best one (for the :code:`knapsack` objective, a subset of the bins is a feasible solution).
+3. **Convergence.** If every bin fits, the solution of the master problem is feasible, and the algorithm stops. Otherwise, no-good cuts are added for the bins which don't fit, and the master problem is solved again.
+
+Subproblems
+-----------
+
+Without the MILP NFP algorithm, the items of a bin are packed by solving a single-bin instance with the :code:`feasibility` objective with the irregular algorithms, in non-anytime mode (a queue of size 128 for the tree search). This finds packings, but it rarely proves that the items don't fit, so the cuts are mostly unproven.
+
+With the :ref:`MILP NFP ` algorithm:
+
+* **Infeasible prefix.** The items of the bin are sorted by decreasing area, and the MILP NFP algorithm is called on the largest one, then on the two largest ones, and so on, until it proves that they don't fit. Proving it for a few large items is often much cheaper than for all the items of the bin, and a small infeasible subset is what the cuts need anyway. If the MILP NFP algorithm is inconclusive (time limit, continuous rotations), the search stops.
+* **Packing.** If no prefix is proven infeasible, the MILP NFP algorithm is called on all the items of the bin. If its relaxation is feasible, the positions of its solution are checked, and used as a packing if the items don't overlap. Otherwise, the single-bin :code:`feasibility` instance is solved, as above.
+
+The answers of the MILP NFP algorithm are stored, so that the same selection of items is never checked twice, and the data of the MILP NFP algorithm (the convex pieces of the pairs of item types, the infeasible rotation combinations) are shared by all its calls.
+
+No-good cuts
+------------
+
+**Minimal infeasible subsets.** The infeasible items of a bin (the infeasible prefix, or all the items of the bin) are reduced to a minimal infeasible subset with the depth-first search of the rectangle version: the items are sorted by increasing area, and removed one at a time, as long as the remaining items don't fit. Each check is a subproblem, which is expensive for irregular items, so the search stops after a single subset per bin by default. The subset gives a no-good cut: no bin of this type contains at least these copies of these item types.
+
+**Lifting.** A proven cut forbidding a set :math:`S` of items is lifted by giving a coefficient 1 to other item types: the cut then forbids any :math:`|S|` items among :math:`S` and the lifted item types. The item types not in the cut are visited by decreasing area. An item type :math:`j` is lifted if every selection made of one copy of :math:`j` and of :math:`|S| - 1` items among :math:`S` and the item types already lifted (:math:`L`) is proven infeasible, either because it contains the items of a proven cut, or by the MILP NFP algorithm. Then no feasible selection reaches :math:`|S|` on the lifted cut, so it stays valid. Unlike in the rectangle version, the coefficients are only 0 or 1: there is no cheap bound, like the bar relaxation, on the number of items of the cut which fit together with :math:`j`. At most 4 item types are lifted in a cut.
+
+Lifting makes each cut much stronger, but it is expensive: on :code:`jakobs2_sb`, it adds about 3 item types per cut, but it takes 60% of the time.
+
+**Proofs.** A cut is *proven* if every check of its derivation proved that the items don't fit, which in practice requires the MILP NFP algorithm. A cut which isn't proven is still added, so that the algorithm keeps converging, but then the master problem may not be a relaxation anymore: while a cut is unproven, the value of the master problem is not reported as a bound of the instance, and the solution found is not proven optimal.
+
+Search parameters
+-----------------
+
+In anytime mode, the algorithm runs until it converges or reaches the time limit. In the non-anytime modes, it also stops after 32 iterations. In the :code:`exact` mode, it runs as in anytime mode, its master problem is solved in :code:`exact` mode, and its subproblems always use the MILP NFP algorithm, so that its bound is proven.
+
+Automatic selection
+-------------------
+
+In the :code:`exact` mode, it is run for the :code:`knapsack` objective with a single bin, alongside the other algorithms. The :ref:`column generation ` algorithm uses it, with the MILP NFP algorithm, to solve its pricing problems when it needs to prove a bound.
+
+It can be selected with :code:`--use-benders-decomposition 1` (CLI) or :code:`use_benders_decomposition` (Python), and its subproblems use the MILP NFP algorithm with :code:`--benders-decomposition-use-milp-nfp 1`. It only finds a solution once every bin of the solution of its master problem is packed, which may take long, while its bound may be good much earlier: it is best run together with other algorithms (e.g. :code:`--use-tree-search 1`), whose solutions may then be proven optimal by this bound.
+
+Strengths and limitations
+-------------------------
+
+The algorithm proves the optimality of the instances in which few items fit in a bin, or with few item types, whose minimal infeasible subsets are small and shared by many selections. With the tree search, in the :code:`exact` mode, on the :code:`bin-packing` instances of :code:`data/irregular/martinez2017`, it proves the optimality of :code:`albano_sb`, :code:`dighe1_sb`, :code:`dighe2_sb`, :code:`fu_sb`, :code:`han_sb`, :code:`jakobs1_sb`, :code:`mao_sb`, :code:`poly1a_sb`, :code:`shapes0_sb`, :code:`shapes1_sb` and :code:`shapes2_sb`, in a few seconds to a few minutes.
+
+When more items fit in a bin, the minimal infeasible subsets have 5 items or more, and the MILP NFP algorithm takes seconds to prove each of them: on :code:`poly2a_sb` (15 item types), the bound stays at the area bound.
+
+Source files
+------------
+
+* :code:`src/irregular/benders_decomposition.hpp`, :code:`src/irregular/benders_decomposition.cpp`: the decomposition
+* :code:`src/irregular/milp_nfp.hpp`, :code:`src/irregular/milp_nfp.cpp`: the MILP NFP algorithm of the subproblems
+* :code:`scripts/doc_figures/irregular_benders_decomposition.py`: the figures of this page
+
+References:
+
+* "Combinatorial Benders Decomposition for the Two-Dimensional Bin Packing Problem" (Côté, Haouari and Iori, 2021)
+
+ * https://doi.org/10.1287/ijoc.2020.1014
+
+* "Facets of the knapsack polytope" (Balas, 1975)
+
+ * https://doi.org/10.1007/BF01580430
diff --git a/doc/internals/irregular/milp_nfp.rst b/doc/internals/irregular/milp_nfp.rst
new file mode 100644
index 000000000..280bb41e9
--- /dev/null
+++ b/doc/internals/irregular/milp_nfp.rst
@@ -0,0 +1,134 @@
+.. _internals_irregular_milp_nfp:
+
+MILP NFP
+========
+
+Objectives
+----------
+
+Given a bin type and a set of items, this algorithm tries to prove that the items don't fit in a bin of this type. It is used in the subproblems of the :ref:`Benders decomposition `.
+
+It also solves the :code:`feasibility` objective with a single bin. If it doesn't prove that the instance is infeasible, the positions of the solution of its relaxation are checked, and used as a solution if the items don't overlap.
+
+It returns *infeasible* (proven), *feasible* (the relaxation is feasible, so the items may fit), or *unknown* (time limit, or an item type with a continuous rotation range).
+
+Principle
+---------
+
+The rotations of the items are enumerated. For a given rotation of each item, the positions of two items which don't overlap are described exactly by their *no-fit polygon*: item :math:`j` overlaps item :math:`i` if and only if the relative position :math:`p_j - p_i` of their reference points is in the interior of the no-fit polygon :math:`\text{NFP}_{ij}`. The complement of the no-fit polygon is not convex, so it is partitioned into convex pieces, and a binary variable selects the piece containing the relative position: this is the mixed-integer linear program (MILP) of Fischetti and Luzzi (2009), with the bounding box of the bin instead of a strip.
+
+In the example below, item :math:`i` is a 4 × 3 rectangle with a 1 × 2 notch, item :math:`j` a 1 × 2 rectangle, and the bin is 8 × 6. The relative positions allowed by the bin form the rectangle :math:`R`. The no-fit polygon covers its middle, and the region outside of it is partitioned into the convex pieces :math:`F_1` to :math:`F_4`. Item :math:`j` also fits exactly in the notch: its relative positions there form a segment inside the no-fit polygon, an additional piece (see *Exact fits* below):
+
+.. image:: ../../img/irregular_milp_nfp_pieces.svg
+ :align: center
+
+The items don't fit if the program of every rotation combination is infeasible. The programs of the rotation combinations are independent, so they are solved in parallel (4 threads by default), and the search stops as soon as one of them is feasible. A single program in which binary variables select the rotations was tried, but its linear relaxation is much weaker and it was several times slower.
+
+The model is a relaxation, so that an infeasible program is a proof:
+
+* the bin is replaced by its bounding box; the defects, the fixed items and the item-item spacing are ignored;
+* the circular arcs of the regions below are approximated by line segments outside of them.
+
+Model
+-----
+
+**Input**, for a rotation combination:
+
+* the items :math:`i = 1, \ldots, n`, each with its rotation;
+* for each item :math:`i`, its *inner-fit rectangle* :math:`\text{IFP}_i`: the positions of its reference point for which its bounding box is in the bounding box of the bin (minus the item-bin spacing);
+* for each pair of items :math:`(i, j)`, the region :math:`R_{ij} = \text{IFP}_j - \text{IFP}_i` of the relative positions allowed by the inner-fit rectangles, and the region :math:`F_{ij} = R_{ij} \setminus \text{int}(\text{NFP}_{ij})` of the ones for which the items don't overlap, partitioned into convex pieces :math:`k \in K_{ij}`. Each piece is described by its edges :math:`(n, c)`, the half-planes :math:`n \cdot d \ge c`.
+
+**Variables**:
+
+* :math:`p_i \in \text{IFP}_i`: the position of the reference point of item :math:`i`
+* :math:`z^{ij}_k \in \{0, 1\}`, :math:`k \in K_{ij}`: :math:`z^{ij}_k = 1` iff the relative position of items :math:`i` and :math:`j` is in piece :math:`k`
+
+There is no objective: only the feasibility of the program matters.
+
+**Constraints**:
+
+* Piece selection: the relative position of each pair of items is in one of the pieces.
+
+.. math::
+
+ \forall (i, j) \qquad \sum_{k \in K_{ij}} z^{ij}_k = 1
+
+* Pieces: the edges of a piece are relaxed with big-M coefficients when the piece isn't selected.
+
+.. math::
+
+ \forall (i, j), \; \forall k \in K_{ij}, \; \forall \text{ edge } (n, c) \text{ of } k \qquad n \cdot (p_j - p_i) \ge c - M (1 - z^{ij}_k)
+
+where :math:`M = c - \min_{d \in R_{ij}} n \cdot d` is the smallest value for which the constraint is always satisfied in :math:`R_{ij}`.
+
+* Symmetry breaking: identical items with the same rotation are sorted by :math:`x`.
+
+**Exact fits.** An item may fit exactly in a notch of another one, or two items may touch along a whole edge: the relative position is then on a line segment or at a point strictly inside the no-fit polygon, but on no edge of the region :math:`F_{ij}`. These feasible positions of null area are returned by the no-fit polygon computation, and each one is an additional convex piece of :math:`F_{ij}`, so that the program stays a relaxation.
+
+Rotation combinations
+---------------------
+
+The rotation combinations are enumerated item by item. Some of them are never solved:
+
+* **Identical rotations.** Two rotations of an item type which give the same shape (for example, the rotations by 0 and 180 degrees of a rectangle) are only considered once.
+* **Identical items.** The rotations of identical items are non-decreasing.
+* **Symmetry of the bin.** The program only considers the bounding box of the bin, so turning a solution by 180 degrees gives another solution. If every rotation of every item type has its counterpart turned by 180 degrees, then an item, the only copy of its item type, is restricted to one rotation of each such pair.
+* **Pairs.** A partial combination in which the region :math:`F_{ij}` of a pair of items is empty isn't extended.
+
+Before solving the program of a rotation combination:
+
+1. **Core widening.** A cheap area test may prove it infeasible (see below).
+2. **Sub-combinations.** Its sub-combinations without one of the items are checked first: if one of them is infeasible, so is the combination. Their programs are cheaper, and each of them is shared by several combinations.
+
+The statuses of the combinations and of the sub-combinations are cached, as well as the convex pieces of the pairs of item types, so that the next calls on other sets of items reuse them. On the 5 items of :code:`data/irregular/tests/feasibility_poly2a_five_items_infeasible.json`, 406 of the 512 rotation combinations are proven infeasible by a sub-combination, and the proof goes from 17.6 to 13 seconds.
+
+Core widening
+-------------
+
+The *core* of an item is the part of its :math:`y`-range that no other item can reach, given the regions :math:`F_{ij}` (each piece is convex, so its :math:`y`-range gives exactly the heights at which the other item can be). Since the rotations are fixed, no other item has any point in the horizontal band of the core of an item, across the whole bin. So the item can be counted as widened to the width :math:`W` of the bin on its core:
+
+.. math::
+
+ \text{widened area}(i) = W \times \text{core height}(i) + \text{area of } i \text{ outside of its core}
+
+In the example below, items :math:`j` and :math:`k` can't be lower than the top of the foot of item :math:`i`, so the band of the foot belongs to item :math:`i` alone, across the whole bin:
+
+.. image:: ../../img/irregular_milp_nfp_core_widening.svg
+ :align: center
+
+The cores of different items are disjoint, so the rotation combination is infeasible if the sum of the widened areas exceeds the area of the bin.
+
+This is not a reduction: the parts of an item outside of its core may be interlocked with other items, so the item can't always be moved against a side of the bin to actually be widened. The test helps when the items are large compared to the bin; when they fill less than about three quarters of it, the cores are usually empty.
+
+Search parameters
+-----------------
+
+The programs are solved with HiGHS, with 4 threads by default, until the time limit. When the algorithm is run on its own, in the :code:`not-anytime-sequential` mode, a single thread is used.
+
+Automatic selection
+-------------------
+
+In the :code:`exact` mode, it is run for the :code:`feasibility` objective with a single bin, alongside the other algorithms. It is always used in the subproblems of the :ref:`Benders decomposition ` in the :code:`exact` mode.
+
+It can be selected with :code:`--use-milp-nfp 1` (CLI) or :code:`use_milp_nfp` (Python), for the :code:`feasibility` objective with a single bin only.
+
+Strengths and limitations
+-------------------------
+
+The number of rotation combinations grows exponentially with the number of items, and the programs get harder as the items get smaller compared to the bin, since the regions :math:`F_{ij}` then have more pieces. The algorithm proves in a fraction of a second that 2 or 3 large items don't fit; for 5 items with 4 rotations each, a proof may take 10 to 20 seconds.
+
+Source files
+------------
+
+* :code:`src/irregular/milp_nfp.hpp`, :code:`src/irregular/milp_nfp.cpp`: the algorithm
+* :code:`scripts/doc_figures/irregular_milp_nfp.py`: the figures of this page
+
+References:
+
+* "Mixed-integer programming models for nesting problems" (Fischetti and Luzzi, 2009)
+
+ * https://doi.org/10.1007/s10732-008-9088-9
+
+* "A branch & bound algorithm for cutting and packing irregularly shaped pieces" (Alvarez-Valdes, Martinez and Tamarit, 2013)
+
+ * https://doi.org/10.1016/j.ijpe.2013.04.007
diff --git a/include/packingsolver/irregular/instance.hpp b/include/packingsolver/irregular/instance.hpp
index 0a4bd6973..8a98d4413 100644
--- a/include/packingsolver/irregular/instance.hpp
+++ b/include/packingsolver/irregular/instance.hpp
@@ -439,6 +439,15 @@ class Instance
/** Get the objective of the problem. */
inline Objective objective() const { return objective_; }
+ /**
+ * Get the knapsack goal: for the 'Knapsack' objective, the search stops
+ * as soon as a solution reaches it, or as soon as the bound proves that
+ * it can't be reached (e.g. a pricing problem of a column generation,
+ * which only needs a column of negative reduced cost, or a proof that
+ * there is none). Infinite by default.
+ */
+ inline Profit knapsack_goal() const { return knapsack_goal_; }
+
/*
* Getters: parameters
*/
@@ -641,6 +650,9 @@ class Instance
/** Objective. */
Objective objective_ = Objective::BinPacking;
+ /** Knapsack goal. */
+ Profit knapsack_goal_ = std::numeric_limits::infinity();
+
/** Parameters. */
Parameters parameters_;
diff --git a/include/packingsolver/irregular/instance_builder.hpp b/include/packingsolver/irregular/instance_builder.hpp
index c94783a2e..608f46521 100644
--- a/include/packingsolver/irregular/instance_builder.hpp
+++ b/include/packingsolver/irregular/instance_builder.hpp
@@ -18,6 +18,9 @@ class InstanceBuilder
/** Set the objective. */
void set_objective(Objective objective) { instance_.objective_ = objective; }
+ /** Set the knapsack goal (see 'Instance::knapsack_goal'). */
+ void set_knapsack_goal(Profit knapsack_goal) { instance_.knapsack_goal_ = knapsack_goal; }
+
/*
* Read from files
*/
diff --git a/include/packingsolver/irregular/optimize.hpp b/include/packingsolver/irregular/optimize.hpp
index 2fff3713c..e9df4a0ab 100644
--- a/include/packingsolver/irregular/optimize.hpp
+++ b/include/packingsolver/irregular/optimize.hpp
@@ -82,9 +82,15 @@ struct Output: packingsolver::Output
if (is_proven_infeasible)
return true;
switch (solution_pool.best().instance().objective()) {
- case Objective::Knapsack:
+ case Objective::Knapsack: {
+ Profit knapsack_goal = solution_pool.best().instance().knapsack_goal();
+ // The bound proves that the knapsack goal can't be reached.
+ if (std::isfinite(knapsack_goal) && knapsack_bound < knapsack_goal)
+ return true;
return solution_pool.best().feasible()
- && equal_profit(knapsack_bound, solution_pool.best().profit());
+ && (equal_profit(knapsack_bound, solution_pool.best().profit())
+ || solution_pool.best().profit() >= knapsack_goal);
+ }
case Objective::BinPacking:
return solution_pool.best().feasible()
&& bin_packing_bound == solution_pool.best().number_of_bins();
@@ -257,6 +263,28 @@ struct OptimizeParameters: packingsolver::Parameters
/** Use column generation algorithm. */
bool use_column_generation = false;
+ /**
+ * Use Benders decomposition algorithm (only for the 'Knapsack',
+ * 'BinPacking' and 'VariableSizedBinPacking' objectives; only selected
+ * automatically in 'Exact' mode, for the 'Knapsack' objective with a
+ * single bin).
+ */
+ bool use_benders_decomposition = false;
+
+ /**
+ * Use the MILP NFP algorithm in the subproblems of the Benders
+ * decomposition algorithm, to prove that the items of a bin don't fit.
+ *
+ * Always used in 'Exact' mode.
+ */
+ bool benders_decomposition_use_milp_nfp = false;
+
+ /**
+ * Use the MILP NFP algorithm (only for the 'Feasibility' objective with a
+ * single bin; only selected automatically in 'Exact' mode).
+ */
+ bool use_milp_nfp = false;
+
/** Initial maximum approximation ratio. */
double initial_maximum_approximation_ratio = 0.20;
@@ -339,6 +367,12 @@ struct OptimizeParameters: packingsolver::Parameters
*/
NodeId column_generation_subproblem_tree_search_queue_size = 128;
+ /**
+ * Size of the queue for the feasibility subproblem of the Benders
+ * decomposition algorithm.
+ */
+ NodeId benders_decomposition_subproblem_tree_search_queue_size = 128;
+
/*
* Parameters for anytime mode
*/
@@ -413,6 +447,9 @@ struct OptimizeParameters: packingsolver::Parameters
/** Number of iterations of the sequential value correction algorithm. */
Counter not_anytime_sequential_value_correction_number_of_iterations = 32;
+ /** Number of iterations of the Benders decomposition algorithm. */
+ Counter not_anytime_benders_decomposition_number_of_iterations = 32;
+
/**
* Maximum number of failed separations of the local search, after which
* a sub-problem is considered infeasible.
diff --git a/python/src/irregular.cpp b/python/src/irregular.cpp
index afb66a255..e3f65ad11 100644
--- a/python/src/irregular.cpp
+++ b/python/src/irregular.cpp
@@ -667,6 +667,9 @@ void bind_irregular(nb::module_& m)
.def_rw("use_local_search_direct_trigonometry", &OptimizeParameters::use_local_search_direct_trigonometry)
.def_rw("use_local_search_black_box_optimization", &OptimizeParameters::use_local_search_black_box_optimization)
.def_rw("use_milp_raster", &OptimizeParameters::use_milp_raster)
+ .def_rw("use_milp_nfp", &OptimizeParameters::use_milp_nfp)
+ .def_rw("use_benders_decomposition", &OptimizeParameters::use_benders_decomposition)
+ .def_rw("benders_decomposition_use_milp_nfp", &OptimizeParameters::benders_decomposition_use_milp_nfp)
.def_rw("use_sequential_single_knapsack", &OptimizeParameters::use_sequential_single_knapsack)
.def_rw("use_sequential_value_correction", &OptimizeParameters::use_sequential_value_correction)
.def_rw("use_dichotomic_search", &OptimizeParameters::use_dichotomic_search)
diff --git a/scripts/doc_figures/irregular_benders_decomposition.py b/scripts/doc_figures/irregular_benders_decomposition.py
new file mode 100644
index 000000000..98f0b7bd6
--- /dev/null
+++ b/scripts/doc_figures/irregular_benders_decomposition.py
@@ -0,0 +1,61 @@
+"""Figures of the detailed description of the Benders decomposition of
+irregular.
+
+Usage, from the root of the repository:
+
+ python3 scripts/doc_figures/irregular_benders_decomposition.py
+"""
+
+import os
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import figure
+from figure import BLUE, RED, YELLOW
+
+SVG_DIR = "doc/img"
+PREFIX = "irregular_benders_decomposition_"
+
+
+def figure_iteration():
+ """Flow of an iteration, with the MILP NFP algorithm in the
+ subproblems."""
+ fig = figure.Figure(unit=30)
+ bw, bh = 11, 1.2
+ step = 2.0
+
+ steps = [
+ ("solve the master problem", BLUE, None),
+ ("can its solution beat the best one?", YELLOW, ("no", "stop")),
+ ("for each bin, add its items, largest first,\nuntil MILP NFP proves that they don't fit", BLUE, None),
+ ("if none is proven infeasible,\npack the items of the bin", BLUE, None),
+ ("does every bin fit?", YELLOW, ("yes", "stop")),
+ ("minimal infeasible subset\nof each bin which doesn't fit", BLUE, None),
+ ("lift the proven cuts,\nadd the cuts to the master problem", BLUE, None),
+ ]
+ x = 0
+ for k, (label, style, side) in enumerate(steps):
+ y = -k * step
+ fig.rect(x - bw / 2, y - bh / 2, bw, bh, label, style + "rounded=1;fontSize=11;")
+ if k + 1 < len(steps):
+ fig.arrow(x, y - bh / 2, x, y - step + bh / 2, "strokeColor=#333333;")
+ if style == YELLOW:
+ answer = "yes" if side[0] == "no" else "no"
+ fig.text(x + 0.3, y - step / 2, answer, w=1, size=11, align="left")
+ if side is not None:
+ answer, action = side
+ fig.arrow(x + bw / 2, y, x + bw / 2 + 2, y, "strokeColor=#333333;")
+ fig.text(x + bw / 2 + 1, y + 0.35, answer, w=1.5, size=11)
+ fig.rect(x + bw / 2 + 2, y - bh / 2, 2.4, bh, action, RED + "rounded=1;fontSize=11;")
+
+ # Back to the master problem.
+ y_last = -(len(steps) - 1) * step
+ fig.polyline(
+ [(x - bw / 2, y_last), (x - bw / 2 - 1, y_last), (x - bw / 2 - 1, 0), (x - bw / 2, 0)],
+ "strokeColor=#333333;", arrow=True)
+
+ fig.write(os.path.join(SVG_DIR, PREFIX + "iteration.svg"))
+
+
+if __name__ == "__main__":
+ figure_iteration()
diff --git a/scripts/doc_figures/irregular_milp_nfp.py b/scripts/doc_figures/irregular_milp_nfp.py
new file mode 100644
index 000000000..63a6966df
--- /dev/null
+++ b/scripts/doc_figures/irregular_milp_nfp.py
@@ -0,0 +1,124 @@
+"""Figures of the detailed description of the MILP NFP algorithm of
+irregular.
+
+Usage, from the root of the repository:
+
+ python3 scripts/doc_figures/irregular_milp_nfp.py
+"""
+
+import os
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
+import figure
+from figure import BLUE, GREEN, YELLOW, NONE
+
+SVG_DIR = "doc/img"
+PREFIX = "irregular_milp_nfp_"
+
+DARK_GRAY = "fillColor=#cccccc;strokeColor=#666666;"
+DOT = "fillColor=#000000;strokeColor=#000000;ellipse;"
+RED_STROKE = "#b85450"
+
+
+def dot(fig, x, y, r=0.08):
+ fig.rect(x - r, y - r, 2 * r, 2 * r, "", DOT)
+
+
+def u_shape(x, y):
+ """Item i: a 4 x 3 rectangle with a 1 x 2 notch on its top side."""
+ return [
+ (x, y), (x + 4, y), (x + 4, y + 3), (x + 2.5, y + 3),
+ (x + 2.5, y + 1), (x + 1.5, y + 1), (x + 1.5, y + 3), (x, y + 3)]
+
+
+def figure_pieces():
+ """No-fit polygon of a U-shaped item and of a 1 x 2 rectangle, and the
+ convex pieces of the region outside of it.
+
+ Bin 8 x 6. The inner-fit rectangles are [0, 4] x [0, 3] for the U and
+ [0, 7] x [0, 4] for the rectangle, so R = [-4, 7] x [-3, 4]. The no-fit
+ polygon is [-1, 4] x [-2, 3], with a slit at x = 1.5, 1 <= y <= 3: the
+ rectangle slides exactly into the notch.
+ """
+ fig = figure.Figure(unit=28)
+
+ # Left: a packing in which the rectangle is exactly in the notch.
+ fig.text(4, 7, "positions in the bin", w=8)
+ fig.bin(0, 0, 8, 6)
+ pi = (1, 1)
+ pj = (2.5, 2)
+ fig.polygon(u_shape(*pi), "i", BLUE, label_position=(pi[0] + 0.75, pi[1] + 1.8))
+ fig.rect(pj[0], pj[1], 1, 2, "j", GREEN)
+ dot(fig, *pi)
+ dot(fig, *pj)
+ fig.text(pi[0] - 0.2, pi[1] - 0.35, "p_i", w=1, size=11, align="right")
+ fig.text(pj[0] + 0.15, pj[1] - 0.35, "p_j", w=1, size=11, align="left")
+
+ # Right: the relative positions d = p_j - p_i.
+ ox, oy = 15, 3
+ fig.text(ox + 1.5, oy + 5, "relative positions d = p_j - p_i", w=11)
+ # Convex pieces of F = R \ int(NFP).
+ pieces = [
+ ((-4, -3), 3, 7, "F1"),
+ ((4, -3), 3, 7, "F2"),
+ ((-1, -3), 5, 1, "F3"),
+ ((-1, 3), 5, 1, "F4"),
+ ]
+ for (x, y), w, h, label in pieces:
+ fig.rect(ox + x, oy + y, w, h, label, GREEN)
+ # No-fit polygon.
+ fig.rect(ox - 1, oy - 2, 5, 5, "", DARK_GRAY)
+ fig.text(ox + 3.0, oy - 1.3, "NFP", w=2, size=13)
+ # R.
+ fig.rect(ox - 4, oy - 3, 11, 7, "", NONE + "strokeWidth=2;dashed=1;")
+ fig.text(ox + 7.2, oy + 3.7, "R", w=1, size=13, align="left")
+ # Exact fit: the slit of the no-fit polygon.
+ fig.polyline([(ox + 1.5, oy + 1), (ox + 1.5, oy + 3)],
+ "strokeColor={};strokeWidth=4;".format(RED_STROKE))
+ fig.polyline([(ox + 2.35, oy + 2.2), (ox + 1.6, oy + 2.2)],
+ "strokeColor={};".format(RED_STROKE))
+ fig.text(ox + 2.4, oy + 2.2, "exact fit", w=3, size=11, align="left",
+ extra="fontColor={};".format(RED_STROKE))
+ # The relative position of the packing on the left.
+ dot(fig, ox + pj[0] - pi[0], oy + pj[1] - pi[1])
+ fig.text(ox + 1.3, oy + 0.75, "d", w=1, size=11, align="right")
+ # Origin.
+ dot(fig, ox, oy, r=0.06)
+ fig.text(ox - 0.15, oy - 0.3, "0", w=1, size=11, align="right")
+
+ fig.write(os.path.join(SVG_DIR, PREFIX + "pieces.svg"))
+
+
+def figure_core_widening():
+ """Core of an item: a horizontal band across the bin which no other item
+ can reach."""
+ fig = figure.Figure(unit=30)
+ W, H = 10, 5
+ core = 1.5
+
+ fig.rect(0, 0, W, core, "", YELLOW + "dashed=1;opacity=60;")
+ fig.text(W - 0.2, core / 2, "core of i", w=3, size=11, align="right")
+ fig.bin(0, 0, W, H)
+ fig.polygon([(0.5, 0), (4, 0), (4, 1.5), (2, 1.5), (2, 3.5), (0.5, 3.5)], "i", BLUE,
+ label_position=(1.25, 2.5))
+ fig.polygon([(4.5, 1.8), (7, 1.8), (7, 4.6), (5.5, 4.6), (5.5, 3), (4.5, 3)], "j", GREEN,
+ label_position=(6.25, 3.2))
+ fig.polygon([(7.5, 1.6), (9.8, 1.6), (9.8, 4.8)], "k", GREEN, label_position=(9.1, 2.4))
+ # Height of the core.
+ fig.polyline([(-0.4, 0), (-0.4, core)])
+ fig.polyline([(-0.55, 0), (-0.25, 0)])
+ fig.polyline([(-0.55, core), (-0.25, core)])
+ fig.text(-0.6, core / 2, "core\nheight", w=2, size=11, align="right")
+ # Width of the bin.
+ fig.polyline([(0, -0.4), (W, -0.4)])
+ fig.polyline([(0, -0.55), (0, -0.25)])
+ fig.polyline([(W, -0.55), (W, -0.25)])
+ fig.text(W / 2, -0.75, "W", w=1, size=11)
+
+ fig.write(os.path.join(SVG_DIR, PREFIX + "core_widening.svg"))
+
+
+if __name__ == "__main__":
+ figure_pieces()
+ figure_core_widening()
diff --git a/src/algorithms/column_generation.hpp b/src/algorithms/column_generation.hpp
index 2c7fc8b66..f4d44a705 100644
--- a/src/algorithms/column_generation.hpp
+++ b/src/algorithms/column_generation.hpp
@@ -675,11 +675,13 @@ PricingOutput ColumnGenerationPricingSolver::infinity();
if (instance_.objective() == Objective::VariableSizedBinPacking
|| instance_.objective() == Objective::BinPacking) {
diff --git a/src/irregular/CMakeLists.txt b/src/irregular/CMakeLists.txt
index e897e6ecc..b751d9ada 100644
--- a/src/irregular/CMakeLists.txt
+++ b/src/irregular/CMakeLists.txt
@@ -25,6 +25,8 @@ target_sources(PackingSolver_irregular PRIVATE
nonlinear_programming/separation_model.cpp
nonlinear_programming/separator.cpp
milp_raster.cpp
+ milp_nfp.cpp
+ benders_decomposition.cpp
trivial.cpp
direct_trigonometry/polygon.cpp
direct_trigonometry/separator.cpp
diff --git a/src/irregular/benders_decomposition.cpp b/src/irregular/benders_decomposition.cpp
new file mode 100644
index 000000000..2b5a6bd7a
--- /dev/null
+++ b/src/irregular/benders_decomposition.cpp
@@ -0,0 +1,917 @@
+#include "irregular/benders_decomposition.hpp"
+
+#include "packingsolver/irregular/algorithm_formatter.hpp"
+#include "packingsolver/irregular/instance_builder.hpp"
+#include "irregular/milp_nfp.hpp"
+
+#include "packingsolver/onedimensional/instance_builder.hpp"
+#include "packingsolver/onedimensional/optimize.hpp"
+
+#include
+#include
+#include
+#include
+#include