17 #ifndef OR_TOOLS_ROUTING_SOLUTION_SERIALIZER_H_
18 #define OR_TOOLS_ROUTING_SOLUTION_SERIALIZER_H_
22 #include <string_view>
26 #include "absl/strings/str_cat.h"
27 #include "absl/strings/str_format.h"
97 using Route = std::vector<Event>;
100 std::vector<int64_t> total_distances, int64_t total_cost = -1,
101 int64_t total_distance = -1,
double total_time = -1.0,
102 std::string_view
name =
"")
103 : routes_(std::move(routes)),
104 total_demands_(std::move(total_demands)),
105 total_distances_(std::move(total_distances)),
106 total_cost_(total_cost),
107 total_distance_(total_distance),
108 total_time_(total_time),
110 CHECK_EQ(routes_.size(), total_demands_.size());
111 CHECK_EQ(routes_.size(), total_distances_.size());
115 return routes_ == other.routes_ && total_demands_ == other.total_demands_ &&
116 total_distances_ == other.total_distances_ &&
117 total_cost_ == other.total_cost_ && total_time_ == other.total_time_;
120 return !(*
this == other);
127 total_distance_ = total_distance;
130 void SetAuthors(std::string_view authors) { authors_ = authors; }
137 static std::vector<std::vector<int64_t>>
SplitRoutes(
138 const std::vector<int64_t>& solution, int64_t separator);
144 const std::vector<std::vector<int64_t>>& routes,
145 std::optional<int64_t> depot = std::nullopt);
155 return SerializeToTSPLIBString();
157 return SerializeToCVRPLIBString();
159 return SerializeToCARPLIBString();
161 return SerializeToNEARPLIBString();
173 return SerializeToTSPLIBSolutionFile();
175 return SerializeToCVRPLIBSolutionFile();
177 return SerializeToCARPLIBSolutionFile();
179 return SerializeToNEARPLIBSolutionFile();
186 const std::string& file_name)
const;
194 std::vector<std::vector<Event>> routes_;
195 std::vector<int64_t> total_demands_;
196 std::vector<int64_t> total_distances_;
201 int64_t total_distance_;
204 std::string authors_;
206 int64_t NumberOfNonemptyRoutes()
const;
215 std::string SerializeToTSPLIBString()
const;
221 std::string SerializeToCVRPLIBString()
const;
227 std::string SerializeToCARPLIBString()
const;
234 std::string SerializeToNEARPLIBString()
const;
238 std::string SerializeToTSPLIBSolutionFile()
const;
239 std::string SerializeToCVRPLIBSolutionFile()
const;
240 std::string SerializeToCARPLIBSolutionFile()
const;
241 std::string SerializeToNEARPLIBSolutionFile()
const;
245 template <
typename T>
252 ABSL_FALLTHROUGH_INTENDED;
260 return absl::StrCat(
value);
273 ABSL_FALLTHROUGH_INTENDED;
275 return absl::StrFormat(
"%s = %f",
name,
value);
277 return absl::StrFormat(
"%s %f",
name,
value);
279 return absl::StrFormat(
"%f",
value);
281 return absl::StrFormat(
"%s : %f",
name,
value);
287 template <
typename T>
void SetTotalTime(double total_time)
static RoutingSolution FromSplitRoutes(const std::vector< std::vector< int64_t >> &routes, std::optional< int64_t > depot=std::nullopt)
static std::vector< std::vector< int64_t > > SplitRoutes(const std::vector< int64_t > &solution, int64_t separator)
bool operator!=(const RoutingSolution &other) 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="")
bool operator==(const RoutingSolution &other) const
void SetTotalDistance(int64_t total_distance)
void WriteToSolutionFile(RoutingOutputFormat format, const std::string &file_name) const
void SetTotalCost(int64_t total_cost)
std::vector< Event > Route
void SetAuthors(std::string_view authors)
std::string SerializeToString(RoutingOutputFormat format) const
std::string SerializeToSolutionFile(RoutingOutputFormat format) const
void SetName(std::string_view name)
Collection of objects used to extend the Constraint Solver library.
RoutingOutputFormat RoutingOutputFormatFromString(std::string_view format)
void PrintStatistic(const std::string &name, T value, RoutingOutputFormat format)
std::string FormatStatistic(const std::string &name, T value, RoutingOutputFormat format)
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