Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
SolverClp Class Reference
Inheritance diagram for SolverClp:
SolverAbstract

Public Member Functions

 SolverClp ()
 Default constructor of a CLP solver.
 
 SolverClp (SolverLogManager &log_manager)
 
 SolverClp (const std::shared_ptr< const SolverAbstract > toCopy)
 Copy constructor of CLP, copy the problem toCopy in memory and name it "name".
 
 SolverClp (const SolverClp &other)=delete
 
SolverClpoperator= (const SolverClp &other)=delete
 
virtual int get_number_of_instances () override
 Returns number of instances of solver currently in memory.
 
virtual std::string get_solver_name () const override
 Returns the solver used.
 
virtual void init () override
 Initializes a problem.
 
virtual void free () override
 Frees all the datas contained in the Solver environment.
 
virtual void write_prob_mps (const std::filesystem::path &filename) override
 writes an optimization problem in a MPS file
 
virtual void write_prob_lp (const std::filesystem::path &filename) override
 writes an optimization problem in a LP file
 
virtual void write_basis (const std::filesystem::path &filename) override
 Writes the current basis to a file for later input into the optimizer.
 
virtual void read_prob_mps (const std::filesystem::path &filename) override
 reads an optimization problem contained in a MPS file
 
virtual void read_prob_lp (const std::filesystem::path &filename) override
 reads an optimization problem contained in a MPS file
 
virtual void read_basis (const std::filesystem::path &filename) override
 Instructs the optimizer to read in a previously saved basis from a file.
 
virtual void copy_prob (const SolverAbstract::Ptr fictif_solv) override
 copy an existing problem
 
virtual int get_ncols () const override
 returns number of columns of the problem
 
virtual int get_nrows () const override
 returns number of rows of the problem
 
virtual int get_nelems () const override
 returns number of non zeros elements in the matrix, excluding objective
 
virtual int get_n_integer_vars () const override
 returns number of integer variables in the problem
 
virtual void get_obj (double *obj, int first, int last) const override
 returns the objective function coefficients for the columns in a given range
 
void set_obj_to_zero () override
 Set the objective function coefficients to zero.
 
void set_obj (const double *obj, int first, int last) override
 Set the objective function coefficients for the columns in a given range.
 
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
 
virtual void get_row_type (char *qrtype, int first, int last) const override
 Returns the row types for the rows in a given range.
 
virtual void get_rhs (double *rhs, int first, int last) const override
 Returns the right-hand sides of the rows in a given range.
 
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.
 
virtual void get_col_type (char *coltype, int first, int last) const override
 Returns the column types for the columns in a given range.
 
virtual void get_lb (double *lb, int fisrt, int last) const override
 Returns the lower bounds for variables in a given range.
 
virtual void get_ub (double *ub, int fisrt, int last) const override
 Returns the upper bounds for variables in a given range.
 
virtual int get_row_index (std::string const &name) override
 Returns the index of row named "name".
 
virtual int get_col_index (std::string const &name) override
 Returns the index of column named "name".
 
virtual 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 methods.
 
virtual std::vector< std::string > get_row_names () override
 Returns the names of rows.
 
virtual 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 solver methods.
 
virtual std::vector< std::string > get_col_names () override
 Returns the names of columns.
 
virtual void del_rows (int first, int last) override
 Deletes rows between index first and last.
 
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.
 
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.
 
virtual void add_name (int type, const char *cnames, int indice) override
 Adds a name to a row or a column.
 
virtual void add_names (int type, const std::vector< std::string > &cnames, int first, int end) override
 
virtual void chg_obj (const std::vector< int > &mindex, const std::vector< double > &obj) override
 Change coefficients in objective function.
 
virtual void chg_obj_direction (const bool minimize) override
 Change the problem's objective function sense to minimize or maximize.
 
virtual void chg_bounds (const std::vector< int > &mindex, const std::vector< char > &qbtype, const std::vector< double > &bnd)
 Change bounds of some variables.
 
