33struct OptionalRangeFormatter {
34 OptionalRangeFormatter(
const std::optional<Range>& range,
const int width)
37 const std::optional<Range>&
range;
41std::ostream&
operator<<(std::ostream& out,
const OptionalRangeFormatter& fmt) {
42 if (!fmt.range.has_value()) {
43 out <<
"no finite values";
47 out <<
'[' << std::setw(fmt.width) << fmt.range->first <<
", "
48 << std::setw(fmt.width) << fmt.range->second <<
']';
54void UpdateOptionalRange(std::optional<Range>&
range,
const double v) {
55 if (std::isinf(v) || v == 0.0) {
59 const double abs_v = std::abs(v);
60 if (
range.has_value()) {
62 range->second = std::max(
range->second, abs_v);
64 range = std::make_pair(abs_v, abs_v);
71 const auto last_precision = out.precision(2);
72 const auto last_flags = out.flags();
73 out.setf(std::ios_base::scientific, std::ios_base::floatfield);
74 out.setf(std::ios_base::left, std::ios_base::adjustfield);
80 constexpr int kWidth = 9;
82 out <<
"Objective terms : "
84 <<
"\nVariable bounds : "
86 <<
"\nLinear constraints bounds : "
88 <<
"\nLinear constraints coeffs : "
91 out.precision(last_precision);
92 out.flags(last_flags);
99 const auto objective =
model.ObjectiveAsQuadraticExpression();
100 for (
const auto& [_, coeff] : objective.linear_terms()) {
103 for (
const auto& [_, coeff] : objective.quadratic_terms()) {
114 for (
const auto& [_row, _col, coeff] :
115 model.storage()->linear_constraint_matrix()) {
double upper_bound() const
double lower_bound() const
An object oriented wrapper for quadratic constraints in ModelStorage.
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
ModelRanges ComputeModelRanges(const Model &model)
Returns the ranges of the finite non-zero values in the given model.
const std::optional< Range > & range
std::optional< Range > variable_bounds
The variables' lower and upper bounds.
std::optional< Range > linear_constraint_bounds
The linear constraints' lower and upper bounds.
std::optional< Range > objective_terms
The linear and quadratic objective terms (not including the offset).
std::optional< Range > linear_constraint_coefficients
The coefficients of the variables in linear constraints.