17#ifndef ORTOOLS_ROUTING_PARSERS_SOLUTION_SERIALIZER_H_
18#define ORTOOLS_ROUTING_PARSERS_SOLUTION_SERIALIZER_H_
27#include "absl/base/attributes.h"
28#include "absl/base/optimization.h"
29#include "absl/log/check.h"
30#include "absl/strings/str_cat.h"
31#include "absl/strings/str_format.h"
32#include "absl/strings/string_view.h"
33#include "absl/types/span.h"
103 std::vector<int64_t> total_distances, int64_t total_cost = -1,
104 int64_t total_distance = -1,
double total_time = -1.0,
105 std::string_view name =
"")
106 : routes_(
std::move(routes)),
107 total_demands_(
std::move(total_demands)),
108 total_distances_(
std::move(total_distances)),
109 total_cost_(total_cost),
110 total_distance_(total_distance),
111 total_time_(total_time),
113 CHECK_EQ(routes_.size(), total_demands_.size());
114 CHECK_EQ(routes_.size(), total_distances_.size());
118 return routes_ == other.routes_ && total_demands_ == other.total_demands_ &&
119 total_distances_ == other.total_distances_ &&
120 total_cost_ == other.total_cost_ && total_time_ == other.total_time_;
123 return !(*
this == other);
130 total_distance_ = total_distance;
132 void SetName(std::string_view name) { name_ = name; }
133 void SetAuthors(std::string_view authors) { authors_ = authors; }
140 static std::vector<std::vector<int64_t>>
SplitRoutes(
141 absl::Span<const int64_t>
solution, int64_t separator);
147 absl::Span<
const std::vector<int64_t>> routes,
148 std::optional<int64_t> depot = std::nullopt);
158 return SerializeToTSPLIBString();
160 return SerializeToCVRPLIBString();
162 return SerializeToCARPLIBString();
164 return SerializeToNEARPLIBString();
177 return SerializeToTSPLIBSolutionFile();
179 return SerializeToCVRPLIBSolutionFile();
181 return SerializeToCARPLIBSolutionFile();
183 return SerializeToNEARPLIBSolutionFile();
191 const std::string& file_name)
const;
199 std::vector<std::vector<Event>> routes_;
200 std::vector<int64_t> total_demands_;
201 std::vector<int64_t> total_distances_;
206 int64_t total_distance_;
209 std::string authors_;
211 int64_t NumberOfNonemptyRoutes()
const;
220 std::string SerializeToTSPLIBString()
const;
226 std::string SerializeToCVRPLIBString()
const;
232 std::string SerializeToCARPLIBString()
const;
239 std::string SerializeToNEARPLIBString()
const;
243 std::string SerializeToTSPLIBSolutionFile()
const;
244 std::string SerializeToCVRPLIBSolutionFile()
const;
245 std::string SerializeToCARPLIBSolutionFile()
const;
246 std::string SerializeToNEARPLIBSolutionFile()
const;
257 ABSL_FALLTHROUGH_INTENDED;
259 return absl::StrCat(name,
" = ", value);
261 return absl::StrCat(name,
" ", value);
265 return absl::StrCat(value);
267 return absl::StrCat(name,
" : ", value);
279 ABSL_FALLTHROUGH_INTENDED;
281 return absl::StrFormat(
"%s = %f", name, value);
283 return absl::StrFormat(
"%s %f", name, value);
285 return absl::StrFormat(
"%f", value);
287 return absl::StrFormat(
"%s : %f", name, value);
static std::vector< std::vector< int64_t > > SplitRoutes(absl::Span< const int64_t > solution, int64_t separator)
std::string SerializeToSolutionFile(RoutingOutputFormat format) const
RoutingSolution(std::vector< Route > routes, std::vector< int64_t > total_demands, std::vector< int64_t > total_distances, int64_t total_cost=-1, int64_t total_distance=-1, double total_time=-1.0, std::string_view name="")
void SetTotalTime(double total_time)
void SetAuthors(std::string_view authors)
std::string SerializeToString(RoutingOutputFormat format) const
static RoutingSolution FromSplitRoutes(absl::Span< const std::vector< int64_t > > routes, std::optional< int64_t > depot=std::nullopt)
bool operator==(const RoutingSolution &other) const
void SetName(std::string_view name)
void WriteToSolutionFile(RoutingOutputFormat format, const std::string &file_name) const
void SetTotalDistance(int64_t total_distance)
std::vector< Event > Route
void SetTotalCost(int64_t total_cost)
bool operator!=(const RoutingSolution &other) const
void PrintStatistic(absl::string_view name, T value, RoutingOutputFormat format)
std::string FormatStatistic(absl::string_view name, T value, RoutingOutputFormat format)
RoutingOutputFormat RoutingOutputFormatFromString(std::string_view format)
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
Event(Type type, int64_t demand_id, Arc arc)
Event(Type type, int64_t demand_id, Arc arc, std::string_view arc_name)
bool operator!=(const Event &other) const
bool operator==(const Event &other) const