Skip to content

Commit 3dffb2f

Browse files
committed
Fix bottom and left soft trims in rectangleguillotine
1 parent 29bf82b commit 3dffb2f

File tree

8 files changed

+143
-26
lines changed

8 files changed

+143
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ID,WIDTH,HEIGHT,LEFT_TRIM,LEFT_TRIM_TYPE,RIGHT_TRIM,RIGHT_TRIM_TYPE,BOTTOM_TRIM,BOTTOM_TRIM_TYPE,TOP_TRIM,TOP_TRIM_TYPE
2+
0,6000,3210,200,1,200,0,200,1,200,0
3+
1,6000,3210,200,1,200,0,200,1,200,0
4+
2,6000,3210,200,1,200,0,200,1,200,0
5+
3,6000,3210,200,1,200,0,200,1,200,0
6+
4,6000,3210,200,1,200,0,200,1,200,0
7+
5,6000,3210,200,1,200,0,200,1,200,0
8+
6,6000,3210,200,1,200,0,200,1,200,0
9+
7,6000,3210,200,1,200,0,200,1,200,0
10+
8,6000,3210,200,1,200,0,200,1,200,0
11+
9,6000,3210,200,1,200,0,200,1,200,0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ID,WIDTH,HEIGHT,STACK_ID
2+
0,950,885,4
3+
1,950,885,5
4+
2,950,885,6
5+
3,950,885,7
6+
4,950,885,8
7+
5,715,1515,0
8+
6,950,885,9
9+
7,904,805,10
10+
8,904,805,11
11+
9,904,805,12
12+
10,904,805,13
13+
11,715,1515,1
14+
12,904,805,14
15+
13,950,885,2
16+
14,950,885,3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
NAME,VALUE
2+
objective,bin-packing-with-leftovers
3+
number_of_stages,3
4+
cut_type,exact
5+
first_stage_orientation,vertical
6+
min_waste,15
7+
min1cut,20
8+
max1cut,2500
9+
cut_thickness,0
10+
cut-through-defect,1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
PLATE_ID,NODE_ID,X,Y,WIDTH,HEIGHT,TYPE,CUT,PARENT
2+
0,0,0,0,6000,3210,0,0,
3+
0,1,5800,3010,200,200,-1,-1,0
4+
0,2,5800,0,200,3010,-1,-1,0
5+
0,3,0,3010,5800,200,-1,-1,0
6+
0,4,0,0,5800,3010,-2,0,0
7+
0,5,0,0,200,3010,-1,1,4
8+
0,6,200,0,805,3010,-2,1,4
9+
0,7,200,0,805,200,-1,2,6
10+
0,8,200,200,805,904,-2,2,6
11+
0,9,200,200,805,904,-2,3,8
12+
0,10,200,200,805,904,7,4,9
13+
0,11,200,1104,805,904,-2,2,6
14+
0,12,200,1104,805,904,-2,3,11
15+
0,13,200,1104,805,904,8,4,12
16+
0,14,200,2008,805,904,-2,2,6
17+
0,15,200,2008,805,904,-2,3,14
18+
0,16,200,2008,805,904,9,4,15
19+
0,17,200,2912,805,98,-1,2,6
20+
0,18,1005,0,950,3010,-2,1,4
21+
0,19,1005,0,950,200,-1,2,18
22+
0,20,1005,200,950,885,-2,2,18
23+
0,21,1005,200,950,885,-2,3,20
24+
0,22,1005,200,950,885,13,4,21
25+
0,23,1005,1085,950,885,-2,2,18
26+
0,24,1005,1085,950,885,-2,3,23
27+
0,25,1005,1085,950,885,14,4,24
28+
0,26,1005,1970,950,885,-2,2,18
29+
0,27,1005,1970,950,885,-2,3,26
30+
0,28,1005,1970,950,885,0,4,27
31+
0,29,1005,2855,950,155,-1,2,18
32+
0,30,1955,0,1808,3010,-2,1,4
33+
0,31,1955,0,1808,200,-1,2,30
34+
0,32,1955,200,1808,805,-2,2,30
35+
0,33,1955,200,904,805,-2,3,32
36+
0,34,1955,200,904,805,10,4,33
37+
0,35,2859,200,904,805,-2,3,32
38+
0,36,2859,200,904,805,12,4,35
39+
0,37,1955,1005,1808,950,-2,2,30
40+
0,38,1955,1005,885,950,-2,3,37
41+
0,39,1955,1005,885,950,1,4,38
42+
0,40,2840,1005,885,950,-2,3,37
43+
0,41,2840,1005,885,950,2,4,40
44+
0,42,3725,1005,38,950,-1,3,37
45+
0,43,1955,1955,1808,950,-2,2,30
46+
0,44,1955,1955,885,950,-2,3,43
47+
0,45,1955,1955,885,950,3,4,44
48+
0,46,2840,1955,885,950,-2,3,43
49+
0,47,2840,1955,885,950,4,4,46
50+
0,48,3725,1955,38,950,-1,3,43
51+
0,49,1955,2905,1808,105,-1,2,30
52+
0,50,3763,0,1430,3010,-2,1,4
53+
0,51,3763,0,1430,200,-1,2,50
54+
0,52,3763,200,1430,1515,-2,2,50
55+
0,53,3763,200,715,1515,-2,3,52
56+
0,54,3763,200,715,1515,5,4,53
57+
0,55,4478,200,715,1515,-2,3,52
58+
0,56,4478,200,715,1515,11,4,55
59+
0,57,3763,1715,1430,885,-2,2,50
60+
0,58,3763,1715,950,885,-2,3,57
61+
0,59,3763,1715,950,885,6,4,58
62+
0,60,4713,1715,480,885,-1,3,57
63+
0,61,3763,2600,1430,410,-1,2,50
64+
0,62,5193,0,607,3010,-3,1,4

