Stay organized with collections
Save and categorize content based on your preferences.
C++ Reference: class LinearConstraintBuilder
Note: This documentation is automatically generated.
Allow to build a LinearConstraint while making sure there is no duplicate
variables. Note that we do not simplify literal/variable that are currently
fixed here.
All the functions manipulate a linear expression with an offset. The final
constraint bounds will include this offset.
Add the corresponding decomposed products (obtained from
TryToDecomposeProduct). The code assumes all literals to be in an
exactly_one relation.
It returns false if one literal does not have an integer view, as it
actually calls AddLiteralTerm().
Add an under linearization of the product of two affine expressions.
If at least one of them is fixed, then we add the exact product (which is
linear). Otherwise, we use McCormick relaxation:
left * right = (left_min + delta_left) * (right_min + delta_right) =
left_min * right_min + delta_left * right_min +
delta_right * left_min + delta_left * delta_right
which is >= (by ignoring the quatratic term)
right_min * left + left_min * right - right_min * left_min
TODO(user): We could use (max - delta) instead of (min + delta) for each
expression instead. This would depend on the LP value of the left and
right.
Builds and returns the corresponding constraint in a canonical form.
All the IntegerVariable will be positive and appear in increasing index
order.
The bounds can be changed here or taken at construction.
TODO(user): this doesn't invalidate the builder object, but if one wants
to do a lot of dynamic editing to the constraint, then then underlying
algorithm needs to be optimized for that.
We support "sticky" kMinIntegerValue for lb and kMaxIntegerValue for ub
for one-sided constraints.
Assumes that the 'model' has IntegerEncoder. The bounds can either be
specified at construction or during the Build() call.
Warning: this version without encoder cannot be used to add literals, so
one shouldn't call AddLiteralTerm() on it. All other functions works.
TODO(user): Have a subclass so we can enforce than caller using
AddLiteralTerm() must construct the Builder with an encoder.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-06 UTC."],[[["\u003cp\u003e\u003ccode\u003eLinearConstraintBuilder\u003c/code\u003e aids in constructing \u003ccode\u003eLinearConstraint\u003c/code\u003e objects in the CP-SAT solver, ensuring no duplicate variables are included.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for adding terms, constants, and linear expressions to the constraint, manipulating it with an offset that is included in the final bounds.\u003c/p\u003e\n"],["\u003cp\u003eThe builder can be initialized with specific lower and upper bounds for the constraint or have them set during the \u003ccode\u003eBuild()\u003c/code\u003e phase.\u003c/p\u003e\n"],["\u003cp\u003eWhile avoiding simplification of fixed literals/variables, the builder ultimately generates the constraint in a canonical form with positive \u003ccode\u003eIntegerVariable\u003c/code\u003es in ascending order.\u003c/p\u003e\n"],["\u003cp\u003eIt's worth noting that a potential future enhancement involves renaming the class to \u003ccode\u003eLinearExpressionBuilder\u003c/code\u003e for improved clarity.\u003c/p\u003e\n"]]],["The `LinearConstraintBuilder` class constructs linear constraints, preventing duplicate variables. It manages a linear expression with an offset, which is included in the final constraint bounds. Key actions include `AddConstant`, `AddTerm`, `AddLinearExpression`, `AddLiteralTerm`, and `AddDecomposedProduct` for building the expression. `AddQuadraticLowerBound` linearizes products of affine expressions. The `Build` and `BuildConstraint` methods finalize and return the constraint. `BuildExpression` returns only the linear expression part. `Clear` resets added terms and constants.\n"],null,[]]