Skip to content

Commit 50112cc

Browse files
committed
format
1 parent d19679f commit 50112cc

File tree

2 files changed

+83
-29
lines changed

2 files changed

+83
-29
lines changed

src/coefficients.jl

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
55

66
Base.@kwdef mutable struct CoefficientsData
7-
87
threshold_dense_fill_in::Float64 = 0.10
98
threshold_dense_entries::Int = 1000
109
threshold_small::Float64 = 1e-5
@@ -13,10 +12,11 @@ Base.@kwdef mutable struct CoefficientsData
1312
number_of_variables::Int = 0
1413
number_of_constraints::Int = 0
1514

16-
constraint_info::Vector{Tuple{DataType, DataType, Int}} = Tuple{DataType, DataType, Int}[]
15+
constraint_info::Vector{Tuple{DataType,DataType,Int}} =
16+
Tuple{DataType,DataType,Int}[]
1717

1818
matrix_nnz::Int = 0
19-
19+
2020
matrix_range::Vector{Float64} = sizehint!(Float64[1.0, 1.0], 2)
2121
bounds_range::Vector{Float64} = sizehint!(Float64[1.0, 1.0], 2)
2222
rhs_range::Vector{Float64} = sizehint!(Float64[1.0, 1.0], 2)
@@ -27,20 +27,46 @@ Base.@kwdef mutable struct CoefficientsData
2727

2828
empty_rows::Vector{ConstraintRef} = ConstraintRef[]
2929
bound_rows::Vector{ConstraintRef} = ConstraintRef[]
30-
dense_rows::Vector{Tuple{ConstraintRef, Int}} = Tuple{ConstraintRef, Int}[]
31-
32-
matrix_small::Vector{Tuple{ConstraintRef, VariableRef, Float64}} = Tuple{ConstraintRef, VariableRef, Float64}[]
33-
matrix_large::Vector{Tuple{ConstraintRef, VariableRef, Float64}} = Tuple{ConstraintRef, VariableRef, Float64}[]
34-
35-
bounds_small::Vector{Tuple{VariableRef, Float64}} = Tuple{VariableRef, Float64}[]
36-
bounds_large::Vector{Tuple{VariableRef, Float64}} = Tuple{VariableRef, Float64}[]
37-
38-
rhs_small::Vector{Tuple{ConstraintRef, Float64}} = Tuple{ConstraintRef, Float64}[]
39-
rhs_large::Vector{Tuple{ConstraintRef, Float64}} = Tuple{ConstraintRef, Float64}[]
40-
41-
objective_small::Vector{Tuple{VariableRef, Float64}} = Tuple{VariableRef, Float64}[]
42-
objective_large::Vector{Tuple{VariableRef, Float64}} = Tuple{VariableRef, Float64}[]
43-
30+
dense_rows::Vector{Tuple{ConstraintRef,Int}} = Tuple{ConstraintRef,Int}[]
31+
32+
nonconvex_rows::Vector{ConstraintRef} = ConstraintRef[]
33+
34+
matrix_small::Vector{Tuple{ConstraintRef,VariableRef,Float64}} =
35+
Tuple{ConstraintRef,VariableRef,Float64}[]
36+
matrix_large::Vector{Tuple{ConstraintRef,VariableRef,Float64}} =
37+
Tuple{ConstraintRef,VariableRef,Float64}[]
38+
39+
bounds_small::Vector{Tuple{VariableRef,Float64}} =
40+
Tuple{VariableRef,Float64}[]
41+
bounds_large::Vector{Tuple{VariableRef,Float64}} =
42+
Tuple{VariableRef,Float64}[]
43+
44+
rhs_small::Vector{Tuple{ConstraintRef,Float64}} =
45+
Tuple{ConstraintRef,Float64}[]
46+
rhs_large::Vector{Tuple{ConstraintRef,Float64}} =
47+
Tuple{ConstraintRef,Float64}[]
48+
49+
objective_small::Vector{Tuple{VariableRef,Float64}} =
50+
Tuple{VariableRef,Float64}[]
51+
objective_large::Vector{Tuple{VariableRef,Float64}} =
52+
Tuple{VariableRef,Float64}[]
53+
54+
has_quadratic_objective::Bool = false
55+
has_quadratic_constraints::Bool = false
56+
57+
objective_quadratic_range = sizehint!(Float64[1.0, 1.0], 2)
58+
matrix_quadratic_range = sizehint!(Float64[1.0, 1.0], 2)
59+
60+
matrix_quadratic_small::Vector{
61+
Tuple{ConstraintRef,VariableRef,VariableRef,Float64},
62+
} = Tuple{ConstraintRef,VariableRef,VariableRef,Float64}[]
63+
matrix_quadratic_large::Vector{
64+
Tuple{ConstraintRef,VariableRef,VariableRef,Float64},
65+
} = Tuple{ConstraintRef,VariableRef,VariableRef,Float64}[]
66+
objective_quadratic_small::Vector{Tuple{VariableRef,VariableRef,Float64}} =
67+
Tuple{VariableRef,VariableRef,Float64}[]
68+
objective_quadratic_large::Vector{Tuple{VariableRef,VariableRef,Float64}} =
69+
Tuple{VariableRef,VariableRef,Float64}[]
4470
end
4571

4672
function _update_range(range::Vector{Float64}, value::Number)
@@ -49,7 +75,11 @@ function _update_range(range::Vector{Float64}, value::Number)
4975
return 1
5076
end
5177

52-
function _get_constraint_data(data, ref::ConstraintRef, func::JuMP.GenericAffExpr)
78+
function _get_constraint_data(
79+
data,
80+
ref::ConstraintRef,
81+
func::JuMP.GenericAffExpr,
82+
)
5383
if length(func.terms) == 1
5484
if first(values(func.terms)) 1.0
5585
push!(data.bound_rows, ref)
@@ -74,7 +104,8 @@ function _get_constraint_data(data, ref::ConstraintRef, func::JuMP.GenericAffExp
74104
push!(data.empty_rows, ref)
75105
return
76106
end
77-
if nnz / data.number_of_variables > data.threshold_dense_fill_in && nnz > data.threshold_dense_entries
107+
if nnz / data.number_of_variables > data.threshold_dense_fill_in &&
108+
nnz > data.threshold_dense_entries
78109
push!(data.dense_rows, (ref, nnz))
79110
end
80111
data.matrix_nnz += nnz
@@ -135,7 +166,12 @@ function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set)
135166
return
136167
end
137168

138-
function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.LessThan)
169+
function _get_constraint_data(
170+
data,
171+
ref,
172+
func::JuMP.GenericAffExpr,
173+
set::MOI.LessThan,
174+
)
139175
coefficient = set.upper - func.constant
140176
if coefficient 0.0
141177
return
@@ -149,7 +185,12 @@ function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.Les
149185
return
150186
end
151187

152-
function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.GreaterThan)
188+
function _get_constraint_data(
189+
data,
190+
ref,
191+
func::JuMP.GenericAffExpr,
192+
set::MOI.GreaterThan,
193+
)
153194
coefficient = set.lower - func.constant
154195
if coefficient 0.0
155196
return
@@ -163,7 +204,12 @@ function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.Gre
163204
return
164205
end
165206

166-
function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.EqualTo)
207+
function _get_constraint_data(
208+
data,
209+
ref,
210+
func::JuMP.GenericAffExpr,
211+
set::MOI.EqualTo,
212+
)
167213
coefficient = set.value - func.constant
168214
if coefficient 0.0
169215
return
@@ -177,7 +223,12 @@ function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.Equ
177223
return
178224
end
179225

180-
function _get_constraint_data(data, ref, func::JuMP.GenericAffExpr, set::MOI.Interval)
226+
function _get_constraint_data(
227+
data,
228+
ref,
229+
func::JuMP.GenericAffExpr,
230+
set::MOI.Interval,
231+
)
181232
coefficient = set.upper - func.constant
182233
if !(coefficient 0.0)
183234
_update_range(data.rhs_range, coefficient)
@@ -214,7 +265,8 @@ function coefficient_analysis(model::JuMP.Model)
214265
data = CoefficientsData()
215266
data.number_of_variables = JuMP.num_variables(model)
216267
sizehint!(data.variables_in_constraints, data.number_of_variables)
217-
data.number_of_constraints = JuMP.num_constraints(model, count_variable_in_set_constraints = false)
268+
data.number_of_constraints =
269+
JuMP.num_constraints(model, count_variable_in_set_constraints = false)
218270
_get_objective_data(data, JuMP.objective_function(model))
219271
for var in JuMP.all_variables(model)
220272
if JuMP.has_lower_bound(var)
@@ -318,14 +370,18 @@ function _print_numerical_stability_report(
318370
println(io, " Large coefficients: ", data.threshold_large)
319371

320372
println(io, " Coefficient ranges:")
321-
warnings = Tuple{String, String}[]
373+
warnings = Tuple{String,String}[]
322374
_print_coefficients(io, "matrix", data, data.matrix_range, warnings)
323375
_print_coefficients(io, "objective", data, data.objective_range, warnings)
324376
_print_coefficients(io, "bounds", data, data.bounds_range, warnings)
325377
_print_coefficients(io, "rhs", data, data.rhs_range, warnings)
326378

327379
# rows that should be bounds
328-
println(io, " Variables not in constraints: ", length(data.variables_not_in_constraints))
380+
println(
381+
io,
382+
" Variables not in constraints: ",
383+
length(data.variables_not_in_constraints),
384+
)
329385
println(io, " Bound rows: ", length(data.bound_rows))
330386
println(io, " Dense constraints: ", length(data.dense_rows))
331387
println(io, " Empty constraints: ", length(data.empty_rows))
@@ -420,5 +476,3 @@ function Base.show(io::IO, data::CoefficientsData; verbose::Bool = false)
420476
_print_numerical_stability_report(io, data, warn = true, verbose = verbose)
421477
return
422478
end
423-
424-
# TODO analyse quadratics

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ model = Model()
1414
@variable(model, y >= 1e-9)
1515
@constraint(model, x + y <= 1e8)
1616
@constraint(model, x + y + 1e7 <= 2)
17-
@constraint(model, 1e6*x + 1e-5*y >= 2)
17+
@constraint(model, 1e6 * x + 1e-5 * y >= 2)
1818
@constraint(model, x <= 100)
1919
@objective(model, Max, x + y)
2020

0 commit comments

Comments
 (0)