Loading...
Searching...
No Matches
LpBase Class Referenceabstract
General Optimization Tools » LP and MIP Solvers

## Detailed Description

Usually this class is not used directly, please use one of the concrete implementations of the solver interface.

`#include <lemon/lp_base.h>`

Inheritance diagram for LpBase:
[legend]

## Classes

class | Col
| Refer to a column of the LP. More...
class | ColIt
| Iterator for iterate over the columns of an LP problem. More...
class | Row
| Refer to a row of the LP. More...
class | RowIt
| Iterator for iterate over the rows of an LP problem. More...
class | Expr
| Linear expression of variables and a constant component. More...
class | Constr
| Linear constraint. More...
class | DualExpr
| Linear expression of rows. More...
class | UnsupportedFormatError
| Unsupported file format exception. More...

## Public Types

enum | SolveExitStatus { SOLVED = 0 , UNSOLVED = 1 }
| Possible outcomes of an LP solving procedure. More...
enum | Sense { MIN , MAX }
| Direction of the optimization. More...
enum | MessageLevel { MESSAGE_NOTHING , MESSAGE_ERROR , MESSAGE_WARNING , MESSAGE_NORMAL , MESSAGE_VERBOSE }
| Enum for `messageLevel()` parameter. More...
typedef double | Value
| The floating point type used by the solver.

## Public Member Functions

virtual | ~LpBase ()
| Virtual destructor.
const char * | solverName () const
| Gives back the name of the solver.
Build Up and Modify the LP
Col | addCol ()
| Add a new empty column (i.e a new variable) to the LP.
template<class T>
int | addColSet (T &t)
| Adds several new columns (i.e variables) at once.
void | col (Col c, const DualExpr &e)
| Set a column (i.e a dual constraint) of the LP.
DualExpr | col (Col c) const
| Get a column (i.e a dual constraint) of the LP.
Col | addCol (const DualExpr &e, Value o=0)
| Add a new column to the LP.
Row | addRow ()
| Add a new empty row (i.e a new constraint) to the LP.
template<class T>
int | addRowSet (T &t)
| Add several new rows (i.e constraints) at once.
void | row (Row r, Value l, const Expr &e, Value u)
| Set a row (i.e a constraint) of the LP.
void | row (Row r, const Constr &c)
| Set a row (i.e a constraint) of the LP.
Expr | row (Row r) const
| Get a row (i.e a constraint) of the LP.
Row | addRow (Value l, const Expr &e, Value u)
| Add a new row (i.e a new constraint) to the LP.
Row | addRow (const Constr &c)
| Add a new row (i.e a new constraint) to the LP.
void | erase (Col c)
| Erase a column (i.e a variable) from the LP.
void | erase (Row r)
| Erase a row (i.e a constraint) from the LP.
std::string | colName (Col c) const
| Get the name of a column.
void | colName (Col c, const std::string &name)
| Set the name of a column.
Col | colByName (const std::string &name) const
| Get the column by its name.
std::string | rowName (Row r) const
| Get the name of a row.
void | rowName (Row r, const std::string &name)
| Set the name of a row.
Row | rowByName (const std::string &name) const
| Get the row by its name.
void | coeff (Row r, Col c, Value val)
| Set an element of the coefficient matrix of the LP.
Value | coeff (Row r, Col c) const
| Get an element of the coefficient matrix of the LP.
void | colLowerBound (Col c, Value value)
| Set the lower bound of a column (i.e a variable).
Value | colLowerBound (Col c) const
| Get the lower bound of a column (i.e a variable).
template<class T>
void | colLowerBound (T &t, Value value)
| Set the lower bound of several columns (i.e variables) at once.
void | colUpperBound (Col c, Value value)
| Set the upper bound of a column (i.e a variable).
Value | colUpperBound (Col c) const
| Get the upper bound of a column (i.e a variable).
template<class T>
void | colUpperBound (T &t, Value value)
| Set the upper bound of several columns (i.e variables) at once.
void | colBounds (Col c, Value lower, Value upper)
| Set the lower and the upper bounds of a column (i.e a variable).
template<class T>
void | colBounds (T &t, Value lower, Value upper)
| Set the lower and the upper bound of several columns (i.e variables) at once.
void | rowLowerBound (Row r, Value value)
| Set the lower bound of a row (i.e a constraint).
Value | rowLowerBound (Row r) const
| Get the lower bound of a row (i.e a constraint).
void | rowUpperBound (Row r, Value value)
| Set the upper bound of a row (i.e a constraint).
Value | rowUpperBound (Row r) const
| Get the upper bound of a row (i.e a constraint).
void | objCoeff (Col c, Value v)
| Set an element of the objective function.
Value | objCoeff (Col c) const
| Get an element of the objective function.
void | obj (const Expr &e)
| Set the objective function.
Expr | obj () const
| Get the objective function.
void | sense (Sense sense)
| Set the direction of optimization.
Sense | sense () const
| Query the direction of the optimization.
void | max ()
| Set the sense to maximization.
void | min ()
| Set the sense to maximization.
void | clear ()
| Clear the problem.
void | messageLevel (MessageLevel level)
| Set the message level of the solver.
void | write (std::string file, std::string format="MPS") const
| Write the problem to a file in the given format.

