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::Model;
37 using ::operations_research::math_opt::SolveResult;
40 using ::operations_research::math_opt::Variable;
42 Model
model(
"my_model");
43 const Variable x =
model.AddBinaryVariable(
"x");
44 const Variable y =
model.AddContinuousVariable(0.0, 2.5,
"y");
45 const LinearConstraint c =
model.AddLinearConstraint(
46 -std::numeric_limits<double>::infinity(), 1.5,
"c");
47 model.set_coefficient(c, x, 1.0);
48 model.set_coefficient(c, y, 1.0);
49 model.set_objective_coefficient(x, 2.0);
50 model.set_objective_coefficient(y, 1.0);
52 const SolveResult result =
Solve(
model, SolverType::kGscip).value();
53 for (
const auto& warning : result.warnings) {
54 std::cerr <<
"Solver warning: " << warning << std::endl;
56 CHECK_EQ(result.termination.reason, TerminationReason::kOptimal)
57 << result.termination;
61 std::cout <<
"objective value: " << result.objective_value()
62 <<
"\nvalue for variable x: " << result.variable_values().at(x)
67 using ::operations_research::math_opt::LinearExpression;
68 using ::operations_research::math_opt::Model;
69 using ::operations_research::math_opt::SolveResult;
72 using ::operations_research::math_opt::Variable;
74 Model
model(
"my_model");
75 const Variable x =
model.AddBinaryVariable(
"x");
76 const Variable y =
model.AddContinuousVariable(0.0, 2.5,
"y");
78 model.AddLinearConstraint(x + y <= 1.5,
"c");
80 LinearExpression objective_expression;
81 objective_expression += 2 * x;
82 objective_expression += y;
83 model.Maximize(objective_expression);
84 const SolveResult result =
Solve(
model, SolverType::kGscip).value();
85 for (
const auto& warning : result.warnings) {
86 std::cerr <<
"Solver warning: " << warning << std::endl;
88 CHECK_EQ(result.termination.reason, TerminationReason::kOptimal)
89 << result.termination;
93 std::cout <<
"objective value: " << result.objective_value()
94 <<
"\nvalue for variable x: " << result.variable_values().at(x)
99int main(
int argc,
char** argv) {
101 absl::ParseCommandLine(argc, argv);
#define CHECK_EQ(val1, val2)
int main(int argc, char **argv)
void InitGoogleLogging(const char *argv0)
absl::StatusOr< SolveResult > Solve(const Model &model, const SolverType solver_type, const SolveArguments &solve_args, const SolverInitArguments &init_args)