A C++ Framework for Optimization
Loading...
Searching...
No Matches
GurobiCallbackI.h
1//
2// Created by henri on 31/03/23.
3//
4
5#ifndef CCG_WITH_NESTED_CG_GUROBICALLBACK_H
6#define CCG_WITH_NESTED_CG_GUROBICALLBACK_H
7
8
9#include <memory>
10#include <list>
11#include "idol/mixed-integer/modeling/constraints/TempCtr.h"
12#include "idol/mixed-integer/optimizers/callbacks/Callback.h"
13#include "idol/mixed-integer/optimizers/wrappers/Gurobi/headers/header_gurobi.h"
14
15namespace idol {
16 namespace Optimizers {
17 class Gurobi;
18 }
19 namespace impl {
20 static int grb_callback(GRBmodel *t_model, void *t_cbdata, int t_where, void *t_usrdata);
21 }
22 class GurobiCallbackI;
23}
24
26
27 Optimizers::Gurobi& m_parent;
28 std::list<std::unique_ptr<Callback>> m_callbacks;
29
30 int m_where = 0;
31 void* m_cbdata = nullptr;
32 double m_best_obj = Inf;
33 double m_best_bound = -Inf;
34
35 struct GurobiTempConstr {
36 std::vector<int> indices;
37 std::vector<double> coefficients;
38 char sense = 0;
39 double rhs = 0;
40 };
41
42 GurobiTempConstr gurobi_temp_constr(const TempCtr& t_temp_ctr) const;
43public:
44 explicit GurobiCallbackI(Optimizers::Gurobi& t_parent);
45
46 void add_callback(Callback* t_callback);
47 void call();
48
49 friend int idol::impl::grb_callback(GRBmodel *t_model, void *t_cbdata, int t_where, void *t_usrdata);
50protected:
51 [[nodiscard]] const Model& original_model() const override;
52 void add_lazy_cut(const TempCtr& t_lazy_cut) override;
53 void add_user_cut(const TempCtr& t_user_cut) override;
54 void submit_heuristic_solution(PrimalPoint t_solution) override;
55 [[nodiscard]] PrimalPoint primal_solution() const override;
56 [[nodiscard]] const Timer &time() const override;
57 [[nodiscard]] double best_obj() const override;
58 [[nodiscard]] double best_bound() const override;
59 void terminate() override;
60};
61
62#endif //CCG_WITH_NESTED_CG_GUROBICALLBACK_H