Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
Problem.h
1//
2// Created by marechaljas on 27/04/2022.
3//
4
5#ifndef ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
6#define ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
7
8#include <utility>
9
10#include "antares-xpansion/multisolver_interface/SolverAbstract.h"
11
16{
17public:
18 Problem() = delete;
19
20 explicit Problem(SolverAbstract::Ptr solver_abstract):
21 solver_abstract_(std::move(solver_abstract))
22 {
23 }
24
25private:
26 const SolverAbstract::Ptr solver_abstract_;
27
28public:
29 [[nodiscard]] unsigned int McYear() const
30 {
31 return mc_year;
32 }
33
34 [[nodiscard]] unsigned int Week() const
35 {
36 return week;
37 }
38
39 unsigned int mc_year = 0;
40 unsigned int week = 0;
41
43 {
44 return solver_abstract_->get_number_of_instances();
45 }
46
47 [[nodiscard]] std::string get_solver_name() const override
48 {
49 return solver_abstract_->get_solver_name();
50 }
51
52 void init() override
53 {
54 solver_abstract_->init();
55 }
56
57 void free() override
58 {
59 solver_abstract_->free();
60 }
61
62 void write_prob_mps(const std::filesystem::path& filename) override
63 {
64 solver_abstract_->write_prob_mps(filename);
65 }
66
67 void write_prob_lp(const std::filesystem::path& filename) override
68 {
69 solver_abstract_->write_prob_lp(filename);
70 }
71
72 void read_prob_mps(const std::filesystem::path& filename) override;
73
74 void read_prob_lp(const std::filesystem::path& filename) override
75 {
76 solver_abstract_->read_prob_lp(filename);
77 }
78
79 void copy_prob(Ptr fictif_solv) override
80 {
81 solver_abstract_->copy_prob(fictif_solv);
82 }
83
84 [[nodiscard]] int get_ncols() const override
85 {
86 return solver_abstract_->get_ncols();
87 }
88
89 [[nodiscard]] int get_nrows() const override
90 {
91 return solver_abstract_->get_nrows();
92 }
93
94 [[nodiscard]] int get_nelems() const override
95 {
96 return solver_abstract_->get_nelems();
97 }
98
99 [[nodiscard]] int get_n_integer_vars() const override
100 {
101 return solver_abstract_->get_n_integer_vars();
102 }
103
104 void get_obj(double* obj, int first, int last) const override
105 {
106 solver_abstract_->get_obj(obj, first, last);
107 }
108
109 void set_obj_to_zero() override
110 {
111 solver_abstract_->set_obj_to_zero();
112 }
113
114 void set_obj(const double* obj, int first, int last) override
115 {
116 solver_abstract_->set_obj(obj, first, last);
117 }
118
119 void get_rows(int* mstart,
120 int* mclind,
121 double* dmatval,
122 int size,
123 int* nels,
124 int first,
125 int last) const override
126 {
127 solver_abstract_->get_rows(mstart, mclind, dmatval, size, nels, first, last);
128 }
129
130 void get_row_type(char* qrtype, int first, int last) const override
131 {
132 solver_abstract_->get_row_type(qrtype, first, last);
133 }
134
135 void get_rhs(double* rhs, int first, int last) const override
136 {
137 solver_abstract_->get_rhs(rhs, first, last);
138 }
139
140 void get_rhs_range(double* range, int first, int last) const override
141 {
142 solver_abstract_->get_rhs_range(range, first, last);
143 }
144
145 void get_col_type(char* coltype, int first, int last) const override
146 {
147 solver_abstract_->get_col_type(coltype, first, last);
148 }
149
150 void get_lb(double* lb, int fisrt, int last) const override
151 {
152 solver_abstract_->get_lb(lb, fisrt, last);
153 }
154
155 void get_ub(double* ub, int fisrt, int last) const override
156 {
157 solver_abstract_->get_ub(ub, fisrt, last);
158 }
159
160 [[nodiscard]] int get_row_index(const std::string& name) override
161 {
162 return solver_abstract_->get_row_index(name);
163 }
164
165 [[nodiscard]] int get_col_index(const std::string& name) override
166 {
167 return solver_abstract_->get_col_index(name);
168 }
169
170 std::vector<std::string> get_row_names(int first, int last) override
171 {
172 return solver_abstract_->get_row_names(first, last);
173 }
174
175 std::vector<std::string> get_row_names() override
176 {
177 return solver_abstract_->get_row_names();
178 }
179
180 std::vector<std::string> get_col_names(int first, int last) override
181 {
182 return solver_abstract_->get_col_names(first, last);
183 }
184
185 std::vector<std::string> get_col_names() override
186 {
187 return solver_abstract_->get_col_names();
188 }
189
190 void del_rows(int first, int last) override
191 {
192 solver_abstract_->del_rows(first, last);
193 }
194
195 void add_rows(int newrows,
196 int newnz,
197 const char* qrtype,
198 const double* rhs,
199 const double* range,
200 const int* mstart,
201 const int* mclind,
202 const double* dmatval,
203 const std::vector<std::string>& names) override
204 {
205 solver_abstract_
206 ->add_rows(newrows, newnz, qrtype, rhs, range, mstart, mclind, dmatval, names);
207 }
208
209 void add_cols(int newcol,
210 int newnz,
211 const double* objx,
212 const int* mstart,
213 const int* mrwind,
214 const double* dmatval,
215 const double* bdl,
216 const double* bdu,
217 const std::vector<std::string>& names) override
218 {
219 solver_abstract_->add_cols(newcol, newnz, objx, mstart, mrwind, dmatval, bdl, bdu, names);
220 }
221
222 void add_name(int type, const char* cnames, int indice) override
223 {
224 solver_abstract_->add_name(type, cnames, indice);
225 }
226
227 void add_names(int type, const std::vector<std::string>& cnames, int first, int end) override
228 {
229 solver_abstract_->add_names(type, cnames, first, end);
230 }
231
232 void chg_obj(const std::vector<int>& mindex, const std::vector<double>& obj) override
233 {
234 solver_abstract_->chg_obj(mindex, obj);
235 }
236
237 void chg_obj_direction(const bool minimize) override
238 {
239 solver_abstract_->chg_obj_direction(minimize);
240 }
241
242 void chg_bounds(const std::vector<int>& mindex,
243 const std::vector<char>& qbtype,
244 const std::vector<double>& bnd) override
245 {
246 solver_abstract_->chg_bounds(mindex, qbtype, bnd);
247 }
248
249 void chg_col_type(const std::vector<int>& mindex, const std::vector<char>& qctype) override
250 {
251 solver_abstract_->chg_col_type(mindex, qctype);
252 }
253
254 void chg_rhs(int id_row, double val) override
255 {
256 solver_abstract_->chg_rhs(id_row, val);
257 }
258
259 void chg_coef(int id_row, int id_col, double val) override
260 {
261 solver_abstract_->chg_coef(id_row, id_col, val);
262 }
263
264 void chg_row_name(int id_row, const std::string& name) override
265 {
266 solver_abstract_->chg_row_name(id_row, name);
267 }
268
269 void chg_col_name(int id_col, const std::string& name) override
270 {
271 solver_abstract_->chg_col_name(id_col, name);
272 }
273
274 int solve_lp() override
275 {
276 return solver_abstract_->solve_lp();
277 }
278
279 int solve_mip() override
280 {
281 return solver_abstract_->solve_mip();
282 }
283
284 void get_basis(int* rstatus, int* cstatus) const override
285 {
286 solver_abstract_->get_basis(rstatus, cstatus);
287 }
288
289 [[nodiscard]] double get_mip_value() const override
290 {
291 return solver_abstract_->get_mip_value();
292 }
293
294 [[nodiscard]] double get_lp_value() const override
295 {
296 return solver_abstract_->get_lp_value();
297 }
298
299 [[nodiscard]] int get_splex_num_of_ite_last() const override
300 {
301 return solver_abstract_->get_splex_num_of_ite_last();
302 }
303
304 void get_lp_sol(double* primals, double* duals, double* reduced_costs) const override
305 {
306 solver_abstract_->get_lp_sol(primals, duals, reduced_costs);
307 }
308
309 void get_mip_sol(double* primals) override
310 {
311 solver_abstract_->get_mip_sol(primals);
312 }
313
314 void set_output_log_level(int loglevel) override
315 {
316 solver_abstract_->set_output_log_level(loglevel);
317 }
318
319 void set_algorithm(const std::string& algo) override
320 {
321 solver_abstract_->set_algorithm(algo);
322 }
323
324 void set_threads(int n_threads) override
325 {
326 solver_abstract_->set_threads(n_threads);
327 }
328
329 void set_optimality_gap(double gap) override
330 {
331 solver_abstract_->set_optimality_gap(gap);
332 }
333
334 void set_simplex_iter(int iter) override
335 {
336 solver_abstract_->set_simplex_iter(iter);
337 }
338
339 void write_basis(const std::filesystem::path& filename) override
340 {
341 solver_abstract_->write_basis(filename);
342 }
343
344 void read_basis(const std::filesystem::path& filename) override
345 {
346 solver_abstract_->read_basis(filename);
347 }
348
349 void save_prob(const std::filesystem::path& filename) override;
350 void restore_prob(const std::filesystem::path& filename) override;
351};
352
353#endif // ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
Decorator to the SolverAbstract class.
Definition Problem.h:16
void set_algorithm(const std::string &algo) override
Sets algorithm used by solver to solve LP's.
Definition Problem.h:319
void init() override
Initializes a problem.
Definition Problem.h:52
void get_row_type(char *qrtype, int first, int last) const override
Returns the row types for the rows in a given range.
Definition Problem.h:130
double get_lp_value() const override
Get the optimal value of a LP problem (available after method "solve_lp" )
Definition Problem.h:294
void chg_row_name(int id_row, const std::string &name) override
Change the name of a constraint.
Definition Problem.h:264
void add_rows(int newrows, int newnz, const char *qrtype, const double *rhs, const double *range, const int *mstart, const int *mclind, const double *dmatval, const std::vector< std::string > &names) override
Adds rows to the problem.
Definition Problem.h:195
void get_basis(int *rstatus, int *cstatus) const override
Returns the current basis into the user’s data arrays.
Definition Problem.h:284
void write_prob_mps(const std::filesystem::path &filename) override
writes an optimization problem in a MPS file
Definition Problem.h:62
void get_mip_sol(double *primals) override
Get MIP solution of a problem (available after method "solve_mip")
Definition Problem.h:309
void add_name(int type, const char *cnames, int indice) override
Adds a name to a row or a column.
Definition Problem.h:222
void set_obj_to_zero() override
Set the objective function coefficients to zero.
Definition Problem.h:109
int solve_mip() override
Solves a problem as MIP.
Definition Problem.h:279
int solve_lp() override
Solves a problem as LP.
Definition Problem.h:274
void get_rhs(double *rhs, int first, int last) const override
Returns the right-hand sides of the rows in a given range.
Definition Problem.h:135
std::vector< std::string > get_col_names() override
Returns the names of columns.
Definition Problem.h:185
void get_lb(double *lb, int fisrt, int last) const override
Returns the lower bounds for variables in a given range.
Definition Problem.h:150
std::vector< std::string > get_row_names(int first, int last) override
Returns the names of row from index first to last cannot be declared as const because of some solver ...
Definition Problem.h:170
int get_number_of_instances() override
Returns number of instances of solver currently in memory.
Definition Problem.h:42
int get_ncols() const override
returns number of columns of the problem
Definition Problem.h:84
void chg_bounds(const std::vector< int > &mindex, const std::vector< char > &qbtype, const std::vector< double > &bnd) override
Change bounds of some variables.
Definition Problem.h:242
void set_threads(int n_threads) override
Sets the maximum number of threads used to perform optimization.
Definition Problem.h:324
void set_obj(const double *obj, int first, int last) override
Set the objective function coefficients for the columns in a given range.
Definition Problem.h:114
void get_rows(int *mstart, int *mclind, double *dmatval, int size, int *nels, int first, int last) const override
get coefficients of rows from index first to last
Definition Problem.h:119
void write_basis(const std::filesystem::path &filename) override
Writes the current basis to a file for later input into the optimizer.
Definition Problem.h:339
void del_rows(int first, int last) override
Deletes rows between index first and last.
Definition Problem.h:190
void chg_rhs(int id_row, double val) override
Change rhs of a row.
Definition Problem.h:254
void chg_obj(const std::vector< int > &mindex, const std::vector< double > &obj) override
Change coefficients in objective function.
Definition Problem.h:232
void get_obj(double *obj, int first, int last) const override
returns the objective function coefficients for the columns in a given range
Definition Problem.h:104
int get_col_index(const std::string &name) override
Returns the index of column named "name".
Definition Problem.h:165
void set_output_log_level(int loglevel) override
Sets log level of the solver.
Definition Problem.h:314
void restore_prob(const std::filesystem::path &filename) override
read an optimisation problem from a file
Definition Problem.cpp:20
void get_lp_sol(double *primals, double *duals, double *reduced_costs) const override
Get LP solution of a problem (available after method "solve_lp")
Definition Problem.h:304
int get_nelems() const override
returns number of non zeros elements in the matrix, excluding objective
Definition Problem.h:94
std::string get_solver_name() const override
Returns the solver used.
Definition Problem.h:47
void get_ub(double *ub, int fisrt, int last) const override
Returns the upper bounds for variables in a given range.
Definition Problem.h:155
void read_prob_lp(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition Problem.h:74
void copy_prob(Ptr fictif_solv) override
copy an existing problem
Definition Problem.h:79
int get_splex_num_of_ite_last() const override
Get the number of simplex iterations done in the last resolution of the problem.
Definition Problem.h:299
void get_col_type(char *coltype, int first, int last) const override
Returns the column types for the columns in a given range.
Definition Problem.h:145
void get_rhs_range(double *range, int first, int last) const override
Returns the right hand side range values for the rows in a given range.
Definition Problem.h:140
std::vector< std::string > get_row_names() override
Returns the names of rows.
Definition Problem.h:175
void write_prob_lp(const std::filesystem::path &filename) override
writes an optimization problem in a LP file
Definition Problem.h:67
int get_row_index(const std::string &name) override
Returns the index of row named "name".
Definition Problem.h:160
void add_cols(int newcol, int newnz, const double *objx, const int *mstart, const int *mrwind, const double *dmatval, const double *bdl, const double *bdu, const std::vector< std::string > &names) override
Adds new columns to the problem.
Definition Problem.h:209
void save_prob(const std::filesystem::path &filename) override
write an optimisation problem in a file
Definition Problem.cpp:15
void read_prob_mps(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition Problem.cpp:9
int get_n_integer_vars() const override
returns number of integer variables in the problem
Definition Problem.h:99
void chg_col_type(const std::vector< int > &mindex, const std::vector< char > &qctype) override
Change type of some columns.
Definition Problem.h:249
void free() override
Frees all the datas contained in the Solver environment.
Definition Problem.h:57
void chg_coef(int id_row, int id_col, double val) override
Change a coefficient in the matrix.
Definition Problem.h:259
void set_optimality_gap(double gap) override
Sets the optimality gap.
Definition Problem.h:329
void chg_obj_direction(const bool minimize) override
Change the problem's objective function sense to minimize or maximize.
Definition Problem.h:237
int get_nrows() const override
returns number of rows of the problem
Definition Problem.h:89
void set_simplex_iter(int iter) override
Sets the maximum number of simplex iterations the solver can perform.
Definition Problem.h:334
void read_basis(const std::filesystem::path &filename) override
Instructs the optimizer to read in a previously saved basis from a file.
Definition Problem.h:344
std::vector< std::string > get_col_names(int first, int last) override
Returns the names of columns from index first to last cannot be declared as const because of some sol...
Definition Problem.h:180
void chg_col_name(int id_col, const std::string &name) override
Change the name of a variable.
Definition Problem.h:269
double get_mip_value() const override
Get the optimal value of a MIP problem (available after method "solve_mip")
Definition Problem.h:289
Definition SolverAbstract.h:200
std::shared_ptr< SolverAbstract > Ptr
Definition SolverAbstract.h:215