16#ifndef OR_TOOLS_MATH_OPT_CONSTRAINTS_INDICATOR_INDICATOR_CONSTRAINT_H_
17#define OR_TOOLS_MATH_OPT_CONSTRAINTS_INDICATOR_INDICATOR_CONSTRAINT_H_
25#include "absl/strings/string_view.h"
40 using IdType = IndicatorConstraintId;
43 IndicatorConstraintId
id);
45 inline int64_t
id()
const;
47 inline IndicatorConstraintId
typed_id()
const;
48 inline const ModelStorage*
storage()
const;
50 inline absl::string_view
name()
const;
75 friend std::ostream&
operator<<(std::ostream& ostr,
79 const ModelStorage* storage_;
80 IndicatorConstraintId id_;
85inline std::ostream&
operator<<(std::ostream& ostr,
99 if (storage_->has_constraint(id_)) {
100 return storage_->constraint_data(id_).name;
106 const std::optional<VariableId> maybe_indicator =
107 storage_->constraint_data(id_).indicator;
108 if (!maybe_indicator.has_value()) {
111 return Variable(storage_, *maybe_indicator);
115 return storage_->constraint_data(id_).activate_on_zero;
124 return lhs.id_ == rhs.id_ && lhs.storage_ == rhs.storage_;
129 return !(lhs == rhs);
134 return H::combine(std::move(h), constraint.id_.value(), constraint.storage_);
140 const absl::string_view
name = constraint.
name();
142 ostr <<
"__indic_con#" << constraint.
id() <<
"__";
150 const IndicatorConstraintId
id)
151 : storage_(storage), id_(id) {}
IndicatorConstraintId IdType
The typed integer used for ids.
absl::string_view name() const
std::vector< Variable > NonzeroVariables() const
friend bool operator==(const IndicatorConstraint &lhs, const IndicatorConstraint &rhs)
IndicatorConstraint(const ModelStorage *storage, IndicatorConstraintId id)
IndicatorConstraintId typed_id() const
std::optional< Variable > indicator_variable() const
const ModelStorage * storage() const
friend H AbslHashValue(H h, const IndicatorConstraint &constraint)
friend bool operator!=(const IndicatorConstraint &lhs, const IndicatorConstraint &rhs)
BoundedLinearExpression ImpliedConstraint() const
std::string ToString() const
bool activate_on_zero() const
The value the indicator variable takes to activate the implied constraint.
friend std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
const std::string name
A name for logging purposes.
An object oriented wrapper for quadratic constraints in ModelStorage.
constexpr absl::string_view kDeletedConstraintDefaultDescription
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
bool operator==(const IndicatorConstraint &lhs, const IndicatorConstraint &rhs)
bool operator!=(const IndicatorConstraint &lhs, const IndicatorConstraint &rhs)
std::vector< Variable > AtomicConstraintNonzeroVariables(const ModelStorage &storage, const IdType id)
H AbslHashValue(H h, const IndicatorConstraint &constraint)
A LinearExpression with upper and lower bounds.