45int main(
int argc,
char** argv) {
49 operations_research::math_opt::ModelProto
model;
50 model.mutable_variables()->add_ids(0);
51 model.mutable_variables()->add_lower_bounds(0.0);
52 model.mutable_variables()->add_upper_bounds(1.0);
53 model.mutable_variables()->add_names(
"x");
54 model.mutable_variables()->add_integers(
false);
55 model.mutable_objective()->set_maximize(
true);
56 model.mutable_objective()->mutable_linear_coefficients()->add_ids(0);
57 model.mutable_objective()->mutable_linear_coefficients()->add_values(1.0);
58 const std::string model_str =
model.SerializeAsString();
59 const void* model_bin = model_str.data();
60 const size_t model_bin_size = model_str.size();
63 const int solver_type =
64 static_cast<int>(operations_research::math_opt::SOLVER_TYPE_GLOP);
67 void* result_bin =
nullptr;
68 size_t result_bin_size = 0;
69 char* status_msg =
nullptr;
72 const int status_code =
MathOptSolve(model_bin, model_bin_size, solver_type,
74 &result_bin_size, &status_msg);
77 if (status_code != 0) {
78 std::cerr << absl::Status(static_cast<absl::StatusCode>(status_code),
87 operations_research::math_opt::SolveResultProto result;
88 if (!result.ParseFromArray(result_bin,
static_cast<int>(result_bin_size))) {
89 std::cout <<
"failed to parse SolveResultProto" << std::endl;
94 std::cout <<
"Termination is optimal: "
95 << (result.termination().reason() ==
96 operations_research::math_opt::TERMINATION_REASON_OPTIMAL)
98 std::cout <<
"Objective value: "
99 << result.termination().objective_bounds().primal_bound()
int MathOptSolve(const void *model, const size_t model_size, const int solver_type, MathOptInterrupter *const interrupter, void **solve_result, size_t *solve_result_size, char **status_msg)