Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <optional>
#include <ostream>
#include <string>
#include <utility>
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "ortools/math_opt/model.pb.h"
#include "ortools/math_opt/model_parameters.pb.h"
Go to the source code of this file.
Macros | |
#define | OR_TOOLS_MATH_OPT_TOOLS_FILE_FORMAT_FLAGS_H_ |
Functions | |
std::ostream & | operator<< (std::ostream &out, FileFormat f) |
Streams the enum value using AbslUnparseFlag(). | |
bool | AbslParseFlag (absl::string_view text, FileFormat *f, std::string *error) |
std::string | AbslUnparseFlag (FileFormat f) |
absl::Span< const FileFormat > | AllFileFormats () |
Returns a span of FileFormat enum values. | |
std::string | OptionalFormatFlagPossibleValuesList () |
std::string | FormatFlagPossibleValuesList () |
absl::flat_hash_map< absl::string_view, FileFormat > | ExtensionToFileFormat () |
Returns a map from file extensions to their format. | |
std::optional< FileFormat > | FormatFromFilePath (absl::string_view file_path) |
std::optional< FileFormat > | FormatFromFlagOrFilePath (std::optional< FileFormat > format_flag_value, absl::string_view file_path) |
absl::StatusOr< std::pair< ModelProto, std::optional< SolutionHintProto > > > | ReadModel (absl::string_view file_path, FileFormat format) |
absl::Status | WriteModel (absl::string_view file_path, const ModelProto &model_proto, const std::optional< SolutionHintProto > &hint_proto, FileFormat format) |
Variables | |
* | FileFormat |
kMathOptText | |
kLinearSolverBinary | |
kLinearSolverText | |
kMPS | |
kLP | |
#define OR_TOOLS_MATH_OPT_TOOLS_FILE_FORMAT_FLAGS_H_ |
bool AbslParseFlag | ( | absl::string_view | text, |
FileFormat * | f, | ||
std::string * | error ) |
Used to define flags with std::optional<FileFormat> or FileFormat.
See OptionalFormatFlagPossibleValuesList() or FormatFlagPossibleValuesList() to build the related help strings.
See FormatFromFlagOrFilePath() to handle the std::nullopt case when using an optional format.
std::string AbslUnparseFlag | ( | FileFormat | f | ) |
absl::Span< const FileFormat > AllFileFormats | ( | ) |
Returns a span of FileFormat enum values.
absl::flat_hash_map< absl::string_view, FileFormat > ExtensionToFileFormat | ( | ) |
Returns a map from file extensions to their format.
std::string FormatFlagPossibleValuesList | ( | ) |
Same as OptionalFormatFlagPossibleValuesList() but for a flag of type FileFormat (i.e. with a mandatory value).
Usage example:
ABSL_FLAG( operations_research::math_opt::FileFormat, output_format, operations_research::math_opt::FileFormat::kMathOptBinary, absl::StrCat( "the format of the --output_file; possible values:", operations_research::math_opt::FormatFlagPossibleValuesList()));
std::optional< FileFormat > FormatFromFilePath | ( | absl::string_view | file_path | ) |
Uses ExtensionToFileFormat() to returns the potential format from a given file path.
std::optional< FileFormat > FormatFromFlagOrFilePath | ( | std::optional< FileFormat > | format_flag_value, |
absl::string_view | file_path ) |
Returns either format_flag_value if not nullopt, else returns the result of FormatFromFilePath() on the input path.
Usage example:
const FileFormat input_format = [&](){ const std::optional<FileFormat> format = FormatFromFlagOrFilePath(absl::GetFlag(FLAGS_input_format), input_file_path); if (format.has_value()) { return *format; } LOG(QFATAL) << "Can't guess the format from the file extension, please " "use --input_format to specify the file format explicitly."; }();
std::ostream & operator<< | ( | std::ostream & | out, |
FileFormat | f ) |
Streams the enum value using AbslUnparseFlag().
std::string OptionalFormatFlagPossibleValuesList | ( | ) |
Returns a multi-line list listing all possible formats that can be used with a –format flag of type std::optional<FileFormat>. Each entry is prefixed by a '
'.
The returned string contains a multiline list of bullet.
See FormatFlagPossibleValuesList() for the alternative to use when the format value is not optional.
Usage example:
ABSL_FLAG( std::optional<operations_research::math_opt::FileFormat>, input_format, std::nullopt, absl::StrCat( "the format of the --input_file; possible values:", operations_research::math_opt::OptionalFormatFlagPossibleValuesList()));
absl::StatusOr< std::pair< ModelProto, std::optional< SolutionHintProto > > > ReadModel | ( | absl::string_view | file_path, |
FileFormat | format ) |
Returns the ModelProto read from the given file. Optionally returns a SolutionHintProto for kLinearSolverXxx format as it may contain one.
absl::Status WriteModel | ( | absl::string_view | file_path, |
const ModelProto & | model_proto, | ||
const std::optional< SolutionHintProto > & | hint_proto, | ||
FileFormat | format ) |
Writes the given model with the given format.
The optional hint is used when the output format supports it (e.g. MPModelProto). It is not yet implemented though; if you need it, please contact us.
* FileFormat |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Library to handles –input_file and –format flags of a binary that reads or writes MathOpt models in various binary or text formats.
This library provides:
Definition at line 24 of file file_format_flags.h.
kLinearSolverBinary |
Definition at line 58 of file file_format_flags.h.
kLinearSolverText |
Definition at line 59 of file file_format_flags.h.
kLP |
Definition at line 61 of file file_format_flags.h.
kMathOptText |
Definition at line 57 of file file_format_flags.h.
kMPS |
Definition at line 60 of file file_format_flags.h.