19 #include "absl/strings/numbers.h"
20 #include "absl/strings/str_split.h"
28 : num_dimensions_(-1),
29 load_status_(NOT_STARTED),
35 if (load_status_ != NOT_STARTED) {
42 ProcessNew2BpLine(
line, instance);
43 if (load_status_ == PARSING_FINISHED) {
47 return num_items_ == problem_.items_size() && num_items_ > 0;
50 void BinPacking2dParser::ProcessNew2BpLine(
const std::string&
line,
52 const std::vector<std::string> words =
53 absl::StrSplit(
line, absl::ByAnyChar(
" :\t\r"), absl::SkipEmpty());
54 if (words.size() == 3 && words[1] ==
"PROBLEM" && words[2] ==
"CLASS") {
57 if (load_status_ == NOT_STARTED && instances_seen_ == instance) {
58 load_status_ = INSTANCE_FOUND;
59 }
else if (instances_seen_ > instance) {
60 load_status_ = PARSING_FINISHED;
64 if (load_status_ == INSTANCE_FOUND) {
67 }
else if (words.size() == 2 || words[2] ==
"H(I),W(I),I=1,...,N") {
69 CHECK_NE(num_items_, 0);
70 CHECK_LT(problem_.items_size(), num_items_);
71 MultipleDimensionsBinPackingItem* item = problem_.add_items();
72 MultipleDimensionsBinPackingShape* shape = item->add_shapes();
74 CHECK(absl::SimpleAtoi(words[0], &dim));
75 shape->add_dimensions(dim);
76 CHECK(absl::SimpleAtoi(words[1], &dim));
77 shape->add_dimensions(dim);
79 }
else if (words[1] ==
"N.") {
80 CHECK(absl::SimpleAtoi(words[0], &num_items_));
81 }
else if (words[2] ==
"RELATIVE") {
84 CHECK(absl::SimpleAtoi(words[0], &local_instance));
85 CHECK_EQ(local_instance, (instance - 1) % 10 + 1);
86 }
else if (words[2] ==
"HBIN,WBIN") {
87 MultipleDimensionsBinPackingShape* box_shape =
88 problem_.mutable_box_shape();
90 CHECK(absl::SimpleAtoi(words[0], &dim));
91 box_shape->add_dimensions(dim);
92 CHECK(absl::SimpleAtoi(words[1], &dim));
93 box_shape->add_dimensions(dim);
bool Load2BPFile(const std::string &file_name, int instance)
Collection of objects used to extend the Constraint Solver library.