![]() |
OpenMS
|
A wrapper class for linear programming (LP) solvers. More...
#include <OpenMS/DATASTRUCTURES/LPWrapper.h>
Classes | |
| struct | SolverParam |
| Struct that holds the parameters of the LP solver. More... | |
Public Types | |
| enum | Type { UNBOUNDED = 1 , LOWER_BOUND_ONLY , UPPER_BOUND_ONLY , DOUBLE_BOUNDED , FIXED } |
| Enumeration for variable/constraint bound types. More... | |
| enum | VariableType { CONTINUOUS = 1 , INTEGER , BINARY } |
| Enumeration for variable types in the LP problem. More... | |
| enum | Sense { MIN = 1 , MAX } |
| Enumeration for optimization direction. More... | |
| enum | WriteFormat { FORMAT_LP = 0 , FORMAT_MPS , FORMAT_GLPK } |
| Enumeration for LP problem file formats. More... | |
| enum | SOLVER { SOLVER_GLPK = 0 } |
| Enumeration for available LP solvers. More... | |
| enum | SolverStatus { UNDEFINED = 1 , OPTIMAL = 5 , FEASIBLE = 2 , NO_FEASIBLE_SOL = 4 } |
| Enumeration for solver status after solving an LP problem. More... | |
Public Member Functions | |
| LPWrapper () | |
| Default constructor. More... | |
| virtual | ~LPWrapper () |
| Virtual destructor. More... | |
| Int | addRow (const std::vector< Int > &row_indices, const std::vector< double > &row_values, const String &name) |
| Adds a row to the LP matrix. More... | |
| Int | addColumn () |
| Adds an empty column to the LP matrix. More... | |
| Int | addColumn (const std::vector< Int > &column_indices, const std::vector< double > &column_values, const String &name) |
| Adds a column to the LP matrix. More... | |
| Int | addRow (const std::vector< Int > &row_indices, const std::vector< double > &row_values, const String &name, double lower_bound, double upper_bound, Type type) |
| Adds a row with boundaries to the LP matrix, returns index. More... | |
| Int | addColumn (const std::vector< Int > &column_indices, const std::vector< double > &column_values, const String &name, double lower_bound, double upper_bound, Type type) |
| Adds a column with boundaries to the LP matrix, returns index. More... | |
| void | deleteRow (Int index) |
| Delete the row at the specified index. More... | |
| void | setColumnName (Int index, const String &name) |
| Set the name of a column. More... | |
| String | getColumnName (Int index) |
| Get the name of a column. More... | |
| String | getRowName (Int index) |
| Get the name of a row. More... | |
| Int | getRowIndex (const String &name) |
| Find the index of a row by its name. More... | |
| Int | getColumnIndex (const String &name) |
| Find the index of a column by its name. More... | |
| double | getColumnUpperBound (Int index) |
| Get the upper bound of a column. More... | |
| double | getColumnLowerBound (Int index) |
| Get the lower bound of a column. More... | |
| double | getRowUpperBound (Int index) |
| Get the upper bound of a row. More... | |
| double | getRowLowerBound (Int index) |
| Get the lower bound of a row. More... | |
| void | setRowName (Int index, const String &name) |
| Set the name of a row. More... | |
| void | setColumnBounds (Int index, double lower_bound, double upper_bound, Type type) |
| Set column bounds. More... | |
| void | setRowBounds (Int index, double lower_bound, double upper_bound, Type type) |
| Set row bounds. More... | |
| void | setColumnType (Int index, VariableType type) |
| Set column/variable type. More... | |
| VariableType | getColumnType (Int index) |
| Get column/variable type. More... | |
| void | setObjective (Int index, double obj_value) |
| Set the objective coefficient for a column/variable. More... | |
| double | getObjective (Int index) |
| Get the objective coefficient for a column/variable. More... | |
| void | setObjectiveSense (Sense sense) |
| Set objective direction. More... | |
| Sense | getObjectiveSense () |
| Get the current objective direction. More... | |
| Int | getNumberOfColumns () |
| Get the number of columns/variables in the LP problem. More... | |
| Int | getNumberOfRows () |
| Get the number of rows/constraints in the LP problem. More... | |
| void | setElement (Int row_index, Int column_index, double value) |
| Set the value of a matrix element at the specified position. More... | |
| double | getElement (Int row_index, Int column_index) |
| Get the value of a matrix element at the specified position. More... | |
| void | readProblem (const String &filename, const String &format) |
| Read LP from file. More... | |
| void | writeProblem (const String &filename, const WriteFormat format) const |
| Write LP formulation to a file. More... | |
| Int | solve (SolverParam &solver_param, const Size verbose_level=0) |
| solve problems, parameters like enabled heuristics can be given via solver_param More... | |
| SolverStatus | getStatus () |
| Get solution status. More... | |
| double | getObjectiveValue () |
| Get the objective function value of the solution. More... | |
| double | getColumnValue (Int index) |
| Get the value of a variable in the solution. More... | |
| Int | getNumberOfNonZeroEntriesInRow (Int idx) |
| Get the number of non-zero entries in a specific row. More... | |
| void | getMatrixRow (Int idx, std::vector< Int > &indexes) |
| Get the indices of non-zero entries in a specific row. More... | |
| SOLVER | getSolver () const |
| Get the currently active solver backend. More... | |
Protected Attributes | |
| glp_prob * | lp_problem_ = nullptr |
| GLPK problem object for the LP problem. More... | |
| SOLVER | solver_ |
| Currently active solver backend. More... | |
A wrapper class for linear programming (LP) solvers.
This class provides a unified interface to different linear programming solvers, including GLPK (GNU Linear Programming Kit) and COIN-OR (if available).
Linear programming is a method to find the best outcome in a mathematical model whose requirements are represented by linear relationships. It is used for optimization problems where the objective function and constraints are linear.
LPWrapper allows you to:
The class supports both continuous and integer variables, allowing for mixed-integer linear programming (MILP) problems.
| enum Sense |
| enum SOLVER |
| enum SolverStatus |
Enumeration for solver status after solving an LP problem.
Defines the possible outcomes after attempting to solve an LP problem.
| enum Type |
Enumeration for variable/constraint bound types.
Defines the type of bounds applied to variables or constraints in the LP problem.
| enum VariableType |
Enumeration for variable types in the LP problem.
Defines whether variables are continuous or discrete (integer/binary).
| enum WriteFormat |
| LPWrapper | ( | ) |
Default constructor.
Initializes a new LP problem with the default solver (GLPK or COIN-OR if available).
|
virtual |
Virtual destructor.
Frees all resources associated with the LP problem.
| Int addColumn | ( | const std::vector< Int > & | column_indices, |
| const std::vector< double > & | column_values, | ||
| const String & | name | ||
| ) |
Adds a column to the LP matrix.
| column_indices | Indices of the rows that have non-zero coefficients in this column |
| column_values | Values of the non-zero coefficients in this column |
| name | Name of the column (for identification purposes) |
| Int addColumn | ( | const std::vector< Int > & | column_indices, |
| const std::vector< double > & | column_values, | ||
| const String & | name, | ||
| double | lower_bound, | ||
| double | upper_bound, | ||
| Type | type | ||
| ) |
Adds a column with boundaries to the LP matrix, returns index.
| column_indices | |
| column_values | |
| name | |
| lower_bound | |
| upper_bound | |
| type | 1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed variable |
| Int addRow | ( | const std::vector< Int > & | row_indices, |
| const std::vector< double > & | row_values, | ||
| const String & | name | ||
| ) |
Adds a row to the LP matrix.
| row_indices | Indices of the columns that have non-zero coefficients in this row |
| row_values | Values of the non-zero coefficients in this row |
| name | Name of the row (for identification purposes) |
| Int addRow | ( | const std::vector< Int > & | row_indices, |
| const std::vector< double > & | row_values, | ||
| const String & | name, | ||
| double | lower_bound, | ||
| double | upper_bound, | ||
| Type | type | ||
| ) |
Adds a row with boundaries to the LP matrix, returns index.
If you have a fixed variable, GLPK requires to use the "fixed" type, instead of "double-bounded" with equal bounds.
| row_indices | |
| row_values | |
| name | |
| lower_bound | |
| upper_bound | |
| type | Type of the row 1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed variable |
| void deleteRow | ( | Int | index | ) |
Delete the row at the specified index.
| index | Index of the row to delete |
Find the index of a column by its name.
| name | Name of the column to find |
| double getColumnLowerBound | ( | Int | index | ) |
Get the lower bound of a column.
| index | Index of the column |
| VariableType getColumnType | ( | Int | index | ) |
Get column/variable type.
| index |
| double getColumnUpperBound | ( | Int | index | ) |
Get the upper bound of a column.
| index | Index of the column |
| double getColumnValue | ( | Int | index | ) |
Get the value of a variable in the solution.
| index | Index of the column/variable |
Get the indices of non-zero entries in a specific row.
| idx | Index of the row |
| indexes | Vector to store the column indices of non-zero entries |
| Int getNumberOfColumns | ( | ) |
Get the number of columns/variables in the LP problem.
Get the number of non-zero entries in a specific row.
| idx | Index of the row |
| Int getNumberOfRows | ( | ) |
Get the number of rows/constraints in the LP problem.
| double getObjective | ( | Int | index | ) |
Get the objective coefficient for a column/variable.
| index | Index of the column/variable |
| Sense getObjectiveSense | ( | ) |
Get the current objective direction.
| double getObjectiveValue | ( | ) |
Get the objective function value of the solution.
Find the index of a row by its name.
| name | Name of the row to find |
| double getRowLowerBound | ( | Int | index | ) |
| double getRowUpperBound | ( | Int | index | ) |
| SOLVER getSolver | ( | ) | const |
Get the currently active solver backend.
| SolverStatus getStatus | ( | ) |
Get solution status.
Read LP from file.
| filename | Filename where to store the LP problem. |
| format | LP, MPS or GLPK. |
Set column bounds.
| index | |
| lower_bound | |
| upper_bound | |
| type | 1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed variable |
Set the name of a column.
| index | Index of the column to rename |
| name | New name for the column |
| void setColumnType | ( | Int | index, |
| VariableType | type | ||
| ) |
Set column/variable type.
| index | |
| type | 1- continuous, 2- integer, 3- binary variable |
| void setObjective | ( | Int | index, |
| double | obj_value | ||
| ) |
Set the objective coefficient for a column/variable.
| index | Index of the column/variable |
| obj_value | Coefficient value in the objective function |
| void setObjectiveSense | ( | Sense | sense | ) |
Set objective direction.
| sense | 1- minimize, 2- maximize |
Set row bounds.
| index | |
| lower_bound | |
| upper_bound | |
| type | 1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed constraint |
Set the name of a row.
| index | Index of the row to rename |
| name | New name for the row |
| Int solve | ( | SolverParam & | solver_param, |
| const Size | verbose_level = 0 |
||
| ) |
solve problems, parameters like enabled heuristics can be given via solver_param
The verbose level (0,1,2) determines if the solver prints status messages and internals.
| solver_param | |
| verbose_level |
| void writeProblem | ( | const String & | filename, |
| const WriteFormat | format | ||
| ) | const |
Write LP formulation to a file.
| filename | output filename, if the filename ends with '.gz' it will be compressed |
| format | MPS-format is supported by GLPK and COIN-OR; LP and GLPK-formats only by GLPK |
|
protected |
GLPK problem object for the LP problem.
|
protected |
Currently active solver backend.