Skip to content

Commit

Permalink
fix IDOL_USE_MIBS
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 1, 2024
1 parent f174fc4 commit ca85af4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/bilevel-optimization/mibs-from-file.example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ int main(int t_argc, const char** t_argv) {
auto [model, description] = Bilevel::read_from_file<Gurobi>(env, aux_filename);

model.use(
Bilevel::MibS(description)
Bilevel::MibS(description)
.with_logs(true)
.with_optimizer(OsiCpxSolverInterface())
.with_osi_interface(OsiCpxSolverInterface())
);

model.optimize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class idol::Bilevel::MibS : public OptimizerFactoryWithDefaultParameters<MibS> {

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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ template<class NodeInfoT>
idol::BranchAndBoundCallback<NodeInfoT> *idol::Heuristics::IntegerMaster<NodeInfoT>::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);
Expand Down
15 changes: 12 additions & 3 deletions lib/src/optimizers/bilevel-optimization/wrappers/MibS/MibS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,26 @@ 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.");
}

m_osi_interface = std::unique_ptr<OsiSolverInterface>(t_osi_optimizer.clone());

return *this;
#else
throw Exception("idol was not linked with MibS.");
#endif
}

0 comments on commit ca85af4

Please sign in to comment.