Skip to content

Commit

Permalink
Simplify SDP index mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 6, 2023
1 parent df1d1f1 commit b80a965
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ end
# Vectorized length for matrix dimension n
sympackedlen(n) = div(n * (n + 1), 2)

matindices(n::Integer) = LinearIndices(trues(n,n))[findall(LinearAlgebra.tril(trues(n,n)))]

function _optimize!(dest::Optimizer, src::OptimizerCache)
MOI.empty!(dest)
TimerOutputs.reset_timer!()
Expand Down Expand Up @@ -281,8 +279,7 @@ function _optimize!(dest::Optimizer, src::OptimizerCache)
for psc in psc_s
tri_len = length(psc)
sq_side = MOI.Utilities.side_dimension_for_vectorized_dimension(tri_len)
mat_inds = matindices(sq_side)
push!(con.sdpcone, SDPSet(psc, mat_inds, tri_len, sq_side))
push!(con.sdpcone, SDPSet(psc, tri_len, sq_side))
end
dest.cones = ConeData(
psc_s,
Expand Down
18 changes: 2 additions & 16 deletions src/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@ function preprocess!(aff::AffineSets, conic_sets::ConicSets)
all_cone_vars = Int[]
for (idx, sdp) in enumerate(conic_sets.sdpcone)
M = zeros(Int, sdp.sq_side, sdp.sq_side)
iv = conic_sets.sdpcone[idx].vec_i
im = conic_sets.sdpcone[idx].mat_i
for i in eachindex(iv)
M[im[i]] = iv[i]
end
X = LinearAlgebra.Symmetric(M, :L)

n = size(X)[1] # columns or line
cont = 1
sdp_vars = zeros(Int, div(sdp.sq_side*(sdp.sq_side+1), 2))
for j in 1:n, i in j:n
sdp_vars[cont] = X[i, j]
cont += 1
end
append!(all_cone_vars, sdp_vars)
append!(all_cone_vars, conic_sets.sdpcone[idx].vec_i)
end
for (idx, soc) in enumerate(conic_sets.socone)
soc_vars = copy(soc.idx)
Expand Down Expand Up @@ -69,4 +55,4 @@ function norm_scaling(affine_sets::AffineSets, cones::ConicSets)
cont += 1
end
return nothing
end
end
1 change: 0 additions & 1 deletion src/structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ end

mutable struct SDPSet
vec_i::Vector{Int}
mat_i::Vector{Int}
tri_len::Int
sq_side::Int
end
Expand Down

0 comments on commit b80a965

Please sign in to comment.