18#ifndef OR_TOOLS_MATH_OPT_CONSTRAINTS_QUADRATIC_QUADRATIC_CONSTRAINT_H_
19#define OR_TOOLS_MATH_OPT_CONSTRAINTS_QUADRATIC_QUADRATIC_CONSTRAINT_H_
27#include "absl/log/check.h"
28#include "absl/strings/string_view.h"
46 using IdType = QuadraticConstraintId;
49 QuadraticConstraintId
id);
51 inline int64_t
id()
const;
53 inline QuadraticConstraintId
typed_id()
const;
54 inline const ModelStorage*
storage()
const;
58 inline absl::string_view
name()
const;
103 const ModelStorage* storage_;
104 QuadraticConstraintId id_;
109inline std::ostream&
operator<<(std::ostream& ostr,
123 return storage_->constraint_data(id_).lower_bound;
127 return storage_->constraint_data(id_).upper_bound;
131 if (storage_->has_constraint(id_)) {
132 return storage_->constraint_data(id_).name;
138 const Variable variable)
const {
148 CHECK_EQ(variable.
storage(), storage_)
150 return storage_->constraint_data(id_).linear_terms.get(variable.typed_id());
157 CHECK_EQ(second_variable.
storage(), storage_)
159 return storage_->constraint_data(id_).quadratic_terms.get(
168 if (!
storage()->has_constraint(id_)) {
171 std::stringstream str;
176bool operator==(
const QuadraticConstraint& lhs,
177 const QuadraticConstraint& rhs) {
178 return lhs.id_ == rhs.id_ && lhs.storage_ == rhs.storage_;
183 return !(lhs == rhs);
188 return H::combine(std::move(h), quadratic_constraint.id_.value(),
189 quadratic_constraint.storage_);
195 const absl::string_view
name = constraint.
name();
197 ostr <<
"__quad_con#" << constraint.
id() <<
"__";
205 const QuadraticConstraintId
id)
206 : storage_(storage), id_(id) {}
bool is_quadratic_coefficient_nonzero(Variable first_variable, Variable second_variable) const
friend std::ostream & operator<<(std::ostream &ostr, const QuadraticConstraint &quadratic_constraint)
friend H AbslHashValue(H h, const QuadraticConstraint &quadratic_constraint)
QuadraticConstraintId typed_id() const
QuadraticConstraint(const ModelStorage *storage, QuadraticConstraintId id)
absl::string_view name() const
friend bool operator!=(const QuadraticConstraint &lhs, const QuadraticConstraint &rhs)
double quadratic_coefficient(Variable first_variable, Variable second_variable) const
QuadraticConstraintId IdType
The typed integer used for ids.
friend bool operator==(const QuadraticConstraint &lhs, const QuadraticConstraint &rhs)
double upper_bound() const
double linear_coefficient(Variable variable) const
std::string ToString() const
double lower_bound() const
std::vector< Variable > NonzeroVariables() const
const ModelStorage * storage() const
bool is_linear_coefficient_nonzero(Variable variable) const
BoundedQuadraticExpression AsBoundedQuadraticExpression() const
VariableId typed_id() const
const ModelStorage * storage() const
const std::string name
A name for logging purposes.
constexpr absl::string_view kObjectsFromOtherModelStorage
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 QuadraticExpression with upper and lower bounds.