18#include "absl/status/status.h"
19#include "absl/strings/str_format.h"
25constexpr double kInf = std::numeric_limits<double>::infinity();
30 return absl::InvalidArgumentError(
31 absl::StrFormat(
"Indicator constraint %s is associated with wrong "
32 "model (expected: %s, actual: %s)",
33 indicator_constraint.
name(),
model.name(),
34 indicator_constraint.
storage()->name()));
37 model.DeleteIndicatorConstraint(indicator_constraint);
38 return absl::OkStatus();
45 return absl::InvalidArgumentError(absl::StrFormat(
46 "In indicator constraint %s: indicator variable %s is "
47 "not a binary variable",
48 indicator_constraint.
name(), indicator_variable.
name()));
58 if (expr_lower_bound == -
kInf) {
59 return absl::InvalidArgumentError(
60 absl::StrFormat(
"In indicator constraint %s: cannot prove that "
61 "implied constraint is unbounded from below",
62 indicator_constraint.
name()));
64 model.AddLinearConstraint(
66 expr_lower_bound + (implied_constraint.
lower_bound - expr_lower_bound) *
71 if (expr_upper_bound ==
kInf) {
72 return absl::InvalidArgumentError(
73 absl::StrFormat(
"In indicator constraint %s: cannot prove that "
74 "implied constraint is unbounded from above",
75 indicator_constraint.
name()));
77 model.AddLinearConstraint(
79 expr_upper_bound + (implied_constraint.
upper_bound - expr_upper_bound) *
82 model.DeleteIndicatorConstraint(indicator_constraint);
83 return absl::OkStatus();
absl::string_view name() const
std::optional< Variable > indicator_variable() const
const ModelStorage * storage() const
BoundedLinearExpression ImpliedConstraint() const
bool activate_on_zero() const
The value the indicator variable takes to activate the implied constraint.
double lower_bound() const
double upper_bound() const
absl::string_view name() const
An object oriented wrapper for quadratic constraints in ModelStorage.
double LowerBound(const LinearExpression &linear_expression)
absl::Status FormulateIndicatorConstraintAsMip(Model &model, const IndicatorConstraint indicator_constraint)
double UpperBound(const LinearExpression &linear_expression)
A LinearExpression with upper and lower bounds.
LinearExpression expression