# 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.

TODO(user): Rename to LinearExpressionBuilder?

Method | |
---|---|

`AddConstant` | Return type: Arguments: Adds the corresponding term to the current linear expression. |

`AddDecomposedProduct` | Return type: Arguments: 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(). |

`AddLinearExpression` | Return type: Arguments: |

`AddLinearExpression` | Return type: Arguments: |

`AddLiteralTerm` | Return type: Arguments: Add literal * coeff to the constaint. Returns false and do nothing if the given literal didn't have an integer view. |

`AddQuadraticLowerBound` | Return type: Arguments: 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. |

`AddTerm` | Return type: Arguments: |

`AddTerm` | Return type: Arguments: |

`Build` | Return type: 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. |

`BuildConstraint` | Return type: Arguments: |

`BuildExpression` | Return type: Returns the linear expression part of the constraint only, without the bounds. |

`Clear` | Return type: Clears all added terms and constants. Keeps the original bounds. |

`LinearConstraintBuilder` | Return type: Arguments: 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. |

`LinearConstraintBuilder` | Arguments: |

`LinearConstraintBuilder` | 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. |