21#include "absl/strings/match.h"
22#include "absl/strings/str_split.h"
23#include "absl/strings/string_view.h"
35 : sections_({{
"VEHICLE", VEHICLE}, {
"CUSTOMER", CUSTOMER}}) {
41 return ParseFile(file_name);
45 const std::string& archive_name) {
47 if (!absl::StartsWith(archive_name,
"/")) {
50 const std::string fake_zip_path =
"/zip" + archive_name;
51 std::shared_ptr<zipfile::ZipArchive> fake_zip_closer(
53 if (
nullptr == fake_zip_closer)
return false;
54 const std::string zip_filename =
file::JoinPath(fake_zip_path, file_name);
55 return ParseFile(zip_filename);
58void SolomonParser::Initialize() {
64 time_windows_.clear();
65 service_times_.clear();
70bool SolomonParser::ParseFile(
const std::string& file_name) {
71 for (
const std::string&
line :
73 const std::vector<std::string> words =
74 absl::StrSplit(
line, absl::ByAnyChar(
" :\t"), absl::SkipEmpty());
76 if (words.empty())
continue;
85 if (words.size() != 2)
return false;
87 if (vehicles_ < 0)
return false;
89 if (capacity_ < 0)
return false;
95 std::vector<int64_t> values;
96 for (
int i = 1;
i < words.size(); ++
i) {
99 if (
value < 0)
return false;
100 values.push_back(
value);
102 coordinates_.push_back({values[0], values[1]});
103 demands_.push_back(values[2]);
104 time_windows_.push_back({values[3], values[4]});
105 service_times_.push_back(values[5]);
111 LOG(ERROR) <<
"Reading data outside section";
129 LOG(ERROR) <<
"Unknown section: " << section_;
135 return section_ == CUSTOMER;
bool LoadFile(const std::string &file_name)
Loads instance from a file.
const MapUtilMappedT< Collection > & FindWithDefault(const Collection &collection, const KeyType &key, const MapUtilMappedT< Collection > &value)
In SWIG mode, we don't want anything besides these top-level includes.
int32_t ParseLeadingInt32Value(const char *str, int32_t deflt)
int64_t ParseLeadingInt64Value(const char *str, int64_t deflt)
std::shared_ptr< ZipArchive > OpenZipArchive(absl::string_view path, const ZipFileOptions &options)