LpBase::Expr Class Reference

- Main Page
- Modules
- Classes
- Namespaces
- Files
- Related Pages

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions | Related Functions
LpBase::Expr Class Reference

## Detailed Description

This data structure stores a linear expression of the variables (Cols) and also has a constant component.

There are several ways to access and modify the contents of this container.

* e[v]=5;
* e[v]+=12;
* e.erase(v);
*

or you can also iterate through its elements.

* double s=0;
* for(LpBase::Expr::ConstCoeffIt i(e);i!=INVALID;++i)
* s+=*i * primal(i);
*

(This code computes the primal value of the expression).

- Numbers (`double`'s) and variables (Cols) directly convert to an Expr and the usual linear operations are defined, so
  * v+w
  * 2*v-3.12*(v-w/2)+2
  * v*2.1+(3*v+(v*12+w+6)*3)/2
  *
  are valid expressions. The usual assignment operations are also defined.
  * e=v+w;
  * e+=2*v-3.12*(v-w/2)+2;
  * e*=3.4;
  * e/=5;
  *
- The constant member can be set and read by dereference operator (unary *)

* *e=12;
* double c=*e;
*

See Also
  Constr

`#include <lemon/lp_base.h>`

## Classes
class | CoeffIt
| Iterator over the expression. More...
class | ConstCoeffIt
| Const iterator over the expression. More...

## Public Types
typedef LpBase::Col | Key
| The key type of the expression.
typedef LpBase::Value | Value
| The value type of the expression.

## Public Member Functions
| Expr ()
| Default constructor. More...
| Expr (const Col &c)
| Construct an expression from a column. More...
| Expr (const Value &v)
| Construct an expression from a constant. More...
Value | operator[] (const Col &c) const
| Returns the coefficient of the column.
Value & | operator[] (const Col &c)
| Returns the coefficient of the column.
void | set (const Col &c, const Value &v)
| Sets the coefficient of the column.
Value & | operator* ()
| Returns the constant component of the expression.
const Value & | operator* () const
| Returns the constant component of the expression.
void | simplify (Value epsilon=0.0)
| Removes the coefficients which's absolute value does not exceed `epsilon`. It also sets to zero the constant component, if it does not exceed epsilon in absolute value.
void | clear ()
| Sets all coefficients and the constant component to 0.
Expr & | operator+= (const Expr &e)
| Compound assignment.
Expr & | operator-= (const Expr &e)
| Compound assignment.
Expr & | operator*= (const Value &v)
| Multiply with a constant.
Expr & | operator/= (const Value &c)
| Division with a constant.

## Related Functions
(Note that these are not member functions.)
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.

## Constructor & Destructor Documentation

Expr | ( |  | ) |
| inline

Construct an empty expression, the coefficients and the constant component are initialized to zero.

Expr | ( | const Col & | c | ) |
| inline

Construct an expression, which has a term with `c` variable and 1.0 coefficient.

Expr | ( | const Value & | v | ) |
| inline

Construct an expression, which's constant component is `v`.