Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hlefebvr/idol
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 30, 2024
2 parents 9e920a5 + 7163617 commit 0af5b61
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class idol::MibSCallbackI : public CallbackI {
m_parent.m_is_heuristic_call = true;
m_parent.call(InvalidSolution);

std::list<Solution::Primal>::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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ 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<double> m_worst_bound;
std::optional<double> m_worst_obj;
std::optional<double> m_best_obj;
std::optional<double> m_best_bound;
protected:
void initialize();
void operator()(CallbackEvent t_event) override;
public:
explicit Strategy(Manager& t_plot_manager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,7 +114,7 @@ class idol::Optimizers::PADM : public Algorithm {
double get_var_result(const Var &t_var, const std::function<double(const Var&, unsigned int)>& t_function) const;
private:
ADM::Formulation m_formulation;
const std::vector<idol::ADM::SubProblem> m_sub_problem_specs;
std::vector<idol::ADM::SubProblem> m_sub_problem_specs;
const std::unique_ptr<PenaltyUpdate> m_penalty_update;
const double m_initial_penalty_parameter;
const unsigned int m_max_inner_loop_iterations = std::numeric_limits<unsigned int>::max();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TCanvas.h>
Expand All @@ -11,11 +12,15 @@
#include <TAxis.h>

idol::Plots::OptimalityGap::Strategy::Strategy(idol::Plots::Manager &t_plot_manager)
: m_plot_manager(t_plot_manager),
m_canvas(t_plot_manager.create<TCanvas>("canvas", "canvas", 800, 600)),
m_graph_bound(t_plot_manager.create<TGraph>()),
m_graph_obj(t_plot_manager.create<TGraph>())
{
: m_plot_manager(t_plot_manager) {

}

void idol::Plots::OptimalityGap::Strategy::initialize() {

m_canvas = m_plot_manager.create<TCanvas>(generate_uuid_v4().c_str(), "canvas", 800, 600);
m_graph_bound = m_plot_manager.create<TGraph>();
m_graph_obj = m_plot_manager.create<TGraph>();

m_graph_bound->SetTitle("Optimality Gap over Time");

Expand All @@ -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();
Expand Down Expand Up @@ -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
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down

0 comments on commit 0af5b61

Please sign in to comment.