18 #include "absl/strings/numbers.h"
19 #include "absl/strings/str_split.h"
34 for (
const std::string& line :
FileLines(filename)) {
35 ProcessLine(line, format, data);
36 if (section_ ==
ERROR)
return false;
38 return section_ ==
END;
41 void ScpParser::ProcessLine(
const std::string& line, Format format,
44 const std::vector<std::string> words =
45 absl::StrSplit(line, absl::ByAnyChar(
" :\t\r"), absl::SkipEmpty());
48 if (words.size() != 2) {
49 LogError(line,
"Problem reading the size of the problem");
52 const int num_rows = strtoint32(words[0]);
53 const int num_columns = strtoint32(words[1]);
78 const int num_items = words.size();
80 LogError(line,
"Too many cost items");
83 for (
int i = 0; i < num_items; ++i) {
95 LogError(line,
"Wrong state in the loader");
99 ABSL_FALLTHROUGH_INTENDED;
101 if (words.size() < 2) {
102 LogError(line,
"Column declaration too short");
105 const int cost = strtoint32(words[0]);
107 const int num_items = strtoint32(words[1]);
108 if (words.size() != 2 + num_items) {
109 LogError(line,
"Mistatch in column declaration");
112 for (
int i = 0; i < num_items; ++i) {
113 const int row = strtoint32(words[i + 2]) - 1;
123 if (words.size() != 3) {
124 LogError(line,
"Column declaration does not contain 3 rows");
128 for (
int i = 0; i < 3; ++i) {
129 const int row = strtoint32(words[i]) - 1;
142 if (words.size() != 1) {
143 LogError(line,
"The header of a column should be one number");
146 remaining_ = strtoint32(words[0]);
151 const int num_items = words.size();
152 if (num_items > remaining_) {
153 LogError(line,
"Too many columns in a row declaration");
156 for (
const std::string& w : words) {
158 const int column = strtoint32(w) - 1;
161 if (remaining_ == 0) {
172 if (words.size() != 1) {
173 LogError(line,
"The header of a column should be one number");
188 void ScpParser::LogError(
const std::string& line,
const std::string&
message) {
189 LOG(
ERROR) <<
"Error on line " << line_ <<
": " <<
message <<
"(" << line
194 int ScpParser::strtoint32(
const std::string& word) {
196 CHECK(absl::SimpleAtoi(word, &result));
200 int64_t ScpParser::strtoint64(
const std::string& word) {
202 CHECK(absl::SimpleAtoi(word, &result));
void SetProblemSize(int num_rows, int num_columns)
void SetColumnCost(int column_id, int cost)
void AddRowInColumn(int row, int column)
void set_is_set_partitioning(bool v)
bool LoadProblem(const std::string &filename, Format format, ScpData *data)
Collection of objects used to extend the Constraint Solver library.