![]() |
OR-Tools
9.6
|
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... | |
|
default |
Creates an empty linear expression with value zero.
| LinearExpr | ( | BoolVar | var | ) |
Constructs a linear expression from a Boolean variable.
It deals with logical negation correctly.
Definition at line 175 of file cp_model.cc.
| LinearExpr | ( | IntVar | var | ) |
Constructs a linear expression from an integer variable.
Definition at line 189 of file cp_model.cc.
| LinearExpr | ( | int64_t | constant | ) |
Constructs a constant linear expression.
Definition at line 195 of file cp_model.cc.
|
inline |
Returns the vector of coefficients.
Definition at line 292 of file cp_model.h.
|
inline |
Returns the constant term.
Definition at line 298 of file cp_model.h.
| 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.
Definition at line 279 of file cp_model.cc.
|
static |
Constructs a linear expr from its proto representation.
Definition at line 197 of file cp_model.cc.
|
inline |
Returns true if the expression has no variables.
Definition at line 295 of file cp_model.h.
| LinearExpr & operator*= | ( | int64_t | factor | ) |
Definition at line 273 of file cp_model.cc.
| LinearExpr & operator+= | ( | const LinearExpr & | other | ) |
Definition at line 254 of file cp_model.cc.
| LinearExpr & operator-= | ( | const LinearExpr & | other | ) |
Definition at line 263 of file cp_model.cc.
|
static |
Constructs the sum of a list of Boolean variables.
Definition at line 214 of file cp_model.cc.
|
static |
Constructs the sum of a list of variables.
Definition at line 206 of file cp_model.cc.
|
static |
Constructs bool * coefficient.
Definition at line 248 of file cp_model.cc.
|
static |
Constructs var * coefficient.
Definition at line 242 of file cp_model.cc.
|
inline |
Returns the vector of variable indices.
Definition at line 289 of file cp_model.h.
|
static |
Constructs the scalar product of Boolean variables and coefficients.
Definition at line 232 of file cp_model.cc.
|
static |
Constructs the scalar product of variables and coefficients.
Definition at line 222 of file cp_model.cc.