Skip to content

Commit

Permalink
all tests OK with OsiCplex
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Feb 7, 2024
1 parent d67c503 commit c820fc7
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/api/optimizers/wrappers/MibS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _api_MibS:

COIN-OR/MibS (BiLevel)
======================

.. doxygenclass:: idol::BiLevel::MibS
6 changes: 6 additions & 0 deletions docs/api/optimizers/wrappers/Osi/OsiCbc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _api_OsiCbc:

OsiCbc
======

.. doxygenclass:: idol::OsiCbc
6 changes: 6 additions & 0 deletions docs/api/optimizers/wrappers/Osi/OsiClp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _api_OsiClp:

OsiClp
======

.. doxygenclass:: idol::OsiClp
6 changes: 6 additions & 0 deletions docs/api/optimizers/wrappers/Osi/OsiCplex.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _api_OsiCplex:

OsiCplex
========

.. doxygenclass:: idol::OsiCplex
6 changes: 6 additions & 0 deletions docs/api/optimizers/wrappers/Osi/OsiSymphony.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _api_OsiSymphony:

OsiSymphony
===========

.. doxygenclass:: idol::OsiSymphony
36 changes: 36 additions & 0 deletions docs/api/optimizers/wrappers/Osi/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. _api_Osi:

COIN-OR/Osi (Cplex, Xpress, Cbc, ...)
==========================================

Idol can be linked with the `coin-or/Osi <https://github.com/coin-or/Osi>`_ library (*Open Solver Interface*) to use any solver having an osi interface.

.. hint::

At the moment, only Cplex has been properly tested and can be used as follows.

.. code-block::
model.use(OsiCplex());
.. hint::

Note that Osi can also be used with *any* Osi object by directly passing the interface as an argument.

.. code-block::
model.use(Osi(OsiCpxSolverInterface())); // same as: model.use(OsiCplex());
.. warning::

Though idol has dedicated optimizers for Symphony, Cbc and Clp, it seems that the osi interface for these solvers do not
fully fulfill the interface requirement to have a stable usage.

.. toctree::
:maxdepth: 1
:glob:

*

.. doxygenclass:: idol::Osi

9 changes: 7 additions & 2 deletions docs/api/optimizers/wrappers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ External Solvers
================

.. toctree::
:maxdepth: 1
:maxdepth: 2
:glob:

*
GLPK
Gurobi
HiGHS
MibS
Osi/index
Mosek
6 changes: 3 additions & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ add_library(idol STATIC
include/idol/optimizers/Optimizer.h
include/idol/optimizers/wrappers/Gurobi/Optimizers_Gurobi.h
include/idol/optimizers/wrappers/OptimizerWithLazyUpdates.h
src/optimizers/wrappers/gurobi/Optimizers_Gurobi.cpp
src/optimizers/wrappers/Gurobi/Optimizers_Gurobi.cpp
src/optimizers/Optimizer.cpp
include/idol/optimizers/Algorithm.h
src/optimizers/Algorithm.cpp
Expand Down Expand Up @@ -105,12 +105,12 @@ add_library(idol STATIC
include/idol/optimizers/wrappers/Gurobi/Gurobi.h
include/idol/optimizers/wrappers/GLPK/GLPK.h
include/idol/optimizers/wrappers/Mosek/Mosek.h
src/optimizers/wrappers/gurobi/Gurobi.cpp
src/optimizers/wrappers/Gurobi/Gurobi.cpp
src/optimizers/wrappers/GLPK/GLPK.cpp
src/optimizers/wrappers/Mosek/Mosek.cpp
include/idol/optimizers/branch-and-bound/callbacks/BranchAndBoundCallbackFactory.h
include/idol/optimizers/callbacks/heuristics/IntegerMaster.h
src/optimizers/wrappers/gurobi/GurobiCallbackI.cpp
src/optimizers/wrappers/Gurobi/GurobiCallbackI.cpp
include/idol/optimizers/callbacks/Callback.h
src/optimizers/callbacks/Callback.cpp
include/idol/optimizers/callbacks/cutting-planes/CutSeparation.h
Expand Down
2 changes: 1 addition & 1 deletion lib/include/idol/modeling/variables/TempVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class idol::TempVar {

/**
* Sets the upper bound of the temporary variable.
* @param t_lb The desired upper bound of the temporary variable.
* @param t_ub The desired upper bound of the temporary variable.
*/
void set_ub(double t_ub) { m_ub = t_ub; }

Expand Down
2 changes: 2 additions & 0 deletions lib/include/idol/modeling/variables/Var.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class idol::Var : public Object<VarVersion, Var> {
* @tparam I Used for recursion.
* @param t_env The environment to store the variables.
* @param t_dim The number of elements in each dimension.
* @param t_lb The lower bound.
* @param t_ub The upper bound.
* @param t_type The type of the variables.
* @param t_name The given name of the variables.
* @return A (nested) vector of variables.
Expand Down
18 changes: 16 additions & 2 deletions lib/src/optimizers/wrappers/Osi/Optimizers_Osi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ idol::SolutionStatus idol::Optimizers::Osi::get_status() const {
return SubOptimal;
}

return Infeasible;
return Infeasible; // TODO This is done because MILPs do not have a proper status when infeasible... at least for Cplex

throw Exception("Osi::get_status could not infer status.");
}
Expand Down Expand Up @@ -324,7 +324,21 @@ void idol::Optimizers::Osi::hook_update(const idol::Var &t_var) {
}

void idol::Optimizers::Osi::hook_update(const idol::Ctr &t_ctr) {
throw Exception("Not implemented Osi::hook_update");

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

double lb = -Inf, ub = Inf;
switch (type) {
case LessOrEqual: ub = rhs; break;
case GreaterOrEqual: lb = rhs; break;
case Equal: ub = lb = rhs; break;
}

m_solver_interface->setRowBounds(impl, lb, ub);

}

void idol::Optimizers::Osi::hook_update_objective() {
Expand Down

0 comments on commit c820fc7

Please sign in to comment.