Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <cp_model.h>
Public Member Functions | |
LinearExpr ()=default | |
Creates an empty linear expression with value zero. | |
LinearExpr (BoolVar var) | |
NOLINTBEGIN(google-explicit-constructor) | |
LinearExpr (IntVar var) | |
Constructs a linear expression from an integer variable. | |
LinearExpr (int64_t constant) | |
Constructs a constant linear expression. | |
LinearExpr & | operator+= (const LinearExpr &other) |
Operators. | |
LinearExpr & | operator-= (const LinearExpr &other) |
LinearExpr & | operator*= (int64_t factor) |
const std::vector< int > & | variables () const |
Returns the vector of variable indices. | |
const std::vector< int64_t > & | coefficients () const |
Returns the vector of coefficients. | |
bool | IsConstant () const |
Returns true if the expression has no variables. | |
int64_t | constant () const |
Returns the constant term. | |
std::string | DebugString (const CpModelProto *proto=nullptr) const |
Static Public Member Functions | |
static LinearExpr | Sum (absl::Span< const IntVar > vars) |
NOLINTEND(google-explicit-constructor) | |
static LinearExpr | Sum (absl::Span< const BoolVar > vars) |
Constructs the sum of a list of Boolean variables. | |
static LinearExpr | WeightedSum (absl::Span< const IntVar > vars, absl::Span< const int64_t > coeffs) |
Constructs the scalar product of variables and coefficients. | |
static LinearExpr | WeightedSum (absl::Span< const BoolVar > vars, absl::Span< const int64_t > coeffs) |
Constructs the scalar product of Boolean variables and coefficients. | |
static LinearExpr | Term (IntVar var, int64_t coefficient) |
Constructs var * coefficient. | |
static LinearExpr | Term (BoolVar var, int64_t coefficient) |
Constructs bool * coefficient. | |
static LinearExpr | FromProto (const LinearExpressionProto &proto) |
Constructs a linear expr from its proto representation. | |
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 246 of file cp_model.h.
|
default |
Creates an empty linear expression with value zero.
operations_research::sat::LinearExpr::LinearExpr | ( | BoolVar | var | ) |
NOLINTBEGIN(google-explicit-constructor)
Constructs a linear expression from a Boolean variable. It deals with logical negation correctly.
We add 1 - var instead.
Definition at line 176 of file cp_model.cc.
operations_research::sat::LinearExpr::LinearExpr | ( | IntVar | var | ) |
Constructs a linear expression from an integer variable.
Definition at line 190 of file cp_model.cc.
operations_research::sat::LinearExpr::LinearExpr | ( | int64_t | constant | ) |
Constructs a constant linear expression.
Definition at line 196 of file cp_model.cc.
|
inline |
Returns the vector of coefficients.
Definition at line 297 of file cp_model.h.
|
inline |
Returns the constant term.
Definition at line 303 of file cp_model.h.
std::string operations_research::sat::LinearExpr::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 280 of file cp_model.cc.
|
static |
Constructs a linear expr from its proto representation.
Definition at line 198 of file cp_model.cc.
|
inline |
Returns true if the expression has no variables.
Definition at line 300 of file cp_model.h.
LinearExpr & operations_research::sat::LinearExpr::operator*= | ( | int64_t | factor | ) |
Definition at line 274 of file cp_model.cc.
LinearExpr & operations_research::sat::LinearExpr::operator+= | ( | const LinearExpr & | other | ) |
Operators.
Definition at line 255 of file cp_model.cc.
LinearExpr & operations_research::sat::LinearExpr::operator-= | ( | const LinearExpr & | other | ) |
Definition at line 264 of file cp_model.cc.
|
static |
Constructs the sum of a list of Boolean variables.
Definition at line 215 of file cp_model.cc.
|
static |
NOLINTEND(google-explicit-constructor)
Constructs the sum of a list of variables.
Definition at line 207 of file cp_model.cc.
|
static |
Constructs bool * coefficient.
Definition at line 249 of file cp_model.cc.
|
static |
Constructs var * coefficient.
Definition at line 243 of file cp_model.cc.
|
inline |
Returns the vector of variable indices.
Definition at line 294 of file cp_model.h.
|
static |
Constructs the scalar product of Boolean variables and coefficients.
Definition at line 233 of file cp_model.cc.
|
static |
Constructs the scalar product of variables and coefficients.
Definition at line 223 of file cp_model.cc.