![]() |
OR-Tools
8.2
|
A class to express a linear objective.
Definition at line 926 of file linear_solver.h.
Public Member Functions | |
void | Clear () |
Clears the offset, all variables and coefficients, and the optimization direction. More... | |
void | SetCoefficient (const MPVariable *const var, double coeff) |
Sets the coefficient of the variable in the objective. More... | |
double | GetCoefficient (const MPVariable *const var) const |
Gets the coefficient of a given variable in the objective. More... | |
const absl::flat_hash_map< const MPVariable *, double > & | terms () const |
Returns a map from variables to their coefficients in the objective. More... | |
void | SetOffset (double value) |
Sets the constant term in the objective. More... | |
double | offset () const |
Gets the constant term in the objective. More... | |
void | 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. More... | |
void | MaximizeLinearExpr (const LinearExpr &linear_expr) |
Resets the current objective to maximize linear_expr. More... | |
void | MinimizeLinearExpr (const LinearExpr &linear_expr) |
Resets the current objective to minimize linear_expr. More... | |
void | AddLinearExpr (const LinearExpr &linear_expr) |
Adds linear_expr to the current objective, does not change the direction. More... | |
void | SetOptimizationDirection (bool maximize) |
Sets the optimization direction (maximize: true or minimize: false). More... | |
void | SetMinimization () |
Sets the optimization direction to minimize. More... | |
void | SetMaximization () |
Sets the optimization direction to maximize. More... | |
bool | maximization () const |
Is the optimization direction set to maximize? More... | |
bool | minimization () const |
Is the optimization direction set to minimize? More... | |
double | Value () const |
Returns the objective value of the best solution found so far. More... | |
double | BestBound () const |
Returns the best objective bound. More... | |
void AddLinearExpr | ( | const LinearExpr & | linear_expr | ) |
Adds linear_expr to the current objective, does not change the direction.
Definition at line 219 of file linear_solver.cc.
double 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.
Definition at line 256 of file linear_solver.cc.
void Clear | ( | ) |
Clears the offset, all variables and coefficients, and the optimization direction.
Definition at line 227 of file linear_solver.cc.
double GetCoefficient | ( | const MPVariable *const | var | ) | const |
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 171 of file linear_solver.cc.
bool maximization | ( | ) | const |
Is the optimization direction set to maximize?
Definition at line 245 of file linear_solver.cc.
|
inline |
Resets the current objective to maximize linear_expr.
Definition at line 971 of file linear_solver.h.
bool minimization | ( | ) | const |
Is the optimization direction set to minimize?
Definition at line 247 of file linear_solver.cc.
|
inline |
Resets the current objective to minimize linear_expr.
Definition at line 975 of file linear_solver.h.
|
inline |
Gets the constant term in the objective.
Definition at line 962 of file linear_solver.h.
void 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 207 of file linear_solver.cc.
void SetCoefficient | ( | const MPVariable *const | 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.
Definition at line 177 of file linear_solver.cc.
|
inline |
Sets the optimization direction to maximize.
Definition at line 989 of file linear_solver.h.
|
inline |
Sets the optimization direction to minimize.
Definition at line 986 of file linear_solver.h.
void SetOffset | ( | double | value | ) |
Sets the constant term in the objective.
Definition at line 192 of file linear_solver.cc.
void SetOptimizationDirection | ( | bool | maximize | ) |
Sets the optimization direction (maximize: true or minimize: false).
Definition at line 234 of file linear_solver.cc.
|
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 954 of file linear_solver.h.
double 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.
Definition at line 249 of file linear_solver.cc.