Skip to content

Commit 3464969

Browse files
fix bugs
1 parent a211d7a commit 3464969

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

src/presolve/postsolve_utils.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function restore_ilow_iupp!(ilow, iupp, ifix)
2+
c_fix = 1
3+
nfix = length(ifix)
4+
5+
nlow = length(ilow)
6+
for i in 1:nlow
7+
while c_fix nfix && ilow[i] ifix[c_fix]
8+
c_fix += 1
9+
end
10+
ilow[i] += c_fix - 1
11+
end
12+
13+
c_fix = 1
14+
nupp = length(iupp)
15+
for i in 1:nupp
16+
while c_fix nfix && iupp[i] ifix[c_fix]
17+
c_fix += 1
18+
end
19+
iupp[i] += c_fix - 1
20+
end
21+
end

src/presolve/presolve.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include("remove_ifix.jl")
22
include("empty_rows.jl")
33
include("singleton_rows.jl")
4+
include("postsolve_utils.jl")
45

56
mutable struct PresolvedData{T, S}
67
ifix::Vector{Int}
@@ -171,13 +172,21 @@ function postsolve!(
171172
x_out::S,
172173
y_in::S,
173174
y_out::S,
175+
s_l::SparseVector{T, Int},
176+
s_u::SparseVector{T, Int},
174177
) where {T, S}
175-
if length(psqm.psd.ifix) > 0
176-
restore_ifix!(psqm.psd.ifix, psqm.psd.xrm, x_in, x_out)
178+
ifix = psqm.psd.ifix
179+
if length(ifix) > 0
180+
restore_ifix!(ifix, psqm.psd.xrm, x_in, x_out)
177181
else
178182
x_out .= @views x_in[1:(qm.meta.nvar)]
179183
end
180184
ncon = length(y_out)
181185
restore_y!(y_in, y_out, psqm.psd.row_cnt, ncon)
182186

187+
ilow, iupp = s_l.nzind, s_u.nzind
188+
restore_ilow_iupp!(ilow, iupp, ifix)
189+
s_l_out = SparseVector(qm.meta.nvar, ilow, s_l.nzval)
190+
s_u_out = SparseVector(qm.meta.nvar, iupp, s_u.nzval)
191+
return s_l_out, s_u_out
183192
end

src/presolve/remove_ifix.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ function remove_ifix!(
8989

9090
# remove ifix in A cols
9191
Awritepos = 1
92-
currentAn = nvar - idxfix + 1 # remove rows if uplo == :U
9392
k = 1
94-
while k <= Annz && Acols[k] <= currentAn
93+
Arm_tmp = 0
94+
while k <= Annz - Arm
9595
Ai, Aj, Ax = Arows[k], Acols[k], Avals[k]
9696
if Aj == newcurrentifix
97-
Arm += 1
97+
Arm_tmp += 1
9898
lcon[Ai] -= Ax * xifix
9999
ucon[Ai] -= Ax * xifix
100100
else
@@ -105,6 +105,7 @@ function remove_ifix!(
105105
end
106106
k += 1
107107
end
108+
Arm += Arm_tmp
108109

109110
# update c0 with c[currentifix] coeff
110111
c0_offset += c[currentifix] * xifix

src/presolve/singleton_rows.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ removed_singleton_rows(row_cnt::Vector{Int}) = findall(isequal(1), row_cnt)
33
function singleton_rows!(Arows, Acols, Avals, lcon::Vector{T}, ucon::Vector{T}, lvar, uvar,
44
nvar, ncon, row_cnt::Vector{Int},
55
singl_rows::Vector{Int}) where {T}
6-
6+
77
# assume Acols is sorted
88
Annz = length(Arows)
99
nsingl = length(singl_rows)
@@ -17,18 +17,17 @@ function singleton_rows!(Arows, Acols, Avals, lcon::Vector{T}, ucon::Vector{T},
1717

1818
# remove singleton rows in A rows
1919
Awritepos = 1
20-
currentAn = nvar - idxsingl + 1
2120
k = 1
2221
while k <= Annz - idxsingl + 1
2322
Ai, Aj, Ax = Arows[k], Acols[k], Avals[k]
2423
if Ai == newcurrentisingl
25-
oldAi = Ai + idxsingl - 1
24+
# oldAi = Ai + idxsingl - 1
2625
if Ax > zero(T)
27-
lvar[Aj] = max(lvar[Aj], lcon[oldAi] / Ax)
28-
uvar[Aj] = min(uvar[Aj], ucon[oldAi] / Ax)
26+
lvar[Aj] = max(lvar[Aj], lcon[currentisingl] / Ax)
27+
uvar[Aj] = min(uvar[Aj], ucon[currentisingl] / Ax)
2928
elseif Ax < zero(T)
30-
lvar[Aj] = max(lvar[Aj], ucon[oldAi] / Ax)
31-
uvar[Aj] = min(uvar[Aj], lcon[oldAi] / Ax)
29+
lvar[Aj] = max(lvar[Aj], ucon[currentisingl] / Ax)
30+
uvar[Aj] = min(uvar[Aj], lcon[currentisingl] / Ax)
3231
else
3332
error("remove explicit zeros in A")
3433
end

0 commit comments

Comments
 (0)