20 #include "absl/strings/numbers.h"
21 #include "absl/strings/str_split.h"
22 #include "ortools/packing/vector_bin_packing.pb.h"
32 load_status_ = DIMENSION_SECTION;
34 if (load_status_ == ERROR_FOUND)
break;
39 if (load_status_ == ERROR_FOUND) {
43 return vbp_.item_size() == num_declared_items_;
46 void VbpParser::ReportError(
const std::string&
line) {
47 LOG(ERROR) <<
"Error: status = " << load_status_ <<
", line = " <<
line;
48 load_status_ = ERROR_FOUND;
51 void VbpParser::ProcessLine(
const std::string&
line) {
52 const std::vector<std::string> words =
53 absl::StrSplit(
line, absl::ByAnyChar(
" :\t\r"), absl::SkipEmpty());
55 if (words.empty())
return;
57 switch (load_status_) {
59 LOG(FATAL) <<
"Should not be here";
61 case DIMENSION_SECTION: {
62 if (words.size() != 1) {
66 num_resources_ = strtoint32(words[0]);
67 load_status_ = BIN_SECTION;
71 if (words.size() != num_resources_) {
75 for (
const std::string& dim_str : words) {
76 vbp_.add_resource_capacity(strtoint64(dim_str));
78 load_status_ = NUMBER_OF_ITEMS_SECTION;
81 case NUMBER_OF_ITEMS_SECTION: {
82 if (words.size() != 1) {
86 num_declared_items_ = strtoint32(words[0]);
87 load_status_ = ITEM_SECTION;
91 if (words.size() != num_resources_ + 1) {
95 Item*
const item = vbp_.add_item();
96 for (
int i = 0; i < num_resources_; ++i) {
97 item->add_resource_usage(strtoint64(words[i]));
99 item->set_num_copies(strtoint32(words[num_resources_]));
100 item->set_max_number_of_copies_per_bin(item->num_copies());
109 int VbpParser::strtoint32(
const std::string& word) {
111 CHECK(absl::SimpleAtoi(word, &result));
115 int64_t VbpParser::strtoint64(
const std::string& word) {
117 CHECK(absl::SimpleAtoi(word, &result));
bool ParseFile(const std::string &data_filename)
Collection of objects used to extend the Constraint Solver library.