idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
Optimizers_HiGHS.h
1//
2// Created by henri on 14/02/23.
3//
4
5#ifndef IDOL_OPTIMIZERS_HIGHS_H
6#define IDOL_OPTIMIZERS_HIGHS_H
7
8#ifdef IDOL_USE_HIGHS
9
10#include "idol/general/optimizers/OptimizerWithLazyUpdates.h"
11#include <Highs.h>
12#include <stack>
13
14namespace idol::Optimizers {
15 class HiGHS;
16}
17
18class idol::Optimizers::HiGHS : public OptimizerWithLazyUpdates<int, int, int, int> {
19
20 bool m_continuous_relaxation;
21
22 ::Highs m_model;
23
24 SolutionStatus m_solution_status = Loaded;
25 SolutionReason m_solution_reason = NotSpecified;
26 double* m_extreme_ray = nullptr;
27 double* m_farkas_certificate = nullptr;
28protected:
29 void hook_build() override;
30 void hook_optimize() override;
31 void run_without_presolve();
32 void hook_write(const std::string &t_name) override;
33 int hook_add(const Var &t_var, bool t_add_column) override;
34 int hook_add(const Ctr &t_ctr) override;
35 int hook_add(const QCtr &t_ctr) override;
36 int hook_add(const SOSCtr &t_ctr) override;
37 void hook_update_objective_sense() override;
38 void update_objective_constant();
39 void hook_update_matrix(const Ctr &t_ctr, const Var &t_var, double t_constant) override;
40 void hook_update() override;
41 void hook_update(const Var &t_var) override;
42 void hook_update(const Ctr &t_ctr) override;
43 void hook_update_objective() override;
44 void hook_update_rhs() override;
45 void hook_remove(const Var &t_var) override;
46 void hook_remove(const Ctr &t_ctr) override;
47 void hook_remove(const QCtr &t_ctr) override;
48 void hook_remove(const SOSCtr &t_ctr) override;
49 void set_var_attr(int t_index, int t_type, double t_lb, double t_ub, double t_obj);
50 void set_var_type(int t_index, int t_type);
51 void set_ctr_attr(int t_index, int t_type, double t_rhs);
52
53 [[nodiscard]] SolutionStatus get_status() const override;
54 [[nodiscard]] SolutionReason get_reason() const override;
55 [[nodiscard]] double get_best_obj() const override;
56 [[nodiscard]] double get_best_bound() const override;
57 [[nodiscard]] double get_var_primal(const Var &t_var) const override;
58 [[nodiscard]] double get_var_reduced_cost(const Var &t_var) const override;
59 [[nodiscard]] double get_var_ray(const Var &t_var) const override;
60 [[nodiscard]] double get_ctr_dual(const Ctr &t_ctr) const override;
61 [[nodiscard]] double get_ctr_farkas(const Ctr &t_ctr) const override;
62 [[nodiscard]] double get_relative_gap() const override;
63 [[nodiscard]] double get_absolute_gap() const override;
64 [[nodiscard]] unsigned int get_n_solutions() const override;
65 [[nodiscard]] unsigned int get_solution_index() const override;
66 void set_solution_index(unsigned int t_index) override;
67
68 void analyze_status(HighsStatus t_status);
69public:
70 explicit HiGHS(const Model& t_model, bool t_continuous_relaxation);
71
72 ~HiGHS();
73
74 [[nodiscard]] std::string name() const override { return "HiGHS"; }
75
76 void set_param_time_limit(double t_time_limit) override;
77
78 void set_param_best_obj_stop(double t_best_obj_stop) override;
79
80 void set_param_best_bound_stop(double t_best_bound_stop) override;
81
82 void set_param_presolve(bool t_value) override;
83
84 void set_param_logs(bool t_value) override;
85
86};
87
88#endif
89
90#endif //IDOL_OPTIMIZERS_HIGHS_H