From ca85af4dbe2678f83b3ee11a79fee64e6f791543 Mon Sep 17 00:00:00 2001 From: Henri Lefebvre Date: Tue, 1 Oct 2024 13:52:12 +0200 Subject: [PATCH] fix IDOL_USE_MIBS --- .../mibs-from-file.example.cpp | 4 ++-- .../assignment-penalty-bap.example.cpp | 2 +- .../bilevel-optimization/wrappers/MibS/MibS.h | 2 +- .../callbacks/heuristics/IntegerMaster.h | 2 +- .../bilevel-optimization/wrappers/MibS/MibS.cpp | 15 ++++++++++++--- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/examples/bilevel-optimization/mibs-from-file.example.cpp b/examples/bilevel-optimization/mibs-from-file.example.cpp index b71d028a..2cbc3bab 100644 --- a/examples/bilevel-optimization/mibs-from-file.example.cpp +++ b/examples/bilevel-optimization/mibs-from-file.example.cpp @@ -18,9 +18,9 @@ int main(int t_argc, const char** t_argv) { auto [model, description] = Bilevel::read_from_file(env, aux_filename); model.use( - Bilevel::MibS(description) + Bilevel::MibS(description) .with_logs(true) - .with_optimizer(OsiCpxSolverInterface()) + .with_osi_interface(OsiCpxSolverInterface()) ); model.optimize(); diff --git a/examples/mixed-integer-optimization/assignment-penalty-bap.example.cpp b/examples/mixed-integer-optimization/assignment-penalty-bap.example.cpp index 188a34fe..7771e378 100644 --- a/examples/mixed-integer-optimization/assignment-penalty-bap.example.cpp +++ b/examples/mixed-integer-optimization/assignment-penalty-bap.example.cpp @@ -79,7 +79,7 @@ int main(int t_argc, const char** t_argv) { .with_subtree_depth(0) .with_branching_rule(MostInfeasible()) .with_node_selection_rule(WorstBound()) - //.add_callback(Heuristics::IntegerMaster().with_optimizer(HiGHS().with_logs(false))) + //.add_callback(Heuristics::IntegerMaster().with_osi_interface(HiGHS().with_logs(false))) .with_logs(true); // Set optimizer diff --git a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibS.h b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibS.h index 3eb4a5e5..7c76054a 100644 --- a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibS.h +++ b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibS.h @@ -37,7 +37,7 @@ class idol::Bilevel::MibS : public OptimizerFactoryWithDefaultParameters { Optimizer *operator()(const Model &t_model) const override; - MibS& with_optimizer(const OsiSolverInterface& t_osi_optimizer); + MibS& with_osi_interface(const OsiSolverInterface& t_osi_optimizer); MibS *clone() const override; }; diff --git a/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/heuristics/IntegerMaster.h b/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/heuristics/IntegerMaster.h index 6d5ef0a6..a0e53a74 100644 --- a/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/heuristics/IntegerMaster.h +++ b/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/heuristics/IntegerMaster.h @@ -91,7 +91,7 @@ template idol::BranchAndBoundCallback *idol::Heuristics::IntegerMaster::operator()() { if (!m_optimizer_factory) { - throw Exception("No solver was given to solve the integer master problem, please call IntegerMaster.rst::with_optimizer to configure."); + throw Exception("No solver was given to solve the integer master problem, please call IntegerMaster.rst::with_osi_interface to configure."); } auto* result = new Strategy(*m_optimizer_factory); diff --git a/lib/src/optimizers/bilevel-optimization/wrappers/MibS/MibS.cpp b/lib/src/optimizers/bilevel-optimization/wrappers/MibS/MibS.cpp index 953095b6..e3086acd 100644 --- a/lib/src/optimizers/bilevel-optimization/wrappers/MibS/MibS.cpp +++ b/lib/src/optimizers/bilevel-optimization/wrappers/MibS/MibS.cpp @@ -51,12 +51,18 @@ idol::Bilevel::MibS *idol::Bilevel::MibS::clone() const { idol::Bilevel::MibS::MibS(const idol::Bilevel::MibS &t_src) : m_description(t_src.m_description), - m_osi_interface(t_src.m_osi_interface ? t_src.m_osi_interface->clone() : nullptr) { + m_osi_interface( +#ifdef IDOL_USE_OSI + t_src.m_osi_interface ? t_src.m_osi_interface->clone() : nullptr +#else + nullptr +#endif + ) { } -idol::Bilevel::MibS &idol::Bilevel::MibS::with_optimizer(const OsiSolverInterface &t_osi_optimizer) { - +idol::Bilevel::MibS &idol::Bilevel::MibS::with_osi_interface(const OsiSolverInterface &t_osi_optimizer) { +#ifdef IDOL_USE_OSI if (m_osi_interface) { throw Exception("The optimizer has already been set."); } @@ -64,4 +70,7 @@ idol::Bilevel::MibS &idol::Bilevel::MibS::with_optimizer(const OsiSolverInterfac m_osi_interface = std::unique_ptr(t_osi_optimizer.clone()); return *this; +#else + throw Exception("idol was not linked with MibS."); +#endif }