18#ifndef OR_TOOLS_MATH_OPT_CPP_OBJECTIVE_H_
19#define OR_TOOLS_MATH_OPT_CPP_OBJECTIVE_H_
26#include "absl/log/check.h"
27#include "absl/strings/string_view.h"
37 "[objective deleted from model]";
56 inline std::optional<int64_t>
id()
const;
72 inline absl::string_view
name()
const;
75 inline double offset()
const;
106 friend inline bool operator==(
const Objective& lhs,
const Objective& rhs);
107 friend inline bool operator!=(
const Objective& lhs,
const Objective& rhs);
108 template <
typename H>
110 friend std::ostream&
operator<<(std::ostream& ostr,
111 const Objective& objective);
142 return storage()->objective_priority(id_);
157 return storage()->num_quadratic_objective_terms(id_);
161 return storage()->num_linear_objective_terms(id_);
167 return storage()->linear_objective_coefficient(id_, variable.typed_id());
171 const Variable second_variable)
const {
176 return storage()->quadratic_objective_coefficient(
183 return storage()->is_linear_objective_coefficient_nonzero(
184 id_, variable.typed_id());
188 const Variable second_variable)
const {
193 return storage()->is_quadratic_objective_coefficient_nonzero(
202 return !(lhs == rhs);
207 return H::combine(std::move(h), objective.id_, objective.
storage());
ModelStorageCPtr storage() const
ModelStorageItem(ModelStorageCPtr storage)
std::string ToString() const
QuadraticExpression AsQuadraticExpression() const
Returns a representation of the objective as a QuadraticExpression.
std::optional< int64_t > id() const
friend bool operator==(const Objective &lhs, const Objective &rhs)
bool is_coefficient_nonzero(Variable variable) const
Returns true if the variable has a nonzero linear coefficient in the model.
friend std::ostream & operator<<(std::ostream &ostr, const Objective &objective)
AuxiliaryObjectiveId IdType
The type used for ids.
double coefficient(Variable variable) const
Returns the linear coefficient for the variable in the model.
ObjectiveId typed_id() const
bool maximize() const
Returns true if the objective is the maximization sense.
LinearExpression AsLinearExpression() const
int64_t num_linear_terms() const
Returns the number of linear terms in the objective.
static Objective Primary(ModelStorageCPtr storage)
Returns an object that refers to the primary objective of the model.
int64_t priority() const
Returns the priority (lower is more important) of the objective.
friend H AbslHashValue(H h, const Objective &objective)
absl::string_view name() const
Returns the name of the objective.
friend bool operator!=(const Objective &lhs, const Objective &rhs)
int64_t num_quadratic_terms() const
Returns the number of quadratic terms in the objective.
double offset() const
Returns the constant offset of the objective.
static Objective Auxiliary(ModelStorageCPtr storage, AuxiliaryObjectiveId id)
Returns an object that refers to an auxiliary objective of the model.
constexpr absl::string_view kObjectsFromOtherModelStorage
An object oriented wrapper for quadratic constraints in ModelStorage.
absl::Nonnull< const ModelStorage * > ModelStorageCPtr
ElementId< ElementType::kAuxiliaryObjective > AuxiliaryObjectiveId
constexpr ObjectiveId kPrimaryObjectiveId
bool operator==(const SecondOrderConeConstraint &lhs, const SecondOrderConeConstraint &rhs)
bool operator!=(const SecondOrderConeConstraint &lhs, const SecondOrderConeConstraint &rhs)
absl::flat_hash_map< Objective, V > ObjectiveMap
std::ostream & operator<<(std::ostream &ostr, const SecondOrderConeConstraint &constraint)
H AbslHashValue(H h, const SecondOrderConeConstraint &constraint)
constexpr absl::string_view kDeletedObjectiveDefaultDescription
std::optional< AuxiliaryObjectiveId > ObjectiveId
nullopt denotes the primary objective.