![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
A linear expression with at most two variables (coeffs can be zero). And some utility to canonicalize them.
Definition at line 348 of file integer_base.h.
#include <integer_base.h>
Public Member Functions | |
LinearExpression2 ()=default | |
LinearExpression2 (IntegerVariable v1, IntegerVariable v2, IntegerValue c1, IntegerValue c2) | |
void | Negate () |
Take the negation of this expression. | |
void | SimpleCanonicalization () |
void | CanonicalizeAndUpdateBounds (IntegerValue &lb, IntegerValue &ub, bool allow_negation=false) |
IntegerValue | DivideByGcd () |
bool | NegateForCanonicalization () |
absl::Span< const IntegerVariable > | non_zero_vars () const |
absl::Span< const IntegerValue > | non_zero_coeffs () const |
bool | operator== (const LinearExpression2 &o) const |
bool | operator< (const LinearExpression2 &o) const |
Static Public Member Functions | |
static LinearExpression2 | Difference (IntegerVariable v1, IntegerVariable v2) |
Build (v1 - v2) |
Public Attributes | |
IntegerValue | coeffs [2] |
IntegerVariable | vars [2] |
|
default |
|
inline |
Definition at line 350 of file integer_base.h.
void operations_research::sat::LinearExpression2::CanonicalizeAndUpdateBounds | ( | IntegerValue & | lb, |
IntegerValue & | ub, | ||
bool | allow_negation = false ) |
Fully canonicalizes the expression and updates the given bounds accordingly. This is the same as SimpleCanonicalization(), DivideByGcd() and the NegateForCanonicalization() with a proper updates of the bounds.
We need to be able to negate without overflow.
Do gcd division.
Definition at line 82 of file integer_base.cc.
|
inlinestatic |
Build (v1 - v2)
Definition at line 359 of file integer_base.h.
IntegerValue operations_research::sat::LinearExpression2::DivideByGcd | ( | ) |
Divides the expression by the gcd of both coefficients, and returns it.
Definition at line 59 of file integer_base.cc.
|
inline |
Take the negation of this expression.
Definition at line 364 of file integer_base.h.
bool operations_research::sat::LinearExpression2::NegateForCanonicalization | ( | ) |
Makes sure expr and -expr have the same canonical representation by negating the expression of it is in the non-canonical form. Returns true if the expression was negated.
Definition at line 69 of file integer_base.cc.
|
inline |
Definition at line 398 of file integer_base.h.
|
inline |
Definition at line 392 of file integer_base.h.
|
inline |
Definition at line 409 of file integer_base.h.
|
inline |
Definition at line 404 of file integer_base.h.
void operations_research::sat::LinearExpression2::SimpleCanonicalization | ( | ) |
This will not change any bounds on the LinearExpression2. That is we will not potentially Negate() the expression like CanonicalizeAndUpdateBounds() might do.
Corner case when the underlying variable is the same.
Make sure variable are positive before merging.
Make sure coeff are positive.
Make sure variable are sorted.
Definition at line 24 of file integer_base.cc.
IntegerValue operations_research::sat::LinearExpression2::coeffs[2] |
Definition at line 414 of file integer_base.h.
IntegerVariable operations_research::sat::LinearExpression2::vars[2] |
Definition at line 415 of file integer_base.h.