Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
SolverClp.h
1#pragma once
2
3#include "ClpSimplex.hpp"
4#include "CoinHelperFunctions.hpp"
5#include "CoinIndexedVector.hpp"
6#include "antares-xpansion/multisolver_interface/SolverAbstract.h"
7
8enum CLP_STATUS
9{
10 CLP_OPTIMAL,
11 CLP_PRIMAL_INFEASIBLE,
12 CLP_DUAL_INFEASIBLE,
13 CLP_STOPPED,
14 CLP_ERRORED
15};
16
22{
23 /*************************************************************************************************
24 ---------------------------------------- ATTRIBUTES
25 ---------------------------------------
26 *************************************************************************************************/
27 static int _NumberOfProblems;
31public:
32 ClpSimplex _clp;
33 const std::string name_ = "CLP";
34
35 /*************************************************************************************************
36 ----------------------------------- Constructor/Desctructor
37 --------------------------------
38 *************************************************************************************************/
39
40public:
44 SolverClp();
45 explicit SolverClp(SolverLogManager& log_manager);
46
54 explicit SolverClp(const std::shared_ptr<const SolverAbstract> toCopy);
55
56 /*SolverClp ctor accept only std::shared_ptr*/
57 SolverClp(const SolverClp& other) = delete;
58 SolverClp& operator=(const SolverClp& other) = delete;
59
60 ~SolverClp() override;
61 virtual int get_number_of_instances() override;
62
63 virtual std::string get_solver_name() const override
64 {
65 return name_;
66 }
67
68 /*************************************************************************************************
69 --------------------------------- Output and stream management
70 -----------------------------
71 *************************************************************************************************/
72
73 /*************************************************************************************************
74 ------ Destruction or creation of inner strctures and datas, closing
75 environments ----------
76 *************************************************************************************************/
77
78public:
79 virtual void init() override;
80 virtual void free() override;
81
82 /*************************************************************************************************
83 ------------------------------- Reading & Writing problems
84 -------------------------------
85 *************************************************************************************************/
86
87public:
88 virtual void write_prob_mps(const std::filesystem::path& filename) override;
89 virtual void write_prob_lp(const std::filesystem::path& filename) override;
90 void save_prob(const std::filesystem::path& filename) override;
91 virtual void write_basis(const std::filesystem::path& filename) override;
92
93 virtual void read_prob_mps(const std::filesystem::path& filename) override;
94 virtual void read_prob_lp(const std::filesystem::path& filename) override;
95 void restore_prob(const std::filesystem::path& filename) override;
96 virtual void read_basis(const std::filesystem::path& filename) override;
97
98 virtual void copy_prob(const SolverAbstract::Ptr fictif_solv) override;
99
100 /*************************************************************************************************
101 ----------------------- Get general informations about problem
102 ----------------------------
103 *************************************************************************************************/
104
105public:
106 virtual int get_ncols() const override;
107 virtual int get_nrows() const override;
108 virtual int get_nelems() const override;
109 virtual int get_n_integer_vars() const override;
110 virtual void get_obj(double* obj, int first, int last) const override;
111 void set_obj_to_zero() override;
112 void set_obj(const double* obj, int first, int last) override;
113 virtual void get_rows(int* mstart,
114 int* mclind,
115 double* dmatval,
116 int size,
117 int* nels,
118 int first,
119 int last) const override;
120 virtual void get_row_type(char* qrtype, int first, int last) const override;
121 virtual void get_rhs(double* rhs, int first, int last) const override;
122 virtual void get_rhs_range(double* range, int first, int last) const override;
123 virtual void get_col_type(char* coltype, int first, int last) const override;
124 virtual void get_lb(double* lb, int fisrt, int last) const override;
125 virtual void get_ub(double* ub, int fisrt, int last) const override;
126
127 virtual int get_row_index(const std::string& name) override;
128 virtual int get_col_index(const std::string& name) override;
129 virtual std::vector<std::string> get_row_names(int first, int last) override;
130 virtual std::vector<std::string> get_row_names() override;
131 virtual std::vector<std::string> get_col_names(int first, int last) override;
132 virtual std::vector<std::string> get_col_names() override;
133
134 /*************************************************************************************************
135 ------------------------------ Methods to modify problem
136 ----------------------------------
137 *************************************************************************************************/
138
139public:
140 virtual void del_rows(int first, int last) override;
141 virtual void add_rows(int newrows,
142 int newnz,
143 const char* qrtype,
144 const double* rhs,
145 const double* range,
146 const int* mstart,
147 const int* mclind,
148 const double* dmatval,
149 const std::vector<std::string>& row_names) override;
150 virtual void add_cols(int newcol,
151 int newnz,
152 const double* objx,
153 const int* mstart,
154 const int* mrwind,
155 const double* dmatval,
156 const double* bdl,
157 const double* bdu,
158 const std::vector<std::string>& col_names) override;
159 virtual void add_name(int type, const char* cnames, int indice) override;
160 virtual void add_names(int type,
161 const std::vector<std::string>& cnames,
162 int first,
163 int end) override;
164 virtual void chg_obj(const std::vector<int>& mindex, const std::vector<double>& obj) override;
165 virtual void chg_obj_direction(const bool minimize) override;
166 virtual void chg_bounds(const std::vector<int>& mindex,
167 const std::vector<char>& qbtype,
168 const std::vector<double>& bnd);
169 virtual void chg_col_type(const std::vector<int>& mindex,
170 const std::vector<char>& qctype) override;
171 virtual void chg_rhs(int id_row, double val) override;
172 virtual void chg_coef(int id_row, int id_col, double val) override;
173 virtual void chg_row_name(int id_row, const std::string& name) override;
174 virtual void chg_col_name(int id_col, const std::string& name) override;
175
176 /*************************************************************************************************
177 ----------------------------- Methods to solve the problem
178 ---------------------------------
179 *************************************************************************************************/
180
181public:
182 virtual int solve_lp() override;
183 virtual int solve_mip() override;
184
185 /*************************************************************************************************
186 ------------------------- Methods to get solutions information
187 -----------------------------
188 *************************************************************************************************/
189
190public:
205 virtual void get_basis(int* rstatus, int* cstatus) const override;
206 virtual double get_mip_value() const override;
207 virtual double get_lp_value() const override;
208 virtual int get_splex_num_of_ite_last() const override;
209 virtual void get_lp_sol(double* primals, double* duals, double* reduced_costs) const override;
210 virtual void get_mip_sol(double* primals) override;
211
212 /*************************************************************************************************
213 ------------------------ Methods to set algorithm or logs levels
214 ---------------------------
215 *************************************************************************************************/
216
217public:
218 void set_output_log_level(int loglevel) final;
219 virtual void set_algorithm(const std::string& algo) override;
220 virtual void set_threads(int n_threads) override;
221 virtual void set_optimality_gap(double gap) override;
222 virtual void set_simplex_iter(int iter) override;
223};
Definition SolverAbstract.h:200
std::shared_ptr< SolverAbstract > Ptr
Definition SolverAbstract.h:215
Definition SolverClp.h:22
virtual void set_threads(int n_threads) override
Sets the maximum number of threads used to perform optimization.
Definition SolverClp.cpp:717
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 SolverClp.cpp:203
virtual std::vector< std::string > get_col_names() override
Returns the names of columns.
Definition SolverClp.cpp:343
virtual void set_algorithm(const std::string &algo) override
Sets algorithm used by solver to solve LP's.
Definition SolverClp.cpp:705
SolverClp()
Default constructor of a CLP solver.
Definition SolverClp.cpp:22
virtual void write_prob_lp(const std::filesystem::path &filename) override
writes an optimization problem in a LP file
Definition SolverClp.cpp:92
virtual void write_prob_mps(const std::filesystem::path &filename) override
writes an optimization problem in a MPS file
Definition SolverClp.cpp:82
virtual void write_basis(const std::filesystem::path &filename) override
Writes the current basis to a file for later input into the optimizer.
Definition SolverClp.cpp:97
virtual int solve_lp() override
Solves a problem as LP.
Definition SolverClp.cpp:559
virtual void chg_col_type(const std::vector< int > &mindex, const std::vector< char > &qctype) override
Change type of some columns.
Definition SolverClp.cpp:474
virtual void free() override
Frees all the datas contained in the Solver environment.
Definition SolverClp.cpp:73
virtual int get_n_integer_vars() const override
returns number of integer variables in the problem
Definition SolverClp.cpp:157
virtual void get_ub(double *ub, int fisrt, int last) const override
Returns the upper bounds for variables in a given range.
Definition SolverClp.cpp:272
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 SolverClp.cpp:237
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 SolverClp.cpp:216
virtual void chg_obj(const std::vector< int > &mindex, const std::vector< double > &obj) override
Change coefficients in objective function.
Definition SolverClp.cpp:431
virtual void chg_bounds(const std::vector< int > &mindex, const std::vector< char > &qbtype, const std::vector< double > &bnd)
Change bounds of some variables.
Definition SolverClp.cpp:446
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, const std::vector< std::string > &col_names) override
Adds new columns to the problem.
Definition SolverClp.cpp:389
virtual void read_basis(const std::filesystem::path &filename) override
Instructs the optimizer to read in a previously saved basis from a file.
Definition SolverClp.cpp:127
virtual void get_mip_sol(double *primals) override
Get MIP solution of a problem (available after method "solve_mip")
Definition SolverClp.cpp:677
virtual double get_lp_value() const override
Get the optimal value of a LP problem (available after method "solve_lp" )
Definition SolverClp.cpp:635
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 SolverClp.cpp:171
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 SolverClp.cpp:640
virtual void get_lb(double *lb, int fisrt, int last) const override
Returns the lower bounds for variables in a given range.
Definition SolverClp.cpp:262
virtual int get_ncols() const override
returns number of columns of the problem
Definition SolverClp.cpp:142
virtual void set_optimality_gap(double gap) override
Sets the optimality gap.
Definition SolverClp.cpp:722
virtual void chg_coef(int id_row, int id_col, double val) override
Change a coefficient in the matrix.
Definition SolverClp.cpp:537
virtual std::string get_solver_name() const override
Returns the solver used.
Definition SolverClp.h:63
virtual void init() override
Initializes a problem.
Definition SolverClp.cpp:68
virtual void add_name(int type, const char *cnames, int indice) override
Adds a name to a row or a column.
Definition SolverClp.cpp:418
virtual int get_nrows() const override
returns number of rows of the problem
Definition SolverClp.cpp:147
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 SolverClp.cpp:224
virtual void chg_obj_direction(const bool minimize) override
Change the problem's objective function sense to minimize or maximize.
Definition SolverClp.cpp:440
virtual std::vector< std::string > get_row_names() override
Returns the names of rows.
Definition SolverClp.cpp:326
void restore_prob(const std::filesystem::path &filename) override
Definition SolverClp.cpp:745
virtual void chg_row_name(int id_row, const std::string &name) override
Change the name of a constraint.
Definition SolverClp.cpp:543
void set_obj_to_zero() override
Set the objective function coefficients to zero.
Definition SolverClp.cpp:181
virtual void set_simplex_iter(int iter) override
Sets the maximum number of simplex iterations the solver can perform.
Definition SolverClp.cpp:727
virtual void read_prob_mps(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition SolverClp.cpp:111
virtual int get_col_index(const std::string &name) override
Returns the index of column named "name".
Definition SolverClp.cpp:298
virtual void copy_prob(const SolverAbstract::Ptr fictif_solv) override
copy an existing problem
Definition SolverClp.cpp:132
virtual double get_mip_value() const override
Get the optimal value of a MIP problem (available after method "solve_mip")
Definition SolverClp.cpp:630
void set_obj(const double *obj, int first, int last) override
Set the objective function coefficients for the columns in a given range.
Definition SolverClp.cpp:188
virtual void del_rows(int first, int last) override
Deletes rows between index first and last.
Definition SolverClp.cpp:353
virtual void chg_col_name(int id_col, const std::string &name) override
Change the name of a variable.
Definition SolverClp.cpp:549
void save_prob(const std::filesystem::path &filename) override
Definition SolverClp.cpp:736
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 SolverClp.cpp:231
virtual int get_row_index(const std::string &name) override
Returns the index of row named "name".
Definition SolverClp.cpp:282
void set_output_log_level(int loglevel) final
Sets log level of the solver.
Definition SolverClp.cpp:693
virtual int get_nelems() const override
returns number of non zeros elements in the matrix, excluding objective
Definition SolverClp.cpp:152
virtual void read_prob_lp(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition SolverClp.cpp:122
virtual int solve_mip() override
Solves a problem as MIP.
Definition SolverClp.cpp:585
virtual int get_number_of_instances() override
Returns number of instances of solver currently in memory.
Definition SolverClp.cpp:54
virtual void get_basis(int *rstatus, int *cstatus) const override
Returns the current basis into the user’s data arrays.
Definition SolverClp.cpp:615
virtual void chg_rhs(int id_row, double val) override
Change rhs of a row.
Definition SolverClp.cpp:502
virtual 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 SolverClp.cpp:645
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 > &row_names) override
Adds rows to the problem.
Definition SolverClp.cpp:363
Definition SolverAbstract.h:17