19#include "absl/flags/parse.h"
20#include "absl/flags/usage.h"
21#include "absl/status/statusor.h"
35 using ::operations_research::math_opt::LinearConstraint;
36 using ::operations_research::math_opt::MathOpt;
37 using ::operations_research::math_opt::Objective;
38 using ::operations_research::math_opt::Result;
39 using ::operations_research::math_opt::SolveParametersProto;
40 using ::operations_research::math_opt::SolveResultProto;
41 using ::operations_research::math_opt::Variable;
43 MathOpt optimizer(operations_research::math_opt::SOLVER_TYPE_GSCIP,
45 const Variable x = optimizer.AddBinaryVariable(
"x");
46 const Variable y = optimizer.AddContinuousVariable(0.0, 2.5,
"y");
47 const LinearConstraint c = optimizer.AddLinearConstraint(
48 -std::numeric_limits<double>::infinity(), 1.5,
"c");
49 c.set_coefficient(x, 1.0);
50 c.set_coefficient(y, 1.0);
51 const Objective obj = optimizer.objective();
52 obj.set_linear_coefficient(x, 2.0);
53 obj.set_linear_coefficient(y, 1.0);
55 const Result result = optimizer.Solve(SolveParametersProto()).value();
56 for (
const auto& warning : result.warnings) {
57 std::cerr <<
"Solver warning: " << warning << std::endl;
60 << result.termination_detail;
64 std::cout <<
"objective value: " << result.objective_value()
65 <<
"\nvalue for variable x: " << result.variable_values().at(x)
70 using ::operations_research::math_opt::LinearExpression;
71 using ::operations_research::math_opt::MathOpt;
72 using ::operations_research::math_opt::Result;
73 using ::operations_research::math_opt::SolveParametersProto;
74 using ::operations_research::math_opt::SolveResultProto;
75 using ::operations_research::math_opt::Variable;
77 MathOpt optimizer(operations_research::math_opt::SOLVER_TYPE_GSCIP,
79 const Variable x = optimizer.AddBinaryVariable(
"x");
80 const Variable y = optimizer.AddContinuousVariable(0.0, 2.5,
"y");
82 optimizer.AddLinearConstraint(x + y <= 1.5,
"c");
84 LinearExpression objective_expression;
85 objective_expression += 2 * x;
86 objective_expression += y;
87 optimizer.objective().Maximize(objective_expression);
88 const Result result = optimizer.Solve(SolveParametersProto()).value();
89 for (
const auto& warning : result.warnings) {
90 std::cerr <<
"Solver warning: " << warning << std::endl;
93 << result.termination_detail;
97 std::cout <<
"objective value: " << result.objective_value()
98 <<
"\nvalue for variable x: " << result.variable_values().at(x)
103int main(
int argc,
char** argv) {
105 absl::ParseCommandLine(argc, argv);
#define CHECK_EQ(val1, val2)
int main(int argc, char **argv)
void InitGoogleLogging(const char *argv0)