Skip to content
Merged
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
3 changes: 2 additions & 1 deletion scripts/visualize_irregular.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def shape_path(path_x, path_y, shape, is_hole=False):
for defect in (solution_bin["defects"]
if "defects" in solution_bin else []):
shape_path(defects_x[bin_pos], defects_y[bin_pos], defect["shape"])
for hole in defect["holes"]:
for hole in (defect["holes"]
if "holes" in defect else []):
shape_path(defects_x[bin_pos], defects_y[bin_pos], hole, True)
for solution_item in solution_bin["items"]:
for item_shape in solution_item["item_shapes"]:
Expand Down
3 changes: 2 additions & 1 deletion scripts/visualize_irregular_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def shape_path(path_x, path_y, shape, is_hole=False):
defects_x[bin_type_id],
defects_y[bin_type_id],
defect["elements"])
for hole in defect["holes"]:
for hole in (defect["holes"]
if "holes" in defect else []):
shape_path(
defects_x[bin_type_id],
defects_y[bin_type_id],
Expand Down
41 changes: 40 additions & 1 deletion src/irregular/instance_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,46 @@ void InstanceBuilder::read(
if (json_item.contains("copies_min"))
copies_min = json_item["copies_min"];

add_bin_type(shape, cost, copies, copies_min);
BinTypeId bin_type_id = add_bin_type(shape, cost, copies, copies_min);

// Read defects.
if (json_item.contains("defects")) {
for (auto it_defect = json_item["defects"].begin();
it_defect != json_item["defects"].end();
++it_defect) {
auto json_defect = *it_defect;

// Read type.
std::cout << "read type" << std::endl;
DefectTypeId defect_type = -1;
if (json_defect.contains("defect_type"))
defect_type = json_defect["defect_type"];

// Read shape.
std::cout << "read shape" << std::endl;
Shape shape = read_shape(json_defect);

// Read holes.
std::cout << "read holes" << std::endl;
std::vector<Shape> holes;
if (json_defect.contains("holes")) {
for (auto it_hole = json_defect["holes"].begin();
it_hole != json_defect["holes"].end();
++it_hole) {
auto json_hole = *it_hole;
Shape hole = read_shape(json_hole);
holes.push_back(hole);
}
}

// Add defect.
add_defect(
bin_type_id,
defect_type,
shape,
holes);
}
}
}

// Read item types.
Expand Down
Loading