## Static Public Member Functions

static int | id (const Col &col)
| Returns the ID of the column.
static Col | colFromId (int id)
| Returns the column with the given ID.
static int | id (const Row &row)
| Returns the ID of the row.
static Row | rowFromId (int id)
| Returns the row with the given ID.

## Static Public Attributes

static const Value | INF
| The infinity constant.
static const Value | NaN
| The not a number constant.

## Related Symbols

(Note that these are not member symbols.)
LpBase::Expr | operator+ (const LpBase::Expr &a, const LpBase::Expr &b)
| Addition.
LpBase::Expr | operator- (const LpBase::Expr &a, const LpBase::Expr &b)
| Substraction.
LpBase::Expr | operator* (const LpBase::Expr &a, const LpBase::Value &b)
| Multiply with constant.
LpBase::Expr | operator* (const LpBase::Value &a, const LpBase::Expr &b)
| Multiply with constant.
LpBase::Expr | operator/ (const LpBase::Expr &a, const LpBase::Value &b)
| Divide with constant.
LpBase::Constr | operator<= (const LpBase::Expr &e, const LpBase::Expr &f)
| Create constraint.
LpBase::Constr | operator<= (const LpBase::Value &e, const LpBase::Expr &f)
| Create constraint.
LpBase::Constr | operator<= (const LpBase::Expr &e, const LpBase::Value &f)
| Create constraint.
LpBase::Constr | operator>= (const LpBase::Expr &e, const LpBase::Expr &f)
| Create constraint.
LpBase::Constr | operator>= (const LpBase::Value &e, const LpBase::Expr &f)
| Create constraint.
LpBase::Constr | operator>= (const LpBase::Expr &e, const LpBase::Value &f)
| Create constraint.
LpBase::Constr | operator== (const LpBase::Expr &e, const LpBase::Value &f)
| Create constraint.
LpBase::Constr | operator== (const LpBase::Expr &e, const LpBase::Expr &f)
| Create constraint.
LpBase::Constr | operator<= (const LpBase::Value &n, const LpBase::Constr &c)
| Create constraint.
LpBase::Constr | operator<= (const LpBase::Constr &c, const LpBase::Value &n)
| Create constraint.
LpBase::Constr | operator>= (const LpBase::Value &n, const LpBase::Constr &c)
| Create constraint.
LpBase::Constr | operator>= (const LpBase::Constr &c, const LpBase::Value &n)
| Create constraint.
LpBase::DualExpr | operator+ (const LpBase::DualExpr &a, const LpBase::DualExpr &b)
| Addition.
LpBase::DualExpr | operator- (const LpBase::DualExpr &a, const LpBase::DualExpr &b)
| Substraction.
LpBase::DualExpr | operator* (const LpBase::DualExpr &a, const LpBase::Value &b)
| Multiply with constant.
LpBase::DualExpr | operator* (const LpBase::Value &a, const LpBase::DualExpr &b)
| Multiply with constant.
LpBase::DualExpr | operator/ (const LpBase::DualExpr &a, const LpBase::Value &b)
| Divide with constant.

## Member Enumeration Documentation

## SolveExitStatus

enum SolveExitStatus

Enumerator
SOLVED | = 0. It means that the problem has been successfully solved: either an optimal solution has been found or infeasibility/unboundedness has been proved.
UNSOLVED | = 1. Any other case (including the case when some user specified limit has been exceeded).

## Sense

enum Sense

Enumerator
MIN | Minimization.
MAX | Maximization.

## MessageLevel

enum MessageLevel

