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"
19 : solver_abstract_(std::move(solver_abstract)) {}
25 [[nodiscard]]
unsigned int McYear()
const {
return mc_year; }
26 [[nodiscard]]
unsigned int Week()
const {
return week; }
28 unsigned int mc_year = 0;
29 unsigned int week = 0;
32 return solver_abstract_->get_number_of_instances();
35 return solver_abstract_->get_solver_name();
37 void init()
override { solver_abstract_->init(); }
38 void free()
override { solver_abstract_->free(); }
40 solver_abstract_->write_prob_mps(filename);
43 solver_abstract_->write_prob_lp(filename);
45 void read_prob_mps(
const std::filesystem::path &filename)
override;
46 void read_prob_lp(
const std::filesystem::path &filename)
override {
47 solver_abstract_->read_prob_lp(filename);
50 solver_abstract_->copy_prob(fictif_solv);
53 return solver_abstract_->get_ncols();
56 return solver_abstract_->get_nrows();
59 return solver_abstract_->get_nelems();
62 return solver_abstract_->get_n_integer_vars();
64 void get_obj(
double *obj,
int first,
int last)
const override {
65 solver_abstract_->get_obj(obj, first, last);
69 void set_obj(
const double *obj,
int first,
int last)
override {
70 solver_abstract_->set_obj(obj, first, last);
72 void get_rows(
int *mstart,
int *mclind,
double *dmatval,
int size,
int *nels,
73 int first,
int last)
const override {
74 solver_abstract_->get_rows(mstart, mclind, dmatval, size, nels, first,
77 void get_row_type(
char *qrtype,
int first,
int last)
const override {
78 solver_abstract_->get_row_type(qrtype, first, last);
80 void get_rhs(
double *rhs,
int first,
int last)
const override {
81 solver_abstract_->get_rhs(rhs, first, last);
84 solver_abstract_->get_rhs_range(range, first, last);
86 void get_col_type(
char *coltype,
int first,
int last)
const override {
87 solver_abstract_->get_col_type(coltype, first, last);
89 void get_lb(
double *lb,
int fisrt,
int last)
const override {
90 solver_abstract_->get_lb(lb, fisrt, last);
92 void get_ub(
double *ub,
int fisrt,
int last)
const override {
93 solver_abstract_->get_ub(ub, fisrt, last);
96 return solver_abstract_->get_row_index(name);
99 return solver_abstract_->get_col_index(name);
102 return solver_abstract_->get_row_names(first, last);
105 return solver_abstract_->get_row_names();
108 return solver_abstract_->get_col_names(first, last);
111 return solver_abstract_->get_col_names();
114 solver_abstract_->del_rows(first, last);
116 void add_rows(
int newrows,
int newnz,
const char *qrtype,
const double *rhs,
117 const double *range,
const int *mstart,
const int *mclind,
118 const double *dmatval,
119 const std::vector<std::string> &names = {})
override {
120 solver_abstract_->add_rows(newrows, newnz, qrtype, rhs, range, mstart,
121 mclind, dmatval, names);
123 void add_cols(
int newcol,
int newnz,
const double *objx,
const int *mstart,
124 const int *mrwind,
const double *dmatval,
const double *bdl,
125 const double *bdu)
override {
126 solver_abstract_->add_cols(newcol, newnz, objx, mstart, mrwind, dmatval,
129 void add_name(
int type,
const char *cnames,
int indice)
override {
130 solver_abstract_->add_name(type, cnames, indice);
132 void add_names(
int type,
const std::vector<std::string> &cnames,
int first,
134 solver_abstract_->add_names(type, cnames, first, end);
137 const std::vector<double> &obj)
override {
138 solver_abstract_->chg_obj(mindex, obj);
141 solver_abstract_->chg_obj_direction(minimize);
144 const std::vector<char> &qbtype,
145 const std::vector<double> &bnd)
override {
146 solver_abstract_->chg_bounds(mindex, qbtype, bnd);
149 const std::vector<char> &qctype)
override {
150 solver_abstract_->chg_col_type(mindex, qctype);
152 void chg_rhs(
int id_row,
double val)
override {
153 solver_abstract_->chg_rhs(id_row, val);
155 void chg_coef(
int id_row,
int id_col,
double val)
override {
156 solver_abstract_->chg_coef(id_row, id_col, val);
159 solver_abstract_->chg_row_name(id_row, name);
162 solver_abstract_->chg_col_name(id_col, name);
164 int solve_lp()
override {
return solver_abstract_->solve_lp(); }
165 int solve_mip()
override {
return solver_abstract_->solve_mip(); }
166 void get_basis(
int *rstatus,
int *cstatus)
const override {
167 solver_abstract_->get_basis(rstatus, cstatus);
170 return solver_abstract_->get_mip_value();
173 return solver_abstract_->get_lp_value();
176 return solver_abstract_->get_splex_num_of_ite_last();
179 double *reduced_costs)
override {
180 solver_abstract_->get_lp_sol(primals, duals, reduced_costs);
183 solver_abstract_->get_mip_sol(primals);
186 solver_abstract_->set_output_log_level(loglevel);
189 solver_abstract_->set_algorithm(algo);
192 solver_abstract_->set_threads(n_threads);
195 solver_abstract_->set_optimality_gap(gap);
198 solver_abstract_->set_simplex_iter(iter);
200 void write_basis(
const std::filesystem::path &filename)
override {
201 solver_abstract_->write_basis(filename);
203 void read_basis(
const std::filesystem::path &filename)
override {
204 solver_abstract_->read_basis(filename);
206 void save_prob(
const std::filesystem::path &filename)
override;
207 void restore_prob(
const std::filesystem::path &filename)
override;
Decorator to the SolverAbstract class.
Definition Problem.h:15
void set_algorithm(const std::string &algo) override
Sets algorithm used by solver to solve LP's.
Definition Problem.h:188
void init() override
Initializes a problem.
Definition Problem.h:37
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:77
double get_lp_value() const override
Get the optimal value of a LP problem (available after method "solve_lp" )
Definition Problem.h:172
void chg_row_name(int id_row, const std::string &name) override
Change the name of a constraint.
Definition Problem.h:158
void get_basis(int *rstatus, int *cstatus) const override
Returns the current basis into the user’s data arrays.
Definition Problem.h:166
void write_prob_mps(const std::filesystem::path &filename) override
writes an optimization problem in a MPS file
Definition Problem.h:39
void get_mip_sol(double *primals) override
Get MIP solution of a problem (available after method "solve_mip")
Definition Problem.h:182
void add_name(int type, const char *cnames, int indice) override
Adds a name to a row or a column.
Definition Problem.h:129
void set_obj_to_zero() override
Set the objective function coefficients to zero.
Definition Problem.h:68
int solve_mip() override
Solves a problem as MIP.
Definition Problem.h:165
int solve_lp() override
Solves a problem as LP.
Definition Problem.h:164
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:80
std::vector< std::string > get_col_names() override
Returns the names of columns.
Definition Problem.h:110
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) override
Adds new columns to the problem.
Definition Problem.h:123
void get_lb(double *lb, int fisrt, int last) const override
Returns the lower bounds for variables in a given range.
Definition Problem.h:89
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:101
int get_number_of_instances() override
Returns number of instances of solver currently in memory.
Definition Problem.h:31
int get_ncols() const override
returns number of columns of the problem
Definition Problem.h:52
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:143
void set_threads(int n_threads) override
Sets the maximum number of threads used to perform optimization.
Definition Problem.h:191
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:69
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:72
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:200
void del_rows(int first, int last) override
Deletes rows between index first and last.
Definition Problem.h:113
void chg_rhs(int id_row, double val) override
Change rhs of a row.
Definition Problem.h:152
void chg_obj(const std::vector< int > &mindex, const std::vector< double > &obj) override
Change coefficients in objective function.
Definition Problem.h:136
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:64
int get_col_index(const std::string &name) override
Returns the index of column named "name".
Definition Problem.h:98
void set_output_log_level(int loglevel) override
Sets log level of the solver.
Definition Problem.h:185
void restore_prob(const std::filesystem::path &filename) override
read an optimisation problem from a file
Definition Problem.cpp:16
int get_nelems() const override
returns number of non zeros elements in the matrix, excluding objective
Definition Problem.h:58
void get_lp_sol(double *primals, double *duals, double *reduced_costs) override
Get LP solution of a problem (available after method "solve_lp")
Definition Problem.h:178
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:116
std::string get_solver_name() const override
Returns the solver used.
Definition Problem.h:34
void get_ub(double *ub, int fisrt, int last) const override
Returns the upper bounds for variables in a given range.
Definition Problem.h:92
void read_prob_lp(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition Problem.h:46
void copy_prob(Ptr fictif_solv) override
copy an existing problem
Definition Problem.h:49
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:175
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:86
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:83
std::vector< std::string > get_row_names() override
Returns the names of rows.
Definition Problem.h:104
void write_prob_lp(const std::filesystem::path &filename) override
writes an optimization problem in a LP file
Definition Problem.h:42
int get_row_index(const std::string &name) override
Returns the index of row named "name".
Definition Problem.h:95
void save_prob(const std::filesystem::path &filename) override
write an optimisation problem in a file
Definition Problem.cpp:13
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:61
void chg_col_type(const std::vector< int > &mindex, const std::vector< char > &qctype) override
Change type of some columns.
Definition Problem.h:148
void free() override
Frees all the datas contained in the Solver environment.
Definition Problem.h:38
void chg_coef(int id_row, int id_col, double val) override
Change a coefficient in the matrix.
Definition Problem.h:155
void set_optimality_gap(double gap) override
Sets the optimality gap.
Definition Problem.h:194
void chg_obj_direction(const bool minimize) override
Change the problem's objective function sense to minimize or maximize.
Definition Problem.h:140
int get_nrows() const override
returns number of rows of the problem
Definition Problem.h:55
void set_simplex_iter(int iter) override
Sets the maximum number of simplex iterations the solver can perform.
Definition Problem.h:197
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:203
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:107
void chg_col_name(int id_col, const std::string &name) override
Change the name of a variable.
Definition Problem.h:161
double get_mip_value() const override
Get the optimal value of a MIP problem (available after method "solve_mip")
Definition Problem.h:169
Definition SolverAbstract.h:170
std::shared_ptr< SolverAbstract > Ptr
Definition SolverAbstract.h:181