QUBO++ Library with QUBO Solver APIs
Author: Koji Nakano, License: Non-commercial research and evaluation purposes without any guarantees.
simple_factorization_grb.cpp
Go to the documentation of this file.
1 
8 #include "qbpp.hpp"
9 #include "qbpp_grb.hpp"
10 
11 int main() {
12  auto x = 1 <= qbpp::var_int("x") <= 100;
13  auto y = 1 <= qbpp::var_int("y") <= 100;
14  auto f = x * y == 97 * 89;
15  auto quad_model = qbpp::QuadModel(simplify_as_binary(reduce(f)));
16  std::cout << "quad_model has " << quad_model.var_count() << " variables, "
17  << quad_model.term_count(1) << " linear terms, and "
18  << quad_model.term_count(2) << " quadratic terms" << std::endl;
19  auto model = qbpp_grb::QuadModel(quad_model);
20  model.set_time_limit(10);
21  auto callback = qbpp_grb::Callback(model);
22  callback.set_target_energy(0);
23  model.set(callback);
24  auto sol = model.optimize();
25  std::cout << "x = " << x << " = " << sol.get(x) << std::endl;
26  std::cout << "y = " << y << " = " << sol.get(y) << std::endl;
27 }
Class to manage a callback function called by Gurobi Optimizer.
Definition: qbpp_grb.hpp:149
Class to store a QUBO model using Gurobi Optimizer through QUBO++ library.
Definition: qbpp_grb.hpp:42
VarIntCore var_int(const std::string &var_str)
Definition: qbpp.hpp:2217
Expr simplify_as_binary(const Expr &expr)
Definition: qbpp.hpp:2759
Expr reduce(const Expr &expr)
Definition: qbpp.hpp:2878
QUBO++, a C++ library for generating expressions for binary and spin variables.
QUBO++ interface to call Gurobi Optimizer.