C++ Reference
C++ Reference: CP-SAT
Detailed Description
A dedicated container for linear expressions with double coefficients.
This is currently only usable to define a floating point objective.
Usage:
This can be used in the objective definition.
Definition at line 345 of file cp_model.h.
Public Member Functions | |
| DoubleLinearExpr () | |
| DoubleLinearExpr (BoolVar var) | |
| Constructs a linear expression from a Boolean variable. More... | |
| DoubleLinearExpr (IntVar var) | |
| Constructs a linear expression from an integer variable. More... | |
| DoubleLinearExpr (double constant) | |
| Constructs a constant linear expression. More... | |
| DoubleLinearExpr & | operator+= (double value) |
| Adds a constant value to the linear expression. More... | |
| DoubleLinearExpr & | operator+= (IntVar var) |
| Adds a single integer variable to the linear expression. More... | |
| DoubleLinearExpr & | operator+= (BoolVar var) |
| DoubleLinearExpr & | operator+= (const DoubleLinearExpr &expr) |
| Adds another linear expression to the linear expression. More... | |
| DoubleLinearExpr & | AddTerm (IntVar var, double coeff) |
| Adds a term (var * coeff) to the linear expression. More... | |
| DoubleLinearExpr & | AddTerm (BoolVar var, double coeff) |
| DoubleLinearExpr & | AddExpression (const LinearExpr &exprs, double coeff=1.0) |
| Adds a linear expression to the double linear expression. More... | |
| DoubleLinearExpr & | operator-= (double value) |
| Adds a constant value to the linear expression. More... | |
| DoubleLinearExpr & | operator-= (IntVar var) |
| Adds a single integer variable to the linear expression. More... | |
| DoubleLinearExpr & | operator-= (const DoubleLinearExpr &expr) |
| Adds another linear expression to the linear expression. More... | |
| DoubleLinearExpr & | operator*= (double coeff) |
| Multiply the linear expression by a constant. More... | |
| const std::vector< int > & | variables () const |
| Returns the vector of variable indices. More... | |
| const std::vector< double > & | coefficients () const |
| Returns the vector of coefficients. More... | |
| const bool | IsConstant () const |
| double | constant () const |
| Returns the constant term. More... | |
| std::string | DebugString (const CpModelProto *proto=nullptr) const |
| Debug string. See the documentation for LinearExpr::DebugString(). More... | |
Static Public Member Functions | |
| static DoubleLinearExpr | Sum (absl::Span< const IntVar > vars) |
| Constructs the sum of a list of variables. More... | |
| static DoubleLinearExpr | Sum (absl::Span< const BoolVar > vars) |
| Constructs the sum of a list of Boolean variables. More... | |
| static DoubleLinearExpr | WeightedSum (absl::Span< const IntVar > vars, absl::Span< const double > coeffs) |
| Constructs the scalar product of variables and coefficients. More... | |
| static DoubleLinearExpr | WeightedSum (absl::Span< const BoolVar > vars, absl::Span< const double > coeffs) |
| Constructs the scalar product of Boolean variables and coefficients. More... | |
Constructor & Destructor Documentation
◆ DoubleLinearExpr() [1/4]
| DoubleLinearExpr | ( | ) |
◆ DoubleLinearExpr() [2/4]
|
explicit |
Constructs a linear expression from a Boolean variable.
It deals with logical negation correctly.
◆ DoubleLinearExpr() [3/4]
|
explicit |
Constructs a linear expression from an integer variable.
◆ DoubleLinearExpr() [4/4]
|
explicit |
Constructs a constant linear expression.
Member Function Documentation
◆ AddExpression()
| DoubleLinearExpr& AddExpression | ( | const LinearExpr & | exprs, |
| double | coeff = 1.0 |
||
| ) |
Adds a linear expression to the double linear expression.
◆ AddTerm() [1/2]
| DoubleLinearExpr& AddTerm | ( | BoolVar | var, |
| double | coeff | ||
| ) |
◆ AddTerm() [2/2]
| DoubleLinearExpr& AddTerm | ( | IntVar | var, |
| double | coeff | ||
| ) |
Adds a term (var * coeff) to the linear expression.
◆ coefficients()
|
inline |
Returns the vector of coefficients.
Definition at line 406 of file cp_model.h.
◆ constant()
|
inline |
Returns the constant term.
Definition at line 412 of file cp_model.h.
◆ DebugString()
| std::string DebugString | ( | const CpModelProto * | proto = nullptr | ) | const |
Debug string. See the documentation for LinearExpr::DebugString().
◆ IsConstant()
|
inline |
Definition at line 409 of file cp_model.h.
◆ operator*=()
| DoubleLinearExpr& operator*= | ( | double | coeff | ) |
Multiply the linear expression by a constant.
◆ operator+=() [1/4]
| DoubleLinearExpr& operator+= | ( | BoolVar | var | ) |
◆ operator+=() [2/4]
| DoubleLinearExpr& operator+= | ( | const DoubleLinearExpr & | expr | ) |
Adds another linear expression to the linear expression.
◆ operator+=() [3/4]
| DoubleLinearExpr& operator+= | ( | double | value | ) |
Adds a constant value to the linear expression.
◆ operator+=() [4/4]
| DoubleLinearExpr& operator+= | ( | IntVar | var | ) |
Adds a single integer variable to the linear expression.
◆ operator-=() [1/3]
| DoubleLinearExpr& operator-= | ( | const DoubleLinearExpr & | expr | ) |
Adds another linear expression to the linear expression.
◆ operator-=() [2/3]
| DoubleLinearExpr& operator-= | ( | double | value | ) |
Adds a constant value to the linear expression.
◆ operator-=() [3/3]
| DoubleLinearExpr& operator-= | ( | IntVar | var | ) |
Adds a single integer variable to the linear expression.
◆ 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.
◆ variables()
|
inline |
Returns the vector of variable indices.
Definition at line 403 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: