Skip to content

Commit c6258bc

Browse files
committed
Implement defect reading from JSON input in irregular solver
1 parent 9739113 commit c6258bc

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

scripts/visualize_irregular.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def shape_path(path_x, path_y, shape, is_hole=False):
8181
for defect in (solution_bin["defects"]
8282
if "defects" in solution_bin else []):
8383
shape_path(defects_x[bin_pos], defects_y[bin_pos], defect["shape"])
84-
for hole in defect["holes"]:
84+
for hole in (defect["holes"]
85+
if "holes" in defect else []):
8586
shape_path(defects_x[bin_pos], defects_y[bin_pos], hole, True)
8687
for solution_item in solution_bin["items"]:
8788
for item_shape in solution_item["item_shapes"]:

scripts/visualize_irregular_instance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def shape_path(path_x, path_y, shape, is_hole=False):
8484
defects_x[bin_type_id],
8585
defects_y[bin_type_id],
8686
defect["elements"])
87-
for hole in defect["holes"]:
87+
for hole in (defect["holes"]
88+
if "holes" in defect else []):
8889
shape_path(
8990
defects_x[bin_type_id],
9091
defects_y[bin_type_id],

src/irregular/instance_builder.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,46 @@ void InstanceBuilder::read(
344344
if (json_item.contains("copies_min"))
345345
copies_min = json_item["copies_min"];
346346

347-
add_bin_type(shape, cost, copies, copies_min);
347+
BinTypeId bin_type_id = add_bin_type(shape, cost, copies, copies_min);
348+
349+
// Read defects.
350+
if (json_item.contains("defects")) {
351+
for (auto it_defect = json_item["defects"].begin();
352+
it_defect != json_item["defects"].end();
353+
++it_defect) {
354+
auto json_defect = *it_defect;
355+
356+
// Read type.
357+
std::cout << "read type" << std::endl;
358+
DefectTypeId defect_type = -1;
359+
if (json_defect.contains("defect_type"))
360+
defect_type = json_defect["defect_type"];
361+
362+
// Read shape.
363+
std::cout << "read shape" << std::endl;
364+
Shape shape = read_shape(json_defect);
365+
366+
// Read holes.
367+
std::cout << "read holes" << std::endl;
368+
std::vector<Shape> holes;
369+
if (json_defect.contains("holes")) {
370+
for (auto it_hole = json_defect["holes"].begin();
371+
it_hole != json_defect["holes"].end();
372+
++it_hole) {
373+
auto json_hole = *it_hole;
374+
Shape hole = read_shape(json_hole);
375+
holes.push_back(hole);
376+
}
377+
}
378+
379+
// Add defect.
380+
add_defect(
381+
bin_type_id,
382+
defect_type,
383+
shape,
384+
holes);
385+
}
386+
}
348387
}
349388

350389
// Read item types.

0 commit comments

Comments
 (0)