Skip to content

Commit acb6614

Browse files
🤖 Format .jl files (#88)
Co-authored-by: geoffroyleconte <[email protected]>
1 parent e4bbd73 commit acb6614

File tree

8 files changed

+44
-44
lines changed

8 files changed

+44
-44
lines changed

src/presolve/empty_rows.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function empty_rows!(
1111
kept_rows::Vector{Bool},
1212
) where {T, S}
1313
empty_row_pass = false
14-
for i=1:ncon
14+
for i = 1:ncon
1515
(kept_rows[i] && (row_cnt[i] == 0)) || continue
1616
empty_row_pass = true
1717
@assert (lcon[i] zero(T) ucon[i])
@@ -22,4 +22,4 @@ function empty_rows!(
2222
return empty_row_pass
2323
end
2424

25-
postsolve!(pt::OutputPoint, operation::EmptyRow) = nothing
25+
postsolve!(pt::OutputPoint, operation::EmptyRow) = nothing

src/presolve/linear_singleton_columns.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function free_linear_singleton_columns!(
2727
free_lsc_pass = false
2828
c0_offset = zero(T)
2929

30-
for j=1:nvar
30+
for j = 1:nvar
3131
(kept_cols[j] && (col_cnt[j] == 1)) || continue
3232
# check infinity bounds and no hessian contribution
3333
if lvar[j] == -T(Inf) && uvar[j] == T(Inf) && isempty(hcols[j].nzind)
@@ -56,7 +56,7 @@ function free_linear_singleton_columns!(
5656
# new row to store for postsolve:
5757
rowi2 = Row(zeros(Int, nb_elem_i), zeros(T, nb_elem_i))
5858
c_i = 1
59-
for k in 1:length(rowi.nzind)
59+
for k = 1:length(rowi.nzind)
6060
j2 = rowi.nzind[k]
6161
# add all col elements to rowi2 except the col j2 == j
6262
if kept_cols[j2] && j2 != j
@@ -93,4 +93,4 @@ function postsolve!(pt::OutputPoint{T, S}, operation::FreeLinearSingletonColumn{
9393
pt.s_l[j] = zero(T)
9494
pt.s_u[j] = zero(T)
9595
pt.y[operation.i] = operation.yi
96-
end
96+
end

src/presolve/postsolve_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function restore_x!(kept_cols, xin::S, xout::S, nvar) where S
1+
function restore_x!(kept_cols, xin::S, xout::S, nvar) where {S}
22
# put x and xps inside xout according to kept_cols
33
cx = 0
44
for i = 1:nvar

src/presolve/presolve.jl

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ end
2020
function get_arows_acols(A::SparseMatrixCOO{T}, row_cnt, col_cnt, nvar, ncon) where {T}
2121
Arows, Acols, Avals = A.rows, A.cols, A.vals
2222
cnt_vec_rows = ones(Int, ncon)
23-
arows = [Row{T}(zeros(Int, row_cnt[i]), fill(T(Inf), row_cnt[i])) for i in 1:ncon]
24-
for k in 1:length(Arows)
23+
arows = [Row{T}(zeros(Int, row_cnt[i]), fill(T(Inf), row_cnt[i])) for i = 1:ncon]
24+
for k = 1:length(Arows)
2525
i, j, Ax = Arows[k], Acols[k], Avals[k]
2626
arows[i].nzind[cnt_vec_rows[i]] = j
2727
arows[i].nzval[cnt_vec_rows[i]] = Ax
2828
cnt_vec_rows[i] += 1
2929
end
3030

3131
cnt_vec_cols = ones(Int, nvar)
32-
acols = [Col{T}(zeros(Int, col_cnt[j]), fill(T(Inf), col_cnt[j])) for j in 1:nvar]
33-
for k in 1:length(Arows)
32+
acols = [Col{T}(zeros(Int, col_cnt[j]), fill(T(Inf), col_cnt[j])) for j = 1:nvar]
33+
for k = 1:length(Arows)
3434
i, j, Ax = Arows[k], Acols[k], Avals[k]
3535
acols[j].nzind[cnt_vec_cols[j]] = i
3636
acols[j].nzval[cnt_vec_cols[j]] = Ax
@@ -42,15 +42,15 @@ end
4242
function get_hcols(H::SparseMatrixCOO{T}, nvar) where {T}
4343
Hrows, Hcols, Hvals = H.rows, H.cols, H.vals
4444
hcol_cnt = zeros(Int, nvar)
45-
for k in 1:length(Hrows)
45+
for k = 1:length(Hrows)
4646
i, j = Hrows[k], Hcols[k]
4747
hcol_cnt[i] += 1
4848
(i != j) && (hcol_cnt[j] += 1)
4949
end
50-
hcols = [Col{T}(zeros(Int, hcol_cnt[i]), fill(T(Inf), hcol_cnt[i])) for i in 1:nvar]
50+
hcols = [Col{T}(zeros(Int, hcol_cnt[i]), fill(T(Inf), hcol_cnt[i])) for i = 1:nvar]
5151

5252
cnt_vec_cols = ones(Int, nvar)
53-
for k in 1:length(Hrows)
53+
for k = 1:length(Hrows)
5454
i, j, Hx = Hrows[k], Hcols[k], Hvals[k]
5555
hcols[j].nzind[cnt_vec_cols[j]] = i
5656
hcols[j].nzval[cnt_vec_cols[j]] = Hx
@@ -89,13 +89,13 @@ mutable struct PresolvedQuadraticModel{T, S, M1, M2} <: AbstractQuadraticModel{T
8989
end
9090

9191
function check_bounds(lvar, uvar, lcon, ucon, nvar, ncon, kept_rows, kept_cols)
92-
for i in 1:ncon
92+
for i = 1:ncon
9393
if kept_rows[i] && lcon[i] > ucon[i]
9494
@warn "row $i primal infeasible"
9595
return true
9696
end
9797
end
98-
for j in 1:nvar
98+
for j = 1:nvar
9999
if kept_cols[j] && lvar[j] > uvar[j]
100100
@warn "col $j primal infeasible"
101101
return true
@@ -189,17 +189,8 @@ function presolve(
189189
kept_cols,
190190
)
191191

192-
unbounded = unconstrained_reductions!(
193-
operations,
194-
c,
195-
hcols,
196-
lvar,
197-
uvar,
198-
xps,
199-
nvar,
200-
col_cnt,
201-
kept_cols,
202-
)
192+
unbounded =
193+
unconstrained_reductions!(operations, c, hcols, lvar, uvar, xps, nvar, col_cnt, kept_cols)
203194

204195
free_lsc_pass, psdata.c0 = free_linear_singleton_columns!(
205196
operations,
@@ -239,12 +230,22 @@ function presolve(
239230

240231
infeasible = check_bounds(lvar, uvar, lcon, ucon, nvar, ncon, kept_rows, kept_cols)
241232

242-
keep_iterating = (empty_row_pass || singl_row_pass || ifix_pass || free_lsc_pass) && (!unbounded || !infeasible)
233+
keep_iterating =
234+
(empty_row_pass || singl_row_pass || ifix_pass || free_lsc_pass) &&
235+
(!unbounded || !infeasible)
243236
keep_iterating && (nb_pass += 1)
244237
end
245238

246239
if !isempty(operations)
247-
remove_rowscols_A!(psdata.A.rows, psdata.A.cols, psdata.A.vals, kept_rows, kept_cols, nvar, ncon)
240+
remove_rowscols_A!(
241+
psdata.A.rows,
242+
psdata.A.cols,
243+
psdata.A.vals,
244+
kept_rows,
245+
kept_cols,
246+
nvar,
247+
ncon,
248+
)
248249
remove_rowscols_H!(psdata.H.rows, psdata.H.cols, psdata.H.vals, kept_cols, nvar)
249250
nconps, nvarps = update_vectors!(lcon, ucon, c, lvar, uvar, kept_rows, kept_cols, ncon, nvar)
250251
end
@@ -335,7 +336,7 @@ function postsolve!(
335336
restore_x!(psqm.psd.kept_cols, x_in, pt_out.x, nvar)
336337
ncon = length(pt_out.y)
337338
restore_y!(psqm.psd.kept_rows, y_in, pt_out.y, ncon)
338-
for i=n_operations:-1:1
339+
for i = n_operations:-1:1
339340
operation_i = psqm.psd.operations[i]
340341
postsolve!(pt_out, operation_i)
341342
end

src/presolve/presolve_utils.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function remove_rowscols_A!(Arows, Acols, Avals, kept_rows, kept_cols, nvar, nco
1313
Arm = 0
1414
nb_rm_rows = 0
1515
# remove rows
16-
for i0=1:ncon
16+
for i0 = 1:ncon
1717
kept_rows[i0] && continue
1818
i = i0 - nb_rm_rows # up idx according to already removed rows
1919
nb_rm_rows += 1
@@ -37,7 +37,7 @@ function remove_rowscols_A!(Arows, Acols, Avals, kept_rows, kept_cols, nvar, nco
3737

3838
# remove cols
3939
nb_rm_cols = 0
40-
for j0=1:nvar
40+
for j0 = 1:nvar
4141
kept_cols[j0] && continue
4242
j = j0 - nb_rm_cols # up idx according to already removed cols
4343
nb_rm_cols += 1
@@ -58,7 +58,7 @@ function remove_rowscols_A!(Arows, Acols, Avals, kept_rows, kept_cols, nvar, nco
5858
end
5959
Arm += Arm_tmp
6060
end
61-
61+
6262
if Arm > 0
6363
Annz -= Arm
6464
resize!(Arows, Annz)
@@ -72,7 +72,7 @@ function remove_rowscols_H!(Hrows, Hcols, Hvals, kept_cols, nvar)
7272
Hrm = 0
7373
nb_rm = 0
7474
# remove rows and cols
75-
for j0=1:nvar
75+
for j0 = 1:nvar
7676
kept_cols[j0] && continue
7777
j = j0 - nb_rm # up idx according to already removed cols
7878
nb_rm += 1
@@ -95,7 +95,7 @@ function remove_rowscols_H!(Hrows, Hcols, Hvals, kept_cols, nvar)
9595
end
9696
Hrm += Hrm_tmp
9797
end
98-
98+
9999
if Hrm > 0
100100
Hnnz -= Hrm
101101
resize!(Hrows, Hnnz)
@@ -129,4 +129,4 @@ function update_vectors!(lcon, ucon, c, lvar, uvar, kept_rows, kept_cols, ncon,
129129
resize!(uvar, nvarps)
130130
resize!(c, nvarps)
131131
return nconps, nvarps
132-
end
132+
end

src/presolve/remove_ifix.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ function remove_ifix!(
2323
kept_cols,
2424
xps,
2525
) where {T, S}
26-
2726
ifix_pass = false
2827
c0_offset = zero(T)
2928

3029
for j = 1:nvar
3130
(kept_cols[j] && (lvar[j] == uvar[j])) || continue
3231
ifix_pass = true
3332
xj = lvar[j]
34-
for k in 1:length(hcols[j].nzind)
33+
for k = 1:length(hcols[j].nzind)
3534
i = hcols[j].nzind[k]
3635
Hx = hcols[j].nzval[k]
3736
if i == j
@@ -42,7 +41,7 @@ function remove_ifix!(
4241
end
4342

4443
# remove ifix in A cols
45-
for k in 1:length(acols[j].nzind)
44+
for k = 1:length(acols[j].nzind)
4645
i = acols[j].nzind[k]
4746
if kept_rows[i]
4847
row_cnt[i] -= 1
@@ -68,4 +67,4 @@ end
6867

6968
function postsolve!(pt::OutputPoint{T, S}, operation::RemoveIfix{T, S}) where {T, S}
7069
pt.x[operation.j] = operation.xj
71-
end
70+
end

src/presolve/singleton_rows.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function singleton_rows!(
2222
# assume Acols is sorted
2323
singl_row_pass = false
2424

25-
for i=1:ncon
25+
for i = 1:ncon
2626
(kept_rows[i] && (row_cnt[i] == 1)) || continue
2727
singl_row_pass = true
2828
tightened_lvar = false
@@ -78,4 +78,4 @@ function postsolve!(pt::OutputPoint{T, S}, operation::SingletonRow{T, S}) where
7878
if !operation.tightened_lvar && !operation.tightened_uvar
7979
pt.y[i] = zero(T)
8080
end
81-
end
81+
end

src/presolve/unconstrained_reductions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function unconstrained_reductions!(
1515
) where {T, S}
1616
unbounded = false
1717
# assume Hcols sorted
18-
for j in 1:nvar
19-
(kept_cols[j] && (col_cnt[j] == 0)) || continue
18+
for j = 1:nvar
19+
(kept_cols[j] && (col_cnt[j] == 0)) || continue
2020
# check empty rows/col j in H
2121
if isempty(hcols[j].nzind)
2222
if c[j] < zero(T)
@@ -41,4 +41,4 @@ function unconstrained_reductions!(
4141
return unbounded
4242
end
4343

44-
postsolve!(pt::OutputPoint, operation::UnconstrainedReduction) = nothing
44+
postsolve!(pt::OutputPoint, operation::UnconstrainedReduction) = nothing

0 commit comments

Comments
 (0)