Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::RoutingSolution Class Reference

#include <solution_serializer.h>

Classes

struct  Event
 

Public Types

using Route = std::vector<Event>
 

Public Member Functions

 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
 
bool operator!= (const RoutingSolution &other) const
 
void SetTotalTime (double total_time)
 Setters for solution metadata.
 
void SetTotalCost (int64_t total_cost)
 
void SetTotalDistance (int64_t total_distance)
 
void SetName (std::string_view name)
 
void SetAuthors (std::string_view authors)
 
std::string SerializeToString (RoutingOutputFormat format) const
 
std::string SerializeToSolutionFile (RoutingOutputFormat format) const
 
void WriteToSolutionFile (RoutingOutputFormat format, const std::string &file_name) const
 

Static Public Member Functions

static std::vector< std::vector< int64_t > > SplitRoutes (const std::vector< int64_t > &solution, int64_t separator)
 Public-facing builders.
 
static RoutingSolution FromSplitRoutes (absl::Span< const std::vector< int64_t > > routes, std::optional< int64_t > depot=std::nullopt)
 

Detailed Description

Describes completely a solution to a routing problem in preparation of its serialization as a string.

Definition at line 54 of file solution_serializer.h.

Member Typedef Documentation

◆ Route

Definition at line 99 of file solution_serializer.h.

Constructor & Destructor Documentation

◆ RoutingSolution()

operations_research::RoutingSolution::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 = "" )
inline

Definition at line 101 of file solution_serializer.h.

Member Function Documentation

◆ FromSplitRoutes()

RoutingSolution operations_research::RoutingSolution::FromSplitRoutes ( absl::Span< const std::vector< int64_t > > routes,
std::optional< int64_t > depot = std::nullopt )
static

Builds a RoutingSolution object from a vector of routes, each represented as a vector of nodes being traversed. All the routes are supposed to start and end at the depot if specified.

Definition at line 68 of file solution_serializer.cc.

◆ operator!=()

bool operations_research::RoutingSolution::operator!= ( const RoutingSolution & other) const
inline

Definition at line 121 of file solution_serializer.h.

◆ operator==()

bool operations_research::RoutingSolution::operator== ( const RoutingSolution & other) const
inline

Definition at line 116 of file solution_serializer.h.

◆ SerializeToSolutionFile()

std::string operations_research::RoutingSolution::SerializeToSolutionFile ( RoutingOutputFormat format) const
inline

Serializes the full solution to the given file, including metadata like instance name or total cost, depending on the format. For TSPLIB, solution files are typically called "tours".

Definition at line 170 of file solution_serializer.h.

◆ SerializeToString()

std::string operations_research::RoutingSolution::SerializeToString ( RoutingOutputFormat format) const
inline

Serializes the bare solution to a string, i.e. only the routes for the vehicles, without other metadata that is typically present in solution files.

Definition at line 152 of file solution_serializer.h.

◆ SetAuthors()

void operations_research::RoutingSolution::SetAuthors ( std::string_view authors)
inline

Definition at line 132 of file solution_serializer.h.

◆ SetName()

void operations_research::RoutingSolution::SetName ( std::string_view name)
inline

Definition at line 131 of file solution_serializer.h.

◆ SetTotalCost()

void operations_research::RoutingSolution::SetTotalCost ( int64_t total_cost)
inline

Definition at line 127 of file solution_serializer.h.

◆ SetTotalDistance()

void operations_research::RoutingSolution::SetTotalDistance ( int64_t total_distance)
inline

Definition at line 128 of file solution_serializer.h.

◆ SetTotalTime()

void operations_research::RoutingSolution::SetTotalTime ( double total_time)
inline

Setters for solution metadata.

Definition at line 126 of file solution_serializer.h.

◆ SplitRoutes()

std::vector< std::vector< int64_t > > operations_research::RoutingSolution::SplitRoutes ( const std::vector< int64_t > & solution,
int64_t separator )
static

Public-facing builders.

Splits a list of nodes whose routes are separated by the given separator (TSPLIB uses -1; it is crucial that the separator cannot be a node) into a vector per route, for use in FromSplit* functions.

The solution vector separates routes by -1: split this vector into a vector per route, where the other helpers can make the rest of the way to a proper RoutingSolution object.

Definition at line 47 of file solution_serializer.cc.

◆ WriteToSolutionFile()

void operations_research::RoutingSolution::WriteToSolutionFile ( RoutingOutputFormat format,
const std::string & file_name ) const

Serializes the full solution to the given file, including metadata like instance name or total cost, depending on the format.

Definition at line 85 of file solution_serializer.cc.


The documentation for this class was generated from the following files: