18#ifndef OR_TOOLS_MATH_OPT_CPP_LINEAR_CONSTRAINT_H_
19#define OR_TOOLS_MATH_OPT_CPP_LINEAR_CONSTRAINT_H_
27#include "absl/log/check.h"
28#include "absl/strings/string_view.h"
50 inline int64_t
id()
const;
52 inline LinearConstraintId
typed_id()
const;
53 inline const ModelStorage*
storage()
const;
57 inline absl::string_view
name()
const;
86 friend std::ostream&
operator<<(std::ostream& ostr,
90 const ModelStorage* storage_;
91 LinearConstraintId id_;
99inline std::ostream&
operator<<(std::ostream& ostr,
113 return storage_->linear_constraint_lower_bound(id_);
117 return storage_->linear_constraint_upper_bound(id_);
121 if (
storage()->has_linear_constraint(id_)) {
122 return storage_->linear_constraint_name(id_);
128 CHECK_EQ(variable.storage(), storage_)
130 return storage_->is_linear_constraint_coefficient_nonzero(
131 id_, variable.typed_id());
135 CHECK_EQ(variable.
storage(), storage_)
137 return storage_->linear_constraint_coefficient(id_, variable.typed_id());
142 for (
const VariableId
var :
153 if (!
storage()->has_linear_constraint(id_)) {
156 std::stringstream str;
161bool operator==(
const LinearConstraint& lhs,
const LinearConstraint& rhs) {
162 return lhs.id_ == rhs.id_ && lhs.storage_ == rhs.storage_;
166 return !(lhs == rhs);
171 return H::combine(std::move(h), linear_constraint.id_.value(),
172 linear_constraint.storage_);
178 const absl::string_view
name = linear_constraint.
name();
180 ostr <<
"__lin_con#" << linear_constraint.
id() <<
"__";
188 const LinearConstraintId
id)
189 : storage_(storage), id_(id) {}
double upper_bound() const
absl::string_view name() const
LinearConstraintId IdType
The typed integer used for ids.
friend bool operator!=(const LinearConstraint &lhs, const LinearConstraint &rhs)
BoundedLinearExpression AsBoundedLinearExpression() const
LinearConstraint(const ModelStorage *storage, LinearConstraintId id)
bool is_coefficient_nonzero(Variable variable) const
friend bool operator==(const LinearConstraint &lhs, const LinearConstraint &rhs)
const ModelStorage * storage() const
LinearConstraintId typed_id() const
std::string ToString() const
double lower_bound() const
friend H AbslHashValue(H h, const LinearConstraint &linear_constraint)
double coefficient(Variable variable) const
Returns 0.0 if the variable is not used in the constraint.
friend std::ostream & operator<<(std::ostream &ostr, const LinearConstraint &linear_constraint)
const ModelStorage * storage() const
const std::string name
A name for logging purposes.
constexpr absl::string_view kObjectsFromOtherModelStorage
absl::flat_hash_map< LinearConstraint, V > LinearConstraintMap
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)
H AbslHashValue(H h, const IndicatorConstraint &constraint)
In SWIG mode, we don't want anything besides these top-level includes.
A LinearExpression with upper and lower bounds.