diff --git a/scripts/visualize_irregular.py b/scripts/visualize_irregular.py index 601acf3d9..4595610b5 100644 --- a/scripts/visualize_irregular.py +++ b/scripts/visualize_irregular.py @@ -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"]: diff --git a/scripts/visualize_irregular_instance.py b/scripts/visualize_irregular_instance.py index 4e0dba3ef..b6c6f910f 100644 --- a/scripts/visualize_irregular_instance.py +++ b/scripts/visualize_irregular_instance.py @@ -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], diff --git a/src/irregular/instance_builder.cpp b/src/irregular/instance_builder.cpp index 98df7ba34..310da9970 100644 --- a/src/irregular/instance_builder.cpp +++ b/src/irregular/instance_builder.cpp @@ -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 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.