16#include "absl/strings/numbers.h"
17#include "absl/strings/str_split.h"
32 for (
const std::string& line :
FileLines(filename)) {
33 ProcessLine(line, format, data);
34 if (section_ ==
ERROR)
return false;
36 return section_ ==
END;
39void ScpParser::ProcessLine(
const std::string& line, Format format,
42 const std::vector<std::string> words =
43 absl::StrSplit(line, absl::ByAnyChar(
" :\t\r"), absl::SkipEmpty());
46 if (words.size() != 2) {
47 LogError(line,
"Problem reading the size of the problem");
50 const int num_rows = strtoint32(words[0]);
51 const int num_columns = strtoint32(words[1]);
76 const int num_items = words.size();
78 LogError(line,
"Too many cost items");
81 for (
int i = 0; i < num_items; ++i) {
93 LogError(line,
"Wrong state in the loader");
97 ABSL_FALLTHROUGH_INTENDED;
99 if (words.size() < 2) {
100 LogError(line,
"Column declaration too short");
103 const int cost = strtoint32(words[0]);
105 const int num_items = strtoint32(words[1]);
106 if (words.size() != 2 + num_items) {
107 LogError(line,
"Mistatch in column declaration");
110 for (
int i = 0; i < num_items; ++i) {
111 const int row = strtoint32(words[i + 2]) - 1;
121 if (words.size() != 3) {
122 LogError(line,
"Column declaration does not contain 3 rows");
126 for (
int i = 0; i < 3; ++i) {
127 const int row = strtoint32(words[i]) - 1;
140 if (words.size() != 1) {
141 LogError(line,
"The header of a column should be one number");
144 remaining_ = strtoint32(words[0]);
149 const int num_items = words.size();
150 if (num_items > remaining_) {
151 LogError(line,
"Too many columns in a row declaration");
154 for (
const std::string& w : words) {
156 const int column = strtoint32(w) - 1;
159 if (remaining_ == 0) {
170 if (words.size() != 1) {
171 LogError(line,
"The header of a column should be one number");
186void ScpParser::LogError(
const std::string& line,
const std::string&
message) {
187 LOG(
ERROR) <<
"Error on line " << line_ <<
": " <<
message <<
"(" << line
192int ScpParser::strtoint32(
const std::string& word) {
194 CHECK(absl::SimpleAtoi(word, &result));
198int64 ScpParser::strtoint64(
const std::string& word) {
200 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)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...