All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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).

*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.
 
 Expr (const Col &c)
 Construct an expression from a column.
 
 Expr (const Value &v)
 Construct an expression from a constant.
 
Value operator[] (const Col &c) const
 Returns the coefficient of the column.
 
Valueoperator[] (const Col &c)
 Returns the coefficient of the column.
 
void set (const Col &c, const Value &v)
 Sets the coefficient of the column.
 
Valueoperator* ()
 Returns the constant component of the expression.
 
const Valueoperator* () 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.
 
Exproperator+= (const Expr &e)
 Compound assignment.
 
Exproperator-= (const Expr &e)
 Compound assignment.
 
Exproperator*= (const Value &v)
 Multiply with a constant.
 
Exproperator/= (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.