src/rectangleguillotine/branching_scheme.cpp

+29-19
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ void BranchingScheme::update(
10591059
}
10601060

10611061
// Update insertion.x1 and insertion.z1 with respect to min1cut()
1062-
//std::cout << "update min1cut " << insertion << std::endl;
1062+
//std::cout << "- update min1cut " << insertion << std::endl;
10631063
if ((insertion.item_type_id_1 != -1 || insertion.item_type_id_2 != -1)
10641064
&& insertion.x1 - x1_prev(parent, insertion.df) < instance.parameters().minimum_distance_1_cuts) {
10651065
if (insertion.z1 == 0) {
@@ -1073,7 +1073,7 @@ void BranchingScheme::update(
10731073
}
10741074

10751075
// Update insertion.y2 and insertion.z2 with respect to min2cut()
1076-
//std::cout << "update min2cut " << insertion << std::endl;
1076+
//std::cout << "- update min2cut " << insertion << std::endl;
10771077
if ((insertion.item_type_id_1 != -1 || insertion.item_type_id_2 != -1)
10781078
&& insertion.y2 - y2_prev(parent, insertion.df) < instance.parameters().minimum_distance_2_cuts) {
10791079
if (insertion.z2 == 0) {
@@ -1089,7 +1089,7 @@ void BranchingScheme::update(
10891089
}
10901090

10911091
// Update insertion.y2 and insertion.z2 with respect to one2cut()
1092-
//std::cout << "update maximum_number_2_cuts " << insertion << std::endl;
1092+
//std::cout << "- update maximum_number_2_cuts " << insertion << std::endl;
10931093
if (instance.parameters().maximum_number_2_cuts != -1
10941094
&& insertion.df == 1
10951095
&& parent.subplate1curr_number_of_2_cuts == instance.parameters().maximum_number_2_cuts
@@ -1106,7 +1106,7 @@ void BranchingScheme::update(
11061106
}
11071107

11081108
// Update insertion.x1 if 2-staged
1109-
//std::cout << "update 2-staged " << insertion << std::endl;
1109+
//std::cout << "- update 2-staged " << insertion << std::endl;
11101110
if (instance.parameters().number_of_stages == 2 && insertion.x1 != w_physical) {
11111111
if (insertion.z1 == 0) {
11121112
if (insertion.x1 + cut_thickness + min_waste > w_physical)
@@ -1118,7 +1118,7 @@ void BranchingScheme::update(
11181118
}
11191119

11201120
// Update insertion.x1 and insertion.z1 with respect to x1_curr() and z1().
1121-
//std::cout << "update x1_curr " << insertion << std::endl;
1121+
//std::cout << "- update x1_curr " << insertion << std::endl;
11221122
if (insertion.df >= 1) {
11231123
if (insertion.z1 == 0) {
11241124
if (insertion.x1 + min_waste + cut_thickness <= parent.x1_curr) {
@@ -1151,7 +1151,7 @@ void BranchingScheme::update(
11511151
}
11521152

11531153
// Update insertion.y2 and insertion.z2 with respect to y2_curr() and z1().
1154-
//std::cout << "update y2_curr " << insertion << std::endl;
1154+
//std::cout << "- update y2_curr " << insertion << std::endl;
11551155
if (insertion.df == 2) {
11561156
if (insertion.z2 == 0) {
11571157
if (insertion.y2 + min_waste <= parent.y2_curr) {
@@ -1222,7 +1222,7 @@ void BranchingScheme::update(
12221222
}
12231223

12241224
// Update insertion.x1 and insertion.z1 with respect to defect intersections.
1225-
//std::cout << "update x1 defects " << insertion << std::endl;
1225+
//std::cout << "- update x1 defects " << insertion << std::endl;
12261226
if (!instance.parameters().cut_through_defects) {
12271227
for (;;) {
12281228
DefectId defect_id = instance.rect_intersects_defect(
@@ -1242,7 +1242,7 @@ void BranchingScheme::update(
12421242
}
12431243

12441244
// Check right soft-trim.
1245-
//std::cout << "update right soft-trim " << insertion << std::endl;
1245+
//std::cout << "- update right soft-trim " << insertion << std::endl;
12461246
if (insertion.x1 > w) {
12471247
if (insertion.x1 == w_physical) {
12481248
} else if (insertion.x1 < w_physical) {
@@ -1261,7 +1261,7 @@ void BranchingScheme::update(
12611261
}
12621262

12631263
// Increase width if too close from border
1264-
//std::cout << "update x border " << insertion << std::endl;
1264+
//std::cout << "- update x border " << insertion << std::endl;
12651265
if (insertion.x1 < w_physical
12661266
&& min_waste > 0
12671267
&& insertion.x1 + cut_thickness + min_waste > w_physical) {
@@ -1275,13 +1275,13 @@ void BranchingScheme::update(
12751275

12761276

12771277
// Check max width
1278-
//std::cout << "update max width " << insertion << std::endl;
1278+
//std::cout << "- update max width " << insertion << std::endl;
12791279
if (insertion.x1 > insertion.x1_max) {
12801280
return;
12811281
}
12821282

12831283
// Update insertion.y2 and insertion.z2 with respect to defect intersections.
1284-
//std::cout << "update y2 defects " << insertion << std::endl;
1284+
//std::cout << "- update y2 defects " << insertion << std::endl;
12851285
bool y2_fixed = (insertion.z2 == 2 || (insertion.df == 2 && parent.z2 == 2));
12861286

12871287
for (;;) {
@@ -1369,7 +1369,7 @@ void BranchingScheme::update(
13691369
}
13701370

13711371
// Check top soft-trim.
1372-
//std::cout << "update top soft-trim " << insertion << std::endl;
1372+
//std::cout << "- update top soft-trim " << insertion << std::endl;
13731373
if (insertion.y2 > h) {
13741374
if (insertion.y2 == h_physical) {
13751375
} else if (insertion.y2 < h_physical) {
@@ -1390,7 +1390,7 @@ void BranchingScheme::update(
13901390
}
13911391

13921392
// Increase height if too close from border
1393-
//std::cout << "update y border " << insertion << std::endl;
1393+
//std::cout << "- update y border " << insertion << std::endl;
13941394
if (insertion.y2 < h_physical
13951395
&& min_waste > 0
13961396
&& insertion.y2 + cut_thickness + min_waste > h_physical) {
@@ -1438,7 +1438,7 @@ void BranchingScheme::update(
14381438
}
14391439

14401440
// Check max height
1441-
//std::cout << "update y max " << insertion << std::endl;
1441+
//std::cout << "- update y max " << insertion << std::endl;
14421442
if (insertion.y2 > insertion.y2_max) {
14431443
return;
14441444
}
@@ -1596,9 +1596,6 @@ Solution BranchingScheme::to_solution(
15961596

15971597
const Node* current_node = descendents[node_pos];
15981598
//std::cout << *current_node << std::endl;
1599-
BinPos i = current_node->number_of_bins - 1;
1600-
BinTypeId bin_type_id = instance().bin_type_id(i);
1601-
const BinType& bin_type = instance().bin_type(bin_type_id);
16021599
bool has_item = (current_node->item_type_id_1 != -1 || current_node->item_type_id_2 != -1);
16031600
Depth df_next = (node_pos < (SolutionNodeId)descendents.size() - 1)?
16041601
descendents[node_pos + 1]->df: -1;
@@ -1609,12 +1606,18 @@ Solution BranchingScheme::to_solution(
16091606
(instance().parameters().number_of_stages == 3 && current_node->first_stage_orientation == CutOrientation::Vertical)
16101607
|| (instance().parameters().number_of_stages == 2 && current_node->first_stage_orientation == CutOrientation::Horizontal))?
16111608
CutOrientation::Vertical: CutOrientation::Horizontal;
1612-
BinTypeId bin_type_id = instance().bin_type_id(number_of_bins);
1609+
number_of_bins++;
1610+
BinTypeId bin_type_id = instance().bin_type_id(number_of_bins - 1);
16131611
solution_builder.add_bin(
16141612
bin_type_id,
16151613
1,
16161614
cut_orientation);
1617-
number_of_bins++;
1615+
1616+
const BinType& bin_type = instance().bin_type(bin_type_id);
1617+
if (bin_type.left_trim_type == TrimType::Soft
1618+
&& bin_type.left_trim > 0) {
1619+
solution_builder.add_node(1, bin_type.left_trim);
1620+
}
16181621
}
16191622

16201623
// Create a new first-level sub-plate.
@@ -1630,6 +1633,13 @@ Solution BranchingScheme::to_solution(
16301633
subplate1_curr_x1 = descendents[node_pos_2]->x1_curr;
16311634
}
16321635
solution_builder.add_node(1, subplate1_curr_x1);
1636+
1637+
BinTypeId bin_type_id = instance().bin_type_id(number_of_bins - 1);
1638+
const BinType& bin_type = instance().bin_type(bin_type_id);
1639+
if (bin_type.bottom_trim_type == TrimType::Soft
1640+
&& bin_type.bottom_trim > 0) {
1641+
solution_builder.add_node(2, bin_type.bottom_trim);
1642+
}
16331643
}
16341644
}
16351645

src/rectangleguillotine/instance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ std::istream& packingsolver::rectangleguillotine::operator>>(
5151
{
5252
std::string token;
5353
in >> token;
54-
if (token == "s" || token == "H" || token == "hard" || token == "Hard" || token == "0") {
54+
if (token == "h" || token == "H" || token == "hard" || token == "Hard" || token == "0") {
5555
trim_type = TrimType::Hard;
5656
} else if (token == "s" || token == "S" || token == "soft" || token == "Soft" || token == "1") {
5757
trim_type = TrimType::Soft;

src/rectangleguillotine/solution_builder.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void SolutionBuilder::add_bin(
106106
node.l = 0;
107107
node.r = bin_type.left_trim;
108108
node.b = (!bottom_trim)? 0: bin_type.bottom_trim;
109-
node.t = bin_type.rect.h - ((!top_trim)? 0: bin_type.top_trim);
109+
node.t = (!top_trim)? bin_type.rect.h: bin_type.rect.h - bin_type.top_trim;
110110
node.item_type_id = -1;
111111
root.children.push_back(bin.nodes.size());
112112
bin.nodes.push_back(node);
@@ -117,7 +117,7 @@ void SolutionBuilder::add_bin(
117117
node.d = -1;
118118
node.f = 0;
119119
node.l = (!left_trim)? 0: bin_type.left_trim;
120-
node.r = bin_type.rect.w - ((!right_trim)? 0: bin_type.right_trim);
120+
node.r = (!right_trim)? bin_type.rect.w: bin_type.rect.w - bin_type.right_trim;
121121
node.b = 0;
122122
node.t = bin_type.bottom_trim;
123123
node.item_type_id = -1;
@@ -132,7 +132,7 @@ void SolutionBuilder::add_bin(
132132
node.l = bin_type.rect.w - bin_type.right_trim;
133133
node.r = bin_type.rect.w;
134134
node.b = (!bottom_trim)? 0: bin_type.bottom_trim;
135-
node.t = bin_type.rect.h - ((!top_trim)? 0: bin_type.top_trim);
135+
node.t = (!top_trim)? bin_type.rect.h: bin_type.rect.h - bin_type.top_trim;
136136
node.item_type_id = -1;
137137
root.children.push_back(bin.nodes.size());
138138
bin.nodes.push_back(node);
@@ -143,7 +143,7 @@ void SolutionBuilder::add_bin(
143143
node.d = -1;
144144
node.f = 0;
145145
node.l = (!left_trim)? 0: bin_type.left_trim;
146-
node.r = bin_type.rect.w - ((!right_trim)? 0: bin_type.right_trim);
146+
node.r = (!right_trim)? bin_type.rect.w: bin_type.rect.w - bin_type.right_trim;
147147
node.b = bin_type.rect.h - bin_type.top_trim;
148148
node.t = bin_type.rect.h;
149149
node.item_type_id = -1;
@@ -155,9 +155,9 @@ void SolutionBuilder::add_bin(
155155
node.d = 0;
156156
node.f = 0;
157157
node.l = (!left_trim)? 0: bin_type.left_trim;
158-
node.r = bin_type.rect.w - ((!right_trim)? 0: bin_type.right_trim);
158+
node.r = (!right_trim)? bin_type.rect.w: bin_type.rect.w - bin_type.right_trim;
159159
node.b = (!bottom_trim)? 0: bin_type.bottom_trim;
160-
node.t = bin_type.rect.h - ((!top_trim)? 0: bin_type.top_trim);
160+
node.t = (!top_trim)? bin_type.rect.h: bin_type.rect.h - bin_type.top_trim;
161161
node.item_type_id = -1;
162162
root.children.push_back(bin.nodes.size());
163163
bin.nodes.push_back(node);

test/rectangleguillotine/branching_scheme/branching_scheme_test.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ INSTANTIATE_TEST_SUITE_P(
117117
fs::path("data") / "rectangleguillotine" / "tests" / "knapsack_soft_trims_3evo" / "items.csv",
118118
fs::path("data") / "rectangleguillotine" / "tests" / "knapsack_soft_trims_3evo" / "parameters.csv",
119119
fs::path("data") / "rectangleguillotine" / "tests" / "knapsack_soft_trims_3evo" / "solution.csv",
120+
}, {
121+
fs::path("data") / "rectangleguillotine" / "users" / "2025-03-04" / "bins.csv",
122+
fs::path(""),
123+
fs::path("data") / "rectangleguillotine" / "users" / "2025-03-04" / "items.csv",
124+
fs::path("data") / "rectangleguillotine" / "users" / "2025-03-04" / "parameters.csv",
125+
fs::path("data") / "rectangleguillotine" / "users" / "2025-03-04" / "solution.csv",
120126
}}));
121127

122128

0 commit comments

Comments
 (0)