17#ifndef OR_TOOLS_ROUTING_PARSERS_SOLUTION_SERIALIZER_H_ 
   18#define OR_TOOLS_ROUTING_PARSERS_SOLUTION_SERIALIZER_H_ 
   26#include "absl/strings/str_cat.h" 
   27#include "absl/strings/str_format.h" 
   28#include "absl/strings/string_view.h" 
   29#include "absl/types/span.h" 
   99  using Route = std::vector<Event>;
 
  102                  std::vector<int64_t> total_distances, int64_t total_cost = -1,
 
  103                  int64_t total_distance = -1, 
double total_time = -1.0,
 
  104                  std::string_view name = 
"")
 
  105      : routes_(
std::move(routes)),
 
  106        total_demands_(
std::move(total_demands)),
 
  107        total_distances_(
std::move(total_distances)),
 
  108        total_cost_(total_cost),
 
  109        total_distance_(total_distance),
 
  110        total_time_(total_time),
 
  112    CHECK_EQ(routes_.size(), total_demands_.size());
 
  113    CHECK_EQ(routes_.size(), total_distances_.size());
 
 
  117    return routes_ == other.routes_ && total_demands_ == other.total_demands_ &&
 
  118           total_distances_ == other.total_distances_ &&
 
  119           total_cost_ == other.total_cost_ && total_time_ == other.total_time_;
 
 
  122    return !(*
this == other);
 
 
  129    total_distance_ = total_distance;
 
 
  131  void SetName(std::string_view name) { name_ = name; }
 
  132  void SetAuthors(std::string_view authors) { authors_ = authors; }
 
  139  static std::vector<std::vector<int64_t>> 
SplitRoutes(
 
  140      absl::Span<const int64_t> 
solution, int64_t separator);
 
  146      absl::Span<
const std::vector<int64_t>> routes,
 
  147      std::optional<int64_t> depot = std::nullopt);
 
  157        return SerializeToTSPLIBString();
 
  159        return SerializeToCVRPLIBString();
 
  161        return SerializeToCARPLIBString();
 
  163        return SerializeToNEARPLIBString();
 
 
  175        return SerializeToTSPLIBSolutionFile();
 
  177        return SerializeToCVRPLIBSolutionFile();
 
  179        return SerializeToCARPLIBSolutionFile();
 
  181        return SerializeToNEARPLIBSolutionFile();
 
 
  188                           const std::string& file_name) 
const;
 
  196  std::vector<std::vector<Event>> routes_;
 
  197  std::vector<int64_t> total_demands_;
 
  198  std::vector<int64_t> total_distances_;
 
  203  int64_t total_distance_;
 
  206  std::string authors_;
 
  208  int64_t NumberOfNonemptyRoutes() 
const;
 
  217  std::string SerializeToTSPLIBString() 
const;
 
  223  std::string SerializeToCVRPLIBString() 
const;
 
  229  std::string SerializeToCARPLIBString() 
const;
 
  236  std::string SerializeToNEARPLIBString() 
const;
 
  240  std::string SerializeToTSPLIBSolutionFile() 
const;
 
  241  std::string SerializeToCVRPLIBSolutionFile() 
const;
 
  242  std::string SerializeToCARPLIBSolutionFile() 
const;
 
  243  std::string SerializeToNEARPLIBSolutionFile() 
const;
 
 
  254      ABSL_FALLTHROUGH_INTENDED;
 
  256      return absl::StrCat(name, 
" = ", value);
 
  258      return absl::StrCat(name, 
" ", value);
 
  262      return absl::StrCat(value);
 
  264      return absl::StrCat(name, 
" : ", value);
 
 
  275      ABSL_FALLTHROUGH_INTENDED;
 
  277      return absl::StrFormat(
"%s = %f", name, value);
 
  279      return absl::StrFormat(
"%s %f", name, value);
 
  281      return absl::StrFormat(
"%f", value);
 
  283      return absl::StrFormat(
"%s : %f", name, value);
 
 
static std::vector< std::vector< int64_t > > SplitRoutes(absl::Span< const int64_t > solution, int64_t separator)
Public-facing builders.
 
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)
Setters for solution metadata.
 
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
 
Common utilities for parsing routing instances.
 
void PrintStatistic(absl::string_view name, T value, RoutingOutputFormat format)
 
std::string FormatStatistic(absl::string_view name, T value, RoutingOutputFormat format)
Formats a solution or solver statistic according to the given 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)
 
Type
Describes the type of events that occur along a route.
 
@ kServeNode
The vehicle serves the demand of the node.
 
@ kStart
The vehicle starts its route at a depot.
 
@ kServeEdge
The vehicle traverses the edge while servicing it.
 
@ kTransit
The vehicle simply goes through an edge or an arc without servicing.
 
@ kServeArc
The vehicle traverses the arc while servicing it.
 
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