6#include "Cbc_C_Interface.h"
7#include "CoinHelperFunctions.hpp"
8#include "CoinMpsIO.hpp"
9#include "OsiClpSolverInterface.hpp"
10#include "antares-xpansion/multisolver_interface/SolverAbstract.h"
23 static int _NumberOfProblems;
28 const std::string name_ =
"CBC";
29 OsiClpSolverInterface _clp_inner_solver;
31 int _current_log_level;
52 explicit SolverCbc(
const std::shared_ptr<const SolverAbstract> toCopy);
66 void defineCbcModelFromInnerSolver();
67 void setClpSimplexColNamesFromInnerSolver(ClpSimplex* clps)
const;
68 void setClpSimplexRowNamesFromInnerSolver(ClpSimplex* clps)
const;
81 virtual void init()
override;
82 virtual void free()
override;
90 virtual void write_prob_mps(
const std::filesystem::path& filename)
override;
91 virtual void write_prob_lp(
const std::filesystem::path& filename)
override;
92 void save_prob(
const std::filesystem::path& filename)
override;
93 virtual void write_basis(
const std::filesystem::path& filename)
override;
95 virtual void read_prob_mps(
const std::filesystem::path& filename)
override;
96 virtual void read_prob_lp(
const std::filesystem::path& filename)
override;
97 void restore_prob(
const std::filesystem::path& filename)
override;
98 virtual void read_basis(
const std::filesystem::path& filename)
override;
112 virtual void get_obj(
double* obj,
int first,
int last)
const override;
114 void set_obj(
const double* obj,
int first,
int last)
override;
121 int last)
const override;
122 virtual void get_row_type(
char* qrtype,
int first,
int last)
const override;
123 virtual void get_rhs(
double* rhs,
int first,
int last)
const override;
124 virtual void get_rhs_range(
double* range,
int first,
int last)
const override;
125 virtual void get_col_type(
char* coltype,
int first,
int last)
const override;
126 virtual void get_lb(
double* lb,
int fisrt,
int last)
const override;
127 virtual void get_ub(
double* ub,
int fisrt,
int last)
const override;
131 virtual std::vector<std::string>
get_row_names(
int first,
int last)
override;
133 virtual std::vector<std::string>
get_col_names(
int first,
int last)
override;
142 virtual void del_rows(
int first,
int last)
override;
150 const double* dmatval,
151 const std::vector<std::string>& row_names)
override;
157 const double* dmatval,
160 const std::vector<std::string>& col_names)
override;
161 virtual void add_name(
int type,
const char* cnames,
int indice)
override;
162 virtual void add_names(
int type,
163 const std::vector<std::string>& cnames,
166 virtual void chg_obj(
const std::vector<int>& mindex,
const std::vector<double>& obj)
override;
168 virtual void chg_bounds(
const std::vector<int>& mindex,
169 const std::vector<char>& qbtype,
170 const std::vector<double>& bnd)
override;
171 virtual void chg_col_type(
const std::vector<int>& mindex,
172 const std::vector<char>& qctype)
override;
173 virtual void chg_rhs(
int id_row,
double val)
override;
174 virtual void chg_coef(
int id_row,
int id_col,
double val)
override;
175 virtual void chg_row_name(
int id_row,
const std::string& name)
override;
176 virtual void chg_col_name(
int id_col,
const std::string& name)
override;
207 virtual void get_basis(
int* rstatus,
int* cstatus)
const override;
211 virtual void get_lp_sol(
double* primals,
double* duals,
double* reduced_costs)
const override;
212 virtual void get_mip_sol(
double* primals)
override;
221 virtual void set_algorithm(
const std::string& algo)
override;
Definition SolverAbstract.h:200
std::shared_ptr< SolverAbstract > Ptr
Definition SolverAbstract.h:215
Definition SolverCbc.h:18
virtual int get_number_of_instances() override
Returns number of instances of solver currently in memory.
Definition SolverCbc.cpp:58
virtual void add_name(int type, const char *cnames, int indice) override
Adds a name to a row or a column.
Definition SolverCbc.cpp:554
virtual void get_ub(double *ub, int fisrt, int last) const override
Returns the upper bounds for variables in a given range.
Definition SolverCbc.cpp:394
virtual int get_row_index(const std::string &name) override
Returns the index of row named "name".
Definition SolverCbc.cpp:405
virtual void read_prob_lp(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition SolverCbc.cpp:240
virtual void get_lb(double *lb, int fisrt, int last) const override
Returns the lower bounds for variables in a given range.
Definition SolverCbc.cpp:384
virtual void init() override
Initializes a problem.
Definition SolverCbc.cpp:80
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 SolverCbc.cpp:789
virtual int solve_lp() override
Solves a problem as LP.
Definition SolverCbc.cpp:701
virtual void read_basis(const std::filesystem::path &filename) override
Instructs the optimizer to read in a previously saved basis from a file.
Definition SolverCbc.cpp:247
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 SolverCbc.cpp:359
virtual void write_prob_lp(const std::filesystem::path &filename) override
writes an optimization problem in a LP file
Definition SolverCbc.cpp:182
virtual void set_optimality_gap(double gap) override
Sets the optimality gap.
Definition SolverCbc.cpp:875
virtual void del_rows(int first, int last) override
Deletes rows between index first and last.
Definition SolverCbc.cpp:489
virtual void get_mip_sol(double *primals) override
Get MIP solution of a problem (available after method "solve_mip")
Definition SolverCbc.cpp:824
virtual void chg_col_name(int id_col, const std::string &name) override
Change the name of a variable.
Definition SolverCbc.cpp:692
virtual std::vector< std::string > get_col_names() override
Returns the names of columns.
Definition SolverCbc.cpp:479
virtual void copy_prob(const SolverAbstract::Ptr fictif_solv) override
copy an existing problem
Definition SolverCbc.cpp:255
void set_obj_to_zero() override
Set the objective function coefficients to zero.
Definition SolverCbc.cpp:299
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 SolverCbc.cpp:525
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 SolverCbc.cpp:340
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 SolverCbc.cpp:347
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 SolverCbc.cpp:321
virtual void chg_obj_direction(const bool minimize) override
Change the problem's objective function sense to minimize or maximize.
Definition SolverCbc.cpp:576
virtual void set_simplex_iter(int iter) override
Sets the maximum number of simplex iterations the solver can perform.
Definition SolverCbc.cpp:880
SolverCbc()
Default constructor of a CBC solver.
Definition SolverCbc.cpp:23
virtual void get_basis(int *rstatus, int *cstatus) const override
Returns the current basis into the user’s data arrays.
Definition SolverCbc.cpp:774
virtual std::vector< std::string > get_row_names() override
Returns the names of rows.
Definition SolverCbc.cpp:455
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 SolverCbc.cpp:794
void set_output_log_level(int loglevel) final
Sets log level of the solver.
Definition SolverCbc.cpp:840
void save_prob(const std::filesystem::path &filename) override
Definition SolverCbc.cpp:889
virtual int get_nrows() const override
returns number of rows of the problem
Definition SolverCbc.cpp:271
virtual void chg_obj(const std::vector< int > &mindex, const std::vector< double > &obj) override
Change coefficients in objective function.
Definition SolverCbc.cpp:567
virtual std::string get_solver_name() const override
Returns the solver used.
Definition SolverCbc.h:60
virtual void chg_rhs(int id_row, double val) override
Change rhs of a row.
Definition SolverCbc.cpp:642
virtual void write_prob_mps(const std::filesystem::path &filename) override
writes an optimization problem in a MPS file
Definition SolverCbc.cpp:95
virtual void chg_row_name(int id_row, const std::string &name) override
Change the name of a constraint.
Definition SolverCbc.cpp:687
virtual double get_lp_value() const override
Get the optimal value of a LP problem (available after method "solve_lp" )
Definition SolverCbc.cpp:784
virtual int get_n_integer_vars() const override
returns number of integer variables in the problem
Definition SolverCbc.cpp:283
virtual int get_nelems() const override
returns number of non zeros elements in the matrix, excluding objective
Definition SolverCbc.cpp:277
virtual void read_prob_mps(const std::filesystem::path &filename) override
reads an optimization problem contained in a MPS file
Definition SolverCbc.cpp:225
virtual int get_col_index(const std::string &name) override
Returns the index of column named "name".
Definition SolverCbc.cpp:420
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 SolverCbc.cpp:289
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 SolverCbc.cpp:333
void restore_prob(const std::filesystem::path &filename) override
Definition SolverCbc.cpp:898
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 SolverCbc.cpp:499
virtual int solve_mip() override
Solves a problem as MIP.
Definition SolverCbc.cpp:732
virtual void free() override
Frees all the datas contained in the Solver environment.
Definition SolverCbc.cpp:86
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 SolverCbc.cpp:582
virtual double get_mip_value() const override
Get the optimal value of a MIP problem (available after method "solve_mip")
Definition SolverCbc.cpp:779
void set_obj(const double *obj, int first, int last) override
Set the objective function coefficients for the columns in a given range.
Definition SolverCbc.cpp:306
virtual void write_basis(const std::filesystem::path &filename) override
Writes the current basis to a file for later input into the optimizer.
Definition SolverCbc.cpp:187
virtual void chg_coef(int id_row, int id_col, double val) override
Change a coefficient in the matrix.
Definition SolverCbc.cpp:678
virtual void set_algorithm(const std::string &algo) override
Sets algorithm used by solver to solve LP's.
Definition SolverCbc.cpp:865
virtual void set_threads(int n_threads) override
Sets the maximum number of threads used to perform optimization.
Definition SolverCbc.cpp:870
virtual int get_ncols() const override
returns number of columns of the problem
Definition SolverCbc.cpp:265
virtual void chg_col_type(const std::vector< int > &mindex, const std::vector< char > &qctype) override
Change type of some columns.
Definition SolverCbc.cpp:610
Definition SolverAbstract.h:17