OpenMS  2.7.0
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
LPWrapper Class Reference

#include <OpenMS/DATASTRUCTURES/LPWrapper.h>

Collaboration diagram for LPWrapper:
[legend]

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
}
 
enum  VariableType { CONTINUOUS = 1 , INTEGER , BINARY }
 
enum  Sense { MIN = 1 , MAX }
 
enum  WriteFormat { FORMAT_LP = 0 , FORMAT_MPS , FORMAT_GLPK }
 
enum  SOLVER { SOLVER_GLPK = 0 }
 
enum  SolverStatus { UNDEFINED = 1 , OPTIMAL = 5 , FEASIBLE = 2 , NO_FEASIBLE_SOL = 4 }
 

Public Member Functions

 LPWrapper ()
 
virtual ~LPWrapper ()
 
Int addRow (const std::vector< Int > &row_indices, const std::vector< double > &row_values, const String &name)
 adds a row to the LP matrix, returns index More...
 
Int addColumn ()
 adds an empty column to the LP matrix, returns index 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, returns index 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 index-th row More...
 
void setColumnName (Int index, const String &name)
 sets name of the index-th column More...
 
String getColumnName (Int index)
 gets name of the index-th column More...
 
String getRowName (Int index)
 sets name of the index-th row More...
 
Int getRowIndex (const String &name)
 gets index of the row with name More...
 
Int getColumnIndex (const String &name)
 gets index of the column with name More...
 
double getColumnUpperBound (Int index)
 gets column's upper bound More...
 
double getColumnLowerBound (Int index)
 gets column's lower bound More...
 
double getRowUpperBound (Int index)
 gets row's upper bound More...
 
double getRowLowerBound (Int index)
 gets row's lower bound More...
 
void setRowName (Int index, const String &name)
 sets name of the index-th 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 objective value for column with index More...
 
double getObjective (Int index)
 get objective value for column with index More...
 
void setObjectiveSense (Sense sense)
 Set objective direction. More...
 
Sense getObjectiveSense ()
 
Int getNumberOfColumns ()
 get number of columns More...
 
Int getNumberOfRows ()
 get number of rows More...
 
void setElement (Int row_index, Int column_index, double value)
 
double getElement (Int row_index, Int column_index)
 
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 ()
 
double getColumnValue (Int index)
 
Int getNumberOfNonZeroEntriesInRow (Int idx)
 
void getMatrixRow (Int idx, std::vector< Int > &indexes)
 
SOLVER getSolver () const
 get currently active solver More...
 

Protected Attributes

glp_prob * lp_problem_ = nullptr
 
SOLVER solver_
 

Member Enumeration Documentation

◆ Sense

enum Sense
Enumerator
MIN 
MAX 

◆ SOLVER

enum SOLVER
Enumerator
SOLVER_GLPK 

◆ SolverStatus

Enumerator
UNDEFINED 
OPTIMAL 
FEASIBLE 
NO_FEASIBLE_SOL 

◆ Type

enum Type
Enumerator
UNBOUNDED 
LOWER_BOUND_ONLY 
UPPER_BOUND_ONLY 
DOUBLE_BOUNDED 
FIXED 

◆ VariableType

Enumerator
CONTINUOUS 
INTEGER 
BINARY 

◆ WriteFormat

Enumerator
FORMAT_LP 
FORMAT_MPS 
FORMAT_GLPK 

Constructor & Destructor Documentation

◆ LPWrapper()

LPWrapper ( )

◆ ~LPWrapper()

virtual ~LPWrapper ( )
virtual

Member Function Documentation

◆ addColumn() [1/3]

Int addColumn ( )

adds an empty column to the LP matrix, returns index

◆ addColumn() [2/3]

Int addColumn ( const std::vector< Int > &  column_indices,
const std::vector< double > &  column_values,
const String name 
)

adds a column to the LP matrix, returns index

◆ addColumn() [3/3]

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.

Parameters
column_indices
column_values
name
lower_bound
upper_bound
type1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed variable

◆ addRow() [1/2]

Int addRow ( const std::vector< Int > &  row_indices,
const std::vector< double > &  row_values,
const String name 
)

adds a row to the LP matrix, returns index

◆ addRow() [2/2]

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.

