QUBO++ Library with QUBO Solver APIs
Author: Koji Nakano, License: Non-commercial research and evaluation purposes without any guarantees.
ilp_abs2.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
31 
32 #include "qbpp.hpp"
33 #include "qbpp_abs2.hpp"
34 
35 int main() {
36  // Define variables
37  auto x1 = 0 <= qbpp::var_int("x1") <= 5;
38  auto x2 = 0 <= qbpp::var_int("x2") <= 4;
39  auto x3 = 0 <= qbpp::var_int("x3") <= 3;
40  auto x4 = 0 <= qbpp::var_int("x4") <= 6;
41 
42  // Define the objective function
43  auto obj = 6 * x1 + 4 * x2 + 3 * x3 + 5 * x4;
44 
45  // Define the constraints
46  auto c1 = x1 + 2 * x2 + 3 * x3 + 4 * x4;
47  auto c2 = 3 * x1 + x2 + 2 * x3 + x4;
48 
49  // Define QUBO expression
50  auto f = -obj + 100 * ((0 <= c1 <= 15) + (0 <= c2 <= 10));
51 
52  auto quad_model = qbpp::QuadModel(f.simplify_as_binary());
53 
54  // Define the solver
55  auto solver = qbpp_abs2::Solver();
56 
57  // Define the parameters
58  auto param = qbpp_abs2::Param();
59 
60  // Set the time limit
61  param.set_time_limit(5);
62 
63  // Create a default callback function
64  qbpp_abs2::Callback callback(quad_model);
65 
66  // Set the callback function
67  param.set(callback);
68 
69  // Solve the ILP problem
70  auto sol = solver(quad_model, param);
71 
72  // Print the solution
73  std::cout << sol << std::endl;
74 
75  std::cout << "x1 = " << eval(x1, sol) << std::endl;
76  std::cout << "x2 = " << eval(x2, sol) << std::endl;
77  std::cout << "x3 = " << eval(x3, sol) << std::endl;
78  std::cout << "x4 = " << eval(x4, sol) << std::endl;
79  std::cout << "c1 = " << eval(c1, sol) << std::endl;
80  std::cout << "c2 = " << eval(c2, sol) << std::endl;
81  std::cout << "Objective value = " << eval(obj, sol) << std::endl;
82 }
A class for defining the ABS2 callback function.
Definition: qbpp_abs2.hpp:204
A class for setting parameters for the ABS2 QUBO solver.
Definition: qbpp_abs2.hpp:104
A class for calling the ABS2 QUBO solver.
Definition: qbpp_abs2.hpp:53
int main()
Definition: ilp_abs2.cpp:35
VarIntCore var_int(const std::string &var_str)
Definition: qbpp.hpp:2217
energy_t eval(const Expr &expr, const Sol &sol)
Definition: qbpp.hpp:2109
QUBO++, a C++ library for generating expressions for binary and spin variables.
QUBO++ interface to call ABS2 GPU QUBO solver.