idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
Optimizers_ColumnAndConstraintGeneration.h
1//
2// Created by henri on 11.12.24.
3//
4
5#ifndef IDOL_OPTIMIZERS_COLUMNANDCONSTRAINTGENERATION_H
6#define IDOL_OPTIMIZERS_COLUMNANDCONSTRAINTGENERATION_H
7
8#include "idol/robust/modeling/Description.h"
9#include "idol/general/optimizers/Algorithm.h"
10#include "idol/general/optimizers/OptimizerFactory.h"
11#include "Formulation.h"
12#include "idol/bilevel/modeling/Description.h"
13
14namespace idol::Optimizers::Robust {
15 class ColumnAndConstraintGeneration;
16}
17
19
20 const ::idol::Robust::Description &m_robust_description;
21 const ::idol::Bilevel::Description &m_bilevel_description;
22 std::unique_ptr<OptimizerFactory> m_master_optimizer;
23 std::unique_ptr<idol::CCG::Formulation> m_formulation;
24 bool m_check_for_repeated_scenarios;
25 unsigned int m_n_iterations = 0;
26
27 // Initial scenarios
28 std::vector<Point<Var>> m_initial_scenarios;
29 std::unique_ptr<OptimizerFactory> m_initial_scenario_by_minimization;
30 std::unique_ptr<OptimizerFactory> m_initial_scenario_by_maximization;
31
32 // Feasibility Separation
33 const bool m_with_feasibility_separation_loop_reset = false;
34 const bool m_with_annotation_for_infeasible_scenario = true;
35 std::vector<std::unique_ptr<OptimizerFactory>> m_optimizer_feasibility_separation;
36 unsigned int m_index_feasibility_separation = 0;
37
38 // Optimality Separation
39 const bool m_with_optimality_separation_loop_reset = false;
40 std::vector<std::unique_ptr<OptimizerFactory>> m_optimizer_optimality_separation;
41 unsigned int m_index_optimality_separation = 0;
42
43 // Joint Separation
44 const bool m_with_joint_separation_loop_reset = false;
45 std::vector<std::unique_ptr<OptimizerFactory>> m_optimizer_joint_separation;
46 unsigned int m_index_joint_separation = 0;
47
48 std::optional<PrimalPoint> m_last_master_solution;
49
50 // Timers
51 Timer m_master_timer;
52 Timer m_separation_timer;
53public:
55 const ::idol::Robust::Description &t_robust_description,
56 const ::idol::Bilevel::Description &t_bilevel_description,
57 const OptimizerFactory &t_master_optimizer,
58 std::vector<Point<Var>> t_initial_scenarios,
59 OptimizerFactory* t_initial_scenario_by_minimization,
60 OptimizerFactory* t_initial_scenario_by_maximization,
61 const std::list<std::unique_ptr<OptimizerFactory>>& t_optimizer_feasibility_separation,
62 const std::list<std::unique_ptr<OptimizerFactory>>& t_optimizer_optimality_separation,
63 const std::list<std::unique_ptr<OptimizerFactory>>& t_optimizer_joint_separation,
64 bool t_check_for_repeated_scenarios);
65
66 [[nodiscard]] std::string name() const override;
67
68 [[nodiscard]] double get_var_primal(const Var &t_var) const override;
69
70 [[nodiscard]] double get_var_reduced_cost(const Var &t_var) const override;
71
72 [[nodiscard]] double get_var_ray(const Var &t_var) const override;
73
74 [[nodiscard]] double get_ctr_dual(const Ctr &t_ctr) const override;
75
76 [[nodiscard]] double get_ctr_farkas(const Ctr &t_ctr) const override;
77
78 [[nodiscard]] unsigned int get_n_solutions() const override;
79
80 [[nodiscard]] unsigned int get_solution_index() const override;
81
82 [[nodiscard]] unsigned int get_n_scenarios() const { return m_formulation->n_added_scenarios(); }
83
84 [[nodiscard]] unsigned int get_n_iterations() const { return m_n_iterations; }
85
86 [[nodiscard]] const Timer& get_master_timer() const { return m_master_timer; }
87
88 [[nodiscard]] const Timer& get_separation_timer() const { return m_separation_timer; }
89
90 [[nodiscard]] bool check_for_repeated_scenarios() const { return m_check_for_repeated_scenarios; }
91
92protected:
93 void add(const Var &t_var) override;
94
95 void add(const Ctr &t_ctr) override;
96
97 void add(const QCtr &t_ctr) override;
98
99 void remove(const Var &t_var) override;
100
101 void remove(const Ctr &t_ctr) override;
102
103 void remove(const QCtr &t_ctr) override;
104
105 void update() override;
106
107 void write(const std::string &t_name) override;
108
109 void hook_before_optimize() override;
110
111 void hook_optimize() override;
112
113 void set_solution_index(unsigned int t_index) override;
114
115 void update_obj_sense() override;
116
117 void update_obj() override;
118
119 void update_rhs() override;
120
121 void update_obj_constant() override;
122
123 void update_mat_coeff(const Ctr &t_ctr, const Var &t_var) override;
124
125 void update_ctr_type(const Ctr &t_ctr) override;
126
127 void update_ctr_rhs(const Ctr &t_ctr) override;
128
129 void update_var_type(const Var &t_var) override;
130
131 void update_var_lb(const Var &t_var) override;
132
133 void update_var_ub(const Var &t_var) override;
134
135 void update_var_obj(const Var &t_var) override;
136
137 void add_initial_scenarios();
138
139 void add_initial_scenario_by_min_or_max(const OptimizerFactory& t_optimizer, double t_coefficient);
140
141 void solve_master_problem();
142
143 void check_termination_criteria();
144
145 void log_banner();
146 void log_iteration(bool t_is_feasibility_separation,
147 const std::string& t_optimizer_name,
148 const SolutionStatus& t_status,
149 const SolutionReason& t_reason,
150 bool t_separation_outcome);
151 void log_iteration_separator();
152
153 void solve_adversarial_problem();
154 unsigned int solve_feasibility_adversarial_problem();
155 unsigned int solve_optimality_adversarial_problem();
156 unsigned int solve_joint_adversarial_problem();
157
158};
159
160
161#endif //IDOL_OPTIMIZERS_COLUMNANDCONSTRAINTGENERATION_H