19#include "absl/algorithm/container.h"
25double ComputeBound(
const LinearExpression& linear_expression,
26 bool is_upper_bound) {
33 std::vector<double> terms_to_add;
34 terms_to_add.reserve(linear_expression.terms().size() + 1);
35 terms_to_add.push_back(linear_expression.offset());
36 for (
const auto [
var,
coef] : linear_expression.terms()) {
38 (is_upper_bound &&
coef > 0) || (!is_upper_bound &&
coef < 0);
41 terms_to_add.push_back(val);
44 absl::c_sort(terms_to_add, [](
const double left,
const double right) {
45 return std::pair(std::abs(left), left) < std::pair(std::abs(right), right);
47 return absl::c_accumulate(terms_to_add, 0.0);
53 return ComputeBound(linear_expression,
false);
57 return ComputeBound(linear_expression,
true);
An object oriented wrapper for quadratic constraints in ModelStorage.
double LowerBound(const LinearExpression &linear_expression)
double UpperBound(const LinearExpression &linear_expression)