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

A class to express a linear objective. More...

#include <linear_solver.h>

Public Member Functions

 MPObjective (const MPObjective &)=delete
 This type is neither copyable nor movable.
 
MPObjectiveoperator= (const MPObjective &)=delete
 
void Clear ()
 
void SetCoefficient (const MPVariable *var, double coeff)
 
double GetCoefficient (const MPVariable *var) const
 --— MPObjective --—
 
const absl::flat_hash_map< const MPVariable *, double > & terms () const
 
void SetOffset (double value)
 Sets the constant term in the objective.
 
double offset () const
 Gets the constant term in the objective.
 
void OptimizeLinearExpr (const LinearExpr &linear_expr, bool is_maximization)
 
void MaximizeLinearExpr (const LinearExpr &linear_expr)
 Resets the current objective to maximize linear_expr.
 
void MinimizeLinearExpr (const LinearExpr &linear_expr)
 Resets the current objective to minimize linear_expr.
 
void AddLinearExpr (const LinearExpr &linear_expr)
 Adds linear_expr to the current objective, does not change the direction.
 
void SetOptimizationDirection (bool maximize)
 Sets the optimization direction (maximize: true or minimize: false).
 
void SetMinimization ()
 Sets the optimization direction to minimize.
 
void SetMaximization ()
 Sets the optimization direction to maximize.
 
bool maximization () const
 Is the optimization direction set to maximize?
 
bool minimization () const
 Is the optimization direction set to minimize?
 
double Value () const
 
double BestBound () const
 

Friends

class MPSolver
 
class MPSolverInterface
 
class CBCInterface
 
class CLPInterface
 
class GLPKInterface
 
class SCIPInterface
 
class SLMInterface
 
class GurobiInterface
 
class CplexInterface
 
class XpressInterface
 
class GLOPInterface
 
class BopInterface
 
class SatInterface
 
class PdlpInterface
 
class HighsInterface
 
class KnapsackInterface
 

Detailed Description

A class to express a linear objective.

Definition at line 1019 of file linear_solver.h.

Constructor & Destructor Documentation

◆ MPObjective()

operations_research::MPObjective::MPObjective ( const MPObjective & )
delete

This type is neither copyable nor movable.

Member Function Documentation

◆ AddLinearExpr()

void operations_research::MPObjective::AddLinearExpr ( const LinearExpr & linear_expr)

Adds linear_expr to the current objective, does not change the direction.

Definition at line 242 of file linear_solver.cc.

◆ BestBound()

double operations_research::MPObjective::BestBound ( ) const

Returns the best objective bound.

In case of minimization, it is a lower bound on the objective value of the optimal integer solution. Only available for discrete problems.

Note(user): the best objective bound belongs to the interface for the same reasons as the objective value does.

Definition at line 279 of file linear_solver.cc.

◆ Clear()

void operations_research::MPObjective::Clear ( )

Clears the offset, all variables and coefficients, and the optimization direction.

Definition at line 250 of file linear_solver.cc.

◆ GetCoefficient()

double operations_research::MPObjective::GetCoefficient ( const MPVariable * var) const

--— MPObjective --—

Gets the coefficient of a given variable in the objective

It returns 0 if the variable does not appear in the objective).

Definition at line 194 of file linear_solver.cc.

◆ maximization()

bool operations_research::MPObjective::maximization ( ) const

Is the optimization direction set to maximize?

Definition at line 268 of file linear_solver.cc.

◆ MaximizeLinearExpr()

void operations_research::MPObjective::MaximizeLinearExpr ( const LinearExpr & linear_expr)
inline

Resets the current objective to maximize linear_expr.

Definition at line 1070 of file linear_solver.h.

◆ minimization()

bool operations_research::MPObjective::minimization ( ) const

Is the optimization direction set to minimize?

Definition at line 270 of file linear_solver.cc.

◆ MinimizeLinearExpr()

void operations_research::MPObjective::MinimizeLinearExpr ( const LinearExpr & linear_expr)
inline

Resets the current objective to minimize linear_expr.

Definition at line 1074 of file linear_solver.h.

◆ offset()

double operations_research::MPObjective::offset ( ) const
inline

Gets the constant term in the objective.

Definition at line 1061 of file linear_solver.h.

◆ operator=()

MPObjective & operations_research::MPObjective::operator= ( const MPObjective & )
delete

◆ OptimizeLinearExpr()

