6#include "antares-xpansion/multisolver_interface/SolverAbstract.h"
7#include "antares-xpansion/multisolver_interface/environment.h"
21 static std::mutex license_guard;
25 const std::string name_ =
"XPRESS";
46 explicit SolverXpress(
const std::shared_ptr<const SolverAbstract> toCopy);
67 virtual void init()
override;
68 virtual void free()
override;
75 virtual void write_prob_mps(
const std::filesystem::path &filename)
override;
76 virtual void write_prob_lp(
const std::filesystem::path &filename)
override;
77 void save_prob(
const std::filesystem::path &filename)
override;
78 virtual void write_basis(
const std::filesystem::path &filename)
override;
80 virtual void read_prob_mps(
const std::filesystem::path &filename)
override;
81 virtual void read_prob_lp(
const std::filesystem::path &filename)
override;
82 void restore_prob(
const std::filesystem::path &filename)
override;
83 virtual void read_basis(
const std::filesystem::path &filename)
override;
88 virtual void read_prob(
const char *prob_name,
const char *flags);
99 virtual void get_obj(
double *obj,
int first,
int last)
const override;
101 void set_obj(
const double *obj,
int first,
int last)
override;
102 virtual void get_rows(
int *mstart,
int *mclind,
double *dmatval,
int size,
103 int *nels,
int first,
int last)
const override;
104 virtual void get_row_type(
char *qrtype,
int first,
int last)
const override;
105 virtual void get_rhs(
double *rhs,
int first,
int last)
const override;
106 virtual void get_rhs_range(
double *range,
int first,
int last)
const override;
107 virtual void get_col_type(
char *coltype,
int first,
int last)
const override;
108 virtual void get_lb(
double *lb,
int fisrt,
int last)
const override;
109 virtual void get_ub(
double *ub,
int fisrt,
int last)
const override;
113 virtual std::vector<std::string>
get_row_names(
int first,
int last)
override;
115 virtual std::vector<std::string>
get_col_names(
int first,
int last)
override;
123 virtual void del_rows(
int first,
int last)
override;
124 virtual void add_rows(
int newrows,
int newnz,
const char *qrtype,
125 const double *rhs,
const double *range,
126 const int *mstart,
const int *mclind,
127 const double *dmatval,
128 const std::vector<std::string> &names = {})
override;
129 virtual void add_cols(
int newcol,
int newnz,
const double *objx,
130 const int *mstart,
const int *mrwind,
131 const double *dmatval,
const double *bdl,
132 const double *bdu)
override;
133 virtual void add_name(
int type,
const char *cnames,
int indice)
override;
134 virtual void add_names(
int type,
const std::vector<std::string> &cnames,
135 int first,
int end)
override;
136 virtual void chg_obj(
const std::vector<int> &mindex,
137 const std::vector<double> &obj)
override;
139 virtual void chg_bounds(
const std::vector<int> &mindex,
140 const std::vector<char> &qbtype,
141 const std::vector<double> &bnd)
override;
142 virtual void chg_col_type(
const std::vector<int> &mindex,
143 const std::vector<char> &qctype)
override;
144 virtual void chg_rhs(
int id_row,
double val)
override;
145 virtual void chg_coef(
int id_row,
int id_col,
double val)
override;
146 virtual void chg_row_name(
int id_row, std::string
const &name)
override;
147 virtual void chg_col_name(
int id_col, std::string
const &name)
override;
178 virtual void get_basis(
int *rstatus,
int *cstatus)
const override;
182 virtual void get_lp_sol(
double *primals,
double *duals,
183 double *reduced_costs)
override;
184 virtual void get_mip_sol(
double *primals)
override;
192 virtual void set_algorithm(std::string
const &algo)
override;
198 std::ofstream _log_stream;
201 std::vector<std::string> get_names(
int type,
int n_elements);
212void errormsg(XPRSprob &xprs,
const char *sSubName,
int nLineNo,
int nErrCode);
222void optimizermsg(XPRSprob prob,
void *stream,
const char *sMsg,
int nLen,
Definition SolverAbstract.h:170
std::shared_ptr< SolverAbstract > Ptr
Definition SolverAbstract.h:181
Definition SolverAbstract.h:16
Definition SolverXpress.h:13
virtual void chg_coef(int id_row, int id_col, double val) override
Change a coefficient in the matrix.
Definition SolverXpress.cpp:442
virtual void chg_obj_direction(const bool minimize) override
Change the problem's objective function sense to minimize or maximize.
Definition SolverXpress.cpp:412
virtual void write_prob_mps(const std::filesystem::path &filename) override
writes an optimization problem in a MPS file
Definition SolverXpress.cpp:127
virtual int solve_lp() override
Solves a problem as LP.
Definition SolverXpress.cpp:461
virtual void get_col_type(char *coltype, int first, int last) const override
Returns the column types for the columns in a given range.
Definition SolverXpress.cpp:270
virtual void write_basis(const std::filesystem::path &filename) override
Writes the current basis to a file for later input into the optimizer.
Definition SolverXpress.cpp:140
virtual std::vector< std::string > get_col_names() override
Returns the names of columns.
Definition SolverXpress.cpp:346
virtual std::string get_solver_name() const override
Returns the solver used.
Definition SolverXpress.h:55
virtual int get_n_integer_vars() const override
returns number of integer variables in the problem
Definition SolverXpress.cpp:223
virtual void init() override
Initializes a problem.
Definition SolverXpress.cpp:101
virtual void get_obj(double *obj, int first, int last) const override
returns the objective function coefficients for the columns in a given range
Definition SolverXpress.cpp:230
virtual void add_name(int type, const char *cnames, int indice) override
Adds a name to a row or a column.
Definition SolverXpress.cpp:388
virtual void write_prob_lp(const std::filesystem::path &filename) override
writes an optimization problem in a LP file
Definition SolverXpress.cpp:133
SolverXpress()
Default constructor of a XPRESS solver.
Definition SolverXpress.cpp:27
virtual int get_nelems() const override
returns number of non zeros elements in the matrix, excluding objective
Definition SolverXpress.cpp:215
virtual void set_optimality_gap(double gap) override
Sets the optimality gap.
Definition SolverXpress.cpp:593
void save_prob(const std::filesystem::path &filename) override
write an optimisation problem in a file
Definition SolverXpress.cpp:606
virtual std::vector< std::string > get_row_names() override
Returns the names of rows.
Definition SolverXpress.cpp:329
virtual void get_basis(int *rstatus, int *cstatus) const override
Returns the current basis into the user’s data arrays.
Definition SolverXpress.cpp:515
virtual void set_algorithm(std::string const &algo) override
Sets algorithm used by solver to solve LP's.
Definition SolverXpress.cpp:571
virtual int get_ncols() const override
returns number of columns of the problem
Definition SolverXpress.cpp:201
void restore_prob(const std::filesystem::path &filename) override
read an optimisation problem from a file
Definition SolverXpress.cpp:615
void set_output_log_level(int loglevel) final
Sets log level of the solver.
Definition SolverXpress.cpp:556
virtual void del_rows(int first, int last) override
Deletes rows between index first and last.
Definition SolverXpress.cpp:355
virtual int get_nrows() const override
returns number of rows of the problem
Definition SolverXpress.cpp:208
XPRSprob _xprs
Definition SolverXpress.h:24
virtual double get_mip_value() const override
Get the optimal value of a MIP problem (available after method "solve_mip")
Definition SolverXpress.cpp:520
virtual 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 SolverXpress.cpp:265
virtual 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 SolverXpress.cpp:379
virtual void copy_prob(const SolverAbstract::Ptr fictif_solv) override
copy an existing problem
Definition SolverXpress.cpp:192
virtual int get_number_of_instances() override
Returns number of instances of solver currently in memory.
Definition SolverXpress.cpp:90
virtual void read_basis(const std::filesystem::path &filename) override
Instructs the optimizer to read in a previously saved basis from a file.
Definition SolverXpress.cpp:187
virtual void chg_row_name(int id_row, std::string const &name) override
Change the name of a constraint.
Definition SolverXpress.cpp:447
virtual void read_prob_lp(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition SolverXpress.cpp:150
virtual void chg_obj(const std::vector< int > &mindex, const std::vector< double > &obj) override
Change coefficients in objective function.
Definition SolverXpress.cpp:404
virtual 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 SolverXpress.cpp:364
virtual int solve_mip() override
Solves a problem as MIP.
Definition SolverXpress.cpp:486
virtual void get_row_type(char *qrtype, int first, int last) const override
Returns the row types for the rows in a given range.
Definition SolverXpress.cpp:255
virtual void get_rhs(double *rhs, int first, int last) const override
Returns the right-hand sides of the rows in a given range.
Definition SolverXpress.cpp:260
virtual int get_splex_num_of_ite_last() const override
Get the number of simplex iterations done in the last resolution of the problem.
Definition SolverXpress.cpp:534
virtual void get_lb(double *lb, int fisrt, int last) const override
Returns the lower bounds for variables in a given range.
Definition SolverXpress.cpp:275
virtual 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 SolverXpress.cpp:248
virtual int get_row_index(std::string const &name) override
Returns the index of row named "name".
Definition SolverXpress.cpp:285
void set_obj_to_zero() override
Set the objective function coefficients to zero.
Definition SolverXpress.cpp:235
virtual void read_prob_mps(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition SolverXpress.cpp:146
virtual void chg_col_type(const std::vector< int > &mindex, const std::vector< char > &qctype) override
Change type of some columns.
Definition SolverXpress.cpp:428
virtual void get_ub(double *ub, int fisrt, int last) const override
Returns the upper bounds for variables in a given range.
Definition SolverXpress.cpp:280
virtual void get_lp_sol(double *primals, double *duals, double *reduced_costs) override
Get LP solution of a problem (available after method "solve_lp")
Definition SolverXpress.cpp:541
void set_obj(const double *obj, int first, int last) override
Set the objective function coefficients for the columns in a given range.
Definition SolverXpress.cpp:241
virtual void set_simplex_iter(int iter) override
Sets the maximum number of simplex iterations the solver can perform.
Definition SolverXpress.cpp:598
virtual 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 SolverXpress.cpp:418
virtual int get_col_index(std::string const &name) override
Returns the index of column named "name".
Definition SolverXpress.cpp:292
virtual void chg_rhs(int id_row, double val) override
Change rhs of a row.
Definition SolverXpress.cpp:436
virtual double get_lp_value() const override
Get the optimal value of a LP problem (available after method "solve_lp" )
Definition SolverXpress.cpp:527
virtual void get_mip_sol(double *primals) override
Get MIP solution of a problem (available after method "solve_mip")
Definition SolverXpress.cpp:547
virtual void set_threads(int n_threads) override
Sets the maximum number of threads used to perform optimization.
Definition SolverXpress.cpp:588
virtual void free() override
Frees all the datas contained in the Solver environment.
Definition SolverXpress.cpp:112
virtual void chg_col_name(int id_col, std::string const &name) override
Change the name of a variable.
Definition SolverXpress.cpp:452