21 #include "absl/strings/match.h"
22 #include "absl/strings/str_split.h"
34 : sections_({{
"VEHICLE", VEHICLE}, {
"CUSTOMER", CUSTOMER}}) {
40 return ParseFile(file_name);
44 const std::string& archive_name) {
46 if (!absl::StartsWith(archive_name,
"/")) {
49 const std::string fake_zip_path =
"/zip" + archive_name;
50 std::shared_ptr<zipfile::ZipArchive> fake_zip_closer(
52 if (
nullptr == fake_zip_closer)
return false;
53 const std::string zip_filename =
file::JoinPath(fake_zip_path, file_name);
54 return ParseFile(zip_filename);
57 void SolomonParser::Initialize() {
63 time_windows_.clear();
64 service_times_.clear();
69 bool SolomonParser::ParseFile(
const std::string& file_name) {
70 for (
const std::string&
line :
72 const std::vector<std::string> words =
73 absl::StrSplit(
line, absl::ByAnyChar(
" :\t"), absl::SkipEmpty());
75 if (words.empty())
continue;
84 if (words.size() != 2)
return false;
86 if (vehicles_ < 0)
return false;
88 if (capacity_ < 0)
return false;
94 std::vector<int64_t> values;
95 for (
int i = 1; i < words.size(); ++i) {
98 if (
value < 0)
return false;
99 values.push_back(
value);
101 coordinates_.push_back({values[0], values[1]});
102 demands_.push_back(values[2]);
103 time_windows_.push_back({values[3], values[4]});
104 service_times_.push_back(values[5]);
110 LOG(ERROR) <<
"Reading data outside section";
128 LOG(ERROR) <<
"Unknown section: " << section_;
134 return section_ == CUSTOMER;
bool LoadFile(const std::string &file_name)
std::string JoinPath(absl::string_view path1, absl::string_view path2)
const Collection::value_type::second_type & FindWithDefault(const Collection &collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
Collection of objects used to extend the Constraint Solver library.
int64_t ParseLeadingInt64Value(const char *str, int64_t deflt)
int32_t ParseLeadingInt32Value(const char *str, int32_t deflt)
std::shared_ptr< ZipArchive > OpenZipArchive(absl::string_view path, const ZipFileOptions &options)