Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
linear_expr_util.h
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14// Methods for manipulating LinearExpressions.
15//
16// Why in labs? Lots of users seem to need this (e.g. for big-M calculations),
17// but there are several possible algorithms, and it is not clear what, if
18// anything, would be used widely. The function also makes many assumptions on
19// the input that are not easy to verify and can lead to confusing errors,
20// it is worth seeing if the API can be hardened a bit.
21#ifndef OR_TOOLS_MATH_OPT_LABS_LINEAR_EXPR_UTIL_H_
22#define OR_TOOLS_MATH_OPT_LABS_LINEAR_EXPR_UTIL_H_
23
25
27
28// Computes a lower bound on the value a linear expression can take based on
29// the variable bounds.
30//
31// The user must ensure:
32// * Variable lower bounds are in [-inf, +inf) (required at solve time as well)
33// * Variable upper bounds are in (-inf, +inf] (required at solve time as well)
34// * Variables bounds are not NaN
35// * The expression has no NaNs and all finite coefficients
36// * The output computation does not overflow when summing finite terms (rarely
37// an issue, as then your problem is very poorly scaled).
38// Under these assumptions, the returned value will be in [-inf, +inf). If an
39// assumption is broken, it is possible to return NaN or +inf.
40//
41// This function is deterministic, but runs in O(n log n) and will allocate.
42//
43// Alternatives:
44// * If more precision is needed, see AccurateSum
45// * For a faster method that does not allocate, is less precise, and not
46// deterministic, simply add each term to the result in the hash map's
47// iteration order.
48double LowerBound(const LinearExpression& linear_expression);
49
50// Computes an upper bound on the value a linear expression can take based on
51// the variable bounds.
52//
53// The returned value will be in (-inf, +inf] on valid input (see LowerBound()
54// above, the requirements are the same).
55//
56// See LowerBound() above for more details.
57double UpperBound(const LinearExpression& linear_expression);
58
59} // namespace operations_research::math_opt
60
61#endif // OR_TOOLS_MATH_OPT_LABS_LINEAR_EXPR_UTIL_H_
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
double LowerBound(const LinearExpression &linear_expression)
double UpperBound(const LinearExpression &linear_expression)