@@ -2,92 +2,82 @@ struct FreeLinearSingletonColumn{T, S} <: PresolveOperation{T, S}
2
2
i:: Int
3
3
j:: Int
4
4
aij:: T
5
- arowi:: Row{T}
6
5
yi:: T
7
6
conival:: T
8
7
end
9
8
10
9
function free_linear_singleton_columns! (
10
+ qmp:: QuadraticModelPresolveData{T, S} ,
11
11
operations:: Vector{PresolveOperation{T, S}} ,
12
- hcols:: Vector{Col{T}} ,
13
- arows:: Vector{Row{T}} ,
14
- acols:: Vector{Col{T}} ,
15
- c:: AbstractVector{T} ,
16
- c0:: T ,
17
- lcon:: AbstractVector{T} ,
18
- ucon:: AbstractVector{T} ,
19
- lvar:: AbstractVector{T} ,
20
- uvar:: AbstractVector{T} ,
21
- nvar,
22
- row_cnt,
23
- col_cnt,
24
- kept_rows,
25
- kept_cols,
26
12
) where {T, S}
27
- free_lsc_pass = false
13
+ qmp . free_lsc_pass = false
28
14
c0_offset = zero (T)
15
+ hcols, arows, acols, c = qmp. hcols, qmp. arows, qmp. acols, qmp. c
16
+ lcon, ucon, lvar, uvar = qmp. lcon, qmp. ucon, qmp. lvar, qmp. uvar
17
+ row_cnt, col_cnt = qmp. row_cnt, qmp. col_cnt
18
+ kept_rows, kept_cols = qmp. kept_rows, qmp. kept_cols
29
19
30
- for j = 1 : nvar
20
+ for j = 1 : qmp . nvar
31
21
(kept_cols[j] && (col_cnt[j] == 1 )) || continue
32
22
# check infinity bounds and no hessian contribution
33
23
if lvar[j] == - T (Inf ) && uvar[j] == T (Inf ) && isempty (hcols[j]. nzind)
34
- # find i the row index of the singleton column j, and Aij
35
- Aij = T (Inf )
24
+ # find i the row index of the singleton column j, and aij
25
+ aij = T (Inf )
36
26
colj = acols[j]
37
27
k = 1
38
28
i = colj. nzind[k]
39
29
while ! (kept_rows[i])
40
30
k += 1
41
31
i = colj. nzind[k]
42
32
end
43
- Aij = colj. nzval[k]
33
+ aij = colj. nzval[k]
44
34
45
- yi = c[j] / Aij
35
+ yi = c[j] / aij
46
36
nzcj = c[j] != zero (T)
47
37
if yi < zero (T)
48
38
lcon[i] = ucon[i]
49
39
elseif yi > zero (T)
50
40
ucon[i] = lcon[i]
51
41
end
52
- if abs (Aij ) > sqrt (eps (T))
42
+ if abs (aij ) > sqrt (eps (T))
53
43
nzcj && (c0_offset += yi * ucon[i]) # update c0
54
- nb_elem_i = row_cnt[i] - 1
55
44
rowi = arows[i] # i-th row
56
45
# new row to store for postsolve:
57
- rowi2 = Row (zeros (Int, nb_elem_i), zeros (T, nb_elem_i))
58
- c_i = 1
59
- for k = 1 : length (rowi. nzind)
60
- j2 = rowi. nzind[k]
46
+ for (l, ail) in zip (rowi. nzind, rowi. nzval)
61
47
# add all col elements to rowi2 except the col j2 == j
62
- if kept_cols[j2] && j2 != j
63
- rowi2. nzind[c_i] = j2
64
- Aij2 = rowi. nzval[k]
65
- rowi2. nzval[c_i] = Aij2
66
- nzcj && (c[j2] -= yi * Aij2) # update c if c[j] != 0
67
- col_cnt[j2] -= 1
68
- c_i += 1
69
- end
48
+ (kept_cols[l] && l != j) || continue
49
+ nzcj && (c[l] -= yi * ail) # update c if c[j] != 0
50
+ col_cnt[l] -= 1
70
51
end
71
52
conival = nzcj ? ucon[i] : (lcon[i] + ucon[i]) / 2 # constant for postsolve
72
- push! (operations, FreeLinearSingletonColumn {T, S} (i, j, Aij, rowi2 , yi, conival))
53
+ push! (operations, FreeLinearSingletonColumn {T, S} (i, j, aij , yi, conival))
73
54
kept_cols[j] = false
74
55
col_cnt[j] = - 1
75
56
kept_rows[i] = false
76
57
row_cnt[i] = - 1
77
- free_lsc_pass = true
58
+ qmp . free_lsc_pass = true
78
59
end
79
60
end
80
61
end
81
- return free_lsc_pass, c0 + c0_offset
62
+ qmp . c0 += c0_offset
82
63
end
83
64
84
- function postsolve! (sol:: QMSolution{T, S} , operation:: FreeLinearSingletonColumn{T, S} ) where {T, S}
65
+ function postsolve! (
66
+ sol:: QMSolution ,
67
+ operation:: FreeLinearSingletonColumn{T, S} ,
68
+ psd:: PresolvedData{T, S} ,
69
+ ) where {T, S}
85
70
x = sol. x
86
- j = operation. j
87
- # x[j] = (coival - Σₖ Aik x[k]) / Aij , where k ≂̸ j
71
+ kept_rows, kept_cols = psd. kept_rows, psd. kept_cols
72
+ i, j = operation. i, operation. j
73
+ arowi = psd. arows[i]
74
+ kept_rows[i] = true
75
+ kept_cols[j] = true
76
+ # x[j] = (coival - Σₖ Aik x[k]) / aij , where k ≂̸ j
88
77
x[j] = operation. conival
89
- for (i, Aij) in zip (operation. arowi. nzind, operation. arowi. nzval)
90
- x[j] -= Aij * x[i]
78
+ for (l, ail) in zip (arowi. nzind, arowi. nzval)
79
+ (l != j && kept_cols[l]) || continue
80
+ x[j] -= ail * x[l]
91
81
end
92
82
x[j] /= operation. aij
93
83
sol. s_l[j] = zero (T)
0 commit comments