Parameters
row_indices
row_values
name
lower_bound
upper_bound
typeType of the row 1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed variable

◆ deleteRow()

void deleteRow ( Int  index)

delete index-th row

◆ getColumnIndex()

Int getColumnIndex ( const String name)

gets index of the column with name

◆ getColumnLowerBound()

double getColumnLowerBound ( Int  index)

gets column's lower bound

◆ getColumnName()

String getColumnName ( Int  index)

gets name of the index-th column

◆ getColumnType()

VariableType getColumnType ( Int  index)

Get column/variable type.

Parameters
index
Returns
1- continuous, 2- integer, 3- binary variable

◆ getColumnUpperBound()

double getColumnUpperBound ( Int  index)

gets column's upper bound

◆ getColumnValue()

double getColumnValue ( Int  index)

◆ getElement()

double getElement ( Int  row_index,
Int  column_index 
)

◆ getMatrixRow()

void getMatrixRow ( Int  idx,
std::vector< Int > &  indexes 
)

◆ getNumberOfColumns()

Int getNumberOfColumns ( )

get number of columns

◆ getNumberOfNonZeroEntriesInRow()

Int getNumberOfNonZeroEntriesInRow ( Int  idx)

◆ getNumberOfRows()

Int getNumberOfRows ( )

get number of rows

◆ getObjective()

double getObjective ( Int  index)

get objective value for column with index

◆ getObjectiveSense()

Sense getObjectiveSense ( )

◆ getObjectiveValue()

double getObjectiveValue ( )

◆ getRowIndex()

Int getRowIndex ( const String name)

gets index of the row with name

◆ getRowLowerBound()

double getRowLowerBound ( Int  index)

gets row's lower bound

◆ getRowName()

String getRowName ( Int  index)

sets name of the index-th row

◆ getRowUpperBound()

double getRowUpperBound ( Int  index)

gets row's upper bound

◆ getSolver()

SOLVER getSolver ( ) const

get currently active solver

◆ getStatus()

SolverStatus getStatus ( )

Get solution status.

Returns
status: 1 - undefined, 2 - integer optimal, 3- integer feasible (no optimality proven), 4- no integer feasible solution

◆ readProblem()

void readProblem ( const String filename,
const String format 
)

Read LP from file.

Parameters
filenameFilename where to store the LP problem.
formatLP, MPS or GLPK.

◆ setColumnBounds()

void setColumnBounds ( Int  index,
double  lower_bound,
double  upper_bound,
Type  type 
)

Set column bounds.

Parameters
index
lower_bound
upper_bound
type1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed variable

◆ setColumnName()

void setColumnName ( Int  index,
const String name 
)

sets name of the index-th column

◆ setColumnType()

void setColumnType ( Int  index,
VariableType  type 
)

Set column/variable type.

Parameters
index
type1- continuous, 2- integer, 3- binary variable

◆ setElement()

void setElement ( Int  row_index,
Int  column_index,
double  value 
)

◆ setObjective()

void setObjective ( Int  index,
double  obj_value 
)

set objective value for column with index

◆ setObjectiveSense()

void setObjectiveSense ( Sense  sense)

Set objective direction.

Parameters
sense1- minimize, 2- maximize

◆ setRowBounds()

void setRowBounds ( Int  index,
double  lower_bound,
double  upper_bound,
Type  type 
)

Set row bounds.

Parameters
index
lower_bound
upper_bound
type1 - unbounded, 2 - only lower bound, 3 - only upper bound, 4 - double-bounded variable, 5 - fixed constraint

◆ setRowName()

void setRowName ( Int  index,
const String name 
)

sets name of the index-th row

◆ solve()

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.

Parameters
solver_param
verbose_level
Returns
solver dependent (todo: fix)

◆ writeProblem()

void writeProblem ( const String filename,
const WriteFormat  format 
) const

Write LP formulation to a file.

Parameters
filenameoutput filename, if the filename ends with '.gz' it will be compressed
formatMPS-format is supported by GLPK and COIN-OR; LP and GLPK-formats only by GLPK

Member Data Documentation

◆ lp_problem_

glp_prob* lp_problem_ = nullptr
protected

◆ solver_

SOLVER solver_
protected