virtual void chg_col_type (const std::vector< int > &mindex, const std::vector< char > &qctype) override
 Change type of some columns.
 
virtual void chg_rhs (int id_row, double val) override
 Change rhs of a row.
 
virtual void chg_coef (int id_row, int id_col, double val) override
 Change a coefficient in the matrix.
 
virtual void chg_row_name (int id_row, std::string const &name) override
 Change the name of a constraint.
 
virtual void chg_col_name (int id_col, std::string const &name) override
 Change the name of a variable.
 
virtual int solve_lp () override
 Solves a problem as LP.
 
virtual int solve_mip () override
 Solves a problem as MIP.
 
virtual void get_basis (int *rstatus, int *cstatus) const override
 Returns the current basis into the user’s data arrays.
 
virtual double get_mip_value () const override
 Get the optimal value of a MIP problem (available after method "solve_mip")
 
virtual double get_lp_value () const override
 Get the optimal value of a LP problem (available after method "solve_lp" )
 
virtual int get_splex_num_of_ite_last () const override
 Get the number of simplex iterations done in the last resolution of the problem.
 
virtual void get_lp_sol (double *primals, double *duals, double *reduced_costs) override
 Get LP solution of a problem (available after method "solve_lp")
 
virtual void get_mip_sol (double *primals) override
 Get MIP solution of a problem (available after method "solve_mip")
 
void set_output_log_level (int loglevel) final
 Sets log level of the solver.
 
virtual void set_algorithm (std::string const &algo) override
 Sets algorithm used by solver to solve LP's.
 
virtual void set_threads (int n_threads) override
 Sets the maximum number of threads used to perform optimization.
 
virtual void set_optimality_gap (double gap) override
 Sets the optimality gap.
 
virtual void set_simplex_iter (int iter) override
 Sets the maximum number of simplex iterations the solver can perform.
 
- Public Member Functions inherited from SolverAbstract
 SolverAbstract ()
 constructor of SolverAbstract class : does nothing
 
 SolverAbstract (const std::string &name, const SolverAbstract::Ptr toCopy)
 Copy constructor, copy the problem "toCopy" in memory and name it "name" if possible.
 
virtual ~SolverAbstract ()
 destructor of SolverAbstract class : does nothing
 
std::list< std::ostream * > & get_stream ()
 returns the list of streams used by the solver instance
 
void add_stream (std::ostream &stream)
 add a stream to the list of streams used by the solver instance
 
void set_fp (FILE *fp)
 
void zero_status_check (int status, const std::string &action_failed, const std::string &log_location) const
 Check if a status code is different to 0, throw InvalidStatusException if it occurs.
 

Public Attributes

ClpSimplex _clp
 
const std::string name_ = "CLP"
 
- Public Attributes inherited from SolverAbstract
std::vector< std::string > SOLVER_STRING_STATUS
 
std::string _name
 
std::list< std::ostream * > _streams
 
FILE * _fp = nullptr
 
std::filesystem::path _log_file = ""
 

Additional Inherited Members

- Public Types inherited from SolverAbstract
typedef std::shared_ptr< SolverAbstractPtr
 

Constructor & Destructor Documentation

◆ SolverClp()

SolverClp::SolverClp ( const std::shared_ptr< const SolverAbstract toCopy)
explicit

Copy constructor of CLP, copy the problem toCopy in memory and name it "name".

Parameters
toCopy: Pointer to an AbstractSolver object, containing a CLP solver to copy

Member Function Documentation

◆ add_cols()

void SolverClp::add_cols ( int  newcol,
int  newnz,
const double *  objx,
const int *  mstart,
const int *  mrwind,
const double *  dmatval,
const double *  bdl,
const double *  bdu 
)
overridevirtual

Adds new columns to the problem.

Parameters
newcol: Number of new columns.
newnz: Number of new nonzeros in the added columns.
objx: Double array of length newcol containing the objective function coefficients of the new columns.
mstart: Integer array of length newcol containing the offsets in the mrwind and dmatval arrays of the start of the elements for each column.
mrwind: Integer array of length newnz containing the row indices for the elements 7 in each column.
dmatval: Double array of length newnz containing the element values.
bdl: Double array of length newcol containing the lower bounds on the added columns.
bdu: Double array of length newcol containing the upper bounds on the added columns.

Implements SolverAbstract.

◆ add_name()

void SolverClp::add_name ( int  type,
const char *  cnames,
int  indice 
)
overridevirtual

Adds a name to a row or a column.

Parameters
type: 1 for row, 2 for column.
cnames: Character buffer containing the null-terminated string names.
indice: index of the row or of the column.

Implements SolverAbstract.

◆ add_names()

void SolverClp::add_names ( int  type,
const std::vector< std::string > &  cnames,
int  first,
int  end 
)
overridevirtual

Implements SolverAbstract.

◆ add_rows()

void SolverClp::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 = {} 
)
overridevirtual

Adds rows to the problem.

Parameters
newrows: Number of new rows.
newnz: Number of new nonzeros in the added rows.
qrtype: Character array of length newrow containing the row types:
rhs: Double array of length newrow containing the right hand side elements.
range: Double array of length newrow containing the row range elements (index read only for R type rows)
mstart: Integer array of length newrow + 1 containing the offsets in the mclind and dmatval arrays of the start of the elements for each row.
mclind: Integer array of length newnz containing the (contiguous) column indices for the elements in each row.
dmatval: Double array of length newnz containing the (contiguous) element values.

Implements SolverAbstract.

◆ chg_bounds()

void SolverClp::chg_bounds ( const std::vector< int > &  mindex,
const std::vector< char > &  qbtype,
const std::vector< double > &  bnd 
)
virtual

Change bounds of some variables.

Parameters
nbds: number of bounds to change
mindex: indices of columns to modify
qbtype: types of the bounds to modify ('U' upper, 'L' lower, 'B' both)
bnd: new values for the bounds

Implements SolverAbstract.

◆ chg_coef()

void SolverClp::chg_coef ( int  id_row,
int  id_col,
double  val 
)
overridevirtual

Change a coefficient in the matrix.

Parameters
id_row: index of the row
id_col: index of the column
val: new value to set in the matrix

Implements SolverAbstract.

◆ chg_col_name()

void SolverClp::chg_col_name ( int  id_col,
std::string const &  name 
)
overridevirtual

Change the name of a variable.

Parameters
id_col: index of the column
name: new name of the column

Implements SolverAbstract.

◆ chg_col_type()

void SolverClp::chg_col_type ( const std::vector< int > &  mindex,
const std::vector< char > &  qctype 
)
overridevirtual

Change type of some columns.

Parameters
nels: number of elements to change
mindex: indices of columns to modify
qctype: New types of columns

Implements SolverAbstract.

◆ chg_obj()

void SolverClp::chg_obj ( const std::vector< int > &  mindex,
const std::vector< double > &  obj 
)
overridevirtual

Change coefficients in objective function.

Parameters
mindex: indices of columns to modify
obj: Values to set in objective function

Implements SolverAbstract.

◆ chg_obj_direction()

void SolverClp::chg_obj_direction ( const bool  minimize)
overridevirtual

Change the problem's objective function sense to minimize or maximize.

Parameters
minimize: boolean that is true for minimize, false for maximization

Implements SolverAbstract.

◆ chg_rhs()

void SolverClp::chg_rhs ( int  id_row,
double  val 
)
overridevirtual

Change rhs of a row.

Parameters
id_row: index of the row
val: new rhs value

Implements SolverAbstract.

◆ chg_row_name()

void SolverClp::chg_row_name ( int  id_row,
std::string const &  name 
)
overridevirtual

Change the name of a constraint.

Parameters
id_row: index of the row
name: new name of the row

