23#include "absl/strings/match.h"
24#include "absl/strings/str_split.h"
25#include "absl/strings/string_view.h"
37 return ParseFile(file_name);
41 absl::string_view archive_name) {
43 if (!absl::StartsWith(archive_name,
"/")) {
46 std::shared_ptr<zipfile::ZipArchive> zip_archive(
48 if (
nullptr == zip_archive) {
55 const int delivery = deliveries_[node];
56 if (delivery == 0)
return std::nullopt;
61 const int pickup = pickups_[node];
62 if (pickup == 0)
return std::nullopt;
66void LiLimParser::Initialize() {
74 time_windows_.clear();
75 service_times_.clear();
78#define PARSE_AND_RETURN_IF_NEGATIVE(str, dest_type, dest) \
79 dest_type dest = strings::ParseLeadingInt32Value(str, -1); \
81 if (dest < 0) return false; \
84bool LiLimParser::ParseFile(absl::string_view file_name) {
85 const int64_t kInvalidDemand = std::numeric_limits<int64_t>::min();
86 bool vehicles_initialized =
false;
91 for (
const std::string&
line :
93 const std::vector<std::string> words =
94 absl::StrSplit(
line, absl::ByAnyChar(
" :\t"), absl::SkipEmpty());
96 if (words.empty())
continue;
97 if (!vehicles_initialized) {
98 if (words.size() != 3)
return false;
102 vehicles_initialized =
true;
106 if (words.size() != 9)
return false;
109 coordinates_.push_back({
x,
y});
112 if (
demand == kInvalidDemand)
return false;
113 demands_.push_back(
demand);
116 time_windows_.push_back({open_time, close_time});
118 service_times_.push_back(service_time);
120 pickups_.push_back(pickup);
122 deliveries_.push_back(delivery);
124 return vehicles_initialized;
127#undef PARSE_AND_RETURN_IF_NEGATIVE
bool LoadFile(absl::string_view file_name)
Loads instance from a file.
std::optional< int > GetDelivery(int node) const
Returns the delivery of a pickup.
std::optional< int > GetPickup(int node) const
Returns the pickup of a delivery.
#define PARSE_AND_RETURN_IF_NEGATIVE(str, dest_type, dest)
absl::Status Open(absl::string_view filename, absl::string_view mode, File **f, Options options)
As of 2016-01, these methods can only be used with flags = file::Defaults().
In SWIG mode, we don't want anything besides these top-level includes.
int64_t ParseLeadingInt64Value(const char *str, int64_t deflt)
std::shared_ptr< ZipArchive > OpenZipArchive(absl::string_view path, const ZipFileOptions &options)