7 #ifndef GUROBI_QBPP_HPP
8 #define GUROBI_QBPP_HPP
13 #include "gurobi_c++.h"
16 #define GRB_SAFE_CALL(func) \
19 } catch (GRBException e) { \
20 std::cerr << e.getErrorCode() << ": " << e.getMessage() << std::endl; \
70 void set(
const std::string &key,
const std::string &val) {
77 set(
"TimeLimit", std::to_string(time_limit));
184 if (where == GRB_CB_MIPSOL) {
186 std::cout <<
"TTS = " << std::fixed << std::setprecision(3)
188 <<
"s Energy = " << energy << std::endl;
225 grb_env.set(GRB_IntParam_OutputFlag, 0);
227 grb_env.set(
"OutputFlag",
"1");
248 if (i < k) obj += coeff *
grb_x[i] *
grb_x[k];
266 sol.
set(i,
int(
grb_x[i].get(GRB_DoubleAttr_X)));
276 std::lock_guard<std::mutex> lock(
mtx);
API for the ABS2 GPU QUBO Solver.
energy_t get_constant() const
vindex_t var_count() const
const std::vector< std::vector< std::pair< vindex_t, coeff_t > > > & get_quadratic() const
const std::vector< coeff_t > & get_linear() const
const std::vector< vindex_t > & get_degree() const
void set_energy(energy_t energy)
void set(vindex_t index, bool value)
energy_t get_energy() const
Class to manage a callback function called by Gurobi Optimizer.
void abort_if_target_energy(qbpp::energy_t energy)
Abort the optimization process if the target energy is achieved.
virtual ~Callback()=default
const QuadModel quad_model
QUBO model.
double getSolutionPublic(GRBVar v)
Calls getSolution() of GRBCallback.
double getDoubleInfoPublic(int what)
Calls GetDoubleInfo() of GRBCallback.
Sol get_sol()
Get the solution obtained by Gurobi Optimizer.
const GRBModel & grb_model
Shortcut to the GRBModel in QuadModel.
virtual void callback() override
Default callback function for Gurobi Optimizer.
Callback(const QuadModel &quad_model)
Constructor: a new Callback object.
std::mutex mtx
Mutex to lock the critical section in get_sol()
void set_target_energy(qbpp::energy_t target_energy)
Set the target energy for Gurobi Optimizer.
std::optional< qbpp::energy_t > target_energy
Target energy to stop the Gurobi optimizer.
Class to store a QUBO model using Gurobi Optimizer through QUBO++ library.
const GRBModel & get_grb_model() const
Get the Gurobi model.
void write(std::string filename)
Write the model to a file.
std::shared_ptr< GRBModel > grb_model_ptr
Gurobi model.
GRBVar get_grb_var(int index) const
Get the Gurobi variable from the index.
Sol optimize()
Optimize the QUBO model.
GRBVar * grb_x
Pointer to Gurobi variables.
GRBEnv grb_env
Gurobi environment.
GRBModel & get_grb_model()
Get the Gurobi model.
Class to store a solution of a QUBO model using Gurobi Optimizer.
qbpp::energy_t get_bound() const
Gets the energy bound of the solution.
qbpp::energy_t bound
Energy Bound obtained by of the Grobi Optimizer.
qbpp::energy_t set_bound(qbpp::energy_t eval)
Sets the energy bound of the solution.
QuadModel(const qbpp::QuadModel &quad_model, bool verbose=false)
Constructor to create a model from QuadModel object.
void set_time_limit(uint32_t time_limit)
Sets time limit to the Gurobi model.
QuadModel(const QuadModel &grb_model)=default
Copy constructor to create a model from another model.
void set(const std::string &key, const std::string &val)
Sets a parameter to the Gurobi environment.
Sol(const qbpp::QuadModel &quad_model)
Creates a solution object from a model.
Namespace to use Gurobi optimizer from QUBO++ library.
Generates a QUBO Expression for the Graph Coloring Problem using QUBO++ library.
energy_t eval(const Expr &expr, const Sol &sol)
QUBO++, a C++ library for generating expressions for binary and spin variables.
#define GRB_SAFE_CALL(func)