Enumerator
MESSAGE_NOTHING | No output (default value).
MESSAGE_ERROR | Error messages only.
MESSAGE_WARNING | Warnings.
MESSAGE_NORMAL | Normal output.
MESSAGE_VERBOSE | Verbose output.

## Member Function Documentation

## colFromId()

Col colFromId | ( | int | id | ) |

inline static

Precondition
  The argument should be a valid column ID in the LP problem.

## rowFromId()

Row rowFromId | ( | int | id | ) |

inline static

Precondition
  The argument should be a valid row ID in the LP problem.

## addColSet()

template<class T>

int addColSet | ( | T & | t | ) |

inline

This magic function takes a container as its argument and fills its elements with new columns (i.e. variables)

Parameters

  t

  can be
  - a standard STL compatible iterable container with Col as its `values_type` like
    std::vector<LpBase::Col>
    std::list<LpBase::Col>
  - a standard STL compatible iterable container with Col as its `mapped_type` like
    std::map<AnyType,LpBase::Col>
  - an iterable lemon write map like
    ListGraph::NodeMap<LpBase::Col>
    ListGraph::ArcMap<LpBase::Col>

Returns
  The number of the created column.

## col() [1/2]

void col | ( | Col | c,
|  | const DualExpr & | e )

inline

Parameters

  c | is the column to be modified
  e | is a dual linear expression (see DualExpr) a better one.

## col() [2/2]

DualExpr col | ( | Col | c | ) | const

inline

Parameters

  c | is the column to get

Returns
  the dual expression associated to the column

## addCol()

Col addCol | ( | const DualExpr & | e,
|  | Value | o = 0 )

inline

Parameters

  e | is a dual linear expression (see DualExpr)
  o | is the corresponding component of the objective function. It is 0 by default.

Returns
  The created column.

## addRow() [1/3]

Row addRow | ( |  | ) |

inline

This function adds a new empty row (i.e a new constraint) to the LP.

Returns
  The created row

## addRowSet()

template<class T>

int addRowSet | ( | T & | t | ) |

inline

This magic function takes a container as its argument and fills its elements with new row (i.e. variables)

Parameters

  t

  can be
  - a standard STL compatible iterable container with Row as its `values_type` like
    std::vector<LpBase::Row>
    std::list<LpBase::Row>
  - a standard STL compatible iterable container with Row as its `mapped_type` like
    std::map<AnyType,LpBase::Row>
  - an iterable lemon write map like
    ListGraph::NodeMap<LpBase::Row>
    ListGraph::ArcMap<LpBase::Row>

Returns
  The number of rows created.

## row() [1/3]

void row | ( | Row | r,
|  | Value | l,
|  | const Expr & | e,
|  | Value | u )

inline

Parameters

  r | is the row to be modified
  l | is lower bound (-INF means no bound)
  e | is a linear expression (see Expr)
  u | is the upper bound (INF means no bound)

## row() [2/3]

void row | ( | Row | r,
|  | const Constr & | c )

inline

Parameters

  r | is the row to be modified
  c | is a linear expression (see Constr)

## row() [3/3]

Expr row | ( | Row | r | ) | const

inline

Parameters

  r | is the row to get

Returns
  the expression associated to the row

## addRow() [2/3]

Row addRow | ( | Value | l,
|  | const Expr & | e,
|  | Value | u )

inline

Parameters

  l | is the lower bound (-INF means no bound)
  e | is a linear expression (see Expr)
  u | is the upper bound (INF means no bound)

Returns
  The created row.

## addRow() [3/3]

Row addRow | ( | const Constr & | c | ) |

inline

Parameters

  c | is a linear expression (see Constr)

Returns
  The created row.

## erase() [1/2]

void erase | ( | Col | c | ) |

inline

Parameters

  c | is the column to be deleted

## erase() [2/2]

void erase | ( | Row | r | ) |

inline

Parameters

  r | is the row to be deleted

## colName() [1/2]

std::string colName | ( | Col | c | ) | const

inline

Parameters

  c | is the coresponding column

Returns
  The name of the colunm

## colName() [2/2]

void colName | ( | Col | c,
|  | const std::string & | name )

inline

Parameters

  c | is the coresponding column
  name | The name to be given

## colByName()

Col colByName | ( | const std::string & | name | ) | const

inline

Parameters

  name | The name of the column

Returns
  the proper column or `INVALID`

## rowName() [1/2]

std::string rowName | ( | Row | r | ) | const

inline

Parameters

  r | is the coresponding row

Returns
  The name of the row

## rowName() [2/2]

void rowName | ( | Row | r,
|  | const std::string & | name )

inline

Parameters

  r | is the coresponding row
  name | The name to be given

## rowByName()

Row rowByName | ( | const std::string & | name | ) | const

inline

Parameters

  name | The name of the row

Returns
  the proper row or `INVALID`

## coeff() [1/2]

void coeff | ( | Row | r,
|  | Col | c,
|  | Value | val )

inline

Parameters

  r | is the row of the element to be modified
  c | is the column of the element to be modified
  val | is the new value of the coefficient

## coeff() [2/2]

Value coeff | ( | Row | r,
|  | Col | c ) const

inline

Parameters

  r | is the row of the element
  c | is the column of the element

Returns
  the corresponding coefficient

## colLowerBound() [1/3]

void colLowerBound | ( | Col | c,
|  | Value | value )

inline

The lower bound of a variable (column) has to be given by an extended number of type Value, i.e. a finite number of type Value or -INF.

## colLowerBound() [2/3]

Value colLowerBound | ( | Col | c | ) | const

inline

This function returns the lower bound for column (variable) `c` (this might be -INF as well).

Returns
  The lower bound for column `c`

## colLowerBound() [3/3]

template<class T>

void colLowerBound | ( | T & | t,
|  | Value | value )

inline

This magic function takes a container as its argument and applies the function on all of its elements. The lower bound of a variable (column) has to be given by an extended number of type Value, i.e. a finite number of type Value or -INF.

## colUpperBound() [1/3]

void colUpperBound | ( | Col | c,
|  | Value | value )

inline

The upper bound of a variable (column) has to be given by an extended number of type Value, i.e. a finite number of type Value or INF.

## colUpperBound() [2/3]

Value colUpperBound | ( | Col | c | ) | const

inline

This function returns the upper bound for column (variable) `c` (this might be INF as well).

Returns
  The upper bound for column `c`

## colUpperBound() [3/3]

template<class T>

void colUpperBound | ( | T & | t,
|  | Value | value )

inline

This magic function takes a container as its argument and applies the function on all of its elements. The upper bound of a variable (column) has to be given by an extended number of type Value, i.e. a finite number of type Value or INF.

## colBounds() [1/2]

void colBounds | ( | Col | c,
|  | Value | lower,
|  | Value | upper )

inline

The lower and the upper bounds of a variable (column) have to be given by an extended number of type Value, i.e. a finite number of type Value, -INF or INF.

## colBounds() [2/2]

template<class T>

void colBounds | ( | T & | t,
|  | Value | lower,
|  | Value | upper )

inline

This magic function takes a container as its argument and applies the function on all of its elements. The lower and the upper bounds of a variable (column) have to be given by an extended number of type Value, i.e. a finite number of type Value, -INF or INF.

## rowLowerBound() [1/2]

void rowLowerBound | ( | Row | r,
|  | Value | value )

inline

The lower bound of a constraint (row) has to be given by an extended number of type Value, i.e. a finite number of type Value or -INF.

## rowLowerBound() [2/2]

Value rowLowerBound | ( | Row | r | ) | const

inline

This function returns the lower bound for row (constraint) `c` (this might be -INF as well).

Returns
  The lower bound for row `r`

## rowUpperBound() [1/2]

void rowUpperBound | ( | Row | r,
|  | Value | value )

inline

The upper bound of a constraint (row) has to be given by an extended number of type Value, i.e. a finite number of type Value or -INF.

## rowUpperBound() [2/2]

Value rowUpperBound | ( | Row | r | ) | const

inline

This function returns the upper bound for row (constraint) `c` (this might be -INF as well).

Returns
  The upper bound for row `r`

## obj() [1/2]

void obj | ( | const Expr & | e | ) |

inline

Parameters

  e | is a linear expression of type Expr.

## obj() [2/2]

Expr obj | ( |  | ) | const

inline

Returns
  the objective function as a linear expression of type Expr.

## write()

void write | ( | std::string | file,
|  | std::string | format = "MPS" ) const

inline

This function writes the problem to a file in the given format. Different solver backends may support different formats. Trying to write in an unsupported format will trigger UnsupportedFormatError. For the supported formats, visit the documentation of the base class of the related backends (CplexBase, GlpkBase etc.)

Parameters

  file | The file path
  format | The output file format.