diff --git a/data/box/tests/bin_packing_lift_item_dimensions/bins.csv b/data/box/tests/bin_packing_lift_item_dimensions/bins.csv new file mode 100644 index 000000000..e93203ffa --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions/bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +10,10,10,1000,5,0,inf diff --git a/data/box/tests/bin_packing_lift_item_dimensions/items.csv b/data/box/tests/bin_packing_lift_item_dimensions/items.csv new file mode 100644 index 000000000..de6ff52c5 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions/items.csv @@ -0,0 +1,3 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ +7,10,10,700,1,1,0,1 +4,10,10,400,1,1,0,1 diff --git a/data/box/tests/bin_packing_lift_item_dimensions/parameters.csv b/data/box/tests/bin_packing_lift_item_dimensions/parameters.csv new file mode 100644 index 000000000..e72e86bc5 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,bin-packing diff --git a/data/box/tests/bin_packing_lift_item_dimensions/reduced_bins.csv b/data/box/tests/bin_packing_lift_item_dimensions/reduced_bins.csv new file mode 100644 index 000000000..e93203ffa --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions/reduced_bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +10,10,10,1000,5,0,inf diff --git a/data/box/tests/bin_packing_lift_item_dimensions/reduced_items.csv b/data/box/tests/bin_packing_lift_item_dimensions/reduced_items.csv new file mode 100644 index 000000000..9663b2e7c --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions/reduced_items.csv @@ -0,0 +1,2 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ +7,10,10,700,2,2,0,1 diff --git a/data/box/tests/bin_packing_lift_item_dimensions/solution.csv b/data/box/tests/bin_packing_lift_item_dimensions/solution.csv new file mode 100644 index 000000000..de4e96193 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions/solution.csv @@ -0,0 +1,5 @@ +TYPE,ID,COPIES,BIN,X,Y,Z,LX,LY,LZ,ROTATION +BIN,0,1,0,0,0,0,10,10,10, +ITEM,0,1,0,0,0,0,7,10,10,XYZ +BIN,0,1,1,0,0,0,10,10,10, +ITEM,1,1,1,0,0,0,4,10,10,XYZ diff --git a/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/bins.csv b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/bins.csv new file mode 100644 index 000000000..e93203ffa --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +10,10,10,1000,5,0,inf diff --git a/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/items.csv b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/items.csv new file mode 100644 index 000000000..a4b275b3c --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/items.csv @@ -0,0 +1,3 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ +7,10,10,700,1,1,0,1 +4,10,10,400,2,2,0,1 diff --git a/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/parameters.csv b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/parameters.csv new file mode 100644 index 000000000..e72e86bc5 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,bin-packing diff --git a/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/reduced_bins.csv b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/reduced_bins.csv new file mode 100644 index 000000000..e93203ffa --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/reduced_bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +10,10,10,1000,5,0,inf diff --git a/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/reduced_items.csv b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/reduced_items.csv new file mode 100644 index 000000000..01ea6ec02 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/reduced_items.csv @@ -0,0 +1,3 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ +8,10,10,700,1,1,0,1 +4,10,10,400,2,2,0,1 diff --git a/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/solution.csv b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/solution.csv new file mode 100644 index 000000000..a4d08990d --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_requires_single_copy/solution.csv @@ -0,0 +1,6 @@ +TYPE,ID,COPIES,BIN,X,Y,Z,LX,LY,LZ,ROTATION +BIN,0,1,0,0,0,0,10,10,10, +ITEM,0,1,0,0,0,0,7,10,10,XYZ +BIN,0,1,1,0,0,0,10,10,10, +ITEM,1,1,1,0,0,0,4,10,10,XYZ +ITEM,1,1,1,4,0,0,4,10,10,XYZ diff --git a/data/box/tests/bin_packing_lift_item_dimensions_rotations/bins.csv b/data/box/tests/bin_packing_lift_item_dimensions_rotations/bins.csv new file mode 100644 index 000000000..e93203ffa --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_rotations/bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +10,10,10,1000,5,0,inf diff --git a/data/box/tests/bin_packing_lift_item_dimensions_rotations/items.csv b/data/box/tests/bin_packing_lift_item_dimensions_rotations/items.csv new file mode 100644 index 000000000..caba290b0 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_rotations/items.csv @@ -0,0 +1,3 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ,ROTATION_YXZ +7,8,4,224,1,1,0,1,1 +4,4,7,112,1,1,0,1,0 diff --git a/data/box/tests/bin_packing_lift_item_dimensions_rotations/parameters.csv b/data/box/tests/bin_packing_lift_item_dimensions_rotations/parameters.csv new file mode 100644 index 000000000..e72e86bc5 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_rotations/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,bin-packing diff --git a/data/box/tests/bin_packing_lift_item_dimensions_rotations/reduced_bins.csv b/data/box/tests/bin_packing_lift_item_dimensions_rotations/reduced_bins.csv new file mode 100644 index 000000000..e93203ffa --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_rotations/reduced_bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +10,10,10,1000,5,0,inf diff --git a/data/box/tests/bin_packing_lift_item_dimensions_rotations/reduced_items.csv b/data/box/tests/bin_packing_lift_item_dimensions_rotations/reduced_items.csv new file mode 100644 index 000000000..5c75dd690 --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_rotations/reduced_items.csv @@ -0,0 +1,3 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ,ROTATION_YXZ +7,8,7,224,1,1,0,1,1 +8,8,7,112,1,1,0,1,0 diff --git a/data/box/tests/bin_packing_lift_item_dimensions_rotations/solution.csv b/data/box/tests/bin_packing_lift_item_dimensions_rotations/solution.csv new file mode 100644 index 000000000..b48db501c --- /dev/null +++ b/data/box/tests/bin_packing_lift_item_dimensions_rotations/solution.csv @@ -0,0 +1,5 @@ +TYPE,ID,COPIES,BIN,X,Y,Z,LX,LY,LZ,ROTATION +BIN,0,1,0,0,0,0,10,10,10, +ITEM,0,1,0,0,0,0,7,8,4,XYZ +BIN,0,1,1,0,0,0,10,10,10, +ITEM,1,1,1,0,0,0,4,4,7,XYZ diff --git a/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/bins.csv b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/bins.csv new file mode 100644 index 000000000..703cb9e7c --- /dev/null +++ b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +12,10,10,1200,1,0,inf diff --git a/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/items.csv b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/items.csv new file mode 100644 index 000000000..80e1e7a2f --- /dev/null +++ b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/items.csv @@ -0,0 +1,4 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ +7,10,10,700,1,1,0,1 +3,10,10,300,1,1,0,1 +5,10,10,500,1,1,0,1 diff --git a/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/parameters.csv b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/parameters.csv new file mode 100644 index 000000000..b1832dc50 --- /dev/null +++ b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,open-dimension-x diff --git a/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/reduced_bins.csv b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/reduced_bins.csv new file mode 100644 index 000000000..703cb9e7c --- /dev/null +++ b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/reduced_bins.csv @@ -0,0 +1,2 @@ +X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +12,10,10,1200,1,0,inf diff --git a/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/reduced_items.csv b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/reduced_items.csv new file mode 100644 index 000000000..80e1e7a2f --- /dev/null +++ b/data/box/tests/open_dimension_x_lift_item_dimensions_skips_x/reduced_items.csv @@ -0,0 +1,4 @@ +X,Y,Z,PROFIT,COPIES,COPIES_MIN,WEIGHT,ROTATION_XYZ +7,10,10,700,1,1,0,1 +3,10,10,300,1,1,0,1 +5,10,10,500,1,1,0,1 diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions/bins.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions/bins.csv new file mode 100644 index 000000000..cfca5f09e --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions/bins.csv @@ -0,0 +1,2 @@ +ID,X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,10,1000,5,0,inf diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions/items.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions/items.csv new file mode 100644 index 000000000..331b11f0c --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions/items.csv @@ -0,0 +1,3 @@ +ID,X,Y,Z,PROFIT,ROTATION_XYZ,WEIGHT,COPIES,COPIES_MIN,GROUP_ID,STACKABILITY_ID +0,7,10,5,350,1,0,1,1,0,0 +1,4,10,5,200,1,0,1,1,0,1 diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions/parameters.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions/parameters.csv new file mode 100644 index 000000000..e72e86bc5 --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,bin-packing diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions/reduced_bins.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions/reduced_bins.csv new file mode 100644 index 000000000..cfca5f09e --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions/reduced_bins.csv @@ -0,0 +1,2 @@ +ID,X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,10,1000,5,0,inf diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions/reduced_items.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions/reduced_items.csv new file mode 100644 index 000000000..16e0b41e2 --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions/reduced_items.csv @@ -0,0 +1,3 @@ +ID,X,Y,Z,PROFIT,ROTATION_XYZ,WEIGHT,COPIES,COPIES_MIN,GROUP_ID,STACKABILITY_ID +0,7,10,10,350,1,0,1,1,0,0 +1,7,10,10,200,1,0,1,1,0,1 diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions/solution.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions/solution.csv new file mode 100644 index 000000000..372c03e4e --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions/solution.csv @@ -0,0 +1,7 @@ +TYPE,ID,COPIES,BIN,STACK,X,Y,LX,LY,ROTATION +BIN,0,1,0,-1,0,0,10,10, +STACK,0,1,0,0,0,0,7,10, +ITEM,0,1,0,0,0,0,7,10,XYZ +BIN,0,1,1,-1,0,0,10,10, +STACK,0,1,1,0,0,0,4,10, +ITEM,1,1,1,0,0,0,4,10,XYZ diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/bins.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/bins.csv new file mode 100644 index 000000000..cfca5f09e --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/bins.csv @@ -0,0 +1,2 @@ +ID,X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,10,1000,5,0,inf diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/items.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/items.csv new file mode 100644 index 000000000..fb13f8cfb --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/items.csv @@ -0,0 +1,4 @@ +ID,X,Y,Z,PROFIT,ROTATION_XYZ,WEIGHT,COPIES,COPIES_MIN,GROUP_ID,STACKABILITY_ID +0,7,10,5,350,1,0,1,1,0,0 +1,4,10,5,200,1,0,1,1,0,1 +2,4,10,5,200,1,0,1,1,0,1 diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/parameters.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/parameters.csv new file mode 100644 index 000000000..e72e86bc5 --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,bin-packing diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/reduced_bins.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/reduced_bins.csv new file mode 100644 index 000000000..cfca5f09e --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/reduced_bins.csv @@ -0,0 +1,2 @@ +ID,X,Y,Z,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,10,1000,5,0,inf diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/reduced_items.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/reduced_items.csv new file mode 100644 index 000000000..bd18c2841 --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/reduced_items.csv @@ -0,0 +1,3 @@ +ID,X,Y,Z,PROFIT,ROTATION_XYZ,WEIGHT,COPIES,COPIES_MIN,GROUP_ID,STACKABILITY_ID +0,8,10,10,350,1,0,1,1,0,0 +1,4,10,5,200,1,0,2,2,0,1 diff --git a/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/solution.csv b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/solution.csv new file mode 100644 index 000000000..407182a9f --- /dev/null +++ b/data/boxstacks/tests/bin_packing_lift_item_dimensions_requires_alone_in_stack/solution.csv @@ -0,0 +1,9 @@ +TYPE,ID,COPIES,BIN,STACK,X,Y,LX,LY,ROTATION +BIN,0,1,0,-1,0,0,10,10, +STACK,0,1,0,0,0,0,7,10, +ITEM,0,1,0,0,0,0,7,10,XYZ +BIN,0,1,1,-1,0,0,10,10, +STACK,0,1,1,0,0,0,4,10, +ITEM,1,1,1,0,0,0,4,10,XYZ +STACK,1,1,1,1,4,0,4,10, +ITEM,2,1,1,1,4,0,4,10,XYZ diff --git a/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/bins.csv b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/bins.csv new file mode 100644 index 000000000..6173b1e5e --- /dev/null +++ b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/bins.csv @@ -0,0 +1,2 @@ +ID,X,Y,Z,COST,COPIES,MAXIMUM_WEIGHT,MAXIMUM_STACK_DENSITY,IS_SEMI_TRAILER_TRUCK,TRACTOR_WEIGHT,FRONT_AXLE_MIDDLE_AXLE_DISTANCE,FRONT_AXLE_TRACTOR_GRAVITY_CENTER_DISTANCE,FRONT_AXLE_HARNESS_DISTANCE,EMPTY_TRAILER_WEIGHT,HARNESS_REAR_AXLE_DISTANCE,TRAILER_GRAVITY_CENTER_REAR_AXLE_DISTANCE,TRAILER_START_HARNESS_DISTANCE,REAR_AXLE_MAXIMUM_WEIGHT,MIDDLE_AXLE_MAXIMUM_WEIGHT +0,1360,240,260,1,1,24000,1000,1,8000,380,100,320,6000,800,400,100,20000,9300 diff --git a/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/items.csv b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/items.csv new file mode 100644 index 000000000..b184a7690 --- /dev/null +++ b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/items.csv @@ -0,0 +1,3 @@ +ID,X,Y,Z,PROFIT,ROTATION_XYZ,WEIGHT,COPIES,COPIES_MIN,GROUP_ID,STACKABILITY_ID +0,1000,240,100,1,1,1000,1,1,0,0 +1,400,240,100,1,1,1000,1,1,0,1 diff --git a/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/parameters.csv b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/parameters.csv new file mode 100644 index 000000000..e72e86bc5 --- /dev/null +++ b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/parameters.csv @@ -0,0 +1,2 @@ +NAME,VALUE +objective,bin-packing diff --git a/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/reduced_bins.csv b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/reduced_bins.csv new file mode 100644 index 000000000..6173b1e5e --- /dev/null +++ b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/reduced_bins.csv @@ -0,0 +1,2 @@ +ID,X,Y,Z,COST,COPIES,MAXIMUM_WEIGHT,MAXIMUM_STACK_DENSITY,IS_SEMI_TRAILER_TRUCK,TRACTOR_WEIGHT,FRONT_AXLE_MIDDLE_AXLE_DISTANCE,FRONT_AXLE_TRACTOR_GRAVITY_CENTER_DISTANCE,FRONT_AXLE_HARNESS_DISTANCE,EMPTY_TRAILER_WEIGHT,HARNESS_REAR_AXLE_DISTANCE,TRAILER_GRAVITY_CENTER_REAR_AXLE_DISTANCE,TRAILER_START_HARNESS_DISTANCE,REAR_AXLE_MAXIMUM_WEIGHT,MIDDLE_AXLE_MAXIMUM_WEIGHT +0,1360,240,260,1,1,24000,1000,1,8000,380,100,320,6000,800,400,100,20000,9300 diff --git a/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/reduced_items.csv b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/reduced_items.csv new file mode 100644 index 000000000..16236b22c --- /dev/null +++ b/data/boxstacks/tests/semi_trailer_truck_lift_item_dimensions_skips_x/reduced_items.csv @@ -0,0 +1,3 @@ +ID,X,Y,Z,PROFIT,ROTATION_XYZ,WEIGHT,COPIES,COPIES_MIN,GROUP_ID,STACKABILITY_ID +0,1000,240,260,1,1,1000,1,1,0,0 +1,400,240,260,1,1,1000,1,1,0,1 diff --git a/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/bins.csv b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/bins.csv new file mode 100644 index 000000000..67f93f1be --- /dev/null +++ b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/bins.csv @@ -0,0 +1,2 @@ +ID,WIDTH,HEIGHT,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,100,1,0,inf diff --git a/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/items.csv b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/items.csv new file mode 100644 index 000000000..129b3f5d2 --- /dev/null +++ b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/items.csv @@ -0,0 +1,3 @@ +ID,WIDTH,HEIGHT,PROFIT,COPIES,COPIES_MIN,ORIENTED,GROUP_ID,WEIGHT +0,6,3,18,1,1,1,0,0 +1,5,9,45,1,1,0,0,0 diff --git a/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/parameters.csv b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/parameters.csv new file mode 100644 index 000000000..950a3149b --- /dev/null +++ b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/parameters.csv @@ -0,0 +1,4 @@ +NAME,VALUE +objective,BinPacking +unloading_constraint,IncreasingX +leftover_mode,Area diff --git a/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/reduced_bins.csv b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/reduced_bins.csv new file mode 100644 index 000000000..67f93f1be --- /dev/null +++ b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/reduced_bins.csv @@ -0,0 +1,2 @@ +ID,WIDTH,HEIGHT,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,100,1,0,inf diff --git a/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/reduced_items.csv b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/reduced_items.csv new file mode 100644 index 000000000..9c774ddb4 --- /dev/null +++ b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/reduced_items.csv @@ -0,0 +1,3 @@ +ID,WIDTH,HEIGHT,PROFIT,COPIES,COPIES_MIN,ORIENTED,GROUP_ID,WEIGHT +0,6,4,18,1,1,1,0,0 +1,5,9,45,1,1,0,0,0 diff --git a/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/solution.csv b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/solution.csv new file mode 100644 index 000000000..2adf5e9c0 --- /dev/null +++ b/data/rectangle/tests/bin_packing_increasing_x_lift_not_applied_on_x/solution.csv @@ -0,0 +1,4 @@ +TYPE,ID,COPIES,BIN,X,Y,LX,LY,GROUP_ID +BIN,0,1,0,0,0,10,10, +ITEM,0,1,0,0,0,6,3,0 +ITEM,1,1,0,0,4,9,5,0 diff --git a/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/bins.csv b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/bins.csv new file mode 100644 index 000000000..67f93f1be --- /dev/null +++ b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/bins.csv @@ -0,0 +1,2 @@ +ID,WIDTH,HEIGHT,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,100,1,0,inf diff --git a/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/items.csv b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/items.csv new file mode 100644 index 000000000..129b3f5d2 --- /dev/null +++ b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/items.csv @@ -0,0 +1,3 @@ +ID,WIDTH,HEIGHT,PROFIT,COPIES,COPIES_MIN,ORIENTED,GROUP_ID,WEIGHT +0,6,3,18,1,1,1,0,0 +1,5,9,45,1,1,0,0,0 diff --git a/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/parameters.csv b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/parameters.csv new file mode 100644 index 000000000..2255036b2 --- /dev/null +++ b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/parameters.csv @@ -0,0 +1,4 @@ +NAME,VALUE +objective,BinPacking +unloading_constraint,OnlyXMovements +leftover_mode,Area diff --git a/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/reduced_bins.csv b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/reduced_bins.csv new file mode 100644 index 000000000..67f93f1be --- /dev/null +++ b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/reduced_bins.csv @@ -0,0 +1,2 @@ +ID,WIDTH,HEIGHT,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT +0,10,10,100,1,0,inf diff --git a/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/reduced_items.csv b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/reduced_items.csv new file mode 100644 index 000000000..8eb5be454 --- /dev/null +++ b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/reduced_items.csv @@ -0,0 +1,3 @@ +ID,WIDTH,HEIGHT,PROFIT,COPIES,COPIES_MIN,ORIENTED,GROUP_ID,WEIGHT +0,9,3,18,1,1,1,0,0 +1,5,9,45,1,1,0,0,0 diff --git a/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/solution.csv b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/solution.csv new file mode 100644 index 000000000..2adf5e9c0 --- /dev/null +++ b/data/rectangle/tests/bin_packing_only_x_movements_lift_not_applied_on_y/solution.csv @@ -0,0 +1,4 @@ +TYPE,ID,COPIES,BIN,X,Y,LX,LY,GROUP_ID +BIN,0,1,0,0,0,10,10, +ITEM,0,1,0,0,0,6,3,0 +ITEM,1,1,0,0,4,9,5,0 diff --git a/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/bins.csv b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/bins.csv new file mode 100644 index 000000000..2c31a1137 --- /dev/null +++ b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/bins.csv @@ -0,0 +1,2 @@ +ID,WIDTH,HEIGHT,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT,IS_SEMI_TRAILER_TRUCK,TRACTOR_WEIGHT,FRONT_AXLE_MIDDLE_AXLE_DISTANCE,FRONT_AXLE_TRACTOR_GRAVITY_CENTER_DISTANCE,FRONT_AXLE_HARNESS_DISTANCE,EMPTY_TRAILER_WEIGHT,HARNESS_REAR_AXLE_DISTANCE,TRAILER_GRAVITY_CENTER_REAR_AXLE_DISTANCE,TRAILER_START_HARNESS_DISTANCE,REAR_AXLE_MAXIMUM_WEIGHT,MIDDLE_AXLE_MAXIMUM_WEIGHT +0,10,10,100,1,0,inf,1,8000,380,100,320,6000,800,400,100,20000,9300 diff --git a/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/items.csv b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/items.csv new file mode 100644 index 000000000..76aeca6b9 --- /dev/null +++ b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/items.csv @@ -0,0 +1,3 @@ +ID,WIDTH,HEIGHT,PROFIT,COPIES,COPIES_MIN,ORIENTED,GROUP_ID,WEIGHT +0,6,3,18,1,1,1,0,100 +1,5,9,45,1,1,0,0,100 diff --git a/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/parameters.csv b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/parameters.csv new file mode 100644 index 000000000..2168aad0d --- /dev/null +++ b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/parameters.csv @@ -0,0 +1,4 @@ +NAME,VALUE +objective,BinPacking +unloading_constraint,None +leftover_mode,Area diff --git a/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/reduced_bins.csv b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/reduced_bins.csv new file mode 100644 index 000000000..2c31a1137 --- /dev/null +++ b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/reduced_bins.csv @@ -0,0 +1,2 @@ +ID,WIDTH,HEIGHT,COST,COPIES,COPIES_MIN,MAXIMUM_WEIGHT,IS_SEMI_TRAILER_TRUCK,TRACTOR_WEIGHT,FRONT_AXLE_MIDDLE_AXLE_DISTANCE,FRONT_AXLE_TRACTOR_GRAVITY_CENTER_DISTANCE,FRONT_AXLE_HARNESS_DISTANCE,EMPTY_TRAILER_WEIGHT,HARNESS_REAR_AXLE_DISTANCE,TRAILER_GRAVITY_CENTER_REAR_AXLE_DISTANCE,TRAILER_START_HARNESS_DISTANCE,REAR_AXLE_MAXIMUM_WEIGHT,MIDDLE_AXLE_MAXIMUM_WEIGHT +0,10,10,100,1,0,inf,1,8000,380,100,320,6000,800,400,100,20000,9300 diff --git a/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/reduced_items.csv b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/reduced_items.csv new file mode 100644 index 000000000..43dd164b0 --- /dev/null +++ b/data/rectangle/tests/bin_packing_semi_trailer_truck_lift_not_applied_on_x/reduced_items.csv @@ -0,0 +1,3 @@ +ID,WIDTH,HEIGHT,PROFIT,COPIES,COPIES_MIN,ORIENTED,GROUP_ID,WEIGHT +0,6,4,18,1,1,1,0,100 +1,5,9,45,1,1,0,0,100 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/items.csv new file mode 100644 index 000000000..d47f9fe17 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,10,70,1,1 +4,10,40,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/parameters.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/parameters.csv new file mode 100644 index 000000000..15bc6d121 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/parameters.csv @@ -0,0 +1,5 @@ +NAME,VALUE +objective,bin-packing +number_of_stages,3 +cut_type,non-exact +first_stage_orientation,vertical diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/reduced_bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/reduced_bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/reduced_bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/reduced_items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/reduced_items.csv new file mode 100644 index 000000000..4b5d45106 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/reduced_items.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,10,70,1,2 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/solution.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/solution.csv new file mode 100644 index 000000000..83d5f903e --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions/solution.csv @@ -0,0 +1,7 @@ +PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT +0,1,0,0,0,10,10,0,0, +0,1,1,0,0,7,10,0,1,0 +0,1,2,7,0,3,10,-1,1,0 +1,1,3,0,0,10,10,0,0, +1,1,4,0,0,4,10,1,1,3 +1,1,5,4,0,6,10,-3,1,3 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/items.csv new file mode 100644 index 000000000..d92c246de --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,6,42,1,1 +4,5,20,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/parameters.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/parameters.csv new file mode 100644 index 000000000..15bc6d121 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/parameters.csv @@ -0,0 +1,5 @@ +NAME,VALUE +objective,bin-packing +number_of_stages,3 +cut_type,non-exact +first_stage_orientation,vertical diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/reduced_bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/reduced_bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/reduced_bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/reduced_items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/reduced_items.csv new file mode 100644 index 000000000..0a417f116 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/reduced_items.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,6,42,1,2 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/solution.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/solution.csv new file mode 100644 index 000000000..39c0d2911 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_both_axes/solution.csv @@ -0,0 +1,11 @@ +PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT +0,1,0,0,0,10,10,0,0, +0,1,1,0,0,7,10,-2,1,0 +0,1,2,0,0,7,6,0,2,1 +0,1,3,0,6,7,4,-1,2,1 +0,1,4,7,0,3,10,-1,1,0 +1,1,5,0,0,10,10,0,0, +1,1,6,0,0,4,10,-2,1,5 +1,1,7,0,0,4,5,1,2,6 +1,1,8,0,5,4,5,-1,2,6 +1,1,9,4,0,6,10,-3,1,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/items.csv new file mode 100644 index 000000000..4a17cb62a --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +6,10,60,1,1 +4,10,40,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/parameters.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/parameters.csv new file mode 100644 index 000000000..6a9515e59 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/parameters.csv @@ -0,0 +1,6 @@ +NAME,VALUE +objective,bin-packing +number_of_stages,3 +cut_type,non-exact +first_stage_orientation,vertical +cut_thickness,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/reduced_bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/reduced_bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/reduced_bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/reduced_items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/reduced_items.csv new file mode 100644 index 000000000..df74681e0 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/reduced_items.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +6,10,60,1,2 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/solution.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/solution.csv new file mode 100644 index 000000000..b57b401e5 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_cut_thickness/solution.csv @@ -0,0 +1,7 @@ +PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT +0,1,0,0,0,10,10,0,0, +0,1,1,0,0,6,10,0,1,0 +0,1,2,7,0,3,10,-1,1,0 +1,1,3,0,0,10,10,0,0, +1,1,4,0,0,4,10,1,1,3 +1,1,5,5,0,5,10,-3,1,3 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/items.csv new file mode 100644 index 000000000..d92c246de --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,6,42,1,1 +4,5,20,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/parameters.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/parameters.csv new file mode 100644 index 000000000..178afb915 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/parameters.csv @@ -0,0 +1,5 @@ +NAME,VALUE +objective,bin-packing +number_of_stages,2 +cut_type,exact +first_stage_orientation,vertical diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/reduced_bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/reduced_bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/reduced_bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/reduced_items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/reduced_items.csv new file mode 100644 index 000000000..60ae596b1 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/reduced_items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,6,42,1,1 +4,6,20,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/solution.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/solution.csv new file mode 100644 index 000000000..39c0d2911 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_exact/solution.csv @@ -0,0 +1,11 @@ +PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT +0,1,0,0,0,10,10,0,0, +0,1,1,0,0,7,10,-2,1,0 +0,1,2,0,0,7,6,0,2,1 +0,1,3,0,6,7,4,-1,2,1 +0,1,4,7,0,3,10,-1,1,0 +1,1,5,0,0,10,10,0,0, +1,1,6,0,0,4,10,-2,1,5 +1,1,7,0,0,4,5,1,2,6 +1,1,8,0,5,4,5,-1,2,6 +1,1,9,4,0,6,10,-3,1,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/items.csv new file mode 100644 index 000000000..d47f9fe17 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,10,70,1,1 +4,10,40,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/parameters.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/parameters.csv new file mode 100644 index 000000000..88e1be26a --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/parameters.csv @@ -0,0 +1,6 @@ +NAME,VALUE +objective,bin-packing +number_of_stages,3 +cut_type,non-exact +first_stage_orientation,vertical +maximum_distance_1_cuts,6 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/reduced_bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/reduced_bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/reduced_bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/reduced_items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/reduced_items.csv new file mode 100644 index 000000000..d47f9fe17 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_maximum_distance_1_cuts/reduced_items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,10,70,1,1 +4,10,40,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/items.csv new file mode 100644 index 000000000..d47f9fe17 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,10,70,1,1 +4,10,40,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/parameters.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/parameters.csv new file mode 100644 index 000000000..220a43131 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/parameters.csv @@ -0,0 +1,6 @@ +NAME,VALUE +objective,bin-packing +number_of_stages,3 +cut_type,non-exact +first_stage_orientation,vertical +minimum_waste_length,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/reduced_bins.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/reduced_bins.csv new file mode 100644 index 000000000..c03ef00fd --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/reduced_bins.csv @@ -0,0 +1,2 @@ +WIDTH,HEIGHT,COPIES +10,10,5 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/reduced_items.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/reduced_items.csv new file mode 100644 index 000000000..d47f9fe17 --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/reduced_items.csv @@ -0,0 +1,3 @@ +WIDTH,HEIGHT,PROFIT,ORIENTED,COPIES +7,10,70,1,1 +4,10,40,1,1 diff --git a/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/solution.csv b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/solution.csv new file mode 100644 index 000000000..83d5f903e --- /dev/null +++ b/data/rectangleguillotine/tests/bin_packing_lift_item_dimensions_skipped_with_minimum_waste/solution.csv @@ -0,0 +1,7 @@ +PLATE_ID,COPIES,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT +0,1,0,0,0,10,10,0,0, +0,1,1,0,0,7,10,0,1,0 +0,1,2,7,0,3,10,-1,1,0 +1,1,3,0,0,10,10,0,0, +1,1,4,0,0,4,10,1,1,3 +1,1,5,4,0,6,10,-3,1,3 diff --git a/include/packingsolver/box/instance_builder.hpp b/include/packingsolver/box/instance_builder.hpp index 380c9d5a1..751bf7190 100644 --- a/include/packingsolver/box/instance_builder.hpp +++ b/include/packingsolver/box/instance_builder.hpp @@ -180,6 +180,11 @@ class InstanceBuilder ItemTypeId item_type_id, const std::vector& rotations); + /** Set the dimensions of an item type. */ + void set_item_type_box( + ItemTypeId item_type_id, + const Box& box); + /** Set the weight of an item type. */ void set_item_type_weight( ItemTypeId item_type_id, diff --git a/include/packingsolver/box/reduction.hpp b/include/packingsolver/box/reduction.hpp index e0a181ba3..4c15add4c 100644 --- a/include/packingsolver/box/reduction.hpp +++ b/include/packingsolver/box/reduction.hpp @@ -48,16 +48,25 @@ struct ReductionParameters: optimizationtools::Parameters * 'Reduction::merge_identical_items'). */ bool merge_identical_items = true; + + /** + * Enable/disable lifting item dimensions via a subset-sum bound (gates + * 'Reduction::lift_item_dimensions'). Still subject to + * 'Reduction::lift_item_dimensions_applies' and + * 'Reduction::lift_item_dimensions_applies_axis' regardless of this + * flag. + */ + bool lift_item_dimensions = true; }; /** * A redundant-rotation removal (see 'remove_redundant_rotations'), a - * negative-profit item trim (see 'remove_negative_profit_items') plus an + * negative-profit item trim (see 'remove_negative_profit_items'), a + * subset-sum item dimension lift (see 'lift_item_dimensions') plus an * identical-item-type merge (see 'merge_identical_items') - the 'box' - * analogue of 'rectangle::Reduction', scoped down to just these three - * operations (rectangle's own companion absorption, subset-sum dimension - * lifting, dominated-item removal and dominated-bin-type removal are not - * implemented here). + * analogue of 'rectangle::Reduction', scoped down to just these four + * operations (rectangle's own companion absorption, dominated-item removal + * and dominated-bin-type removal are not implemented here). * * - Removing redundant rotations (see 'remove_redundant_rotations'): a * rotation of an item type is redundant if another allowed rotation gives @@ -88,6 +97,36 @@ struct ReductionParameters: optimizationtools::Parameters * indirect benefit this purely per-item check cannot see. See * 'remove_negative_profit_items_applies()'. * + * - Lifting item dimensions via subset sum (see 'lift_item_dimensions'): + * the 3D version of rectangle's own operation. Along an axis, the bin + * is first shrunk to the largest total length of the items not + * exceeding it ("shrinking the bins", see 'shrunk_bin_length'). Then, + * for an item type with a single copy, if no combination of the other + * items can fill the space left beside it in the shrunk bin, the item + * type is enlarged to close that gap. Sound because any solution can be + * compacted along the axis (every item pushed towards the origin while + * the other two coordinates stay fixed): the position of each item is + * then the total length of a chain of items before it, and the items of + * any chain through the lifted item, other than itself, fill at most the + * gap's complement - so the enlarged item still fits. Only applied to an + * item type whose allowed rotations all put the same one of its own + * dimensions along the axis (otherwise growing that dimension would also + * change its extent along other axes for some rotation), with no fixed + * copies. The other item types count in the bound with every length + * their allowed rotations give them along the axis. Requires a single + * bin type without fixed items (fixed items cannot be moved by the + * compaction). An objective measuring how far the items extend along an + * axis ('OpenDimensionX'/'Y'/'Z', or 'BinPackingWithLeftovers' with a + * 'LeftoverMode' involving the axis) never lifts along it. + * 'reduction_to_instance' writes the enlarged boxes into the reduced + * instance, and 'unreduce_solution' places the true items at the + * position and rotation the solve chose for their enlarged stand-ins. + * Runs in a loop with 'remove_redundant_rotations', since lifting can + * make more rotations redundant, and before 'merge_identical_items', + * which compares the current (possibly enlarged) boxes. See + * 'lift_item_dimensions_applies()' and + * 'lift_item_dimensions_applies_axis()'. + * * - Merging identical item types (see 'merge_identical_items'): a merged * item type's copies stay fully visible and independently placed in the * reduced instance (nothing is hidden from the downstream solve), so this @@ -140,6 +179,24 @@ class Reduction */ static bool remove_negative_profit_items_applies(const Instance& instance); + /** + * 'true' iff lifting item dimensions (see 'lift_item_dimensions') is + * meaningful for 'instance' - a single bin type, without fixed items. + * Does not check 'parameters.reduce' - the constructor only calls this + * after already checking it. + */ + static bool lift_item_dimensions_applies(const Instance& instance); + + /** + * 'true' iff lifting item dimensions is sound along axis 'axis' ('0' + * for 'x', '1' for 'y', '2' for 'z') for 'instance': 'false' when the + * objective measures how far the items extend along it - see the + * class-level doc comment. + */ + static bool lift_item_dimensions_applies_axis( + const Instance& instance, + int axis); + /* * Private types */ @@ -175,6 +232,12 @@ class Reduction */ std::vector rotations; + /** + * Current (possibly enlarged) box. Starts at the original item + * type's own box and only ever grows, via 'lift_item_dimensions'. + */ + Box box; + /** * Current (possibly reduced) number of copies. Starts at the * original instance's own copies and only ever decreases, via @@ -213,6 +276,35 @@ class Reduction bool remove_negative_profit_items( std::vector& reduction_item_types) const; + /** + * Upper bound on the largest total length along axis 'axis', not + * exceeding 'capacity', of the current copies of the not-yet-'removed' + * item types, each taken with any of its allowed rotations - except, + * if 'excluded_item_type_id' is not '-1', one copy of that item type. + */ + Length max_achievable_dimension_sum( + const std::vector& reduction_item_types, + Length capacity, + int axis, + ItemTypeId excluded_item_type_id) const; + + /** + * Largest total length along axis 'axis' of the remaining items not + * exceeding the length of the (single) bin type along it ("shrinking + * the bins", see the class-level doc comment). + */ + Length shrunk_bin_length( + const std::vector& reduction_item_types, + int axis) const; + + /** + * Enlarges the item types along every axis allowed by + * 'lift_item_dimensions_applies_axis' - see the class-level doc + * comment. Returns 'true' iff at least one item type was enlarged. + */ + bool lift_item_dimensions( + std::vector& reduction_item_types) const; + /** * 'true' iff item types 'item_type_id_1' and 'item_type_id_2' are * truly interchangeable and safe to merge (see the class-level doc diff --git a/include/packingsolver/boxstacks/instance_builder.hpp b/include/packingsolver/boxstacks/instance_builder.hpp index fdbed1a50..a68ad5bb3 100644 --- a/include/packingsolver/boxstacks/instance_builder.hpp +++ b/include/packingsolver/boxstacks/instance_builder.hpp @@ -190,6 +190,11 @@ class InstanceBuilder ItemTypeId item_type_id, const std::vector& rotations); + /** Set the dimensions of an item type. */ + void set_item_type_box( + ItemTypeId item_type_id, + const Box& box); + /** Set the group of an item type. */ void set_item_type_group( ItemTypeId item_type_id, diff --git a/include/packingsolver/boxstacks/reduction.hpp b/include/packingsolver/boxstacks/reduction.hpp index e640abb58..1ef441204 100644 --- a/include/packingsolver/boxstacks/reduction.hpp +++ b/include/packingsolver/boxstacks/reduction.hpp @@ -48,6 +48,15 @@ struct ReductionParameters: optimizationtools::Parameters * 'Reduction::merge_identical_items'). */ bool merge_identical_items = true; + + /** + * Enable/disable lifting item dimensions (gates + * 'Reduction::lift_item_dimensions'). Still subject to + * 'Reduction::lift_item_dimensions_applies' and + * 'Reduction::lift_item_dimensions_applies_axis' regardless of this + * flag. + */ + bool lift_item_dimensions = true; }; /** @@ -55,7 +64,7 @@ struct ReductionParameters: optimizationtools::Parameters * 'rectangle::Reduction''s operations (see its own class-level doc comment * for the full six-operation version), restricted here to the two whose * soundness argument does not depend on anything specific to 2D geometry, - * plus a redundant-rotation removal: + * plus a redundant-rotation removal and an item dimension lift: * * - Removing redundant rotations (see 'remove_redundant_rotations'): items * are packed upright, so an item type allows at most rotations 'XYZ' and @@ -84,6 +93,52 @@ struct ReductionParameters: optimizationtools::Parameters * mechanism at all (unlike 'rectangle'), so no indirect profit bonus can * ever make a negative-profit copy worth keeping. * + * - Lifting item dimensions (see 'lift_item_dimensions'): rectangle's own + * subset-sum lift, applied to the footprints of the stacks. Only applied + * to an item type with a single copy whose 'stackability_id' no other + * remaining item type shares: such an item is always alone in its + * stack, so its footprint is the footprint of its stack, and enlarging + * it changes no stacking possibility. Along 'x' or 'y', the bin is first + * shrunk to the largest total length of the items not exceeding it + * ("shrinking the bins", see 'shrunk_bin_length'); then, if no + * combination of the other items can fill the space left beside the + * item in the shrunk bin, the item is enlarged to close that gap. Sound + * because any solution can be compacted along the axis (every stack + * pushed towards the origin while its other coordinate stays fixed): the + * position of a stack is then the total length of a chain of stacks + * before it, so the items of any chain through the lifted item, other + * than itself, fill at most the gap's complement. Counting every other + * item on its own, rather than one footprint per stack, only makes the + * bound larger, which is safe. Requires the item type to have a single + * allowed rotation (growing its 'x' would otherwise also change its + * extent along 'y' when rotated). Along 'z', the item is enlarged to the + * height of the bin, since its stack contains nothing else. The + * compaction moves stacks, and the enlarged footprint changes the + * reduced instance's view of some constraints, so: + * - nothing is lifted with a single bin type that has defects or fixed + * items (see 'lift_item_dimensions_applies'); + * - nothing is lifted along 'x' with a semi-trailer truck: the axle + * weights depend on the 'x' positions and on the 'x' centers of the + * stacks; + * - with an unloading constraint, nothing is lifted along the axis whose + * compaction could break it: 'x' for 'OnlyYMovements' and + * 'IncreasingX', 'y' for 'OnlyXMovements' and 'IncreasingY' + * (compacting along 'x' keeps the 'y' coordinates and the order along + * 'x' of the stacks whose 'y' ranges intersect, so it keeps the + * constraints that only depend on those); + * - the footprint is only lifted if the item alone satisfies the maximum + * stack density of the bin type with its true footprint, since the + * reduced instance checks it against the enlarged one; + * - an objective measuring how far the items extend along an axis + * ('OpenDimensionX'/'OpenDimensionY', or 'BinPackingWithLeftovers' + * with a 'LeftoverMode' involving the axis) never lifts along it. + * 'unreduce_solution' places the true items in stacks of their true + * footprint, at the positions the solve chose for their enlarged + * stand-ins. Runs before 'merge_identical_items'; a lifted item type is + * never merged, since its 'stackability_id' is unique. See + * 'lift_item_dimensions_applies()' and + * 'lift_item_dimensions_applies_axis()'. + * * - Merging identical item types (see 'merge_identical_items'): a merged * item type's copies stay fully visible and independently placed in the * reduced instance (nothing is hidden from the downstream solve), so this @@ -135,6 +190,24 @@ class Reduction */ static bool remove_negative_profit_items_applies(const Instance& instance); + /** + * 'true' iff lifting item dimensions (see 'lift_item_dimensions') is + * meaningful for 'instance' - a single bin type, without defects or + * fixed items. Does not check 'parameters.reduce' - the constructor + * only calls this after already checking it. + */ + static bool lift_item_dimensions_applies(const Instance& instance); + + /** + * 'true' iff lifting item dimensions is sound along axis 'axis' ('0' + * for 'x', '1' for 'y', '2' for 'z') for 'instance' - see the + * class-level doc comment for the objective, semi-trailer truck and + * unloading constraint exclusions. + */ + static bool lift_item_dimensions_applies_axis( + const Instance& instance, + int axis); + /* * Private types */ @@ -146,11 +219,12 @@ class Reduction * reduction is running (only marked 'removed'): this keeps every id * stable throughout, and this vector's own indices double as * original-instance item type ids. Only ever holds what the reduction - * process can actually change ('copies', via a negative-profit trim) - * plus the bookkeeping needed to fold a merged-away item type into its - * survivor ('merged_into'). Every other item type field (profit, - * rotations, weight, ...) never changes during the process, so it is - * read directly from 'original_instance_' wherever needed. + * process can actually change ('copies', via a negative-profit trim, + * 'rotations' and 'box') plus the bookkeeping needed to fold a + * merged-away item type into its survivor ('merged_into'). Every other + * item type field (profit, weight, ...) never changes during the + * process, so it is read directly from 'original_instance_' wherever + * needed. */ struct ReductionItemType { @@ -179,6 +253,12 @@ class Reduction * 'remove_negative_profit_items'. */ ItemPos copies = 0; + + /** + * Current (possibly enlarged) box. Starts at the original item + * type's own box and only ever grows, via 'lift_item_dimensions'. + */ + Box box; }; /** @@ -213,6 +293,37 @@ class Reduction bool remove_negative_profit_items( std::vector& reduction_item_types) const; + /** + * Upper bound on the largest total length along axis 'axis' ('0' for + * 'x', '1' for 'y'), not exceeding 'capacity', of the current copies + * of the not-yet-'removed' item types, each taken with any of its + * allowed rotations - except, if 'excluded_item_type_id' is not '-1', + * one copy of that item type. + */ + Length max_achievable_dimension_sum( + const std::vector& reduction_item_types, + Length capacity, + int axis, + ItemTypeId excluded_item_type_id) const; + + /** + * Largest total length along axis 'axis' ('0' for 'x', '1' for 'y') of + * the remaining items not exceeding the length of the (single) bin + * type along it ("shrinking the bins", see the class-level doc + * comment). + */ + Length shrunk_bin_length( + const std::vector& reduction_item_types, + int axis) const; + + /** + * Enlarges the item types along every axis allowed by + * 'lift_item_dimensions_applies_axis' - see the class-level doc + * comment. Returns 'true' iff at least one item type was enlarged. + */ + bool lift_item_dimensions( + std::vector& reduction_item_types) const; + /** * 'true' iff item types 'item_type_id_1' and 'item_type_id_2' are truly * interchangeable and safe to merge - see the class-level doc comment's diff --git a/include/packingsolver/rectangle/instance.hpp b/include/packingsolver/rectangle/instance.hpp index 7297703ac..a7d153def 100644 --- a/include/packingsolver/rectangle/instance.hpp +++ b/include/packingsolver/rectangle/instance.hpp @@ -499,11 +499,12 @@ class Instance /** * Return 'true' iff the instance has a single bin type with a finite - * maximum weight and at least one item type with a nonzero weight - - * i.e. iff its weight capacity is an actual, non-trivial per-bin - * aggregate constraint (see 'Reduction::companion_absorption_applies' - * for why this matters there: a per-bin aggregate is invisible to - * per-group geometric-only reasoning). + * maximum weight (or a semi-trailer truck with a finite axle maximum + * weight) and at least one item type with a nonzero weight - i.e. iff + * its weight capacity is an actual, non-trivial per-bin aggregate + * constraint (see 'Reduction::companion_absorption_applies' for why + * this matters there: a per-bin aggregate is invisible to per-group + * geometric-only reasoning). */ bool weight_matters() const; diff --git a/include/packingsolver/rectangle/reduction.hpp b/include/packingsolver/rectangle/reduction.hpp index 066b4c9b7..50ec61ccf 100644 --- a/include/packingsolver/rectangle/reduction.hpp +++ b/include/packingsolver/rectangle/reduction.hpp @@ -243,11 +243,12 @@ struct ReductionParameters: optimizationtools::Parameters * so the item's own dimension can be grown to close it - with zero real * companions attached (unlike wide/tall, this never removes or hides * any other item type from the reduced instance). Because nothing is - * ever hidden this way, none of companion absorption's weight/resource/ - * unloading-constraint exclusions apply here, and - like + * ever hidden this way, none of companion absorption's whole-bin + * weight/resource/unloading-constraint exclusions apply here, and - like * 'merge_identical_items' - nothing about it depends on every item * necessarily being packed, so it runs for *any* objective, on either - * axis independently, with one exception: an objective that directly + * axis independently, with the per-axis exceptions below. First, an + * objective that directly * measures how far items extend along a given axis * ('Objective::OpenDimensionX'/'OpenDimensionY', or * 'Objective::BinPackingWithLeftovers' with a 'LeftoverMode' that @@ -267,12 +268,24 @@ struct ReductionParameters: optimizationtools::Parameters * decisions - against the *enlarged* footprint, potentially settling * for a worse arrangement than the true, smaller footprint would have * allowed, since it believes reach along that axis is already - * unavoidable when it is not. See 'lift_item_dimensions_applies_axis()'. - * It does still need a single bin type (the bin's own true dimension - * must be unambiguous) and no defects (a defect sitting inside the - * claimed "provably empty" margin would be invisible to this purely 1D - * argument, the same blind spot as companion absorption's own geometric - * checks) - see 'lift_item_dimensions_applies()'. + * unavoidable when it is not. The soundness argument compacts any + * solution along the axis (every item pushed towards the origin while + * its other coordinate stays fixed: its position is then the total + * width of a chain of items before it), which moves items along the + * axis, so nothing is lifted along 'x' with a semi-trailer truck (the + * axle weights depend on the 'x' positions and centers of the items), + * and, with an unloading constraint, nothing is lifted along an axis + * whose compaction could break it ('x' for 'OnlyYMovements' and + * 'IncreasingX', 'y' for 'OnlyXMovements' and 'IncreasingY': compacting + * along 'x' keeps the 'y' coordinates and the order along 'x' of the + * items whose 'y' ranges intersect). See + * 'lift_item_dimensions_applies_axis()'. It does still need a single bin + * type (the bin's own true dimension must be unambiguous) and no defects + * or fixed items (a defect or a fixed item sitting inside the claimed + * "provably empty" margin would be invisible to this purely 1D argument, + * the same blind spot as companion absorption's own geometric checks, + * and cannot be moved by the compaction) - see + * 'lift_item_dimensions_applies()'. * * - Trimming negative-profit item types (see * 'remove_negative_profit_items'): only for 'Knapsack' - for every other @@ -524,13 +537,14 @@ class Reduction * regardless of axis - the class-level doc comment's "Lifting item * dimensions via subset sum" paragraph: only for instances with a * single bin type (the bin's own true dimension must be unambiguous - - * like companion absorption's own precondition) and no defects (a - * defect sitting inside the claimed "provably empty" margin would be - * invisible to this purely 1D argument). Unlike - * 'companion_absorption_applies', not restricted by weight, resources, - * or unloading constraint - see the class-level doc comment for why - * none of those apply here. Objective restrictions are per-axis, not - * covered here - see 'lift_item_dimensions_applies_axis()'. Does not + * like companion absorption's own precondition) and no defects or + * fixed items (a defect or a fixed item sitting inside the claimed + * "provably empty" margin would be invisible to this purely 1D + * argument). Unlike 'companion_absorption_applies', not restricted by + * weight or resources - see the class-level doc comment for why + * neither applies here. Objective, semi-trailer truck and unloading + * constraint restrictions are per-axis, not covered here - see + * 'lift_item_dimensions_applies_axis()'. Does not * check 'parameters.reduce' - the constructor only calls this after * already checking it. */ @@ -546,7 +560,11 @@ class Reduction * 'OpenDimensionY' (for 'y'), or 'Objective::BinPackingWithLeftovers' * with a 'LeftoverMode' that depends on this axis ('LeftoverMode::X' * for 'x', 'LeftoverMode::Y' for 'y', 'LeftoverMode::Area' for - * either). Independent of 'lift_item_dimensions_applies()' - both + * either); and 'false' when the compaction along this axis could break + * a constraint: along 'x' with a semi-trailer truck, or with an + * unloading constraint 'OnlyYMovements'/'IncreasingX' (resp. + * 'OnlyXMovements'/'IncreasingY' along 'y') - see the class-level doc + * comment. Independent of 'lift_item_dimensions_applies()' - both * must hold for lifting to actually run on a given axis (see * 'lift_item_dimensions'). */ diff --git a/include/packingsolver/rectangleguillotine/reduction.hpp b/include/packingsolver/rectangleguillotine/reduction.hpp index 443828fc8..b1fd46efd 100644 --- a/include/packingsolver/rectangleguillotine/reduction.hpp +++ b/include/packingsolver/rectangleguillotine/reduction.hpp @@ -49,37 +49,94 @@ struct ReductionParameters: optimizationtools::Parameters * 'Reduction::items_mergeable''s own doc comment. */ bool merge_identical_items = true; + + /** + * Enable/disable lifting item dimensions via a subset-sum bound (gates + * 'Reduction::lift_item_dimensions'). Still subject to + * 'Reduction::lift_item_dimensions_applies' and + * 'Reduction::lift_item_dimensions_applies_axis' regardless of this + * flag. + */ + bool lift_item_dimensions = true; }; /** - * A two-operation subset of 'rectangle::Reduction' (see there for the full, - * six-operation version this mirrors): a negative-profit item trim (see - * 'remove_negative_profit_items') and an identical-item-type merge (see - * 'merge_identical_items'). The other four rectangle operations (companion - * absorption, subset-sum-based item dimension lifting, dominated-item - * removal, dominated-bin-type removal) all reason about geometry in ways - * that assume a solution is a free 2D placement - not obviously true of a - * guillotine cut tree, whose stage structure and cut-count/cut-distance - * constraints these two operations never touch - so they are deliberately - * out of scope here. + * A three-operation subset of 'rectangle::Reduction' (see there for the + * full, six-operation version this mirrors): a negative-profit item trim + * (see 'remove_negative_profit_items'), a subset-sum item dimension lift + * adapted to cut trees (see 'lift_item_dimensions'), and an + * identical-item-type merge (see 'merge_identical_items'). The other + * rectangle operations (companion absorption, dominated-item removal, + * dominated-bin-type removal) reason about geometry in ways that assume a + * solution is a free 2D placement - not obviously true of a guillotine cut + * tree - so they are deliberately out of scope here. * - * Both operations run for any objective except where noted, with no - * shared precondition beyond 'parameters.reduce' - see + * The trim and the merge run for any objective except where noted, with + * no shared precondition beyond 'parameters.reduce' - see * 'remove_negative_profit_items_applies()' and 'items_mergeable()' for - * their own, independent preconditions. Both also share the same - * stack-alone restriction (an item type sharing a stack with others is - * left untouched by either operation) - see 'items_mergeable()''s own doc - * comment for why, and 'remove_negative_profit_items()''s own for why - * trimming needs it too, not just merging. + * their own, independent preconditions. All three operations share the + * same stack-alone restriction (an item type sharing a stack with others + * is left untouched) - see 'items_mergeable()''s own doc comment for why, + * and 'remove_negative_profit_items()''s own for why trimming needs it + * too, not just merging. + * + * Lifting item dimensions (see 'lift_item_dimensions'): along an axis, if + * no combination of the other items can fill the space left beside an + * item type with a single copy, the item type is enlarged to close that + * gap - rectangle's own operation, against the bin shrunk to the largest + * total length of the items not exceeding it ("shrinking the bins"). For + * a cut tree, the argument is a compaction of the tree along the axis: + * every node delimited along the axis is pushed back against its previous + * sibling, and every node is shrunk to its content. The tree structure + * (depths, number of cuts) is unchanged, and the extent of the root along + * the axis is then the largest total length, plus one cut thickness + * between consecutive items, of a chain of items. Hence every length below + * is increased by the cut thickness (bin lengths included). After + * compaction, the items of any chain through the lifted item, other than + * itself, fill at most the gap's complement, so the enlarged item still + * fits. Enlarging the item may require trimming its siblings in the + * stacking direction, which depends on the cut type: + * - 'NonExact': the extra trimming cut absorbs it, any axis can be lifted; + * - 'Exact': only the axis of the last-stage cuts can be lifted (an item of + * the last stage fills its node along the other axis, as its siblings + * do), and only with a fixed first stage orientation; + * - 'Roadef2018': only the axis of the extra cuts can be lifted (two items + * sharing an extra cut fill their node along the other axis), and only + * with a fixed first stage orientation; + * - 'Homogenous': nothing is lifted. + * The compaction can make a distance between two cuts or a waste smaller, + * and 'unreduce_solution' adds a cut separating the true item from the + * provably empty margin, so nothing is lifted with a minimum distance + * between 1-cuts or 2-cuts, a minimum waste length, or a maximum number of + * 1-cuts or 2-cuts. A maximum distance between 1-cuts (resp. 2-cuts) is + * handled as a second capacity along the axes the 1-cuts (resp. 2-cuts) + * may be along: the item is lifted to the smaller of the two bounds, and + * only if it fits the maximum distance along both axes (since + * 'unreduce_solution' may turn its node into a plate subject to it). Also + * requires a single bin type without defects or fixed items, no trims when + * the cut thickness is not zero, an oriented item type alone in its stack + * without fixed copies, and an objective that only depends on which items + * and bins are used ('Knapsack', 'BinPacking', 'VariableSizedBinPacking', + * 'Feasibility'), or 'OpenDimensionX'/'OpenDimensionY' for the other axis. + * 'unreduce_solution' rewrites the cut tree around each enlarged item: if + * its node is delimited along the lifted axis, the node is shrunk, and the + * freed length goes to the first waste after it (the siblings in between + * are moved back), or to a new waste at the end of its parent; + * otherwise, the true item goes into a child node, followed by a waste; if + * the node is already at the deepest level allowed, its parent, which then + * only contains the item and a waste, is shrunk instead. See + * 'lift_item_dimensions_applies()' and + * 'lift_item_dimensions_applies_axis()'. * * Only ever needs one pass (unlike 'rectangle::Reduction''s fixpoint - * loop): neither operation here ever changes an item type's own - * dimensions or exposes a new merge/trim opportunity for the other - - * trimming a negative-profit item type down to its 'copies_min' can only - * ever narrow a later merge candidate's mandatory-vs-optional status - * (never flip a type that was already fully mandatory or fully optional - * into the other category - see 'effective_copies_min'), and merging - * never changes any type's own profit or copies_min. + * loop): trimming a negative-profit item type down to its 'copies_min' + * can only ever narrow a later merge candidate's mandatory-vs-optional + * status (never flip a type that was already fully mandatory or fully + * optional into the other category - see 'effective_copies_min'), merging + * never changes any type's own profit or copies_min, and lifting only + * changes the dimensions of oriented item types with a single copy, which + * the redundant rotation removal does not look at. Lifting runs before + * merging, which compares the current (possibly enlarged) dimensions. * * Before both operations, redundant rotations are removed (see * 'remove_redundant_rotations'). The rotation of a non-oriented item type is @@ -131,12 +188,28 @@ class Reduction */ static bool remove_negative_profit_items_applies(const Instance& instance); + /** + * 'true' iff lifting item dimensions (see 'lift_item_dimensions') is + * meaningful for 'instance' - see the class-level doc comment. Does not + * check 'parameters.reduce' - the constructor only calls this after + * already checking it. + */ + static bool lift_item_dimensions_applies(const Instance& instance); + + /** + * 'true' iff lifting item dimensions is sound along axis 'axis' ('0' + * for 'x', '1' for 'y') for 'instance' - see the class-level doc + * comment for the objective and cut type restrictions. + */ + static bool lift_item_dimensions_applies_axis( + const Instance& instance, + int axis); + /** * Working representation of an item type during the reduction * process. Unlike 'rectangle::Reduction::ReductionItemType', carries - * no 'rect' or companion bookkeeping - neither operation here ever - * changes an item type's own dimensions or hides another item type - * behind it. + * no companion bookkeeping - no operation here hides another item + * type behind it. */ struct ReductionItemType { @@ -150,11 +223,17 @@ class Reduction ItemTypeId merged_into = -1; /** - * Dimensions. Start at the original instance's own dimensions, and - * are only ever swapped, via 'remove_redundant_rotations'. + * Dimensions. Start at the original instance's own dimensions, can + * be swapped, via 'remove_redundant_rotations', and then only ever + * grow, via 'lift_item_dimensions'. */ Rectangle rect; + /** + * Whether 'remove_redundant_rotations' swapped the dimensions. + */ + bool swapped = false; + /** * Whether the item type is oriented. Starts at the original * instance's own value, and can only ever become 'true', via @@ -213,6 +292,28 @@ class Reduction void remove_negative_profit_items( std::vector& reduction_item_types) const; + /** + * Upper bound on the largest total of the lengths along axis 'axis' + * ('0' for 'x', '1' for 'y'), each increased by 'offset', not exceeding + * 'capacity', of the current copies of the not-yet-'removed' item + * types, each taken in any orientation it allows - except, if + * 'excluded_item_type_id' is not '-1', one copy of that item type. + */ + Length max_achievable_dimension_sum( + const std::vector& reduction_item_types, + Length capacity, + int axis, + Length offset, + ItemTypeId excluded_item_type_id) const; + + /** + * Enlarges the item types along every axis allowed by + * 'lift_item_dimensions_applies_axis' - see the class-level doc + * comment. Returns 'true' iff at least one item type was enlarged. + */ + bool lift_item_dimensions( + std::vector& reduction_item_types) const; + /** * 'true' iff item types 'item_type_id_1' and 'item_type_id_2' are * interchangeable and can be merged into one - same dimensions, same @@ -279,6 +380,18 @@ class Reduction /** Reduced instance. */ Instance instance_; + /** + * For each item type of the original instance, its dimensions in the + * reduced instance (see 'ReductionItemType::rect'). + */ + std::vector reduced_rects_; + + /** + * For each item type of the original instance, whether its dimensions + * were swapped (see 'ReductionItemType::swapped'). + */ + std::vector swapped_item_types_; + /** * One contiguous run of a reduced item type's copies that all came * from the same original item type - the survivor's own copies form diff --git a/python/src/box.cpp b/python/src/box.cpp index 46b63aa15..d57126a30 100644 --- a/python/src/box.cpp +++ b/python/src/box.cpp @@ -334,7 +334,8 @@ void bind_box(nb::module_& m) .def_rw("reduce", &ReductionParameters::reduce) .def_rw("remove_redundant_rotations", &ReductionParameters::remove_redundant_rotations) .def_rw("remove_negative_profit_items", &ReductionParameters::remove_negative_profit_items) - .def_rw("merge_identical_items", &ReductionParameters::merge_identical_items); + .def_rw("merge_identical_items", &ReductionParameters::merge_identical_items) + .def_rw("lift_item_dimensions", &ReductionParameters::lift_item_dimensions); nb::class_ parameters = bind_parameters_base(m); parameters diff --git a/python/src/boxstacks.cpp b/python/src/boxstacks.cpp index ef37fac3c..775624428 100644 --- a/python/src/boxstacks.cpp +++ b/python/src/boxstacks.cpp @@ -461,7 +461,8 @@ void bind_boxstacks(nb::module_& m) .def_rw("reduce", &ReductionParameters::reduce) .def_rw("remove_redundant_rotations", &ReductionParameters::remove_redundant_rotations) .def_rw("remove_negative_profit_items", &ReductionParameters::remove_negative_profit_items) - .def_rw("merge_identical_items", &ReductionParameters::merge_identical_items); + .def_rw("merge_identical_items", &ReductionParameters::merge_identical_items) + .def_rw("lift_item_dimensions", &ReductionParameters::lift_item_dimensions); nb::class_ parameters = bind_parameters_base(m); parameters diff --git a/python/src/rectangleguillotine.cpp b/python/src/rectangleguillotine.cpp index c258a127d..77bbbd091 100644 --- a/python/src/rectangleguillotine.cpp +++ b/python/src/rectangleguillotine.cpp @@ -468,7 +468,8 @@ void bind_rectangleguillotine(nb::module_& m) .def_rw("reduce", &ReductionParameters::reduce) .def_rw("remove_redundant_rotations", &ReductionParameters::remove_redundant_rotations) .def_rw("remove_negative_profit_items", &ReductionParameters::remove_negative_profit_items) - .def_rw("merge_identical_items", &ReductionParameters::merge_identical_items); + .def_rw("merge_identical_items", &ReductionParameters::merge_identical_items) + .def_rw("lift_item_dimensions", &ReductionParameters::lift_item_dimensions); nb::class_ parameters = bind_parameters_base(m); parameters diff --git a/python/tests/test_box.py b/python/tests/test_box.py index a4e57a752..913c55782 100644 --- a/python/tests/test_box.py +++ b/python/tests/test_box.py @@ -217,6 +217,8 @@ def test_kept_methods(): NOT_BOUND = { "add_bin_type_resource": "creates a resource with its own id; kept as a builder method", + "set_item_type_box": + "the dimensions are the positional arguments of add_item_type", } @@ -428,6 +430,9 @@ def test_parameters(): assert not parameters.reduction_parameters.reduce parameters.reduction_parameters.merge_identical_items = False assert not parameters.reduction_parameters.merge_identical_items + assert parameters.reduction_parameters.lift_item_dimensions + parameters.reduction_parameters.lift_item_dimensions = False + assert not parameters.reduction_parameters.lift_item_dimensions parameters.verbosity_level = 0 output = psb.optimize(bin_packing_instance(9), parameters) assert output.solution.number_of_bins() == 2 diff --git a/python/tests/test_boxstacks.py b/python/tests/test_boxstacks.py index a805bf6f9..629158bca 100644 --- a/python/tests/test_boxstacks.py +++ b/python/tests/test_boxstacks.py @@ -284,6 +284,8 @@ def test_removed_setters(): # C++ per-type methods intentionally not available as keywords. NOT_BOUND = { + "set_item_type_box": + "the dimensions are the positional arguments of add_item_type", } @@ -683,6 +685,9 @@ def test_parameters(): parameters.reduction_parameters.reduce = False assert not parameters.reduction_parameters.reduce assert parameters.reduction_parameters.merge_identical_items + assert parameters.reduction_parameters.lift_item_dimensions + parameters.reduction_parameters.lift_item_dimensions = False + assert not parameters.reduction_parameters.lift_item_dimensions parameters.verbosity_level = 0 output = psbs.optimize(bin_packing_instance(5), parameters) assert output.solution.number_of_bins() == 2 diff --git a/python/tests/test_rectangleguillotine.py b/python/tests/test_rectangleguillotine.py index f2330a08a..b278edf0a 100644 --- a/python/tests/test_rectangleguillotine.py +++ b/python/tests/test_rectangleguillotine.py @@ -566,6 +566,9 @@ def test_parameters(): assert not parameters.reduction_parameters.reduce parameters.reduction_parameters.merge_identical_items = False assert not parameters.reduction_parameters.merge_identical_items + assert parameters.reduction_parameters.lift_item_dimensions + parameters.reduction_parameters.lift_item_dimensions = False + assert not parameters.reduction_parameters.lift_item_dimensions parameters.verbosity_level = 0 output = psg.optimize(bin_packing_instance(5), parameters) assert output.solution.number_of_bins() == 2 diff --git a/src/algorithms/subset_sum_bound.hpp b/src/algorithms/subset_sum_bound.hpp new file mode 100644 index 000000000..69df62ea3 --- /dev/null +++ b/src/algorithms/subset_sum_bound.hpp @@ -0,0 +1,90 @@ +#pragma once + +#include "packingsolver/algorithms/common.hpp" + +#include "multiplechoicesubsetsumsolver/instance_builder.hpp" +#include "multiplechoicesubsetsumsolver/algorithms/dynamic_programming_bellman.hpp" + +#include +#include + +namespace packingsolver +{ + +/** + * The lengths a group of identical item copies may take along an axis: one + * value per orientation the copies may be packed with, and the number of + * copies. + */ +struct SubsetSumBoundItem +{ + /** Possible lengths of each copy along the axis. */ + std::vector lengths; + + /** Number of copies. */ + ItemPos copies = 0; +}; + +/** + * Upper bound on the largest total length, not exceeding 'capacity', of a + * subset of the copies of 'items', each copy taken with one of its own + * lengths. + * + * Computed with 'multiplechoicesubsetsumsolver', one group per copy. For + * large capacities, the memory of the dynamic programming would be too + * large: 'capacity' itself is returned instead, a weaker but still valid + * bound. + */ +inline Length subset_sum_bound( + const std::vector& items, + Length capacity) +{ + if (capacity <= 0) + return 0; + + multiplechoicesubsetsumsolver::InstanceBuilder mcss_instance_builder; + mcss_instance_builder.set_capacity(capacity); + multiplechoicesubsetsumsolver::GroupId mcss_group_id = 0; + Length length_sum = 0; + for (const SubsetSumBoundItem& item: items) { + if (item.copies <= 0) + continue; + std::vector lengths; + for (Length length: item.lengths) { + if (length <= 0 || length > capacity) + continue; + if (std::find(lengths.begin(), lengths.end(), length) == lengths.end()) + lengths.push_back(length); + } + if (lengths.empty()) + continue; + Length length_min = *std::min_element(lengths.begin(), lengths.end()); + Length length_max = *std::max_element(lengths.begin(), lengths.end()); + // No subset within 'capacity' can use more copies than this. + ItemPos copies = (std::min)(item.copies, (ItemPos)(capacity / length_min)); + for (ItemPos copy = 0; copy < copies; ++copy) { + for (Length length: lengths) + mcss_instance_builder.add_item(mcss_group_id, length); + ++mcss_group_id; + } + length_sum += copies * length_max; + if (length_sum >= capacity) + length_sum = capacity; + } + + // Every copy fits with its largest length. + if (length_sum < capacity) + return length_sum; + if (capacity > 100000000) + return capacity; + + multiplechoicesubsetsumsolver::Instance mcss_instance = mcss_instance_builder.build(); + multiplechoicesubsetsumsolver::Parameters mcss_parameters; + mcss_parameters.verbosity_level = 0; + auto mcss_output = multiplechoicesubsetsumsolver::dynamic_programming_bellman_word_ram( + mcss_instance, + mcss_parameters); + return mcss_output.bound; +} + +} diff --git a/src/box/instance_builder.cpp b/src/box/instance_builder.cpp index 6840b63bd..04278edf5 100644 --- a/src/box/instance_builder.cpp +++ b/src/box/instance_builder.cpp @@ -346,6 +346,27 @@ void InstanceBuilder::set_item_type_rotations( instance_.item_types_[item_type_id].rotations = rotations; } +void InstanceBuilder::set_item_type_box( + ItemTypeId item_type_id, + const Box& box) +{ + if (item_type_id < 0 || item_type_id >= (ItemTypeId)instance_.item_types_.size()) { + throw std::invalid_argument( + FUNC_SIGNATURE + ": " + "invalid 'item_type_id'; " + "item_type_id: " + std::to_string(item_type_id) + "."); + } + if (box.x <= 0 || box.y <= 0 || box.z <= 0) { + throw std::invalid_argument( + FUNC_SIGNATURE + ": " + "item dimensions must be > 0; " + "box.x: " + std::to_string(box.x) + "; " + "box.y: " + std::to_string(box.y) + "; " + "box.z: " + std::to_string(box.z) + "."); + } + instance_.item_types_[item_type_id].box = box; +} + void InstanceBuilder::set_item_type_weight( ItemTypeId item_type_id, Weight weight) diff --git a/src/box/reduction.cpp b/src/box/reduction.cpp index 1f67f6125..9e86e2ae9 100644 --- a/src/box/reduction.cpp +++ b/src/box/reduction.cpp @@ -2,6 +2,7 @@ #include "packingsolver/box/instance_builder.hpp" #include "box/solution_builder.hpp" +#include "algorithms/subset_sum_bound.hpp" #include #include @@ -45,6 +46,34 @@ std::array rotation_set(const std::vector& return set; } +/** Length of 'box' along axis 'axis' ('0' for 'x', '1' for 'y', '2' for 'z'). */ +Length box_length( + const Box& box, + int axis) +{ + return (axis == 0)? box.x: (axis == 1)? box.y: box.z; +} + +/** Mutable version of 'box_length'. */ +Length& box_length( + Box& box, + int axis) +{ + return (axis == 0)? box.x: (axis == 1)? box.y: box.z; +} + +/** + * The dimension of an item (in its own, unrotated frame) that rotation + * 'rotation' puts along axis 'axis'. + */ +int rotated_dimension( + Rotation rotation, + int axis) +{ + Box box = {0, 1, 2}; + return (int)box_length(box.rotate(rotation), axis); +} + } Reduction::Reduction( @@ -62,6 +91,7 @@ Reduction::Reduction( ++item_type_id) { reduction_item_types[item_type_id].copies = instance.item_type(item_type_id).copies; reduction_item_types[item_type_id].rotations = instance.item_type(item_type_id).rotations; + reduction_item_types[item_type_id].box = instance.item_type(item_type_id).box; } if (parameters.remove_redundant_rotations) @@ -72,6 +102,24 @@ Reduction::Reduction( remove_negative_profit_items(reduction_item_types); } + // Lifting can make more rotations redundant (two rotations giving the + // same enlarged box, or a rotation of the enlarged box fitting in no + // bin type), and removing rotations can enable lifting (it requires + // every allowed rotation to put the same dimension along the axis). + if (parameters.lift_item_dimensions + && lift_item_dimensions_applies(instance)) { + for (;;) { + if (parameters.timer.needs_to_end()) + break; + if (!lift_item_dimensions(reduction_item_types)) + break; + if (!parameters.remove_redundant_rotations + || !remove_redundant_rotations(reduction_item_types)) { + break; + } + } + } + if (parameters.merge_identical_items) merge_identical_items(reduction_item_types); @@ -143,10 +191,10 @@ bool Reduction::remove_redundant_rotations( // Keep the first rotation of each rotated box. std::vector distinct_rotations; for (Rotation rotation: item.rotations) { - Box box = item_type.box.rotate(rotation); + Box box = item.box.rotate(rotation); bool duplicate = false; for (Rotation distinct_rotation: distinct_rotations) { - if (item_type.box.rotate(distinct_rotation) == box) { + if (item.box.rotate(distinct_rotation) == box) { duplicate = true; break; } @@ -159,7 +207,7 @@ bool Reduction::remove_redundant_rotations( // none fits. std::vector fitting_rotations; for (Rotation rotation: distinct_rotations) { - Box box = item_type.box.rotate(rotation); + Box box = item.box.rotate(rotation); for (BinTypeId bin_type_id = 0; bin_type_id < original_instance_->number_of_bin_types(); ++bin_type_id) { @@ -209,6 +257,139 @@ bool Reduction::remove_negative_profit_items( return found; } +bool Reduction::lift_item_dimensions_applies(const Instance& instance) +{ + // A single bin type, so that the bin dimensions are unambiguous, and + // no fixed items, which the compaction argument of the class-level doc + // comment cannot move. + return instance.number_of_bin_types() == 1 + && instance.bin_type(0).fixed_items.empty(); +} + +bool Reduction::lift_item_dimensions_applies_axis( + const Instance& instance, + int axis) +{ + // See the class-level doc comment: the downstream solve would reason + // against the enlarged items instead of the true ones. + Objective open_dimension_objective + = (axis == 0)? Objective::OpenDimensionX: + (axis == 1)? Objective::OpenDimensionY: + Objective::OpenDimensionZ; + if (instance.objective() == open_dimension_objective) + return false; + if (instance.objective() == Objective::BinPackingWithLeftovers) { + LeftoverMode leftover_mode = instance.parameters().leftover_mode; + bool x = (leftover_mode == LeftoverMode::X + || leftover_mode == LeftoverMode::XY + || leftover_mode == LeftoverMode::XZ + || leftover_mode == LeftoverMode::XYZ); + bool y = (leftover_mode == LeftoverMode::Y + || leftover_mode == LeftoverMode::XY + || leftover_mode == LeftoverMode::YZ + || leftover_mode == LeftoverMode::XYZ); + bool z = (leftover_mode == LeftoverMode::Z + || leftover_mode == LeftoverMode::XZ + || leftover_mode == LeftoverMode::YZ + || leftover_mode == LeftoverMode::XYZ); + if ((axis == 0 && x) || (axis == 1 && y) || (axis == 2 && z)) + return false; + } + return true; +} + +Length Reduction::max_achievable_dimension_sum( + const std::vector& reduction_item_types, + Length capacity, + int axis, + ItemTypeId excluded_item_type_id) const +{ + std::vector items; + for (ItemTypeId item_type_id = 0; + item_type_id < (ItemTypeId)reduction_item_types.size(); + ++item_type_id) { + const ReductionItemType& item = reduction_item_types[item_type_id]; + if (item.removed) + continue; + SubsetSumBoundItem subset_sum_item; + subset_sum_item.copies = item.copies; + if (item_type_id == excluded_item_type_id) + subset_sum_item.copies--; + for (Rotation rotation: item.rotations) + subset_sum_item.lengths.push_back(box_length(item.box.rotate(rotation), axis)); + items.push_back(subset_sum_item); + } + return subset_sum_bound(items, capacity); +} + +Length Reduction::shrunk_bin_length( + const std::vector& reduction_item_types, + int axis) const +{ + return max_achievable_dimension_sum( + reduction_item_types, + box_length(original_instance_->bin_type(0).box, axis), + axis, + -1); +} + +bool Reduction::lift_item_dimensions( + std::vector& reduction_item_types) const +{ + bool found = false; + for (int axis = 0; axis < 3; ++axis) { + if (!lift_item_dimensions_applies_axis(*original_instance_, axis)) + continue; + + // Lifting an item type never changes the shrunk bin: every + // combination of items containing the enlarged item type still + // fits in it. + Length bin_length = shrunk_bin_length(reduction_item_types, axis); + + for (ItemTypeId item_type_id = 0; + item_type_id < (ItemTypeId)reduction_item_types.size(); + ++item_type_id) { + ReductionItemType& item = reduction_item_types[item_type_id]; + if (item.removed || item.rotations.empty()) + continue; + // A single copy: the bound below only holds for one occurrence + // of the item type - every copy of an enlarged item type is + // enlarged, while the other items could fill the gap beside + // each of them separately (see + // 'rectangle::Reduction::lift_item_dimensions_axis'). + if (item.copies != 1) + continue; + if (original_instance_->item_type(item_type_id).copies_fixed > 0) + continue; + // Every allowed rotation must put the same dimension of the + // item along this axis, so that growing it only changes the + // extent of the item along this axis. + int dimension = rotated_dimension(item.rotations.front(), axis); + bool same_dimension = true; + for (Rotation rotation: item.rotations) { + if (rotated_dimension(rotation, axis) != dimension) { + same_dimension = false; + break; + } + } + if (!same_dimension) + continue; + + Length& item_length = box_length(item.box, dimension); + Length capacity = bin_length - item_length; + if (capacity <= 0) + continue; + Length achievable_other = max_achievable_dimension_sum( + reduction_item_types, capacity, axis, item_type_id); + if (achievable_other >= capacity) + continue; + item_length = bin_length - achievable_other; + found = true; + } + } + return found; +} + bool Reduction::items_mergeable( const std::vector& reduction_item_types, ItemTypeId item_type_id_1, @@ -217,7 +398,9 @@ bool Reduction::items_mergeable( const ItemType& item_type_1 = original_instance_->item_type(item_type_id_1); const ItemType& item_type_2 = original_instance_->item_type(item_type_id_2); - if (item_type_1.box != item_type_2.box) + // Current boxes: two item types with the same original box may have + // been enlarged differently by 'lift_item_dimensions'. + if (reduction_item_types[item_type_id_1].box != reduction_item_types[item_type_id_2].box) return false; if (rotation_set(reduction_item_types[item_type_id_1].rotations) != rotation_set(reduction_item_types[item_type_id_2].rotations)) @@ -353,13 +536,15 @@ Instance Reduction::reduction_to_instance( // 'add_item_type(original_instance, id)' copies every field // (box, rotations, profit, weight, resource consumptions) from the // survivor's own original item type; only 'copies'/'copies_min' - // need overriding afterwards to reflect the merge, and 'rotations' - // to reflect 'remove_redundant_rotations'. + // need overriding afterwards to reflect the merge, 'rotations' to + // reflect 'remove_redundant_rotations', and 'box' to reflect + // 'lift_item_dimensions'. ItemTypeId new_item_type_id = instance_builder.add_item_type( *original_instance_, item_type_id); instance_builder.set_item_type_copies(new_item_type_id, total_copies); instance_builder.set_item_type_copies_min(new_item_type_id, total_copies_min); instance_builder.set_item_type_rotations(new_item_type_id, item.rotations); + instance_builder.set_item_type_box(new_item_type_id, item.box); reduced_item_origin_runs_.push_back(std::move(origin_runs)); } diff --git a/src/boxstacks/instance_builder.cpp b/src/boxstacks/instance_builder.cpp index d710e347b..53a5ca9bc 100644 --- a/src/boxstacks/instance_builder.cpp +++ b/src/boxstacks/instance_builder.cpp @@ -382,6 +382,27 @@ void InstanceBuilder::set_item_type_rotations( add_item_type_rotation(item_type_id, rotation); } +void InstanceBuilder::set_item_type_box( + ItemTypeId item_type_id, + const Box& box) +{ + if (item_type_id < 0 || item_type_id >= (ItemTypeId)instance_.item_types_.size()) { + throw std::invalid_argument( + FUNC_SIGNATURE + ": " + "invalid 'item_type_id'; " + "item_type_id: " + std::to_string(item_type_id) + "."); + } + if (box.x <= 0 || box.y <= 0 || box.z <= 0) { + throw std::invalid_argument( + FUNC_SIGNATURE + ": " + "item dimensions must be > 0; " + "box.x: " + std::to_string(box.x) + "; " + "box.y: " + std::to_string(box.y) + "; " + "box.z: " + std::to_string(box.z) + "."); + } + instance_.item_types_[item_type_id].box = box; +} + void InstanceBuilder::set_item_type_group( ItemTypeId item_type_id, GroupId group_id) diff --git a/src/boxstacks/reduction.cpp b/src/boxstacks/reduction.cpp index 104350f31..2dbc55cd2 100644 --- a/src/boxstacks/reduction.cpp +++ b/src/boxstacks/reduction.cpp @@ -2,6 +2,7 @@ #include "packingsolver/boxstacks/instance_builder.hpp" #include "boxstacks/solution_builder.hpp" +#include "algorithms/subset_sum_bound.hpp" #include @@ -63,8 +64,8 @@ bool Reduction::remove_redundant_rotations( for (Rotation rotation: item.rotations) { bool duplicate = false; for (Rotation distinct_rotation: distinct_rotations) { - if (rotated_footprint(item_type.box, distinct_rotation) - == rotated_footprint(item_type.box, rotation)) { + if (rotated_footprint(item.box, distinct_rotation) + == rotated_footprint(item.box, rotation)) { duplicate = true; break; } @@ -77,7 +78,7 @@ bool Reduction::remove_redundant_rotations( // unless none fits. std::vector fitting_rotations; for (Rotation rotation: distinct_rotations) { - std::pair footprint = rotated_footprint(item_type.box, rotation); + std::pair footprint = rotated_footprint(item.box, rotation); for (BinTypeId bin_type_id = 0; bin_type_id < original_instance_->number_of_bin_types(); ++bin_type_id) { @@ -147,6 +148,184 @@ bool same_rotations( } +bool Reduction::lift_item_dimensions_applies(const Instance& instance) +{ + // A single bin type, so that the bin dimensions are unambiguous, and + // no defects or fixed items, which the compaction argument of the + // class-level doc comment cannot move. + return instance.number_of_bin_types() == 1 + && instance.bin_type(0).defects.empty() + && instance.bin_type(0).fixed_items.empty(); +} + +bool Reduction::lift_item_dimensions_applies_axis( + const Instance& instance, + int axis) +{ + // See the class-level doc comment for each exclusion. + rectangle::UnloadingConstraint unloading_constraint = instance.unloading_constraint(); + LeftoverMode leftover_mode = instance.parameters().leftover_mode; + if (axis == 0) { + if (instance.objective() == Objective::OpenDimensionX) + return false; + if (instance.objective() == Objective::BinPackingWithLeftovers + && (leftover_mode == LeftoverMode::X + || leftover_mode == LeftoverMode::XY)) { + return false; + } + if (instance.bin_type(0).semi_trailer_truck_data.is) + return false; + if (unloading_constraint == rectangle::UnloadingConstraint::OnlyYMovements + || unloading_constraint == rectangle::UnloadingConstraint::IncreasingX) { + return false; + } + } else if (axis == 1) { + if (instance.objective() == Objective::OpenDimensionY) + return false; + if (instance.objective() == Objective::BinPackingWithLeftovers + && (leftover_mode == LeftoverMode::Y + || leftover_mode == LeftoverMode::XY)) { + return false; + } + if (unloading_constraint == rectangle::UnloadingConstraint::OnlyXMovements + || unloading_constraint == rectangle::UnloadingConstraint::IncreasingY) { + return false; + } + } else { + if (instance.objective() == Objective::OpenDimensionZ) + return false; + } + return true; +} + +Length Reduction::max_achievable_dimension_sum( + const std::vector& reduction_item_types, + Length capacity, + int axis, + ItemTypeId excluded_item_type_id) const +{ + std::vector items; + for (ItemTypeId item_type_id = 0; + item_type_id < (ItemTypeId)reduction_item_types.size(); + ++item_type_id) { + const ReductionItemType& item = reduction_item_types[item_type_id]; + if (item.removed) + continue; + SubsetSumBoundItem subset_sum_item; + subset_sum_item.copies = item.copies; + if (item_type_id == excluded_item_type_id) + subset_sum_item.copies--; + for (Rotation rotation: item.rotations) { + std::pair footprint = rotated_footprint(item.box, rotation); + subset_sum_item.lengths.push_back((axis == 0)? footprint.first: footprint.second); + } + items.push_back(subset_sum_item); + } + return subset_sum_bound(items, capacity); +} + +Length Reduction::shrunk_bin_length( + const std::vector& reduction_item_types, + int axis) const +{ + const Box& bin_box = original_instance_->bin_type(0).box; + return max_achievable_dimension_sum( + reduction_item_types, + (axis == 0)? bin_box.x: bin_box.y, + axis, + -1); +} + +bool Reduction::lift_item_dimensions( + std::vector& reduction_item_types) const +{ + const BinType& bin_type = original_instance_->bin_type(0); + bool found = false; + for (int axis = 0; axis < 3; ++axis) { + if (!lift_item_dimensions_applies_axis(*original_instance_, axis)) + continue; + + // Lifting an item type never changes the shrunk bin: every + // combination of items containing the enlarged item type still + // fits in it. + Length bin_length = (axis == 2)? + bin_type.box.z: + shrunk_bin_length(reduction_item_types, axis); + + for (ItemTypeId item_type_id = 0; + item_type_id < (ItemTypeId)reduction_item_types.size(); + ++item_type_id) { + ReductionItemType& item = reduction_item_types[item_type_id]; + if (item.removed || item.rotations.empty()) + continue; + // A single copy: the bound below only holds for one occurrence + // of the item type (see + // 'rectangle::Reduction::lift_item_dimensions_axis'). + if (item.copies != 1) + continue; + const ItemType& item_type = original_instance_->item_type(item_type_id); + if (item_type.copies_fixed > 0) + continue; + + // Alone in its stack: no other remaining item type shares its + // stackability id. + bool alone = true; + for (ItemTypeId other_item_type_id = 0; + other_item_type_id < (ItemTypeId)reduction_item_types.size(); + ++other_item_type_id) { + if (other_item_type_id == item_type_id + || reduction_item_types[other_item_type_id].removed) { + continue; + } + if (original_instance_->item_type(other_item_type_id).stackability_id + == item_type.stackability_id) { + alone = false; + break; + } + } + if (!alone) + continue; + + if (axis == 2) { + // Nothing else is ever packed in its stack. + if (item.box.z < bin_length) { + item.box.z = bin_length; + found = true; + } + continue; + } + + // A single rotation, so that growing 'x' (or 'y') only changes + // the extent of the item along this axis. + if (item.rotations.size() != 1) + continue; + // The maximum stack density is checked by the reduced instance + // against the enlarged footprint: the item must satisfy it with + // its true footprint. + if (strictly_greater( + (double)item_type.weight / item_type.box.x / item_type.box.y, + bin_type.maximum_stack_density)) { + continue; + } + + Rotation rotation = item.rotations.front(); + // The dimension of the box along the axis for this rotation. + bool along_x = ((axis == 0) == (rotation != Rotation::YXZ)); + Length& item_length = (along_x)? item.box.x: item.box.y; + Length capacity = bin_length - item_length; + if (capacity <= 0) + continue; + Length achievable_other = max_achievable_dimension_sum( + reduction_item_types, capacity, axis, item_type_id); + if (achievable_other >= capacity) + continue; + item_length = bin_length - achievable_other; + found = true; + } + } + return found; +} + bool Reduction::items_mergeable( const std::vector& reduction_item_types, ItemTypeId item_type_id_1, @@ -155,9 +334,12 @@ bool Reduction::items_mergeable( const ItemType& item_type_1 = original_instance_->item_type(item_type_id_1); const ItemType& item_type_2 = original_instance_->item_type(item_type_id_2); - if (item_type_1.box.x != item_type_2.box.x - || item_type_1.box.y != item_type_2.box.y - || item_type_1.box.z != item_type_2.box.z) + // Current boxes: see 'lift_item_dimensions'. + const Box& box_1 = reduction_item_types[item_type_id_1].box; + const Box& box_2 = reduction_item_types[item_type_id_2].box; + if (box_1.x != box_2.x + || box_1.y != box_2.y + || box_1.z != box_2.z) return false; // Profit is only compared for 'Knapsack': for every other objective @@ -283,6 +465,7 @@ Instance Reduction::reduction_to_instance( instance_builder.set_item_type_copies(new_item_type_id, total_copies); instance_builder.set_item_type_copies_min(new_item_type_id, total_copies_min); instance_builder.set_item_type_rotations(new_item_type_id, item.rotations); + instance_builder.set_item_type_box(new_item_type_id, item.box); reduced_item_origin_runs_.push_back(std::move(origin_runs)); } @@ -304,6 +487,7 @@ Reduction::Reduction( ++item_type_id) { reduction_item_types[item_type_id].copies = instance.item_type(item_type_id).copies; reduction_item_types[item_type_id].rotations = instance.item_type(item_type_id).rotations; + reduction_item_types[item_type_id].box = instance.item_type(item_type_id).box; } if (parameters.remove_redundant_rotations) @@ -314,6 +498,23 @@ Reduction::Reduction( remove_negative_profit_items(reduction_item_types); } + // Lifting can make more rotations redundant (e.g. a square enlarged + // footprint), and removing rotations can enable lifting along 'x' and + // 'y' (it requires a single allowed rotation). + if (parameters.lift_item_dimensions + && lift_item_dimensions_applies(instance)) { + for (;;) { + if (parameters.timer.needs_to_end()) + break; + if (!lift_item_dimensions(reduction_item_types)) + break; + if (!parameters.remove_redundant_rotations + || !remove_redundant_rotations(reduction_item_types)) { + break; + } + } + } + if (parameters.merge_identical_items) merge_identical_items(reduction_item_types); @@ -340,6 +541,27 @@ Solution Reduction::unreduce_solution( // between (or interferes with) separate 'unreduce_solution' calls. std::vector> remaining_runs = reduced_item_origin_runs_; + // Footprint of a stack with the true dimensions of its items: a stack + // containing a lifted item type contains nothing else (see + // 'lift_item_dimensions'), and every item type merged into another one + // has the same original box (a lifted item type is never merged), so + // the original box of any origin of the first item gives it. + auto true_footprint = [this](const SolutionStack& solution_stack) + -> std::pair + { + if (solution_stack.items.empty()) { + return { + solution_stack.x_end - solution_stack.x_start, + solution_stack.y_end - solution_stack.y_start}; + } + const SolutionItem& solution_item = solution_stack.items.front(); + ItemTypeId original_item_type_id + = reduced_item_origin_runs_[solution_item.item_type_id].front().item_type_id; + return rotated_footprint( + original_instance_->item_type(original_item_type_id).box, + solution_item.rotation); + }; + // How many of the *current* pattern's item slots (across every // stack) reference each reduced item type - needed to tell whether a // whole physical bin's worth of a given type can still be drawn from @@ -402,12 +624,13 @@ Solution Reduction::unreduce_solution( } BinPos new_bin_pos = solution_builder.add_bin(solution_bin.bin_type_id, batch); for (const SolutionStack& solution_stack: solution_bin.stacks) { + std::pair footprint = true_footprint(solution_stack); StackId new_stack_id = solution_builder.add_stack( new_bin_pos, solution_stack.x_start, - solution_stack.x_end, + solution_stack.x_start + footprint.first, solution_stack.y_start, - solution_stack.y_end); + solution_stack.y_start + footprint.second); for (const SolutionItem& solution_item: solution_stack.items) { ItemTypeId original_item_type_id = remaining_runs[solution_item.item_type_id].back().item_type_id; @@ -432,12 +655,13 @@ Solution Reduction::unreduce_solution( // proportional to 'remaining_bin_copies'). BinPos new_bin_pos = solution_builder.add_bin(solution_bin.bin_type_id, 1); for (const SolutionStack& solution_stack: solution_bin.stacks) { + std::pair footprint = true_footprint(solution_stack); StackId new_stack_id = solution_builder.add_stack( new_bin_pos, solution_stack.x_start, - solution_stack.x_end, + solution_stack.x_start + footprint.first, solution_stack.y_start, - solution_stack.y_end); + solution_stack.y_start + footprint.second); for (const SolutionItem& solution_item: solution_stack.items) { ItemTypeId original_item_type_id = consume_one_origin(remaining_runs[solution_item.item_type_id]); diff --git a/src/rectangle/instance.cpp b/src/rectangle/instance.cpp index ac8cbbdbb..151c5c809 100644 --- a/src/rectangle/instance.cpp +++ b/src/rectangle/instance.cpp @@ -1,6 +1,7 @@ #include "packingsolver/rectangle/instance.hpp" #include +#include #include #include #include @@ -270,7 +271,13 @@ bool Instance::weight_matters() const { if (number_of_bin_types() != 1) return false; - if (bin_type(0).maximum_weight == std::numeric_limits::infinity()) + const BinType& bin_type = this->bin_type(0); + // The axle weights of a semi-trailer truck are per-bin aggregates too. + bool axle_weights = bin_type.semi_trailer_truck_data.is + && (std::isfinite(bin_type.semi_trailer_truck_data.middle_axle_maximum_weight) + || std::isfinite(bin_type.semi_trailer_truck_data.rear_axle_maximum_weight)); + if (bin_type.maximum_weight == std::numeric_limits::infinity() + && !axle_weights) return false; for (ItemTypeId item_type_id = 0; item_type_id < number_of_item_types(); diff --git a/src/rectangle/reduction.cpp b/src/rectangle/reduction.cpp index 8cd804fdb..b5a9d2661 100644 --- a/src/rectangle/reduction.cpp +++ b/src/rectangle/reduction.cpp @@ -2111,12 +2111,15 @@ bool Reduction::lift_item_dimensions_applies(const Instance& instance) // // Still needs a single bin type - the bin's own true dimension this // operation reasons against would otherwise be ambiguous - and no - // defects - a defect sitting inside the margin this operation claims - // is "provably empty" would be invisible to its purely 1D subset-sum - // argument, the same blind spot as companion absorption's own - // geometric checks (see 'companion_absorption_applies'). + // defects or fixed items - a defect or a fixed item sitting inside the + // margin this operation claims is "provably empty" would be invisible + // to its purely 1D subset-sum argument, the same blind spot as + // companion absorption's own geometric checks (see + // 'companion_absorption_applies'), and neither can be moved by the + // compaction the argument relies on. return instance.number_of_bin_types() == 1 - && instance.number_of_defects() == 0; + && instance.number_of_defects() == 0 + && instance.bin_type(0).fixed_items.empty(); } bool Reduction::lift_item_dimensions_applies_axis( @@ -2130,6 +2133,17 @@ bool Reduction::lift_item_dimensions_applies_axis( // this axis directly would have that solve reason - and make // placement/objective-value decisions - against an artificially // enlarged footprint instead of the item's true one. + // + // The soundness argument compacts any solution along this axis, which + // moves items along it: a constraint depending on the positions along + // this axis blocks it. The semi-trailer truck axle weights depend on + // the 'x' positions of the items, and on their 'x' centers, which the + // reduced instance computes from the enlarged items. Compacting along + // 'x' keeps the 'y' coordinates and the order along 'x' of the items + // whose 'y' ranges intersect, so it keeps 'OnlyXMovements' and + // 'IncreasingY', but not 'OnlyYMovements' and 'IncreasingX' (and + // symmetrically along 'y'). + UnloadingConstraint unloading_constraint = instance.unloading_constraint(); if (width_axis) { if (instance.objective() == Objective::OpenDimensionX) return false; @@ -2137,6 +2151,11 @@ bool Reduction::lift_item_dimensions_applies_axis( && (instance.parameters().leftover_mode == LeftoverMode::X || instance.parameters().leftover_mode == LeftoverMode::Area)) return false; + if (instance.bin_type(0).semi_trailer_truck_data.is) + return false; + if (unloading_constraint == UnloadingConstraint::OnlyYMovements + || unloading_constraint == UnloadingConstraint::IncreasingX) + return false; } else { if (instance.objective() == Objective::OpenDimensionY) return false; @@ -2144,6 +2163,9 @@ bool Reduction::lift_item_dimensions_applies_axis( && (instance.parameters().leftover_mode == LeftoverMode::Y || instance.parameters().leftover_mode == LeftoverMode::Area)) return false; + if (unloading_constraint == UnloadingConstraint::OnlyXMovements + || unloading_constraint == UnloadingConstraint::IncreasingY) + return false; } return true; } diff --git a/src/rectangleguillotine/reduction.cpp b/src/rectangleguillotine/reduction.cpp index 02e2fee7a..59b7e83c1 100644 --- a/src/rectangleguillotine/reduction.cpp +++ b/src/rectangleguillotine/reduction.cpp @@ -2,6 +2,9 @@ #include "packingsolver/rectangleguillotine/instance_builder.hpp" #include "rectangleguillotine/solution_builder.hpp" +#include "algorithms/subset_sum_bound.hpp" + +#include using namespace packingsolver; using namespace packingsolver::rectangleguillotine; @@ -79,6 +82,7 @@ bool Reduction::remove_redundant_rotations( } else if (!fits && fits_rotated) { item.oriented = true; std::swap(item.rect.w, item.rect.h); + item.swapped = true; found = true; } } @@ -131,6 +135,233 @@ void Reduction::remove_negative_profit_items( } } +bool Reduction::lift_item_dimensions_applies(const Instance& instance) +{ + // Objectives only depending on which items and bins are used (see the + // class-level doc comment); the open dimension ones only lift along the + // other axis (see 'lift_item_dimensions_applies_axis'). + if (instance.objective() != Objective::Knapsack + && instance.objective() != Objective::BinPacking + && instance.objective() != Objective::VariableSizedBinPacking + && instance.objective() != Objective::Feasibility + && instance.objective() != Objective::OpenDimensionX + && instance.objective() != Objective::OpenDimensionY) { + return false; + } + if (instance.number_of_bin_types() != 1) + return false; + const BinType& bin_type = instance.bin_type(0); + if (!bin_type.defects.empty() || !bin_type.fixed_items.empty()) + return false; + const Parameters& parameters = instance.parameters(); + if (parameters.cut_type != CutType::NonExact + && parameters.cut_type != CutType::Exact + && parameters.cut_type != CutType::Roadef2018) { + return false; + } + // The compaction can make a distance between two cuts or a waste + // smaller, and 'unreduce_solution' adds cuts. + if (parameters.minimum_distance_1_cuts > 0 + || parameters.minimum_distance_2_cuts > 0 + || parameters.minimum_waste_length > 0 + || parameters.maximum_number_1_cuts >= 0 + || parameters.maximum_number_2_cuts >= 0) { + return false; + } + // With a cut thickness, the extent of a chain of items next to a trim + // depends on whether the trim is cut. + if (parameters.cut_thickness > 0 + && (bin_type.left_trim > 0 + || bin_type.right_trim > 0 + || bin_type.bottom_trim > 0 + || bin_type.top_trim > 0)) { + return false; + } + return true; +} + +namespace +{ + +/** + * 'true' iff the nodes at depth 'depth' are delimited along 'x', i.e. are + * the result of cuts along 'x' ('l' and 'r' are cut positions), for a + * first cut orientation 'first_cut_orientation' ('Vertical' or + * 'Horizontal'). Mirrors 'SolutionBuilder::add_node'. + */ +bool delimited_along_x( + CutOrientation first_cut_orientation, + Depth depth) +{ + return (first_cut_orientation == CutOrientation::Vertical && depth % 2 == 1) + || (first_cut_orientation == CutOrientation::Horizontal && depth % 2 == 0); +} + +} + +bool Reduction::lift_item_dimensions_applies_axis( + const Instance& instance, + int axis) +{ + bool along_x = (axis == 0); + if (along_x && instance.objective() == Objective::OpenDimensionX) + return false; + if (!along_x && instance.objective() == Objective::OpenDimensionY) + return false; + + // See the class-level doc comment for the cut type restrictions. + const Parameters& parameters = instance.parameters(); + if (parameters.cut_type == CutType::NonExact) + return true; + if (parameters.first_stage_orientation == CutOrientation::Any) + return false; + Depth depth = (parameters.cut_type == CutType::Exact)? + parameters.number_of_stages: + parameters.number_of_stages + 1; + return delimited_along_x(parameters.first_stage_orientation, depth) == along_x; +} + +Length Reduction::max_achievable_dimension_sum( + const std::vector& reduction_item_types, + Length capacity, + int axis, + Length offset, + ItemTypeId excluded_item_type_id) const +{ + std::vector items; + for (ItemTypeId item_type_id = 0; + item_type_id < (ItemTypeId)reduction_item_types.size(); + ++item_type_id) { + const ReductionItemType& item = reduction_item_types[item_type_id]; + if (item.removed) + continue; + SubsetSumBoundItem subset_sum_item; + subset_sum_item.copies = item.copies; + if (item_type_id == excluded_item_type_id) + subset_sum_item.copies--; + subset_sum_item.lengths.push_back(((axis == 0)? item.rect.w: item.rect.h) + offset); + if (!item.oriented) + subset_sum_item.lengths.push_back(((axis == 0)? item.rect.h: item.rect.w) + offset); + items.push_back(subset_sum_item); + } + return subset_sum_bound(items, capacity); +} + +bool Reduction::lift_item_dimensions( + std::vector& reduction_item_types) const +{ + const Parameters& parameters = original_instance_->parameters(); + const BinType& bin_type = original_instance_->bin_type(0); + Length cut_thickness = parameters.cut_thickness; + CutOrientation first_stage_orientation = parameters.first_stage_orientation; + + // For each maximum distance between cuts, the axes it may apply to. + // 1-cuts are along 'x' if the first stage is vertical. + struct MaximumDistance + { + Length distance; + bool along_x; + bool along_y; + }; + std::vector maximum_distances; + if (parameters.maximum_distance_1_cuts >= 0) { + maximum_distances.push_back({ + parameters.maximum_distance_1_cuts, + first_stage_orientation != CutOrientation::Horizontal, + first_stage_orientation != CutOrientation::Vertical}); + } + if (parameters.maximum_distance_2_cuts >= 0) { + maximum_distances.push_back({ + parameters.maximum_distance_2_cuts, + first_stage_orientation != CutOrientation::Vertical, + first_stage_orientation != CutOrientation::Horizontal}); + } + + bool found = false; + for (int axis = 0; axis < 2; ++axis) { + if (!lift_item_dimensions_applies_axis(*original_instance_, axis)) + continue; + bool along_x = (axis == 0); + + // Lengths a chain of items along this axis must fit in: the bin + // without its trims, and the maximum distances between cuts along + // this axis. Each one is increased by the cut thickness and shrunk + // to the largest total length of the items (each also increased by + // the cut thickness) not exceeding it. Lifting an item type never + // changes them: every combination of items containing the enlarged + // item type still fits. + std::vector capacities; + capacities.push_back((along_x)? + bin_type.rect.w - bin_type.left_trim - bin_type.right_trim: + bin_type.rect.h - bin_type.bottom_trim - bin_type.top_trim); + for (const MaximumDistance& maximum_distance: maximum_distances) + if ((along_x)? maximum_distance.along_x: maximum_distance.along_y) + capacities.push_back(maximum_distance.distance); + std::vector shrunk_capacities; + for (Length capacity: capacities) { + shrunk_capacities.push_back(max_achievable_dimension_sum( + reduction_item_types, + capacity + cut_thickness, + axis, + cut_thickness, + -1)); + } + + for (ItemTypeId item_type_id = 0; + item_type_id < (ItemTypeId)reduction_item_types.size(); + ++item_type_id) { + ReductionItemType& item = reduction_item_types[item_type_id]; + if (item.removed) + continue; + // Oriented, so that growing one dimension only changes the + // extent of the item along this axis, and a single copy, since + // the bound below only holds for one occurrence of the item + // type (see 'rectangle::Reduction::lift_item_dimensions_axis'). + if (!item.oriented || item.copies != 1) + continue; + const ItemType& item_type = original_instance_->item_type(item_type_id); + if (item_type.copies_fixed > 0) + continue; + // Alone in its stack. + if (original_instance_->stack_size(item_type.stack_id) != 1) + continue; + // 'unreduce_solution' may turn the node of the item into a + // plate, subject to the maximum distances between cuts. + bool fits_maximum_distances = true; + for (const MaximumDistance& maximum_distance: maximum_distances) { + if ((maximum_distance.along_x && item.rect.w > maximum_distance.distance) + || (maximum_distance.along_y && item.rect.h > maximum_distance.distance)) { + fits_maximum_distances = false; + break; + } + } + if (!fits_maximum_distances) + continue; + + Length& item_length = (along_x)? item.rect.w: item.rect.h; + Length new_item_length = -1; + for (Length shrunk_capacity: shrunk_capacities) { + Length capacity = shrunk_capacity - (item_length + cut_thickness); + Length achievable_other = (capacity <= 0)? 0: + max_achievable_dimension_sum( + reduction_item_types, + capacity, + axis, + cut_thickness, + item_type_id); + Length length = shrunk_capacity - achievable_other - cut_thickness; + if (new_item_length == -1 || new_item_length > length) + new_item_length = length; + } + if (new_item_length <= item_length) + continue; + item_length = new_item_length; + found = true; + } + } + return found; +} + namespace { @@ -381,13 +612,175 @@ Reduction::Reduction( && parameters.remove_negative_profit_items) { remove_negative_profit_items(reduction_item_types); } + if (parameters.lift_item_dimensions + && lift_item_dimensions_applies(instance) + && !parameters.timer.needs_to_end()) { + lift_item_dimensions(reduction_item_types); + } if (parameters.merge_identical_items) merge_identical_items(reduction_item_types); } + for (const ReductionItemType& item: reduction_item_types) { + reduced_rects_.push_back(item.rect); + swapped_item_types_.push_back(item.swapped); + } + instance_ = reduction_to_instance(reduction_item_types); } +namespace +{ + +Length& node_start( + SolutionNode& node, + bool along_x) +{ + return (along_x)? node.l: node.b; +} + +Length& node_end( + SolutionNode& node, + bool along_x) +{ + return (along_x)? node.r: node.t; +} + +/** 'true' iff node 'node' is a waste without children. */ +bool is_waste(const SolutionNode& node) +{ + return (node.item_type_id == -1 || node.item_type_id == -3) + && node.children.empty(); +} + +/** Moves node 'node_id' and all its descendants by 'delta' along an axis. */ +void shift_subtree( + std::vector& nodes, + SolutionNodeId node_id, + bool along_x, + Length delta) +{ + node_start(nodes[node_id], along_x) += delta; + node_end(nodes[node_id], along_x) += delta; + for (SolutionNodeId child_id: nodes[node_id].children) + shift_subtree(nodes, child_id, along_x, delta); +} + +/** + * Shrinks node 'node_id', delimited along the axis, by 'delta' at its end. + * Its next siblings are moved back by 'delta' up to the first waste, which + * grows by 'delta' instead. Without a waste after the node, the freed length + * becomes a waste at the end of the parent when the tree is replayed (see + * 'SolutionBuilder::add_node'). This adds a child to the parent only if it + * has no waste after the node. + */ +void shrink_in_parent( + std::vector& nodes, + SolutionNodeId node_id, + bool along_x, + Length delta) +{ + node_end(nodes[node_id], along_x) -= delta; + Depth depth = nodes[node_id].d; + bool after = false; + for (SolutionNodeId sibling_id: nodes[nodes[node_id].f].children) { + if (sibling_id == node_id) { + after = true; + continue; + } + if (!after || nodes[sibling_id].d != depth) + continue; + if (is_waste(nodes[sibling_id])) { + node_start(nodes[sibling_id], along_x) -= delta; + return; + } + shift_subtree(nodes, sibling_id, along_x, -delta); + } +} + +/** + * Shrinks the item of leaf node 'node_id' by 'delta' along an axis (see + * 'Reduction''s class-level doc comment): in place if the node is + * delimited along the axis; otherwise, by moving the item into a child + * node, if 'maximum_depth' allows it; otherwise, by shrinking the parent, + * which must be delimited along the axis and only contain wastes besides + * the item. Returns the id of the node containing the item. + */ +SolutionNodeId shrink_item_node( + std::vector& nodes, + SolutionNodeId node_id, + bool along_x, + Length delta, + Depth maximum_depth, + CutOrientation first_cut_orientation) +{ + Depth depth = nodes[node_id].d; + if (delimited_along_x(first_cut_orientation, depth) == along_x) { + shrink_in_parent(nodes, node_id, along_x, delta); + return node_id; + } + + if (depth + 1 <= maximum_depth) { + SolutionNode child = nodes[node_id]; + child.f = node_id; + child.d = depth + 1; + child.children.clear(); + node_end(child, along_x) -= delta; + SolutionNodeId child_id = nodes.size(); + nodes[node_id].item_type_id = -2; + nodes[node_id].children = {child_id}; + nodes.push_back(child); + return child_id; + } + + SolutionNodeId parent_id = nodes[node_id].f; + bool parent_ok = (nodes[parent_id].d >= 1); + for (SolutionNodeId child_id: nodes[parent_id].children) + if (child_id != node_id && !is_waste(nodes[child_id])) + parent_ok = false; + if (!parent_ok) { + throw std::logic_error( + FUNC_SIGNATURE + ": " + "unable to shrink an enlarged item; " + "depth: " + std::to_string(depth) + "."); + } + for (SolutionNodeId child_id: nodes[parent_id].children) + node_end(nodes[child_id], along_x) -= delta; + shrink_in_parent(nodes, parent_id, along_x, delta); + return node_id; +} + +/** + * Adds the descendants of node 'node_id' of a cut tree to 'solution_builder', + * in depth-first order (see 'SolutionBuilder::add_node': a node is appended + * as the last child of the last node added at the parent depth). The nodes + * of depth '0' or less (the root, the trims, and the plate inside the hard + * trims) are not added, 'SolutionBuilder::add_bin' adds them, but their + * descendants are. + */ +void add_subtree( + SolutionBuilder& solution_builder, + const std::vector& nodes, + SolutionNodeId node_id, + CutOrientation first_cut_orientation) +{ + for (SolutionNodeId child_id: nodes[node_id].children) { + const SolutionNode& child = nodes[child_id]; + if (child.d <= 0) { + add_subtree(solution_builder, nodes, child_id, first_cut_orientation); + continue; + } + solution_builder.add_node( + child.d, + (delimited_along_x(first_cut_orientation, child.d))? child.r: child.t); + if (child.item_type_id >= 0) + solution_builder.set_last_node_item(child.item_type_id); + add_subtree(solution_builder, nodes, child_id, first_cut_orientation); + } +} + +} + ItemTypeId Reduction::consume_one_origin( std::vector& runs) { @@ -402,6 +795,14 @@ Solution Reduction::unreduce_solution( { SolutionBuilder solution_builder(*original_instance_); + // Deepest level of a node: the number of stages, plus the extra cut + // for the cut types allowing one. + const Parameters& parameters = original_instance_->parameters(); + Depth maximum_depth = (parameters.cut_type == CutType::Exact + || parameters.cut_type == CutType::Homogenous)? + parameters.number_of_stages: + parameters.number_of_stages + 1; + // A working copy of 'reduced_item_origin_runs_' that this call // consumes from (via 'consume_one_origin') as it scans 'solution' - // kept local rather than a member so nothing here needs resetting @@ -483,49 +884,91 @@ Solution Reduction::unreduce_solution( } } - // Replay every node of the cut tree exactly as-is (same - // depths, same cut positions - see 'SolutionBuilder::add_node' - // 's own doc comment: nodes are appended as the last child of - // the last node added at the parent depth, so replaying - // 'solution_bin.nodes' in their own stored order - already the - // order they were built in - reconstructs an identical tree), - // substituting each leaf's reduced item type id for its true - // original one. - // - // Which of 'r'/'t' a given depth's cut position actually is - // depends on 'solution_bin.first_cut_orientation', not on - // depth parity alone - see 'SolutionBuilder::add_node''s own - // condition, which this mirrors exactly. - // ('InstanceFlipper::unflip_solution' gets away with the - // depth-parity-only shortcut only because it always forces the - // flipped instance's own first cut to 'Vertical', so - // 'first_cut_orientation' is never actually a free variable - // there - not true here, since this reduction never touches - // cut orientation and the instance may leave it unconstrained - // ('Any').) - solution_builder.add_bin( - solution_bin.bin_type_id, - batch, - solution_bin.first_cut_orientation); - for (const SolutionNode& node: solution_bin.nodes) { - if (node.d <= 0) + // Copy of the cut tree, with the original item type id of each + // item. Resolved in the stored order of the nodes, any + // consistent order works since a reduced item type's copies + // are interchangeable by construction. + // The children are rebuilt from the parents, in the stored + // order of the nodes, which is the order they were built in. + std::vector nodes = solution_bin.nodes; + for (SolutionNode& node: nodes) + node.children.clear(); + for (SolutionNodeId node_id = 0; + node_id < (SolutionNodeId)nodes.size(); + ++node_id) { + SolutionNode& node = nodes[node_id]; + if (node.f >= 0) + nodes[node.f].children.push_back(node_id); + if (node.d <= 0 || node.item_type_id < 0) + continue; + node.item_type_id = (bin_fits_in_current_runs)? + remaining_runs[node.item_type_id].back().item_type_id: + consume_one_origin(remaining_runs[node.item_type_id]); + } + + // Give each item enlarged by 'lift_item_dimensions' its true + // dimensions (see the class-level doc comment). + SolutionNodeId number_of_nodes = nodes.size(); + for (SolutionNodeId node_id = 0; node_id < number_of_nodes; ++node_id) { + if (nodes[node_id].d <= 0 || nodes[node_id].item_type_id < 0) continue; - bool cut_along_x = - (solution_bin.first_cut_orientation == CutOrientation::Vertical && node.d % 2 == 1) - || (solution_bin.first_cut_orientation == CutOrientation::Horizontal && node.d % 2 == 0); - if (cut_along_x) { - solution_builder.add_node(node.d, node.r); - } else { - solution_builder.add_node(node.d, node.t); + ItemTypeId item_type_id = nodes[node_id].item_type_id; + // True dimensions, in the orientation of the reduced item + // type, then in the orientation of the node. + Rectangle rect = original_instance_->item_type(item_type_id).rect; + if (swapped_item_types_[item_type_id]) + std::swap(rect.w, rect.h); + const Rectangle& reduced_rect = reduced_rects_[item_type_id]; + const SolutionNode& node = nodes[node_id]; + if (node.r - node.l != reduced_rect.w + || node.t - node.b != reduced_rect.h) { + std::swap(rect.w, rect.h); } - if (node.item_type_id >= 0) { - ItemTypeId original_item_type_id = (bin_fits_in_current_runs)? - remaining_runs[node.item_type_id].back().item_type_id: - consume_one_origin(remaining_runs[node.item_type_id]); - solution_builder.set_last_node_item(original_item_type_id); + Length delta_x = (node.r - node.l) - rect.w; + Length delta_y = (node.t - node.b) - rect.h; + if (delta_x < 0 || delta_y < 0) { + throw std::logic_error( + FUNC_SIGNATURE + ": " + "item larger than its node; " + "item_type_id: " + std::to_string(item_type_id) + "."); + } + // First along the axis the node is delimited along, then + // along the other one (see 'shrink_item_node'). + bool first_along_x = delimited_along_x(solution_bin.first_cut_orientation, node.d); + Length first_delta = (first_along_x)? delta_x: delta_y; + Length second_delta = (first_along_x)? delta_y: delta_x; + SolutionNodeId item_node_id = node_id; + if (first_delta > 0) { + item_node_id = shrink_item_node( + nodes, + item_node_id, + first_along_x, + first_delta, + maximum_depth, + solution_bin.first_cut_orientation); + } + if (second_delta > 0) { + shrink_item_node( + nodes, + item_node_id, + !first_along_x, + second_delta, + maximum_depth, + solution_bin.first_cut_orientation); } } + // Replay the cut tree (see 'add_subtree'). + solution_builder.add_bin( + solution_bin.bin_type_id, + batch, + solution_bin.first_cut_orientation); + add_subtree( + solution_builder, + nodes, + 0, + solution_bin.first_cut_orientation); + if (bin_fits_in_current_runs) { for (ItemTypeId reduced_item_type_id: touched_types) { OriginRun& run = remaining_runs[reduced_item_type_id].back(); diff --git a/test/box/reduction_test.cpp b/test/box/reduction_test.cpp index c5fb6c270..944e7c3ea 100644 --- a/test/box/reduction_test.cpp +++ b/test/box/reduction_test.cpp @@ -327,5 +327,43 @@ INSTANTIATE_TEST_SUITE_P( // both allow the same rotations and merge. fs::path("data") / "box" / "tests" / "bin_packing_merge_identical_items_after_removing_redundant_rotations", ReductionParameters(), + }, { + // Bin 10x10x10. Item types 7x10x10 and 4x10x10, oriented, + // one copy each: they can't share a bin, so the bin is + // shrunk along 'x' to 7, and the 4x10x10 item type is + // lifted to 7x10x10 (nothing else fits beside it). Both + // item types are then identical and merge. + fs::path("data") / "box" / "tests" / "bin_packing_lift_item_dimensions", + ReductionParameters(), + }, { + // Bin 10x10x10. Item type 7x10x10 with one copy, item type + // 4x10x10 with two copies, oriented. Along 'x', the bin is + // shrunk to 8 (the two 4x10x10 copies), and the 7x10x10 + // item type is lifted to 8x10x10 (no other item fits beside + // it). The 4x10x10 item type has two copies, so it is not + // lifted. + fs::path("data") / "box" / "tests" / "bin_packing_lift_item_dimensions_requires_single_copy", + ReductionParameters(), + }, { + // Bin 10x10x10. Item type 7x8x4 allowing 'XYZ' and 'YXZ', + // item type 4x4x7 oriented. The first item type is only + // lifted along 'z', the only axis both its rotations put + // the same dimension along, to 7. The second item type is + // lifted along 'x' and 'y' to 8 (the shrunk bin). + fs::path("data") / "box" / "tests" / "bin_packing_lift_item_dimensions_rotations", + ReductionParameters(), + }, { + // 'OpenDimensionX', bin 12x10x10. Item types 7x10x10, + // 3x10x10 and 5x10x10, oriented, one copy each. Along 'x', + // the 3x10x10 item type would be lifted to 5 (the bin is + // shrunk to 12 = 7 + 5, and only 7 fits beside it), but the + // objective measures the extent of the items along 'x', so + // nothing is lifted. 'skip_optimize_check': only the + // reduced instance is checked. + fs::path("data") / "box" / "tests" / "open_dimension_x_lift_item_dimensions_skips_x", + ReductionParameters(), + false, + false, + true, }, })); diff --git a/test/boxstacks/reduction_test.cpp b/test/boxstacks/reduction_test.cpp index ddfee2f05..1c6e6bac6 100644 --- a/test/boxstacks/reduction_test.cpp +++ b/test/boxstacks/reduction_test.cpp @@ -263,5 +263,35 @@ INSTANTIATE_TEST_SUITE_P( // 'YXZ', is a solution of the original instance. fs::path("data") / "boxstacks" / "tests" / "remove_redundant_rotations_rotation_fits_no_bin", ReductionParameters(), + }, { + // Bin 10x10x10. Item types 7x10x5 and 4x10x5, oriented, one + // copy each, with different stackability ids: each one is + // always alone in its stack. They can't share a bin, so the + // bin is shrunk along 'x' to 7, and the 4x10x5 item type is + // lifted to 7 along 'x'. Along 'z', both are lifted to the + // height of the bin. + fs::path("data") / "boxstacks" / "tests" / "bin_packing_lift_item_dimensions", + ReductionParameters(), + }, { + // Bin 10x10x10. Item type 7x10x5 with stackability id 0, + // and two item types 4x10x5 with stackability id 1, one + // copy each. The two 4x10x5 item types may share a stack, + // so they are not lifted (and they merge). The 7x10x5 item + // type is lifted to 8 along 'x' (the bin is shrunk to 8, + // and no other item fits beside it) and to 10 along 'z'. + fs::path("data") / "boxstacks" / "tests" / "bin_packing_lift_item_dimensions_requires_alone_in_stack", + ReductionParameters(), + }, { + // Semi-trailer truck 1360x240x260. Item types 1000x240x100 + // and 400x240x100, one copy each, with different + // stackability ids. Along 'x', the 400x240x100 item type + // would be lifted to 1000, but the axle weights depend on + // the 'x' positions of the stacks, so nothing is lifted + // along 'x'. Both are lifted along 'z' to the height of the + // truck. 'skip_optimize_check': only the reduced instance + // is checked. + fs::path("data") / "boxstacks" / "tests" / "semi_trailer_truck_lift_item_dimensions_skips_x", + ReductionParameters(), + true, }, })); diff --git a/test/rectangle/reduction_test.cpp b/test/rectangle/reduction_test.cpp index 4aa43fe54..edb0dae1f 100644 --- a/test/rectangle/reduction_test.cpp +++ b/test/rectangle/reduction_test.cpp @@ -1039,6 +1039,41 @@ INSTANTIATE_TEST_SUITE_P( fs::path("data") / "rectangle" / "tests" / "bin_packing_with_leftovers_y_lift_not_applied_on_y", ReductionParameters(), false, + }, { + // Same instance, 'BinPacking' with the 'OnlyXMovements' + // unloading constraint: the soundness argument of lifting + // compacts the solution along the lifted axis, and + // compacting along 'y' can change which items block each + // other along 'x', so only the y lift is blocked: item 0 + // is lifted to (9, 3). (Companion absorption is skipped + // with an unloading constraint.) + fs::path("data") / "rectangle" / "tests" / "bin_packing_only_x_movements_lift_not_applied_on_y", + ReductionParameters(), + false, + }, { + // Same instance, 'BinPacking' with the 'IncreasingX' + // unloading constraint, which depends on the 'x' + // positions of the items: only the x lift is blocked, item + // 0 is lifted to (6, 4). + fs::path("data") / "rectangle" / "tests" / "bin_packing_increasing_x_lift_not_applied_on_x", + ReductionParameters(), + false, + }, { + // Same instance, 'BinPacking' in a semi-trailer truck with + // weighted items: the axle weights depend on the 'x' + // positions and centers of the items, so only the x lift + // is blocked, item 0 is lifted to (6, 4). The axle weights + // are a per-bin aggregate, so companion absorption is + // skipped too (see 'Instance::weight_matters'), even though + // the maximum weight of the truck is infinite. + // 'skip_optimize_check': only the reduced instance is + // checked. + fs::path("data") / "rectangle" / "tests" / "bin_packing_semi_trailer_truck_lift_not_applied_on_x", + ReductionParameters(), + false, + false, + false, + true, }, { // Bin 100x100. Item type 0 (10x10) is a square: its // rotation is redundant, it becomes oriented. Item type 1 diff --git a/test/rectangleguillotine/reduction_test.cpp b/test/rectangleguillotine/reduction_test.cpp index c40167d45..c28b658be 100644 --- a/test/rectangleguillotine/reduction_test.cpp +++ b/test/rectangleguillotine/reduction_test.cpp @@ -374,5 +374,50 @@ INSTANTIATE_TEST_SUITE_P( // identical and merge. fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_merge_identical_items_after_removing_redundant_rotations", ReductionParameters(), + }, { + // Bin 10x10, 'NonExact'. Item types 7x10 and 4x10, oriented, + // one copy each: they can't share a bin, so the bin is shrunk + // along 'x' to 7, and the 4x10 item type is lifted to 7x10. + // Both item types are then identical and merge. + fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_lift_item_dimensions", + ReductionParameters(), + }, { + // Bin 10x10, 'NonExact'. Item types 7x6 and 4x5, oriented, + // one copy each: the 4x5 item type is lifted to 7 along 'x' + // and to 6 along 'y', and merges with the 7x6 one. The + // solution of the reduced instance needs its cut tree to be + // rewritten along both axes. + fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_lift_item_dimensions_both_axes", + ReductionParameters(), + }, { + // Same items as above, 2 stages, 'Exact', vertical first + // stage. Only the axis of the 2-cuts ('y') can be lifted: + // the 4x5 item type is lifted to 4x6. + fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_lift_item_dimensions_exact", + ReductionParameters(), + }, { + // Bin 10x10, cut thickness 1. Item types 6x10 and 4x10, + // oriented, one copy each: with the cut thickness, they + // can't share a bin (6 + 1 + 4 > 10), so the 4x10 item + // type is lifted to 6x10, and merges with the other one. + fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_lift_item_dimensions_cut_thickness", + ReductionParameters(), + }, { + // Same as 'bin_packing_lift_item_dimensions', with a + // minimum waste length: nothing is lifted. + fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_lift_item_dimensions_skipped_with_minimum_waste", + ReductionParameters(), + }, { + // Same as 'bin_packing_lift_item_dimensions', with a + // maximum distance between 1-cuts of 6: the 4x10 item type + // would be lifted to 7 against the bin, but a 1-cut plate + // containing it is at most 6 wide, and nothing else fits + // beside it there, so the bound for the plate keeps it at 4. + // The 7x10 item type is wider than the maximum distance, so + // it is not lifted either. 'skip_optimize_check': only the + // reduced instance is checked. + fs::path("data") / "rectangleguillotine" / "tests" / "bin_packing_lift_item_dimensions_maximum_distance_1_cuts", + ReductionParameters(), + true, }, }));