Implements SolverAbstract.

◆ copy_prob()

void SolverClp::copy_prob ( const SolverAbstract::Ptr  fictif_solv)
overridevirtual

copy an existing problem

Parameters
prb_to_copy: Ptr to the

Implements SolverAbstract.

◆ del_rows()

void SolverClp::del_rows ( int  first,
int  last 
)
overridevirtual

Deletes rows between index first and last.

Parameters
first: first row index to delete
last: last row index to delete

Implements SolverAbstract.

◆ free()

void SolverClp::free ( )
overridevirtual

Frees all the datas contained in the Solver environment.

Implements SolverAbstract.

◆ get_basis()

void SolverClp::get_basis ( int *  rstatus,
int *  cstatus 
) const
overridevirtual

Returns the current basis into the user’s data arrays.

Parameters
rstatus: Integer array of length ROWS to the basis status of the slack, surplus or artifficial variable associated with each row. The status will be one of: 0 slack, surplus or artifficial is free; 1 slack, surplus or artifficial is basic; 2 slack, surplus or artifficial is at upper bound; 3 slack, surplus or artifficial is at lower bound; 4 slack, surplus or artifficial is super basic. May be NULL if not required.
cstatus: Integer array of length COLS to hold the basis status of the columns in the constraint matrix. The status will be one of: 0 variable is free; 1 variable is basic; 2 variable is at upper bound; 3 variable is at lower bound; 4 variable is super basic May be NULL if not required.

Implements SolverAbstract.

◆ get_col_index()

int SolverClp::get_col_index ( std::string const &  name)
overridevirtual

Returns the index of column named "name".

Parameters
name: name of column to get the index

Implements SolverAbstract.

◆ get_col_names() [1/2]

std::vector< std::string > SolverClp::get_col_names ( )
overridevirtual

Returns the names of columns.

Returns
names : vector of names

Implements SolverAbstract.

◆ get_col_names() [2/2]

std::vector< std::string > SolverClp::get_col_names ( int  first,
int  last 
)
overridevirtual

Returns the names of columns from index first to last cannot be declared as const because of some solver methods.

Parameters
first: first index from which name has be returned
last: last index from which name has be returned
Returns
names : vector of names

Implements SolverAbstract.

◆ get_col_type()

void SolverClp::get_col_type ( char *  coltype,
int  first,
int  last 
) const
overridevirtual

Returns the column types for the columns in a given range.

Parameters
coltype: Character array of length last-first+1 where the column types will be returned (C: continuous, I: integer, B: binary, S: semi-continuous, R: semi-continuous integer, P: partial integer)
first: first index of row to get
last: last index of row to get

Implements SolverAbstract.

◆ get_lb()

void SolverClp::get_lb ( double *  lb,
int  fisrt,
int  last 
) const
overridevirtual

Returns the lower bounds for variables in a given range.

Parameters
lb: Double array of length last-first+1 where the lower bounds are to be placed.
first: First column in the range.
last: Last column in the range.

Implements SolverAbstract.

◆ get_lp_sol()

void SolverClp::get_lp_sol ( double *  primals,
double *  duals,
double *  reduced_costs 
)
overridevirtual

Get LP solution of a problem (available after method "solve_lp")

Parameters
primals: values of primal variables
duals: values of dual variables
reduced_costreduced_cost in an optimal basis

Implements SolverAbstract.

◆ get_lp_value()

double SolverClp::get_lp_value ( ) const
overridevirtual

Get the optimal value of a LP problem (available after method "solve_lp" )

Returns
lb : optimal value of a LP problem

Implements SolverAbstract.

◆ get_mip_sol()

void SolverClp::get_mip_sol ( double *  primals)
overridevirtual

Get MIP solution of a problem (available after method "solve_mip")

Parameters
primals: values of primal variables

Implements SolverAbstract.

◆ get_mip_value()

double SolverClp::get_mip_value ( ) const
overridevirtual

