You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiontest()
rng = Random.MersenneTwister(1)
m =3
n =1
u =rand(rng, m, n)
w =rand(rng, m)
btilde =rand(rng, n)
######## generate data ########
b =zeros(m * n + m + n +3m)
b[1:n] .= btilde
for i in1:m
# b[m * n + n + 3(i - 1) + 2] = -1.0
b[m * n + n + m +3(i -1) +2] =-1.0end
u =vec(u')
sparse_u =sparse(u)
nnz_u =nnz(sparse_u)
println(nnz_u)
row_indices =zeros(Int, nnz_u)
for i =1:nnz_u
row_indices[i] = (sparse_u.nzind[i] -1) ÷ n +1+ n
end
c =zeros(m*n +2*m)
@views c[m*n+1:2:m*n+2*m-1] .=-w
row1 =1:(m * n)
row1 = row1 .+ n .+ m
col1 =1:(m * n)
val1 =fill(1.0, m * n)
rows =repeat(1:n, m)
cols =repeat((0:(m-1)) * n, inner=n) .+repeat(1:n, m)
values =ones(n * m)
rows =vcat([rows, row1]...)
cols =vcat([cols, col1]...)
val =vcat([values, val1]...)
row2 = row_indices
col2 = sparse_u.nzind
val2 =-sparse_u.nzval
row =vcat([rows, row2]...)
col =vcat([cols, col2]...)
val =vcat([val, val2]...)
row3 = (n+1) : (n+m)
row3 = row3
col3 = m * n .+2.* (1:m) .-1
val3 =fill(1.0, m)
row =vcat([row, row3]...)
col =vcat([col, col3]...)
val =vcat([val, val3]...)
row4 =vcat([[3*i +1, 3i+3] for i in0:(m-1)]...) .+ (m + n)
row4 = row4 .+ (n * m)
col4 =Vector{Integer}(1:2m)
col4 = col4 .+ (m * n)
val4 =fill(1.0, 2m)
row =vcat([row, row4]...)
col =vcat([col, col4]...)
val =vcat([val, val4]...)
A =sparse(row, col, val, m + n +3m + m *n, m*n + m + m)
A =SparseMatrixCSC(A)
mA, nA =size(A)
######### solve with scs #########
model =Model(SCS.Optimizer)
@variable(model, x[1:nA])
@objective(model, Min, c'* x)
@constraint(model, A[1:m+n, :] * x .== b[1:m+n]) # 1:m+n@constraint(model, A[m+n+1:m+n+m*n, :] * x .>= b[m+n+1:m+n+m*n]) # m+n+1:m+n+m*n@constraint(model, con[i=1:m], [A[m+n+m*n+3(i-1)+1, :]'* x - b[m+n+m*n+3(i-1)+1], A[m+n+m*n+3(i-1)+2, :]'* x - b[m+n+m*n+3(i-1)+2], A[m+n+m*n+3(i-1)+3, :]'* x - b[m+n+m*n+3(i-1)+3]] in MOI.ExponentialCone())
# @constraint(model, con[i=1:m], [x[m*n + 2*i - 1], 1.0, x[m*n + 2*i]] in MOI.ExponentialCone())optimize!(model)
println("objective_value: ", objective_value(model))
println("x: ", value.(x))
println("outer A.nzval: ", A.nzval)
println("outer A.rowval: ", A.rowval)
println("outer A.colptr: ", A.colptr)
sol_res = SCS.scs_solve(
SCS.DirectSolver,
mA,
nA,
A,
sparse(zeros(nA, nA)),
-b,
c,
m + n, # z
m * n, # l
Float64[], # bu
Float64[], # blVector{Integer}([]), # qVector{Integer}([]), # s
m,
0,
Float64[],
zeros(nA),
zeros(mA),
zeros(mA)
)
endtest()
The results between JUMP api and scs_solve are different. What is the reason?
The text was updated successfully, but these errors were encountered:
zhenweilin
changed the title
Different result when using Jump wrapper and scs_solve
Different results when using Jump wrapper and scs_solve
Dec 18, 2024
The testing code are:
The results between JUMP api and scs_solve are different. What is the reason?
The text was updated successfully, but these errors were encountered: