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.
or you can also iterate through its elements.
(This code computes the primal value of the expression).
double
's) and variables (Cols) directly convert to an Expr and the usual linear operations are defined, so #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. | |
|
inline |
Construct an empty expression, the coefficients and the constant component are initialized to zero.
Construct an expression, which has a term with c
variable and 1.0 coefficient.