void operations_research::MPObjective::OptimizeLinearExpr ( const LinearExpr & linear_expr,
bool is_maximization )

Resets the current objective to take the value of linear_expr, and sets the objective direction to maximize if "is_maximize", otherwise minimizes.

Definition at line 230 of file linear_solver.cc.

◆ SetCoefficient()

void operations_research::MPObjective::SetCoefficient ( const MPVariable * var,
double coeff )

Sets the coefficient of the variable in the objective.

If the variable does not belong to the solver, the function just returns, or crashes in non-opt mode.

See the discussion on MPConstraint::SetCoefficient() for 0 coefficients, the same reasoning applies here.

Definition at line 200 of file linear_solver.cc.

◆ SetMaximization()

void operations_research::MPObjective::SetMaximization ( )
inline

Sets the optimization direction to maximize.

Definition at line 1088 of file linear_solver.h.

◆ SetMinimization()

void operations_research::MPObjective::SetMinimization ( )
inline

Sets the optimization direction to minimize.

Definition at line 1085 of file linear_solver.h.

◆ SetOffset()

void operations_research::MPObjective::SetOffset ( double value)

Sets the constant term in the objective.

Definition at line 215 of file linear_solver.cc.

◆ SetOptimizationDirection()

void operations_research::MPObjective::SetOptimizationDirection ( bool maximize)

Sets the optimization direction (maximize: true or minimize: false).

Note(user): The maximize_ bool would more naturally belong to the MPObjective, but it actually has to be a member of MPSolverInterface, because some implementations (such as GLPK) need that bool for the MPSolverInterface constructor, i.e. at a time when the MPObjective is not constructed yet (MPSolverInterface is always built before MPObjective when a new MPSolver is constructed).

Definition at line 257 of file linear_solver.cc.

◆ terms()

const absl::flat_hash_map< const MPVariable *, double > & operations_research::MPObjective::terms ( ) const
inline

Returns a map from variables to their coefficients in the objective.

If a variable is not present in the map, then its coefficient is zero.

Definition at line 1053 of file linear_solver.h.

◆ Value()

double operations_research::MPObjective::Value ( ) const

Returns the objective value of the best solution found so far.

It is the optimal objective value if the problem has been solved to optimality.

Note: the objective value may be slightly different than what you could compute yourself using MPVariable::solution_value(); please use the –verify_solution flag to gain confidence about the numerical stability of your solution.

Note(user): implementation-wise, the objective value belongs more naturally to the MPSolverInterface, since all of its implementations write to it directly.

Definition at line 272 of file linear_solver.cc.

Friends And Related Symbol Documentation

◆ BopInterface

friend class BopInterface
friend

Definition at line 1129 of file linear_solver.h.

◆ CBCInterface

friend class CBCInterface
friend

Definition at line 1120 of file linear_solver.h.

◆ CLPInterface

friend class CLPInterface
friend

Definition at line 1121 of file linear_solver.h.

◆ CplexInterface

friend class CplexInterface
friend

Definition at line 1126 of file linear_solver.h.

◆ GLOPInterface

friend class GLOPInterface
friend

Definition at line 1128 of file linear_solver.h.

◆ GLPKInterface

friend class GLPKInterface
friend

Definition at line 1122 of file linear_solver.h.

◆ GurobiInterface

friend class GurobiInterface
friend

Definition at line 1125 of file linear_solver.h.

◆ HighsInterface

friend class HighsInterface
friend

Definition at line 1132 of file linear_solver.h.

◆ KnapsackInterface

friend class KnapsackInterface
friend

Definition at line 1133 of file linear_solver.h.

◆ MPSolver

friend class MPSolver
friend

Definition at line 1118 of file linear_solver.h.

◆ MPSolverInterface

friend class MPSolverInterface
friend

Definition at line 1119 of file linear_solver.h.

◆ PdlpInterface

friend class PdlpInterface
friend

Definition at line 1131 of file linear_solver.h.

◆ SatInterface

friend class SatInterface
friend

Definition at line 1130 of file linear_solver.h.

◆ SCIPInterface

friend class SCIPInterface
friend

Definition at line 1123 of file linear_solver.h.

◆ SLMInterface

friend class SLMInterface
friend

Definition at line 1124 of file linear_solver.h.

◆ XpressInterface

friend class XpressInterface
friend

Definition at line 1127 of file linear_solver.h.


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