5#ifndef ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
6#define ANTARESXPANSION_SRC_CPP_LPNAMER_MODEL_PROBLEM_H_
11#include "antares-xpansion/multisolver_interface/SolverAbstract.h"
21 [[nodiscard]]
Problem* clone()
const override
26 explicit Problem(std::shared_ptr<SolverAbstract> solver_abstract):
27 solver_abstract_(std::move(solver_abstract))
32 const std::shared_ptr<SolverAbstract> solver_abstract_;
35 [[nodiscard]]
unsigned int McYear()
const
40 [[nodiscard]]
unsigned int Week()
const
45 unsigned int mc_year = 0;
46 unsigned int week = 0;
50 return solver_abstract_->get_number_of_instances();
55 return solver_abstract_->get_solver_name();
60 solver_abstract_->init();
65 solver_abstract_->free();
70 solver_abstract_->write_prob_mps(filename);
75 solver_abstract_->write_prob_lp(filename);
78 void read_prob_mps(
const std::filesystem::path& filename)
override;
82 solver_abstract_->read_prob_lp(filename);
87 return solver_abstract_->get_ncols();
92 return solver_abstract_->get_nrows();
97 return solver_abstract_->get_nelems();
102 return solver_abstract_->get_n_integer_vars();
105 void get_obj(
double* obj,
int first,
int last)
const override
107 solver_abstract_->get_obj(obj, first, last);
112 solver_abstract_->set_obj_to_zero();
115 void set_obj(
const double* obj,
int first,
int last)
override
117 solver_abstract_->set_obj(obj, first, last);
126 int last)
const override
128 solver_abstract_->get_rows(mstart, mclind, dmatval, size, nels, first, last);
133 solver_abstract_->get_row_type(qrtype, first, last);
136 void get_rhs(
double* rhs,
int first,
int last)
const override
138 solver_abstract_->get_rhs(rhs, first, last);
143 solver_abstract_->get_rhs_range(range, first, last);
152 int last)
const override
154 solver_abstract_->get_cols(mstart, mrwind, dmatval, size, nels, first, last);
159 solver_abstract_->get_col_type(coltype, first, last);
162 void get_lb(
double* lb,
int fisrt,
int last)
const override
164 solver_abstract_->get_lb(lb, fisrt, last);
167 void get_ub(
double* ub,
int fisrt,
int last)
const override
169 solver_abstract_->get_ub(ub, fisrt, last);
174 return solver_abstract_->get_row_index(name);
179 return solver_abstract_->get_col_index(name);
184 return solver_abstract_->get_row_names(first, last);
189 return solver_abstract_->get_row_names();
194 return solver_abstract_->get_col_names(first, last);
199 return solver_abstract_->get_col_names();
204 solver_abstract_->del_rows(first, last);
209 solver_abstract_->del_cols(first, last);
219 const double* dmatval,
220 const std::vector<std::string>& names)
override
223 ->add_rows(newrows, newnz, qrtype, rhs, range, mstart, mclind, dmatval, names);
231 const double* dmatval,
234 const std::vector<std::string>& names)
override
236 solver_abstract_->add_cols(newcol, newnz, objx, mstart, mrwind, dmatval, bdl, bdu, names);
239 void add_name(
int type,
const char* cnames,
int indice)
override
241 solver_abstract_->add_name(type, cnames, indice);
244 void add_names(
int type,
const std::vector<std::string>& cnames,
int first,
int end)
override
246 solver_abstract_->add_names(type, cnames, first, end);
249 void chg_obj(
const std::vector<int>& mindex,
const std::vector<double>& obj)
override
251 solver_abstract_->chg_obj(mindex, obj);
256 solver_abstract_->chg_obj_direction(minimize);
260 const std::vector<char>& qbtype,
261 const std::vector<double>& bnd)
override
263 solver_abstract_->chg_bounds(mindex, qbtype, bnd);
266 void chg_col_type(
const std::vector<int>& mindex,
const std::vector<char>& qctype)
override
268 solver_abstract_->chg_col_type(mindex, qctype);
273 solver_abstract_->chg_rhs(id_row, val);
276 void chg_coef(
int id_row,
int id_col,
double val)
override
278 solver_abstract_->chg_coef(id_row, id_col, val);
283 solver_abstract_->chg_row_name(id_row, name);
288 solver_abstract_->chg_col_name(id_col, name);
293 return solver_abstract_->solve_lp();
298 return solver_abstract_->solve_mip();
301 void get_basis(
int* rstatus,
int* cstatus)
const override
303 solver_abstract_->get_basis(rstatus, cstatus);
308 return solver_abstract_->get_mip_value();
313 return solver_abstract_->get_lp_value();
318 return solver_abstract_->get_splex_num_of_ite_last();
321 void get_lp_sol(
double* primals,
double* duals,
double* reduced_costs)
const override
323 solver_abstract_->get_lp_sol(primals, duals, reduced_costs);
328 solver_abstract_->get_mip_sol(primals);
333 solver_abstract_->set_output_log_level(loglevel);
338 solver_abstract_->set_algorithm(algo);
343 solver_abstract_->set_threads(n_threads);
348 solver_abstract_->set_optimality_gap(gap);
353 solver_abstract_->set_simplex_iter(iter);
358 solver_abstract_->write_basis(filename);
361 void read_basis(
const std::filesystem::path& filename)
override
363 solver_abstract_->read_basis(filename);
366 void set_basis(std::span<int> rstatus, std::span<int> cstatus)
override
368 solver_abstract_->set_basis(rstatus, cstatus);
373 solver_abstract_->get_presolve_map(rowmap, colmap);
378 solver_abstract_->presolve_only();
383 solver_abstract_->mark_indices_to_keep_presolve(nrows, ncols, rowind, colind);
386 void save_prob(
const std::filesystem::path& filename)
override;
387 void restore_prob(
const std::filesystem::path& filename)
override;
Decorator to the SolverAbstract class.
Definition Problem.h:17
void set_algorithm(const std::string &algo) override
Sets algorithm used by solver to solve LP's.
Definition Problem.h:336
void init() override
Initializes a problem.
Definition Problem.h:58
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:131
void get_cols(int *mstart, int *mrwind, double *dmatval, int size, int *nels, int first, int last) const override
get coefficients of cols from index first to last
Definition Problem.h:146
double get_lp_value() const override
Get the optimal value of a LP problem (available after method "solve_lp" )
Definition Problem.h:311
void chg_row_name(int id_row, const std::string &name) override
Change the name of a constraint.
Definition Problem.h:281
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:212
void get_basis(int *rstatus, int *cstatus) const override
Returns the current basis into the user's data arrays.
Definition Problem.h:301
void write_prob_mps(const std::filesystem::path &filename) override
writes an optimization problem in a MPS file
Definition Problem.h:68
void get_mip_sol(double *primals) override
Get MIP solution of a problem (available after method "solve_mip")
Definition Problem.h:326
void add_name(int type, const char *cnames, int indice) override
Adds a name to a row or a column.
Definition Problem.h:239
std::vector< std::string > get_row_names(int first, int last) const override
Returns the names of row from index first to last cannot be declared as const because of some solver ...
Definition Problem.h:182
void set_obj_to_zero() override
Set the objective function coefficients to zero.
Definition Problem.h:110
int solve_mip() override
Solves a problem as MIP.
Definition Problem.h:296
int solve_lp() override
Solves a problem as LP.
Definition Problem.h:291
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:136
std::vector< std::string > get_col_names() override
Returns the names of columns.
Definition Problem.h:197
void get_lb(double *lb, int fisrt, int last) const override
Returns the lower bounds for variables in a given range.
Definition Problem.h:162
int get_number_of_instances() override
Returns number of instances of solver currently in memory.
Definition Problem.h:48
int get_ncols() const override
returns number of columns of the problem
Definition Problem.h:85
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:259
void set_threads(int n_threads) override
Sets the maximum number of threads used to perform optimization.
Definition Problem.h:341
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:115
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:120
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:356
void del_rows(int first, int last) override
Deletes rows between index first and last.
Definition Problem.h:202
void chg_rhs(int id_row, double val) override
Change rhs of a row.
Definition Problem.h:271
void chg_obj(const std::vector< int > &mindex, const std::vector< double > &obj) override
Change coefficients in objective function.
Definition Problem.h:249
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:105
int get_col_index(const std::string &name) override
Returns the index of column named "name".
Definition Problem.h:177
void set_output_log_level(int loglevel) override
Sets log level of the solver.
Definition Problem.h:331
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:321
int get_nelems() const override
returns number of non zeros elements in the matrix, excluding objective
Definition Problem.h:95
std::string get_solver_name() const override
Returns the solver used.
Definition Problem.h:53
void get_ub(double *ub, int fisrt, int last) const override
Returns the upper bounds for variables in a given range.
Definition Problem.h:167
void read_prob_lp(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition Problem.h:80
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:316
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:157
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:141
std::vector< std::string > get_row_names() override
Returns the names of rows.
Definition Problem.h:187
void write_prob_lp(const std::filesystem::path &filename) override
writes an optimization problem in a LP file
Definition Problem.h:73
int get_row_index(const std::string &name) override
Returns the index of row named "name".
Definition Problem.h:172
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:226
void save_prob(const std::filesystem::path &filename) override
write an optimisation problem in a file
Definition Problem.cpp:15
std::vector< std::string > get_col_names(int first, int last) const override
Returns the names of columns from index first to last cannot be declared as const because of some sol...
Definition Problem.h:192
void read_prob_mps(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition Problem.cpp:9
void mark_indices_to_keep_presolve(int nrows, int ncols, int *rowind, int *colind) override
Mark indices to keep during presolve (to be implemented by derived classes)
Definition Problem.h:381
int get_n_integer_vars() const override
returns number of integer variables in the problem
Definition Problem.h:100
void chg_col_type(const std::vector< int > &mindex, const std::vector< char > &qctype) override
Change type of some columns.
Definition Problem.h:266
void free() override
Frees all the datas contained in the Solver environment.
Definition Problem.h:63
void del_cols(int first, int last) override
Deletes col at index first and last.
Definition Problem.h:207
void chg_coef(int id_row, int id_col, double val) override
Change a coefficient in the matrix.
Definition Problem.h:276
void set_optimality_gap(double gap) override
Sets the optimality gap.
Definition Problem.h:346
void get_presolve_map(int *rowmap, int *colmap) const override
Get the presolve map (to be implemented by derived classes)
Definition Problem.h:371
void chg_obj_direction(const bool minimize) override
Change the problem's objective function sense to minimize or maximize.
Definition Problem.h:254
int get_nrows() const override
returns number of rows of the problem
Definition Problem.h:90
void set_simplex_iter(int iter) override
Sets the maximum number of simplex iterations the solver can perform.
Definition Problem.h:351
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:361
void chg_col_name(int id_col, const std::string &name) override
Change the name of a variable.
Definition Problem.h:286
void presolve_only() override
Presolve the problem (to be implemented by derived classes)
Definition Problem.h:376
double get_mip_value() const override
Get the optimal value of a MIP problem (available after method "solve_mip")
Definition Problem.h:306
Definition SolverAbstract.h:203