Skip to content

Commit

Permalink
add Tolerance::Digits
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 22, 2023
1 parent 766208d commit 18f434f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.22)
project(idol VERSION 0.0.1)
project(idol VERSION 0.4.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${idol_SOURCE_DIR}/cmake")
Expand Down
2 changes: 2 additions & 0 deletions lib/include/idol/modeling/numericals.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace idol {
*/
static double Sparsity = 1e-8;

static unsigned int Digits = 8;

/**
* **Default:** \f$ 10^{-4} \f$
*
Expand Down
7 changes: 6 additions & 1 deletion lib/include/idol/optimizers/solvers/Optimizers_HiGHS.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifdef IDOL_USE_HIGHS

#include "OptimizerWithLazyUpdates.h"
#include <Highs.h>
#include <stack>

namespace idol::Optimizers {
class HiGHS;
Expand All @@ -17,13 +19,16 @@ class idol::Optimizers::HiGHS : public OptimizerWithLazyUpdates<int, int> {

bool m_continuous_relaxation;

// glp_prob* m_model;
::Highs m_solver;
bool m_solved_as_mip = false;

SolutionStatus m_solution_status = Loaded;
SolutionReason m_solution_reason = NotSpecified;
std::optional<Solution::Primal> m_unbounded_ray;
std::optional<Solution::Dual> m_farkas_certificate;

std::stack<int> m_deleted_variables;
std::stack<int> m_deleted_constraints;
protected:
void hook_build() override;

Expand Down
5 changes: 4 additions & 1 deletion lib/src/optimizers/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ double idol::impl::Optimizer::as_numeric(const Constant &t_constant) {
throw Exception("Constant is not numeric.");
}

return t_constant.numerical();
const double multiplier = std::pow(10, Tolerance::Digits);
const double numerical = t_constant.numerical();

return std::round(numerical * multiplier) / multiplier;
}

idol::impl::Optimizer::Optimizer(const Model &t_parent) : m_parent(t_parent) {
Expand Down
12 changes: 2 additions & 10 deletions lib/src/optimizers/solvers/Optimizers_HiGHS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void idol::Optimizers::HiGHS::hook_build() {
}

void idol::Optimizers::HiGHS::hook_write(const std::string &t_name) {
// glp_write_lp(m_model, nullptr, t_name.c_str());
m_solver.writeModel(t_name);
}

void idol::Optimizers::HiGHS::set_var_attr(int t_index, int t_type, double t_lb, double t_ub, double t_obj) {
Expand Down Expand Up @@ -181,7 +181,6 @@ void idol::Optimizers::HiGHS::hook_update() {

void idol::Optimizers::HiGHS::hook_update(const Var &t_var) {

/*
const auto& model = parent();
auto& impl = lazy(t_var).impl();
const double lb = model.get_var_lb(t_var);
Expand All @@ -191,33 +190,26 @@ void idol::Optimizers::HiGHS::hook_update(const Var &t_var) {

set_var_attr(impl, type, lb, ub, as_numeric(obj));

*/

}

void idol::Optimizers::HiGHS::hook_update(const Ctr &t_ctr) {

/*
const auto& model = parent();
auto& impl = lazy(t_ctr).impl();
const auto& rhs = model.get_ctr_row(t_ctr).rhs();
const auto type = model.get_ctr_type(t_ctr);

set_ctr_attr(impl, type, as_numeric(rhs));
*/

}

void idol::Optimizers::HiGHS::hook_update_objective() {

/*
const auto& model = parent();

for (const auto& var : model.vars()) {
const auto& obj = model.get_var_column(var).obj();
glp_set_obj_coef(m_model, lazy(var).impl(), as_numeric(obj));
// glp_set_obj_coef(m_model, lazy(var).impl(), as_numeric(obj));
}
*/

}

Expand Down

0 comments on commit 18f434f

Please sign in to comment.