C++ Reference
C++ Reference: CP-SAT
Detailed Description
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... | |
Constructor & Destructor Documentation
◆ LinearExpr() [1/4]
LinearExpr | ( | ) |
◆ LinearExpr() [2/4]
LinearExpr | ( | BoolVar | var | ) |
Constructs a linear expression from a Boolean variable.
It deals with logical negation correctly.
◆ LinearExpr() [3/4]
LinearExpr | ( | IntVar | var | ) |
Constructs a linear expression from an integer variable.
◆ LinearExpr() [4/4]
LinearExpr | ( | int64 | constant | ) |
Constructs a constant linear expression.
Member Function Documentation
◆ AddConstant()
LinearExpr & AddConstant | ( | int64 | value | ) |
Adds a constant value to the linear expression.
◆ AddTerm()
void AddTerm | ( | IntVar | var, |
int64 | coeff | ||
) |
Adds a term (var * coeff) to the linear expression.
◆ AddVar()
void AddVar | ( | IntVar | var | ) |
Adds a single integer variable to the linear expression.
◆ BooleanScalProd()
|
static |
Constructs the scalar product of Booleans and coefficients.
◆ BooleanSum()
|
static |
Constructs the sum of a list of Booleans.
◆ coefficients()
|
inline |
Returns the vector of coefficients.
Definition at line 294 of file cp_model.h.
◆ constant()
|
inline |
Returns the constant term.
Definition at line 297 of file cp_model.h.
◆ ScalProd()
|
static |
Constructs the scalar product of variables and coefficients.
◆ Sum()
|
static |
Constructs the sum of a list of variables.
◆ Term()
|
static |
Construncts var * coefficient.
◆ variables()
|
inline |
Returns the vector of variables.
Definition at line 291 of file cp_model.h.
The documentation for this class was generated from the following file: