Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #101

Merged
merged 2 commits into from
Oct 23, 2024
Merged

Dev #101

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_1.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,50
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_1.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_10.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,130
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_10.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_11.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,130
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_11.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_12.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,61
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_12.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_13.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,50
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_13.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_14.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,92
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_14.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_15.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,104
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_15.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_16.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,87
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_16.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_17.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,87
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_17.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_18.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,104
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_18.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_19.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,92
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_19.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_2.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,50
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_2.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_20.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,130
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_20.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_21.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,50
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_21.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_22.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,61
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_22.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_23.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,130
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_23.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_24.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,92
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_24.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_25.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,130
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_25.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_3.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,61
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_3.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_4.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,61
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_4.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_5.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,87
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_5.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_6.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,87
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_6.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_7.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,104
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_7.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_8.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,92
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_8.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions data/rectangle/long2020/Instance_9.txt_parameters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NAME,VALUE
max1cut,104
1 change: 0 additions & 1 deletion data/rectangle/long2020/Instance_9.txt_parameters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions include/packingsolver/irregular/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ struct Shape
const std::string& file_path) const;
};

Shape build_polygon_shape(const std::vector<Point>& points);

double compute_svg_factor(double width);

std::string to_svg(
Expand Down
5 changes: 3 additions & 2 deletions scripts/convert_rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ def convert_long2020(filename):
write_dict(bins, filename + "_bins.csv")
write_dict(items, filename + "_items.csv")
p = os.path.join("data", "rectangle", filename.replace(" ", "_"))
with open(p + "_parameters.txt", "w") as params_file:
params_file.write("--max1cut " + str(max1cut) + "\n")
with open(p + "_parameters.csv", "w") as params_file:
params_file.write("NAME,VALUE\n")
params_file.write("max1cut," + str(max1cut) + "\n")


###############################################################################
Expand Down
164 changes: 22 additions & 142 deletions src/irregular/branching_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,152 +155,32 @@ BranchingScheme::BranchingScheme(
BranchingSchemeBinType& bb_bin_type_x = bin_types_[(int)Direction::LeftToRightThenBottomToTop][bin_type_id];
BranchingSchemeBinType& bb_bin_type_y = bin_types_[(int)Direction::BottomToTopThenLeftToRight][bin_type_id];

// Bin borders.
Shape shape_border;
ElementPos element_0_pos = 0;
for (ElementPos element_pos = 0;
element_pos < bin_type.shape.elements.size();
++element_pos) {
const ShapeElement& shape_element = bin_type.shape.elements[element_pos];
if (shape_element.start.x == bin_type.x_min) {
element_0_pos = element_pos;
break;
}
}
// 0: left; 1: bottom; 2: right; 3: top.
const ShapeElement& element_0 = bin_type.shape.elements[element_0_pos];
int start_border = (element_0.start.y == bin_type.y_min)? 1: 0;
LengthDbl start_coordinate = element_0.start.y;
for (ElementPos element_pos = 0;
element_pos < bin_type.shape.elements.size();
++element_pos) {
const ShapeElement& element = bin_type.shape.elements[(element_0_pos + element_pos) % bin_type.shape.elements.size()];
//std::cout << "element_pos " << ((element_0_pos + element_pos) % bin_type.shape.elements.size()) << " / " << bin_type.shape.elements.size() << ": " << element.to_string() << std::endl;
shape_border.elements.push_back(element);
bool close = false;
if (start_border == 0) {
if (equal(element.end.x, bin_type.x_min)) {
ShapeElement new_element;
new_element.type = ShapeElementType::LineSegment;
new_element.start = element.end;
new_element.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element);
close = true;
start_border = 0;
} else if (equal(element.end.y, bin_type.y_min)) {
ShapeElement new_element_1;
new_element_1.type = ShapeElementType::LineSegment;
new_element_1.start = element.end;
new_element_1.end = {bin_type.x_min, bin_type.y_min};
shape_border.elements.push_back(new_element_1);
ShapeElement new_element_2;
new_element_2.type = ShapeElementType::LineSegment;
new_element_2.start = new_element_1.end;
new_element_2.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element_2);
close = true;
start_border = 1;
}
} else if (start_border == 1) {
if (equal(element.end.y, bin_type.y_min)) {
ShapeElement new_element;
new_element.type = ShapeElementType::LineSegment;
new_element.start = element.end;
new_element.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element);
close = true;
start_border = 1;
} else if (equal(element.end.x, bin_type.x_max)) {
ShapeElement new_element_1;
new_element_1.type = ShapeElementType::LineSegment;
new_element_1.start = element.end;
new_element_1.end = {bin_type.x_max, bin_type.y_min};
shape_border.elements.push_back(new_element_1);
ShapeElement new_element_2;
new_element_2.type = ShapeElementType::LineSegment;
new_element_2.start = new_element_1.end;
new_element_2.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element_2);
close = true;
start_border = 2;
}
} else if (start_border == 2) {
if (equal(element.end.x, bin_type.x_max)) {
ShapeElement new_element;
new_element.type = ShapeElementType::LineSegment;
new_element.start = element.end;
new_element.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element);
close = true;
start_border = 2;
} else if (equal(element.end.y, bin_type.y_max)) {
ShapeElement new_element_1;
new_element_1.type = ShapeElementType::LineSegment;
new_element_1.start = element.end;
new_element_1.end = {bin_type.x_max, bin_type.y_max};
shape_border.elements.push_back(new_element_1);
ShapeElement new_element_2;
new_element_2.type = ShapeElementType::LineSegment;
new_element_2.start = new_element_1.end;
new_element_2.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element_2);
close = true;
start_border = 3;
}
} else if (start_border == 3) {
if (equal(element.end.y, bin_type.y_max)) {
ShapeElement new_element;
new_element.type = ShapeElementType::LineSegment;
new_element.start = element.end;
new_element.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element);
close = true;
start_border = 3;
} else if (equal(element.end.x, bin_type.x_min)) {
ShapeElement new_element_1;
new_element_1.type = ShapeElementType::LineSegment;
new_element_1.start = element.end;
new_element_1.end = {bin_type.x_min, bin_type.y_max};
shape_border.elements.push_back(new_element_1);
ShapeElement new_element_2;
new_element_2.type = ShapeElementType::LineSegment;
new_element_2.start = new_element_1.end;
new_element_2.end = shape_border.elements[0].start;
shape_border.elements.push_back(new_element_2);
close = true;
start_border = 0;
}
}
// New shape.
if (close) {
Shape reversed_shape = shape_border.reverse();
{
Shape cleaned_shape = clean_shape(reversed_shape);
//std::cout << cleaned_shape.to_string(0) << std::endl;
if (cleaned_shape.elements.size() > 2) {
auto trapezoids = polygon_trapezoidation(cleaned_shape);
for (const GeneralizedTrapezoid& trapezoid: trapezoids) {
UncoveredTrapezoid defect(
-1,
trapezoid.clean().inflate(instance.parameters().item_bin_minimum_spacing));
bb_bin_type_x.defects.push_back(defect);
}
for (const Shape& shape_border: borders(bin_type.shape)) {
{
Shape cleaned_shape = clean_shape(shape_border);
//std::cout << cleaned_shape.to_string(0) << std::endl;
if (cleaned_shape.elements.size() > 2) {
auto trapezoids = polygon_trapezoidation(cleaned_shape);
for (const GeneralizedTrapezoid& trapezoid: trapezoids) {
UncoveredTrapezoid defect(
-1,
trapezoid.clean().inflate(instance.parameters().item_bin_minimum_spacing));
bb_bin_type_x.defects.push_back(defect);
}
}
{
Shape sym_shape = reversed_shape.axial_symmetry_identity_line();
Shape cleaned_shape = clean_shape(sym_shape);
if (cleaned_shape.elements.size() > 2) {
auto trapezoids = polygon_trapezoidation(cleaned_shape);
for (const GeneralizedTrapezoid& trapezoid: trapezoids) {
UncoveredTrapezoid defect(
-1,
trapezoid.clean().inflate(instance.parameters().item_bin_minimum_spacing));
bb_bin_type_y.defects.push_back(defect);
}
}
{
Shape sym_shape = shape_border.axial_symmetry_identity_line();
Shape cleaned_shape = clean_shape(sym_shape);
if (cleaned_shape.elements.size() > 2) {
auto trapezoids = polygon_trapezoidation(cleaned_shape);
for (const GeneralizedTrapezoid& trapezoid: trapezoids) {
UncoveredTrapezoid defect(
-1,
trapezoid.clean().inflate(instance.parameters().item_bin_minimum_spacing));
bb_bin_type_y.defects.push_back(defect);
}
}
shape_border.elements.clear();
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/irregular/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,22 @@ void Shape::write_svg(
file << "</svg>" << std::endl;
}

Shape packingsolver::irregular::build_polygon_shape(
const std::vector<Point>& points)
{
Shape shape;
ElementPos pos_prev = points.size() - 1;
for (ElementPos pos = 0; pos < (ElementPos)points.size(); ++pos) {
ShapeElement element;
element.type = ShapeElementType::LineSegment;
element.start = points[pos_prev];
element.end = points[pos];
shape.elements.push_back(element);
pos_prev = pos;
}
return shape;
}

double irregular::compute_svg_factor(
double width)
{
Expand Down
Loading
Loading