Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::Objective Class Referencefinal

#include <objective.h>

Inheritance diagram for operations_research::math_opt::Objective:
operations_research::math_opt::ModelStorageItem

Public Types

using IdType = AuxiliaryObjectiveId
 The type used for ids.

Public Member Functions

std::optional< int64_t > id () const
ObjectiveId typed_id () const
bool is_primary () const
bool maximize () const
 Returns true if the objective is the maximization sense.
int64_t priority () const
 Returns the priority (lower is more important) of the objective.
absl::string_view name () const
 Returns the name of the objective.
double offset () const
 Returns the constant offset of the objective.
int64_t num_linear_terms () const
 Returns the number of linear terms in the objective.
int64_t num_quadratic_terms () const
 Returns the number of quadratic terms in the objective.
double coefficient (Variable variable) const
 Returns the linear coefficient for the variable in the model.
double coefficient (Variable first_variable, Variable second_variable) const
 Returns the quadratic coefficient for the pair of variables in the model.
bool is_coefficient_nonzero (Variable variable) const
 Returns true if the variable has a nonzero linear coefficient in the model.
bool is_coefficient_nonzero (Variable first_variable, Variable second_variable) const
LinearExpression AsLinearExpression () const
QuadraticExpression AsQuadraticExpression () const
 Returns a representation of the objective as a QuadraticExpression.
std::string ToString () const
Public Member Functions inherited from operations_research::math_opt::ModelStorageItem
ModelStorageCPtr storage () const

Static Public Member Functions

static Objective Primary (ModelStorageCPtr storage)
 Returns an object that refers to the primary objective of the model.
static Objective Auxiliary (ModelStorageCPtr storage, AuxiliaryObjectiveId id)
 Returns an object that refers to an auxiliary objective of the model.

Friends

bool operator== (const Objective &lhs, const Objective &rhs)
bool operator!= (const Objective &lhs, const Objective &rhs)
template<typename H>
AbslHashValue (H h, const Objective &objective)
std::ostream & operator<< (std::ostream &ostr, const Objective &objective)

Additional Inherited Members

Protected Member Functions inherited from operations_research::math_opt::ModelStorageItem
 ModelStorageItem (ModelStorageCPtr storage)
 ModelStorageItem (const ModelStorageItem &)=default
ModelStorageItemoperator= (const ModelStorageItem &)=default
 ModelStorageItem (ModelStorageItem &&)=default
ModelStorageItemoperator= (ModelStorageItem &&)=default
 ~ModelStorageItem ()=default

Detailed Description

A value type that references an objective (either primary or auxiliary) from ModelStorage. Usually this type is passed by copy.

This type implements https://abseil.io/docs/cpp/guides/hash.

Definition at line 43 of file objective.h.

Member Typedef Documentation

◆ IdType

The type used for ids.

Definition at line 46 of file objective.h.

Member Function Documentation

◆ AsLinearExpression()

LinearExpression operations_research::math_opt::Objective::AsLinearExpression ( ) const

Returns a representation of the objective as a LinearExpression.

Note
This will CHECK fail if the objective has quadratic terms.

Definition at line 29 of file objective.cc.

◆ AsQuadraticExpression()

QuadraticExpression operations_research::math_opt::Objective::AsQuadraticExpression ( ) const

Returns a representation of the objective as a QuadraticExpression.

Definition at line 40 of file objective.cc.

◆ Auxiliary()

Objective operations_research::math_opt::Objective::Auxiliary ( ModelStorageCPtr storage,
AuxiliaryObjectiveId id )
inlinestatic

Returns an object that refers to an auxiliary objective of the model.

Definition at line 219 of file objective.h.

◆ coefficient() [1/2]

double operations_research::math_opt::Objective::coefficient ( Variable first_variable,
Variable second_variable ) const
inline

Returns the quadratic coefficient for the pair of variables in the model.

Definition at line 172 of file objective.h.

◆ coefficient() [2/2]

double operations_research::math_opt::Objective::coefficient ( Variable variable) const
inline

Returns the linear coefficient for the variable in the model.

Definition at line 166 of file objective.h.

◆ id()

std::optional< int64_t > operations_research::math_opt::Objective::id ( ) const
inline

Returns the raw integer ID associated with the objective: nullopt for the primary objective, a nonnegative int64_t for an auxiliary objective.

Inline function implementations

Definition at line 132 of file objective.h.

◆ is_coefficient_nonzero() [1/2]

bool operations_research::math_opt::Objective::is_coefficient_nonzero ( Variable first_variable,
Variable second_variable ) const
inline

Returns true if the pair of variables has a nonzero quadratic coefficient in the model.

Definition at line 189 of file objective.h.

◆ is_coefficient_nonzero() [2/2]

bool operations_research::math_opt::Objective::is_coefficient_nonzero ( Variable variable) const
inline

Returns true if the variable has a nonzero linear coefficient in the model.

Definition at line 182 of file objective.h.

◆ is_primary()

bool operations_research::math_opt::Objective::is_primary ( ) const
inline

Returns true if the ID corresponds to the primary objective, and false if it is an auxiliary objective.

Definition at line 141 of file objective.h.

◆ maximize()

bool operations_research::math_opt::Objective::maximize ( ) const
inline

Returns true if the objective is the maximization sense.

Definition at line 147 of file objective.h.

◆ name()

absl::string_view operations_research::math_opt::Objective::name ( ) const
inline

Returns the name of the objective.

Definition at line 149 of file objective.h.

◆ num_linear_terms()

int64_t operations_research::math_opt::Objective::num_linear_terms ( ) const
inline

Returns the number of linear terms in the objective.

Definition at line 162 of file objective.h.

◆ num_quadratic_terms()

int64_t operations_research::math_opt::Objective::num_quadratic_terms ( ) const
inline

Returns the number of quadratic terms in the objective.

Definition at line 158 of file objective.h.

◆ offset()

double operations_research::math_opt::Objective::offset ( ) const
inline

Returns the constant offset of the objective.

Definition at line 156 of file objective.h.

◆ Primary()

Objective operations_research::math_opt::Objective::Primary ( ModelStorageCPtr storage)
inlinestatic

Returns an object that refers to the primary objective of the model.

Definition at line 215 of file objective.h.

◆ priority()

int64_t operations_research::math_opt::Objective::priority ( ) const
inline

Returns the priority (lower is more important) of the objective.

Definition at line 143 of file objective.h.

◆ ToString()

std::string operations_research::math_opt::Objective::ToString ( ) const

Returns a detailed string description of the contents of the objective (not its name, use << for that instead).

Definition at line 52 of file objective.cc.

◆ typed_id()

ObjectiveId operations_research::math_opt::Objective::typed_id ( ) const
inline

Returns the strong int ID associated with the objective: nullopt for the primary objective, an AuxiliaryObjectiveId for an auxiliary objective.

Definition at line 139 of file objective.h.

◆ AbslHashValue

template<typename H>
H AbslHashValue ( H h,
const Objective & objective )
friend

Definition at line 208 of file objective.h.

◆ operator!=

bool operator!= ( const Objective & lhs,
const Objective & rhs )
friend

Definition at line 203 of file objective.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & ostr,
const Objective & objective )
friend

Streams the name of the objective, as registered upon objective creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 61 of file objective.cc.

◆ operator==

bool operator== ( const Objective & lhs,
const Objective & rhs )
friend

Definition at line 199 of file objective.h.


The documentation for this class was generated from the following files: