C++ Reference
C++ Reference: CP-SAT
Detailed Description
A dedicated container for 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. It also support operator overloads to construct the linear expression naturally.
Furthermore, static methods allow to construct a linear expression from sums or scalar products.
Usage:
This can be used implicitly in some of the CpModelBuilder methods.
Definition at line 241 of file cp_model.h.
Public Member Functions | |
| LinearExpr ()=default | |
| Creates an empty linear expression with value zero. More... | |
| 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_t constant) | |
| Constructs a constant linear expression. More... | |
| LinearExpr & | operator+= (const LinearExpr &other) |
| LinearExpr & | operator-= (const LinearExpr &other) |
| LinearExpr & | operator*= (int64_t factor) |
| const std::vector< int > & | variables () const |
| Returns the vector of variable indices. More... | |
| const std::vector< int64_t > & | coefficients () const |
| Returns the vector of coefficients. More... | |
| const bool | IsConstant () const |
| Returns true if the expression has no variables. More... | |
| int64_t | constant () const |
| Returns the constant term. More... | |
| std::string | DebugString (const CpModelProto *proto=nullptr) const |
| Debug string. More... | |
Static Public Member Functions | |
| static LinearExpr | Sum (absl::Span< const IntVar > vars) |
| Constructs the sum of a list of variables. More... | |
| static LinearExpr | Sum (absl::Span< const BoolVar > vars) |
| Constructs the sum of a list of Boolean variables. More... | |
| static LinearExpr | WeightedSum (absl::Span< const IntVar > vars, absl::Span< const int64_t > coeffs) |
| Constructs the scalar product of variables and coefficients. More... | |
| static LinearExpr | WeightedSum (absl::Span< const BoolVar > vars, absl::Span< const int64_t > coeffs) |
| Constructs the scalar product of Boolean variables and coefficients. More... | |
| static LinearExpr | Term (IntVar var, int64_t coefficient) |
| Constructs var * coefficient. More... | |
| static LinearExpr | Term (BoolVar var, int64_t coefficient) |
| Constructs bool * coefficient. More... | |
| static LinearExpr | FromProto (const LinearExpressionProto &proto) |
| Constructs a linear expr from its proto representation. More... | |
Constructor & Destructor Documentation
◆ LinearExpr() [1/4]
|
default |
Creates an empty linear expression with value zero.
◆ 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_t | constant | ) |
Constructs a constant linear expression.
Member Function Documentation
◆ coefficients()
|
inline |
Returns the vector of coefficients.
Definition at line 292 of file cp_model.h.
◆ constant()
|
inline |
Returns the constant term.
Definition at line 298 of file cp_model.h.
◆ DebugString()
| std::string DebugString | ( | const CpModelProto * | proto = nullptr | ) | const |
Debug string.
If the CpModelBuilder is passed, the string will include variable names and domains. Otherwise, you will get a shorter string with only variable indices.
◆ FromProto()
|
static |
Constructs a linear expr from its proto representation.
◆ IsConstant()
|
inline |
Returns true if the expression has no variables.
Definition at line 295 of file cp_model.h.
◆ operator*=()
| LinearExpr& operator*= | ( | int64_t | factor | ) |
◆ operator+=()
| LinearExpr& operator+= | ( | const LinearExpr & | other | ) |
◆ operator-=()
| LinearExpr& operator-= | ( | const LinearExpr & | other | ) |
◆ Sum() [1/2]
|
static |
Constructs the sum of a list of Boolean variables.
◆ Sum() [2/2]
|
static |
Constructs the sum of a list of variables.
◆ Term() [1/2]
|
static |
Constructs bool * coefficient.
◆ Term() [2/2]
|
static |
Constructs var * coefficient.
◆ variables()
|
inline |
Returns the vector of variable indices.
Definition at line 289 of file cp_model.h.
◆ WeightedSum() [1/2]
|
static |
Constructs the scalar product of Boolean variables and coefficients.
◆ WeightedSum() [2/2]
|
static |
Constructs the scalar product of variables and coefficients.
The documentation for this class was generated from the following file: