OR-Tools  9.6
statistics.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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 #ifndef OR_TOOLS_MATH_OPT_CPP_STATISTICS_H_
15 #define OR_TOOLS_MATH_OPT_CPP_STATISTICS_H_
16 
17 #include <iostream>
18 #include <optional>
19 #include <ostream>
20 #include <utility>
21 
23 
25 
26 // A range of values, first is the minimum, second is the maximum.
27 using Range = std::pair<double, double>;
28 
29 // The ranges of the absolute values of the finite non-zero values in the model.
30 //
31 // Each range is optional since there may be no finite non-zero values
32 // (e.g. empty model, empty objective, all variables unbounded, ...).
33 struct ModelRanges {
34  // The linear and quadratic objective terms (not including the offset).
35  std::optional<Range> objective_terms;
36 
37  // The variables' lower and upper bounds.
38  std::optional<Range> variable_bounds;
39 
40  // The linear constraints' lower and upper bounds.
41  std::optional<Range> linear_constraint_bounds;
42 
43  // The coefficients of the variables in linear constraints.
44  std::optional<Range> linear_constraint_coefficients;
45 };
46 
47 // Prints the ranges with std::setprecision(2) and std::scientific (restoring
48 // the stream flags after printing).
49 //
50 // It prints a multi-line table list of ranges. The last line does NOT end with
51 // a new line thus the caller should use std::endl if appropriate (see example).
52 //
53 // Example:
54 //
55 // std::cout << "Model xxx ranges:\n" << ComputeModelRanges(model)
56 // << std::endl;
57 //
58 // LOG(INFO) << "Model xxx ranges:\n" << ComputeModelRanges(model);
59 //
60 std::ostream& operator<<(std::ostream& out, const ModelRanges& ranges);
61 
62 // Returns the ranges of the finite non-zero values in the given model.
64 
65 } // namespace operations_research::math_opt
66 
67 #endif // OR_TOOLS_MATH_OPT_CPP_STATISTICS_H_
GRBmodel * model
ModelRanges ComputeModelRanges(const Model &model)
Definition: statistics.cc:96
std::pair< double, double > Range
Definition: statistics.h:27
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
std::optional< Range > linear_constraint_coefficients
Definition: statistics.h:44
std::optional< Range > linear_constraint_bounds
Definition: statistics.h:41
std::optional< Range > variable_bounds
Definition: statistics.h:38
std::optional< Range > objective_terms
Definition: statistics.h:35