Get the optimal value of a MIP problem (available after method "solve_mip")

Returns
lb : optimal value of a MIP problem

Implements SolverAbstract.

◆ get_n_integer_vars()

int SolverClp::get_n_integer_vars ( ) const
overridevirtual

returns number of integer variables in the problem

Implements SolverAbstract.

◆ get_ncols()

int SolverClp::get_ncols ( ) const
overridevirtual

returns number of columns of the problem

Implements SolverAbstract.

◆ get_nelems()

int SolverClp::get_nelems ( ) const
overridevirtual

returns number of non zeros elements in the matrix, excluding objective

Implements SolverAbstract.

◆ get_nrows()

int SolverClp::get_nrows ( ) const
overridevirtual

returns number of rows of the problem

Implements SolverAbstract.

◆ get_number_of_instances()

int SolverClp::get_number_of_instances ( )
overridevirtual

Returns number of instances of solver currently in memory.

Implements SolverAbstract.

◆ get_obj()

void SolverClp::get_obj ( double *  obj,
int  first,
int  last 
) const
overridevirtual

returns the objective function coefficients for the columns in a given range

Implements SolverAbstract.

◆ get_rhs()

void SolverClp::get_rhs ( double *  rhs,
int  first,
int  last 
) const
overridevirtual

Returns the right-hand sides of the rows in a given range.

Parameters
qrtype: Character array of length last-first+1 characters where the rhs will be stored
first: first index of row to get
last: last index of row to get

Implements SolverAbstract.

◆ get_rhs_range()

void SolverClp::get_rhs_range ( double *  range,
int  first,
int  last 
) const
overridevirtual

Returns the right hand side range values for the rows in a given range.

Parameters
range: Double array of length last-first+1 where the right hand side range values are to be placed.
first: first index of row to get
last: last index of row to get

Implements SolverAbstract.

◆ get_row_index()

int SolverClp::get_row_index ( std::string const &  name)
overridevirtual

Returns the index of row named "name".

Parameters
name: name of row to get the index

Implements SolverAbstract.

◆ get_row_names() [1/2]

std::vector< std::string > SolverClp::get_row_names ( )
overridevirtual

Returns the names of rows.

Returns
names : vector of names

Implements SolverAbstract.

◆ get_row_names() [2/2]

std::vector< std::string > SolverClp::get_row_names ( int  first,
int  last 
)
overridevirtual

Returns the names of row from index first to last cannot be declared as const because of some solver methods.

Parameters
first: first index from which name has be returned
last: last index from which name has be returned
Returns
names : vector of names

Implements SolverAbstract.

◆ get_row_type()

void SolverClp::get_row_type ( char *  qrtype,
int  first,
int  last 
) const
overridevirtual

Returns the row types for the rows in a given range.

Parameters
qrtype: Character array of length last-first+1 characters where the row types will be returned (N, E, L, G, R)
first: first index of row to get
last: last index of row to get

Implements SolverAbstract.

◆ get_rows()

void SolverClp::get_rows ( int *  mstart,
int *  mclind,
double *  dmatval,
int  size,
int *  nels,
int  first,
int  last 
) const
overridevirtual

get coefficients of rows from index first to last

Parameters
mstart: Integer array which will be filled with the indices indicating the starting offsets in the mclind and dmatval arrays for each requested row.
mclind: array containing the column indices of the elements contained in dmatval
dmatval: array containing non zero elements of the rows
size: maximum number of elements to be retrieved
nels: array containing number of elements in dmatval and mclind
first: first index of row to get
last: last index of row to get

Implements SolverAbstract.

◆ get_solver_name()

virtual std::string SolverClp::get_solver_name ( ) const
inlineoverridevirtual

Returns the solver used.

Implements SolverAbstract.

◆ get_splex_num_of_ite_last()

int SolverClp::get_splex_num_of_ite_last ( ) const
overridevirtual

