diff --git a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibSCallbackI.h b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibSCallbackI.h index 5f60fccb..303563c1 100644 --- a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibSCallbackI.h +++ b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/MibSCallbackI.h @@ -51,7 +51,7 @@ class idol::MibSCallbackI : public CallbackI { m_parent.m_is_heuristic_call = true; m_parent.call(InvalidSolution); - std::list::iterator solution = m_solutions.end(); + auto solution = m_solutions.end(); double current_best = m_parent.best_obj(); for (auto it = m_solutions.begin(), end = m_solutions.end(); it != end ; ++it) { if (it->objective_value() < current_best) { @@ -142,11 +142,11 @@ class idol::MibSCallbackI : public CallbackI { BlisHeuristic& heuristic() { return *m_heuristic; } - const BlisHeuristic& heuristic() const { return *m_heuristic; } + [[nodiscard]] const BlisHeuristic& heuristic() const { return *m_heuristic; } CglCutGenerator& cut_generator() { return *m_cut_generator; } - const CglCutGenerator& cut_generator() const { return *m_cut_generator; } + [[nodiscard]] const CglCutGenerator& cut_generator() const { return *m_cut_generator; } protected: [[nodiscard]] const Model &original_model() const override { return m_parent.m_model; diff --git a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/Optimizers_MibS.h b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/Optimizers_MibS.h index 5b81b5b5..da3fd575 100644 --- a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/Optimizers_MibS.h +++ b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/Optimizers_MibS.h @@ -53,6 +53,8 @@ class idol::Optimizers::Bilevel::MibS : public Optimizer { unsigned int get_solution_index() const override; void add_callback(Callback* t_callback); + const idol::Bilevel::LowerLevelDescription& bilevel_description() const { return m_description; } + protected: void build() override; void add(const Var &t_var) override; diff --git a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/impl_MibSFromAPI.h b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/impl_MibSFromAPI.h index d8448ce5..806d9a57 100644 --- a/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/impl_MibSFromAPI.h +++ b/lib/include/idol/optimizers/bilevel-optimization/wrappers/MibS/impl_MibSFromAPI.h @@ -54,19 +54,19 @@ class idol::impl::MibSFromAPI : public idol::impl::MibS { void solve() override; - double get_best_obj() const override; + [[nodiscard]] double get_best_obj() const override; - double get_best_bound() const override; + [[nodiscard]] double get_best_bound() const override; - double get_var_primal(const Var& t_var) const override; + [[nodiscard]] double get_var_primal(const Var& t_var) const override; - idol::SolutionStatus get_status() const override; + [[nodiscard]] idol::SolutionStatus get_status() const override; - idol::SolutionReason get_reason() const override; + [[nodiscard]] idol::SolutionReason get_reason() const override; friend class ::idol::MibSCallbackI; }; -#endif - #endif //IDOL_IMPL_MIBS_FROM_API_H + +#endif \ No newline at end of file diff --git a/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.h b/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.h index da82311b..6c5bf0af 100644 --- a/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.h +++ b/lib/include/idol/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.h @@ -22,9 +22,9 @@ class idol::Plots::OptimalityGap : public CallbackFactory { public: class Strategy : public Callback { Manager& m_plot_manager; - TCanvas* m_canvas; - TGraph* m_graph_bound; - TGraph* m_graph_obj; + TCanvas* m_canvas = nullptr; + TGraph* m_graph_bound = nullptr; + TGraph* m_graph_obj = nullptr; int m_n_points_bound = 0; int m_n_points_obj = 0; std::optional m_worst_bound; @@ -32,6 +32,7 @@ class idol::Plots::OptimalityGap : public CallbackFactory { std::optional m_best_obj; std::optional m_best_bound; protected: + void initialize(); void operator()(CallbackEvent t_event) override; public: explicit Strategy(Manager& t_plot_manager); diff --git a/lib/include/idol/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.h b/lib/include/idol/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.h index aae67b02..6a140551 100644 --- a/lib/include/idol/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.h +++ b/lib/include/idol/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.h @@ -45,6 +45,8 @@ class idol::Optimizers::PADM : public Algorithm { unsigned int get_inner_loop_iteration_count() const; + ADM::SubProblem& sub_problem_spec(unsigned int t_sub_problem_id); + class IterationPlot; protected: void add(const Var &t_var) override; @@ -112,7 +114,7 @@ class idol::Optimizers::PADM : public Algorithm { double get_var_result(const Var &t_var, const std::function& t_function) const; private: ADM::Formulation m_formulation; - const std::vector m_sub_problem_specs; + std::vector m_sub_problem_specs; const std::unique_ptr m_penalty_update; const double m_initial_penalty_parameter; const unsigned int m_max_inner_loop_iterations = std::numeric_limits::max(); diff --git a/lib/include/idol/optimizers/mixed-integer-optimization/padm/SubProblem.h b/lib/include/idol/optimizers/mixed-integer-optimization/padm/SubProblem.h index d39e5621..fa5d284a 100644 --- a/lib/include/idol/optimizers/mixed-integer-optimization/padm/SubProblem.h +++ b/lib/include/idol/optimizers/mixed-integer-optimization/padm/SubProblem.h @@ -27,7 +27,7 @@ class idol::ADM::SubProblem { SubProblem& with_optimizer(const OptimizerFactory& t_optimizer_factory); - SubProblem& with_initial_point(const Solution::Primal& t_initial_point); + SubProblem& with_initial_point(const Solution::Primal& t_initial_point, bool t_force = false); const OptimizerFactory& optimizer_factory() const; diff --git a/lib/src/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.cpp b/lib/src/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.cpp index 47b92538..a124308a 100644 --- a/lib/src/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.cpp +++ b/lib/src/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.cpp @@ -3,6 +3,7 @@ // #include "idol/optimizers/mixed-integer-optimization/callbacks/watchers/Plots_OptimalityGap.h" #include "idol/optimizers/Timer.h" +#include "idol/containers/uuid.h" #ifdef IDOL_USE_ROOT #include @@ -11,11 +12,15 @@ #include idol::Plots::OptimalityGap::Strategy::Strategy(idol::Plots::Manager &t_plot_manager) - : m_plot_manager(t_plot_manager), - m_canvas(t_plot_manager.create("canvas", "canvas", 800, 600)), - m_graph_bound(t_plot_manager.create()), - m_graph_obj(t_plot_manager.create()) -{ + : m_plot_manager(t_plot_manager) { + +} + +void idol::Plots::OptimalityGap::Strategy::initialize() { + + m_canvas = m_plot_manager.create(generate_uuid_v4().c_str(), "canvas", 800, 600); + m_graph_bound = m_plot_manager.create(); + m_graph_obj = m_plot_manager.create(); m_graph_bound->SetTitle("Optimality Gap over Time"); @@ -30,11 +35,14 @@ idol::Plots::OptimalityGap::Strategy::Strategy(idol::Plots::Manager &t_plot_mana m_graph_obj->SetMarkerColor(kRed); m_canvas->cd(); - } void idol::Plots::OptimalityGap::Strategy::operator()(CallbackEvent t_event) { + if (!m_canvas) { + initialize(); + } + const double t = time().count(); const double bound = best_bound(); const double obj = best_obj(); @@ -117,8 +125,13 @@ idol::Plots::OptimalityGap::Strategy::Strategy(idol::Plots::Manager & t_plot_man { throw idol::Exception("idol was not compiled with ROOT."); } + +void idol::Plots::OptimalityGap::Strategy::initialize() { + +} + void idol::Plots::OptimalityGap::Strategy::operator()(idol::CallbackEvent t_event){ throw idol::Exception("idol was not compiled with ROOT."); } -#endif \ No newline at end of file +#endif diff --git a/lib/src/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.cpp b/lib/src/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.cpp index e8dd32ab..839ebfce 100644 --- a/lib/src/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.cpp +++ b/lib/src/optimizers/mixed-integer-optimization/padm/Optimizers_PADM.cpp @@ -639,6 +639,10 @@ void idol::Optimizers::PADM::restart() { ++m_n_restart; } +idol::ADM::SubProblem &idol::Optimizers::PADM::sub_problem_spec(unsigned int t_sub_problem_id) { + return m_sub_problem_specs.at(t_sub_problem_id); +} + idol::Optimizers::PADM::IterationPlot::IterationPlot(idol::Plots::Manager &t_manager) : m_manager(t_manager) { } diff --git a/lib/src/optimizers/mixed-integer-optimization/padm/SubProblem.cpp b/lib/src/optimizers/mixed-integer-optimization/padm/SubProblem.cpp index 325812dd..3eec2d35 100644 --- a/lib/src/optimizers/mixed-integer-optimization/padm/SubProblem.cpp +++ b/lib/src/optimizers/mixed-integer-optimization/padm/SubProblem.cpp @@ -29,9 +29,9 @@ const idol::OptimizerFactory &idol::ADM::SubProblem::optimizer_factory() const { return *m_optimizer_factory; } -idol::ADM::SubProblem &idol::ADM::SubProblem::with_initial_point(const Solution::Primal &t_initial_point) { +idol::ADM::SubProblem &idol::ADM::SubProblem::with_initial_point(const Solution::Primal &t_initial_point, bool t_force) { - if (m_initial_point) { + if (!t_force && m_initial_point) { throw Exception("The initial point has already been set."); }