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

#include <objective.h>

Public Types

using IdType = AuxiliaryObjectiveId
 The type used for ids.
 

Public Member Functions

std::optional< int64_t > id () const
 
ObjectiveId typed_id () const
 
const ModelStorage * storage () const
 Returns a const-pointer to the underlying storage object for the model.
 
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
 

Static Public Member Functions

static Objective Primary (const ModelStorage *storage)
 Returns an object that refers to the primary objective of the model.
 
static Objective Auxiliary (const ModelStorage *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)
 

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 ( const ModelStorage * storage,
AuxiliaryObjectiveId id )
inlinestatic

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

Definition at line 224 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 177 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 171 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 135 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 194 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 187 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 146 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 152 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 154 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 167 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 163 of file objective.h.

◆ offset()

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

Returns the constant offset of the objective.

Definition at line 161 of file objective.h.

◆ Primary()

Objective operations_research::math_opt::Objective::Primary ( const ModelStorage * storage)
inlinestatic

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

Definition at line 220 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 148 of file objective.h.

◆ storage()

const ModelStorage * operations_research::math_opt::Objective::storage ( ) const
inline

Returns a const-pointer to the underlying storage object for the model.

Definition at line 144 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 142 of file objective.h.

Friends And Related Symbol Documentation

◆ AbslHashValue

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

Definition at line 213 of file objective.h.

◆ operator!=

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

Definition at line 208 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 204 of file objective.h.


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