Get the number of simplex iterations done in the last resolution of the problem.

Returns
result : number of simplex iterations done in the last resolution of the problem

Implements SolverAbstract.

◆ get_ub()

void SolverClp::get_ub ( double *  ub,
int  fisrt,
int  last 
) const
overridevirtual

Returns the upper bounds for variables in a given range.

Parameters
lb: Double array of length last-first+1 where the upper bounds are to be placed.
first: First column in the range.
last: Last column in the range.

Implements SolverAbstract.

◆ init()

void SolverClp::init ( )
overridevirtual

Initializes a problem.

Implements SolverAbstract.

◆ read_basis()

void SolverClp::read_basis ( const std::filesystem::path &  filename)
overridevirtual

Instructs the optimizer to read in a previously saved basis from a file.

Parameters
filenameFile name where the basis is to be read

Implements SolverAbstract.

◆ read_prob_lp()

void SolverClp::read_prob_lp ( const std::filesystem::path &  filename)
overridevirtual

reads an optimization problem contained in a MPS file

Parameters
name: name of the file to read

Implements SolverAbstract.

◆ read_prob_mps()

void SolverClp::read_prob_mps ( const std::filesystem::path &  filename)
overridevirtual

reads an optimization problem contained in a MPS file

Parameters
name: name of the file to read

Implements SolverAbstract.

◆ set_algorithm()

void SolverClp::set_algorithm ( std::string const &  algo)
overridevirtual

Sets algorithm used by solver to solve LP's.

Parameters
algo: string of the name of the algorithm

Implements SolverAbstract.

◆ set_obj()

void SolverClp::set_obj ( const double *  obj,
int  first,
int  last 
)
overridevirtual

Set the objective function coefficients for the columns in a given range.

Implements SolverAbstract.

◆ set_obj_to_zero()

void SolverClp::set_obj_to_zero ( )
overridevirtual

Set the objective function coefficients to zero.

Implements SolverAbstract.

◆ set_optimality_gap()

void SolverClp::set_optimality_gap ( double  gap)
overridevirtual

Sets the optimality gap.

Parameters
gapdouble of the value of wanted gap

Implements SolverAbstract.

◆ set_output_log_level()

void SolverClp::set_output_log_level ( int  loglevel)
finalvirtual

Sets log level of the solver.

Parameters
loglevel: level of log to set

Implements SolverAbstract.

◆ set_simplex_iter()

void SolverClp::set_simplex_iter ( int  iter)
overridevirtual

Sets the maximum number of simplex iterations the solver can perform.

Parameters
itermaximum number of simplex iterations

Implements SolverAbstract.

◆ set_threads()

void SolverClp::set_threads ( int  n_threads)
overridevirtual

Sets the maximum number of threads used to perform optimization.

Parameters
n_threadsmaximum number of threads

Implements SolverAbstract.

◆ solve_lp()

int SolverClp::solve_lp ( )
overridevirtual

Solves a problem as LP.

Returns
lp_status : status of the problem after resolution

Implements SolverAbstract.

◆ solve_mip()

int SolverClp::solve_mip ( )
overridevirtual

Solves a problem as MIP.

Returns
lp_status : status of the problem after resolution

Implements SolverAbstract.

◆ write_basis()

void SolverClp::write_basis ( const std::filesystem::path &  filename)
overridevirtual

Writes the current basis to a file for later input into the optimizer.

Parameters
filename: file name where the basis is written

Implements SolverAbstract.

◆ write_prob_lp()

void SolverClp::write_prob_lp ( const std::filesystem::path &  filename)
overridevirtual

writes an optimization problem in a LP file

Parameters
name: name of the file to write

Implements SolverAbstract.

◆ write_prob_mps()

void SolverClp::write_prob_mps ( const std::filesystem::path &  filename)
overridevirtual

writes an optimization problem in a MPS file

Parameters
name: name of the file to write

Implements SolverAbstract.


The documentation for this class was generated from the following files: