22 #include <type_traits>
32 struct OptionalRangeFormatter {
33 OptionalRangeFormatter(
const std::optional<Range>&
range,
const int width)
36 const std::optional<Range>&
range;
40 std::ostream&
operator<<(std::ostream& out,
const OptionalRangeFormatter& fmt) {
41 if (!fmt.range.has_value()) {
42 out <<
"no finite values";
46 out <<
'[' << std::setw(fmt.width) << fmt.range->first <<
", "
47 << std::setw(fmt.width) << fmt.range->second <<
']';
53 void UpdateOptionalRange(std::optional<Range>&
range,
const double v) {
54 if (std::isinf(v) || v == 0.0) {
58 const double abs_v = std::abs(v);
59 if (
range.has_value()) {
63 range = std::make_pair(abs_v, abs_v);
70 const auto last_precision = out.precision(2);
71 const auto last_flags = out.flags();
72 out.setf(std::ios_base::scientific, std::ios_base::floatfield);
73 out.setf(std::ios_base::left, std::ios_base::adjustfield);
79 constexpr
int kWidth = 9;
81 out <<
"Objective terms : "
83 <<
"\nVariable bounds : "
85 <<
"\nLinear constraints bounds : "
87 <<
"\nLinear constraints coeffs : "
90 out.precision(last_precision);
91 out.flags(last_flags);
98 const auto objective =
model.ObjectiveAsQuadraticExpression();
99 for (
const auto& [_, coeff] : objective.linear_terms()) {
102 for (
const auto& [_, coeff] : objective.quadratic_terms()) {
113 for (
const auto& [_row, _col, coeff] :
114 model.storage()->linear_constraint_matrix()) {
ModelRanges ComputeModelRanges(const Model &model)
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
const std::optional< Range > & range
std::optional< Range > linear_constraint_coefficients
std::optional< Range > linear_constraint_bounds
std::optional< Range > variable_bounds
std::optional< Range > objective_terms