1
1
include (" remove_ifix.jl" )
2
2
include (" empty_rows.jl" )
3
+ include (" singleton_rows.jl" )
3
4
4
5
mutable struct PresolvedData{T, S}
6
+ ifix:: Vector{Int}
5
7
xrm:: S
6
8
row_cnt:: Vector{Int}
7
9
nconps:: Int
@@ -48,7 +50,35 @@ function presolve(
48
50
lcon, ucon = psqm. meta. lcon, psqm. meta. ucon
49
51
nvar, ncon = psqm. meta. nvar, psqm. meta. ncon
50
52
51
- ifix = qm. meta. ifix
53
+ # empty rows
54
+ row_cnt = zeros (Int, ncon)
55
+ row_cnt! (psdata. A. rows, row_cnt) # number of coefficients per row
56
+ rows_rm = removed_empty_rows (row_cnt) # indices of the empty rows
57
+ if length (rows_rm) > 0
58
+ Arows_sortperm = sortperm (psdata. A. rows) # permute rows
59
+ Arows_s = @views psdata. A. rows[Arows_sortperm]
60
+ nconps = empty_rows! (psdata. A. rows, lcon, ucon, ncon, row_cnt, rows_rm, Arows_s)
61
+ else
62
+ nconps = ncon
63
+ end
64
+
65
+ # remove singleton rows
66
+ if nconps != ncon
67
+ row_cnt2 = Vector {Int} (undef, nconps)
68
+ else
69
+ row_cnt2 = row_cnt
70
+ end
71
+ row_cnt2 .= 0
72
+ row_cnt! (psdata. A. rows, row_cnt2) # number of coefficients per rows
73
+ singl_rows = removed_singleton_rows (row_cnt2) # indices of the empty rows
74
+ if length (singl_rows) > 0
75
+ nconps = singleton_rows! (psdata. A. rows, psdata. A. cols, psdata. A. vals, lcon, ucon, lvar, uvar, nvar, nconps, row_cnt2, singl_rows)
76
+ else
77
+ nconps = nconps
78
+ end
79
+
80
+ # remove fixed variables
81
+ ifix = findall (lvar .== uvar)
52
82
if length (ifix) > 0
53
83
xrm, psdata. c0, nvarps = remove_ifix! (
54
84
ifix,
@@ -71,13 +101,6 @@ function presolve(
71
101
xrm = S (undef, 0 )
72
102
end
73
103
74
- # remove constraints
75
- row_cnt = zeros (Int, ncon)
76
- row_cnt! (psdata. A. rows, row_cnt)
77
- rows_rm = removed_rows (row_cnt)
78
- Arows_sortperm = sortperm (psdata. A. rows)
79
- nconps = empty_rows! (psdata. A. rows, lcon, ucon, ncon, row_cnt, rows_rm, Arows_sortperm)
80
-
81
104
# form meta
82
105
nnzh = length (psdata. H. vals)
83
106
if ! (nnzh == length (psdata. H. rows) == length (psdata. H. cols))
@@ -122,7 +145,7 @@ function presolve(
122
145
minimize = qm. meta. minimize,
123
146
kwargs... ,
124
147
)
125
- psd = PresolvedData {T, S} (xrm, row_cnt, nconps)
148
+ psd = PresolvedData {T, S} (ifix, xrm, row_cnt, nconps)
126
149
ps = PresolvedQuadraticModel (psmeta, Counters (), psdata, psd)
127
150
return GenericExecutionStats (
128
151
:unknown ,
@@ -149,8 +172,8 @@ function postsolve!(
149
172
y_in:: S ,
150
173
y_out:: S ,
151
174
) where {T, S}
152
- if length (qm . meta . ifix) > 0
153
- restore_ifix! (qm . meta . ifix, psqm. psd. xrm, x_in, x_out)
175
+ if length (psqm . psd . ifix) > 0
176
+ restore_ifix! (psqm . psd . ifix, psqm. psd. xrm, x_in, x_out)
154
177
else
155
178
x_out .= @views x_in[1 : (qm. meta. nvar)]
156
179
end
0 commit comments