14 #ifndef OR_TOOLS_MATH_OPT_SOLVERS_GLPK_SOLVER_H_
15 #define OR_TOOLS_MATH_OPT_SOLVERS_GLPK_SOLVER_H_
23 #include "absl/container/flat_hash_map.h"
24 #include "absl/status/status.h"
25 #include "absl/status/statusor.h"
27 #include "ortools/math_opt/callback.pb.h"
30 #include "ortools/math_opt/model.pb.h"
31 #include "ortools/math_opt/model_parameters.pb.h"
32 #include "ortools/math_opt/model_update.pb.h"
33 #include "ortools/math_opt/parameters.pb.h"
34 #include "ortools/math_opt/result.pb.h"
45 static absl::StatusOr<std::unique_ptr<SolverInterface>>
New(
50 absl::StatusOr<SolveResultProto>
Solve(
52 const ModelSolveParametersProto& model_parameters,
54 const CallbackRegistrationProto& callback_registration,
Callback cb,
56 absl::StatusOr<bool>
Update(
const ModelUpdateProto& model_update)
override;
67 static constexpr
auto kSetBounds = glp_set_col_bnds;
68 static constexpr
auto kGetLb = glp_get_col_lb;
69 static constexpr
auto kGetUb = glp_get_col_ub;
70 static constexpr
auto kGetType = glp_get_col_type;
71 static constexpr
auto kDelElts = glp_del_cols;
74 static inline bool IsInteger(glp_prob*
const problem,
const int j);
85 std::vector<int64_t> ids;
89 absl::flat_hash_map<int64_t, int> id_to_index;
96 std::vector<double> unrounded_lower_bounds;
101 std::vector<double> unrounded_upper_bounds;
107 struct LinearConstraints {
108 static constexpr
auto kSetBounds = glp_set_row_bnds;
109 static constexpr
auto kGetLb = glp_get_row_lb;
110 static constexpr
auto kGetUb = glp_get_row_ub;
111 static constexpr
auto kGetType = glp_get_row_type;
112 static constexpr
auto kDelElts = glp_del_rows;
116 static bool IsInteger(glp_prob*,
int) {
return false; }
127 std::vector<int64_t> ids;
132 absl::flat_hash_map<int64_t, int> id_to_index;
138 void AddVariables(
const VariablesProto& new_variables);
141 void AddLinearConstraints(
142 const LinearConstraintsProto& new_linear_constraints);
146 void UpdateObjectiveCoefficients(
147 const SparseDoubleVectorProto& coefficients_proto);
155 void UpdateLinearConstraintMatrix(
156 const SparseDoubleMatrixProto& matrix_updates,
157 std::optional<int64_t> first_new_var_id,
158 std::optional<int64_t> first_new_cstr_id);
166 void AddPrimalSolution(
int (*get_prim_stat)(glp_prob*),
167 double (*obj_val)(glp_prob*),
168 double (*col_val)(glp_prob*,
int),
169 const ModelSolveParametersProto& model_parameters,
170 SolutionProto& solution_proto);
180 void AddDualSolution(
int (*get_dual_stat)(glp_prob*),
181 double (*obj_val)(glp_prob*),
182 double (*row_dual)(glp_prob*,
int),
183 double (*col_dual)(glp_prob*,
int),
184 const ModelSolveParametersProto& model_parameters,
185 SolutionProto& solution_proto);
189 absl::Status AddPrimalOrDualRay(
190 const ModelSolveParametersProto& model_parameters,
191 SolveResultProto& result);
194 absl::Status CheckCurrentThread();
197 const std::thread::id thread_id_;
199 glp_prob*
const problem_;
201 Variables variables_;
202 LinearConstraints linear_constraints_;
209 bool GlpkSolver::Variables::IsInteger(glp_prob*
const problem,
const int j) {
210 const int kind = glp_get_col_kind(problem, j);
220 LOG(FATAL) <<
"Unexpected column kind: " << kind;
absl::StatusOr< bool > Update(const ModelUpdateProto &model_update) override
static absl::StatusOr< std::unique_ptr< SolverInterface > > New(const ModelProto &model, const InitArgs &init_args)
absl::StatusOr< SolveResultProto > Solve(const SolveParametersProto ¶meters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, SolveInterrupter *interrupter) override
std::function< void(const std::vector< std::string > &)> MessageCallback
std::function< absl::StatusOr< CallbackResultProto >(const CallbackDataProto &)> Callback
Collection of objects used to extend the Constraint Solver library.