![]() |
Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
|
This file allows you to write natural code (like a mathematical equation) to model optimization problems with MPSolver. It is syntactic sugar on top of the MPSolver API, it provides no additional functionality. Use of these APIs makes it much easier to write code that is both simple and big-O optimal for creating your model, at the cost of some additional constant factor overhead. If model creation is a bottleneck in your problem, consider using the MPSolver API directly instead.
This file contains two classes:
Recommended use (avoids dangerous code):
WARNING, AVOID THIS TRAP:
In evaluating "x+5" above, x is NOT converted to a LinearExpr before the addition, but rather is treated as a pointer, so x+5 gives a new pointer to garbage memory.
For this reason, when using LinearExpr, it is best practice to:
Likewise, the following code is NOT recommended:
While it is correct, it violates the natural assumption that the + operator is associative. Thus you are setting a trap for future modifications of the code, as any of the following changes would lead to the above failure mode:
Definition in file linear_expr.h.
#include <ostream>#include <string>#include "absl/container/flat_hash_map.h"Go to the source code of this file.
Classes | |
| class | operations_research::LinearExpr |
| class | operations_research::LinearRange |
Namespaces | |
| namespace | operations_research |
| OR-Tools root namespace. | |
Functions | |
| std::ostream & | operations_research::operator<< (std::ostream &stream, const LinearExpr &linear_expr) |
| LinearExpr | operations_research::operator+ (LinearExpr lhs, const LinearExpr &rhs) |
| LinearExpr | operations_research::operator- (LinearExpr lhs, const LinearExpr &rhs) |
| LinearExpr | operations_research::operator* (LinearExpr lhs, double rhs) |
| LinearExpr | operations_research::operator/ (LinearExpr lhs, double rhs) |
| LinearExpr | operations_research::operator* (double lhs, LinearExpr rhs) |
| LinearRange | operations_research::operator<= (const LinearExpr &lhs, const LinearExpr &rhs) |
| LinearRange | operations_research::operator== (const LinearExpr &lhs, const LinearExpr &rhs) |
| LinearRange | operations_research::operator>= (const LinearExpr &lhs, const LinearExpr &rhs) |