39#include "absl/flags/flag.h"
40#include "absl/status/status.h"
41#include "absl/strings/str_cat.h"
42#include "absl/strings/string_view.h"
51 std::string, input_file,
"",
52 "the file containing the model to solve; use --input_format to specify"
55 std::optional<operations_research::math_opt::FileFormat>, input_format,
58 "the format of the --input_file; possible values:",
62 "the file to write to; use --output_format to specify"
65 std::optional<operations_research::math_opt::FileFormat>, output_format,
68 "the format of the --output_file; possible values:",
72 "use the names in the input models; ignoring names is useful when "
73 "the input contains duplicates or if the model must be anonymized");
83 const absl::string_view format_flag_name,
84 const std::optional<FileFormat> format_flag_value,
85 const absl::string_view file_path_flag_name,
86 const absl::string_view file_path_flag_value) {
87 const std::optional<FileFormat> format =
89 if (format.has_value()) {
92 LOG(QFATAL) <<
"Can't guess the format from the --" << file_path_flag_name
93 <<
" extension, please use --" << format_flag_name
94 <<
" to specify the file format explicitly.";
98 const std::string input_file_path = absl::GetFlag(FLAGS_input_file);
99 if (input_file_path.empty()) {
100 LOG(QFATAL) <<
"The flag --input_file is mandatory.";
102 const std::string output_file_path = absl::GetFlag(FLAGS_output_file);
103 if (output_file_path.empty()) {
104 LOG(QFATAL) <<
"The flag --output_file is mandatory.";
107 const FileFormat input_format = ParseOptionalFormatFlag(
108 "input_format", absl::GetFlag(FLAGS_input_format),
109 "input_file", input_file_path);
110 const FileFormat output_format = ParseOptionalFormatFlag(
111 "output_format", absl::GetFlag(FLAGS_output_format),
112 "output_file", output_file_path);
116 ReadModel(input_file_path, input_format),
117 _ <<
"failed to read " << input_file_path);
119 if (!absl::GetFlag(FLAGS_names)) {
125 WriteModel(output_file_path, model_proto, optional_hint, output_format))
126 <<
"failed to write " << output_file_path;
128 return absl::OkStatus();
134int main(
int argc,
char* argv[]) {
137 const absl::Status
status = operations_research::math_opt::Main();
#define RETURN_IF_ERROR(expr)
void InitGoogle(const char *usage, int *argc, char ***argv, bool deprecated)
input_file model textproto input_format linear_solver_txt output_file model mps input_file model pb output_file model_linear_solver pb output_format linear_solver input_file model pb output_file model lp input_file model pb nonames output_file anonymous model pb ABSL_FLAG(std::string, input_file, "", "the file containing the model to solve; use --input_format to specify" " the file format")
int main(int argc, char *argv[])
An object oriented wrapper for quadratic constraints in ModelStorage.
std::optional< FileFormat > FormatFromFlagOrFilePath(const std::optional< FileFormat > format_flag_value, const absl::string_view file_path)
std::string OptionalFormatFlagPossibleValuesList()
absl::Status WriteModel(const absl::string_view file_path, const ModelProto &model_proto, const std::optional< SolutionHintProto > &hint_proto, const FileFormat format)
absl::StatusOr< std::pair< ModelProto, std::optional< SolutionHintProto > > > ReadModel(const absl::string_view file_path, const FileFormat format)
void RemoveNames(ModelProto &model)
Removes the model, variables and constraints names of the provided model.
#define OR_ASSIGN_OR_RETURN3(lhs, rexpr, error_expression)