Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::sat::LinearExpression2 Struct Reference

Detailed Description

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]

Constructor & Destructor Documentation

◆ LinearExpression2() [1/2]

operations_research::sat::LinearExpression2::LinearExpression2 ( )
default

◆ LinearExpression2() [2/2]

operations_research::sat::LinearExpression2::LinearExpression2 ( IntegerVariable v1,
IntegerVariable v2,
IntegerValue c1,
IntegerValue c2 )
inline

Definition at line 350 of file integer_base.h.

Member Function Documentation

◆ CanonicalizeAndUpdateBounds()

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.

◆ Difference()

LinearExpression2 operations_research::sat::LinearExpression2::Difference ( IntegerVariable v1,
IntegerVariable v2 )
inlinestatic

Build (v1 - v2)

Definition at line 359 of file integer_base.h.

◆ DivideByGcd()

IntegerValue operations_research::sat::LinearExpression2::DivideByGcd ( )

Divides the expression by the gcd of both coefficients, and returns it.

Note
we always return something >= 1 even if both coefficients are zero.

Definition at line 59 of file integer_base.cc.

◆ Negate()

void operations_research::sat::LinearExpression2::Negate ( )
inline

Take the negation of this expression.

Definition at line 364 of file integer_base.h.

◆ NegateForCanonicalization()

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.

◆ non_zero_coeffs()

absl::Span< const IntegerValue > operations_research::sat::LinearExpression2::non_zero_coeffs ( ) const
inline

Definition at line 398 of file integer_base.h.

◆ non_zero_vars()

absl::Span< const IntegerVariable > operations_research::sat::LinearExpression2::non_zero_vars ( ) const
inline

Definition at line 392 of file integer_base.h.

◆ operator<()

bool operations_research::sat::LinearExpression2::operator< ( const LinearExpression2 & o) const
inline

Definition at line 409 of file integer_base.h.

◆ operator==()

bool operations_research::sat::LinearExpression2::operator== ( const LinearExpression2 & o) const
inline

Definition at line 404 of file integer_base.h.

◆ SimpleCanonicalization()

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.

Note
since kNoIntegerVariable=-1 and we sort the variables, if we any one zero and one non-zero we will always have the zero first.

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.

Member Data Documentation

◆ coeffs

IntegerValue operations_research::sat::LinearExpression2::coeffs[2]

Definition at line 414 of file integer_base.h.

◆ vars

IntegerVariable operations_research::sat::LinearExpression2::vars[2]

Definition at line 415 of file integer_base.h.


The documentation for this struct was generated from the following files: