19#include "absl/strings/numbers.h"
20#include "absl/strings/str_split.h"
21#include "absl/strings/string_view.h"
29 : num_dimensions_(-1),
30 load_status_(NOT_STARTED),
36 if (load_status_ != NOT_STARTED) {
43 ProcessNew2BpLine(
line, instance);
44 if (load_status_ == PARSING_FINISHED) {
48 return num_items_ == problem_.items_size() && num_items_ > 0;
51void BinPacking2dParser::ProcessNew2BpLine(
const std::string&
line,
53 const std::vector<std::string> words =
54 absl::StrSplit(
line, absl::ByAnyChar(
" :\t\r"), absl::SkipEmpty());
55 if (words.size() == 3 && words[1] ==
"PROBLEM" && words[2] ==
"CLASS") {
58 if (load_status_ == NOT_STARTED && instances_seen_ == instance) {
59 load_status_ = INSTANCE_FOUND;
60 }
else if (instances_seen_ > instance) {
61 load_status_ = PARSING_FINISHED;
65 if (load_status_ == INSTANCE_FOUND) {
68 }
else if (words.size() == 2 || words[2] ==
"H(I),W(I),I=1,...,N") {
70 CHECK_NE(num_items_, 0);
71 CHECK_LT(problem_.items_size(), num_items_);
72 MultipleDimensionsBinPackingItem* item = problem_.add_items();
73 MultipleDimensionsBinPackingShape* shape = item->add_shapes();
75 CHECK(absl::SimpleAtoi(words[0], &dim));
76 shape->add_dimensions(dim);
77 CHECK(absl::SimpleAtoi(words[1], &dim));
78 shape->add_dimensions(dim);
80 }
else if (words[1] ==
"N.") {
81 CHECK(absl::SimpleAtoi(words[0], &num_items_));
82 }
else if (words[2] ==
"RELATIVE") {
85 CHECK(absl::SimpleAtoi(words[0], &local_instance));
86 CHECK_EQ(local_instance, (instance - 1) % 10 + 1);
87 }
else if (words[2] ==
"HBIN,WBIN") {
88 MultipleDimensionsBinPackingShape* box_shape =
89 problem_.mutable_box_shape();
91 CHECK(absl::SimpleAtoi(words[0], &dim));
92 box_shape->add_dimensions(dim);
93 CHECK(absl::SimpleAtoi(words[1], &dim));
94 box_shape->add_dimensions(dim);
bool Load2BPFile(absl::string_view file_name, int instance)
In SWIG mode, we don't want anything besides these top-level includes.