![]() |
OR-Tools
8.2
|
A dedicated container for linear expressions.
This class helps building and manipulating linear expressions. With the use of implicit constructors, it can accept integer values, Boolean and Integer variables. Note that Not(x) will be silently transformed into 1 - x when added to the linear expression.
Furthermore, static methods allows sums and scalar products, with or without an additional constant.
Usage:
This can be used implicitly in some of the CpModelBuilder methods.
Definition at line 248 of file cp_model.h.
Public Member Functions | |
LinearExpr () | |
LinearExpr (BoolVar var) | |
Constructs a linear expression from a Boolean variable. More... | |
LinearExpr (IntVar var) | |
Constructs a linear expression from an integer variable. More... | |
LinearExpr (int64 constant) | |
Constructs a constant linear expression. More... | |
LinearExpr & | AddConstant (int64 value) |
Adds a constant value to the linear expression. More... | |
void | AddVar (IntVar var) |
Adds a single integer variable to the linear expression. More... | |
void | AddTerm (IntVar var, int64 coeff) |
Adds a term (var * coeff) to the linear expression. More... | |
const std::vector< IntVar > & | variables () const |
Returns the vector of variables. More... | |
const std::vector< int64 > & | coefficients () const |
Returns the vector of coefficients. More... | |
int64 | constant () const |
Returns the constant term. More... | |
Static Public Member Functions | |
static LinearExpr | Sum (absl::Span< const IntVar > vars) |
Constructs the sum of a list of variables. More... | |
static LinearExpr | ScalProd (absl::Span< const IntVar > vars, absl::Span< const int64 > coeffs) |
Constructs the scalar product of variables and coefficients. More... | |
static LinearExpr | BooleanSum (absl::Span< const BoolVar > vars) |
Constructs the sum of a list of Booleans. More... | |
static LinearExpr | BooleanScalProd (absl::Span< const BoolVar > vars, absl::Span< const int64 > coeffs) |
Constructs the scalar product of Booleans and coefficients. More... | |
static LinearExpr | Term (IntVar var, int64 coefficient) |
Construncts var * coefficient. More... | |
LinearExpr | ( | ) |
Definition at line 135 of file cp_model.cc.
LinearExpr | ( | BoolVar | var | ) |
Constructs a linear expression from a Boolean variable.
It deals with logical negation correctly.
Definition at line 137 of file cp_model.cc.
LinearExpr | ( | IntVar | var | ) |
Constructs a linear expression from an integer variable.
Definition at line 139 of file cp_model.cc.
LinearExpr | ( | int64 | constant | ) |
Constructs a constant linear expression.
Definition at line 141 of file cp_model.cc.
LinearExpr & AddConstant | ( | int64 | value | ) |
Adds a constant value to the linear expression.
Definition at line 185 of file cp_model.cc.
Adds a term (var * coeff) to the linear expression.
Definition at line 192 of file cp_model.cc.
void AddVar | ( | IntVar | var | ) |
Adds a single integer variable to the linear expression.
Definition at line 190 of file cp_model.cc.
|
static |
Constructs the scalar product of Booleans and coefficients.
Definition at line 175 of file cp_model.cc.
|
static |
Constructs the sum of a list of Booleans.
Definition at line 167 of file cp_model.cc.
|
inline |
Returns the vector of coefficients.
Definition at line 294 of file cp_model.h.
|
inline |
Returns the constant term.
Definition at line 297 of file cp_model.h.
|
static |
Constructs the scalar product of variables and coefficients.
Definition at line 151 of file cp_model.cc.
|
static |
Constructs the sum of a list of variables.
Definition at line 143 of file cp_model.cc.
|
static |
Construncts var * coefficient.
Definition at line 161 of file cp_model.cc.
|
inline |
Returns the vector of variables.
Definition at line 291 of file cp_model.h.