5#ifndef ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
6#define ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
10#include "antares-xpansion/multisolver_interface/SolverAbstract.h"
21 solver_abstract_(std::move(solver_abstract))
29 [[nodiscard]]
unsigned int McYear()
const
34 [[nodiscard]]
unsigned int Week()
const
39 unsigned int mc_year = 0;
40 unsigned int week = 0;
44 return solver_abstract_->get_number_of_instances();
49 return solver_abstract_->get_solver_name();
54 solver_abstract_->init();
59 solver_abstract_->free();
64 solver_abstract_->write_prob_mps(filename);
69 solver_abstract_->write_prob_lp(filename);
72 void read_prob_mps(
const std::filesystem::path& filename)
override;
76 solver_abstract_->read_prob_lp(filename);
81 solver_abstract_->copy_prob(fictif_solv);
86 return solver_abstract_->get_ncols();
91 return solver_abstract_->get_nrows();
96 return solver_abstract_->get_nelems();
101 return solver_abstract_->get_n_integer_vars();
104 void get_obj(
double* obj,
int first,
int last)
const override
106 solver_abstract_->get_obj(obj, first, last);
111 solver_abstract_->set_obj_to_zero();
114 void set_obj(
const double* obj,
int first,
int last)
override
116 solver_abstract_->set_obj(obj, first, last);
125 int last)
const override
127 solver_abstract_->get_rows(mstart, mclind, dmatval, size, nels, first, last);
132 solver_abstract_->get_row_type(qrtype, first, last);
135 void get_rhs(
double* rhs,
int first,
int last)
const override
137 solver_abstract_->get_rhs(rhs, first, last);
142 solver_abstract_->get_rhs_range(range, first, last);
147 solver_abstract_->get_col_type(coltype, first, last);
150 void get_lb(
double* lb,
int fisrt,
int last)
const override
152 solver_abstract_->get_lb(lb, fisrt, last);
155 void get_ub(
double* ub,
int fisrt,
int last)
const override
157 solver_abstract_->get_ub(ub, fisrt, last);
162 return solver_abstract_->get_row_index(name);
167 return solver_abstract_->get_col_index(name);
172 return solver_abstract_->get_row_names(first, last);
177 return solver_abstract_->get_row_names();
182 return solver_abstract_->get_col_names(first, last);
187 return solver_abstract_->get_col_names();
192 solver_abstract_->del_rows(first, last);
202 const double* dmatval,
203 const std::vector<std::string>& names)
override
206 ->add_rows(newrows, newnz, qrtype, rhs, range, mstart, mclind, dmatval, names);
214 const double* dmatval,
217 const std::vector<std::string>& names)
override
219 solver_abstract_->add_cols(newcol, newnz, objx, mstart, mrwind, dmatval, bdl, bdu, names);
222 void add_name(
int type,
const char* cnames,
int indice)
override
224 solver_abstract_->add_name(type, cnames, indice);
227 void add_names(
int type,
const std::vector<std::string>& cnames,
int first,
int end)
override
229 solver_abstract_->add_names(type, cnames, first, end);
232 void chg_obj(
const std::vector<int>& mindex,
const std::vector<double>& obj)
override
234 solver_abstract_->chg_obj(mindex, obj);
239 solver_abstract_->chg_obj_direction(minimize);
243 const std::vector<char>& qbtype,
244 const std::vector<double>& bnd)
override
246 solver_abstract_->chg_bounds(mindex, qbtype, bnd);
249 void chg_col_type(
const std::vector<int>& mindex,
const std::vector<char>& qctype)
override
251 solver_abstract_->chg_col_type(mindex, qctype);
256 solver_abstract_->chg_rhs(id_row, val);
259 void chg_coef(
int id_row,
int id_col,
double val)
override
261 solver_abstract_->chg_coef(id_row, id_col, val);
266 solver_abstract_->chg_row_name(id_row, name);
271 solver_abstract_->chg_col_name(id_col, name);
276 return solver_abstract_->solve_lp();
281 return solver_abstract_->solve_mip();
284 void get_basis(
int* rstatus,
int* cstatus)
const override
286 solver_abstract_->get_basis(rstatus, cstatus);
291 return solver_abstract_->get_mip_value();
296 return solver_abstract_->get_lp_value();
301 return solver_abstract_->get_splex_num_of_ite_last();
304 void get_lp_sol(
double* primals,
double* duals,
double* reduced_costs)
const override
306 solver_abstract_->get_lp_sol(primals, duals, reduced_costs);
311 solver_abstract_->get_mip_sol(primals);
316 solver_abstract_->set_output_log_level(loglevel);
321 solver_abstract_->set_algorithm(algo);
326 solver_abstract_->set_threads(n_threads);
331 solver_abstract_->set_optimality_gap(gap);
336 solver_abstract_->set_simplex_iter(iter);
341 solver_abstract_->write_basis(filename);
344 void read_basis(
const std::filesystem::path& filename)
override
346 solver_abstract_->read_basis(filename);
349 void save_prob(
const std::filesystem::path& filename)
override;
350 void restore_prob(
const std::filesystem::path& filename)
override;
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