Skip to content

Commit

Permalink
fix presolve set to boolean illegal for HiGHS
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 29, 2023
1 parent 3060a3c commit c32554d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/include/idol/optimizers/wrappers/HiGHS/Optimizers_HiGHS.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class idol::Optimizers::HiGHS : public OptimizerWithLazyUpdates<int, int> {
public:
explicit HiGHS(const Model& t_model, bool t_continuous_relaxation);

~HiGHS();

[[nodiscard]] std::string name() const override { return "glpk"; }

void set_param_time_limit(double t_time_limit) override;
Expand Down
21 changes: 16 additions & 5 deletions lib/src/optimizers/wrappers/HiGHS/Optimizers_HiGHS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ int idol::Optimizers::HiGHS::hook_add(const Var &t_var, bool t_add_column) {

const int index = (int) m_model.getNumCol();

const double lb = parent().get_var_lb(t_var);
const double ub = parent().get_var_ub(t_var);
double lb = parent().get_var_lb(t_var);
double ub = parent().get_var_ub(t_var);
const auto& column = parent().get_var_column(t_var);
const auto type = parent().get_var_type(t_var);

lb = is_neg_inf(lb) ? -m_model.getInfinity() : lb;
ub = is_pos_inf(ub) ? m_model.getInfinity() : ub;

if (t_add_column) {

const auto& column_linear = column.linear();
Expand Down Expand Up @@ -301,7 +304,7 @@ void idol::Optimizers::HiGHS::hook_optimize() {

}

if (get_param_infeasible_or_unbounded_info() && m_solution_status == Infeasible) {
if (get_param_infeasible_or_unbounded_info() && m_solution_status == Infeasible && get_remaining_time() > 0) {

bool has_dual_ray;
m_farkas_certificate = new double[m_model.getNumRow()];
Expand All @@ -311,7 +314,7 @@ void idol::Optimizers::HiGHS::hook_optimize() {
run_without_presolve();
m_model.getDualRay(has_dual_ray, m_farkas_certificate);
if (!has_dual_ray) {
throw Exception("Cannot save dual ray.");
throw Exception("Cannot save Farkas certificate.");
}
}

Expand Down Expand Up @@ -395,7 +398,7 @@ void idol::Optimizers::HiGHS::set_param_best_bound_stop(double t_best_bound_stop
}

void idol::Optimizers::HiGHS::set_param_presolve(bool t_value) {
m_model.setOptionValue("presolve", t_value);
m_model.setOptionValue("presolve", t_value ? "on" : "off");
Optimizer::set_param_presolve(t_value);
}

Expand Down Expand Up @@ -425,6 +428,9 @@ double idol::Optimizers::HiGHS::get_best_bound() const {
}

double idol::Optimizers::HiGHS::get_var_primal(const Var &t_var) const {
if (!m_model.getSolution().value_valid) {
throw Exception("Cannot access primal values");
}
return m_model.getSolution().col_value[lazy(t_var).impl()];
}

Expand Down Expand Up @@ -484,4 +490,9 @@ void idol::Optimizers::HiGHS::set_param_log_level(idol::LogLevel t_log_level) {
Optimizer::set_param_log_level(t_log_level);
}

idol::Optimizers::HiGHS::~HiGHS() {
delete[] m_farkas_certificate;
delete[] m_extreme_ray;
}

#endif

0 comments on commit c32554d

Please sign in to comment.