Skip to content

Commit ed144dc

Browse files
authored
Improve performance of QolElemAtom (#620)
1 parent 9b619a2 commit ed144dc

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/VectorAffineFunctionAsMatrix.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function MOI.output_dimension(v::VectorAffineFunctionAsMatrix)
2121
return size(v.matrix, 1)
2222
end
2323

24+
to_vaf(tape::SPARSE_VECTOR) = tape
25+
2426
function to_vaf(tape::SparseTape)
2527
op = SparseAffineOperation(tape)
2628
return to_vaf(VectorAffineFunctionAsMatrix(op, tape.variables))

src/atoms/QolElemAtom.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ end
3434
function new_conic_form!(context::Context{T}, q::QolElemAtom) where {T}
3535
x, y = q.children
3636
t = Variable(x.size)
37-
for i in 1:length(x)
38-
f = vcat(t[i], (1 / T(2)) * y[i], x[i])
39-
add_constraint!(
40-
context,
41-
GenericConstraint{MOI.RotatedSecondOrderCone}(f),
42-
)
37+
t_tape = conic_form!(context, t)
38+
y_tape = conic_form!(context, y)
39+
x_tape = conic_form!(context, x)
40+
x_fn = MOI.Utilities.scalarize(to_vaf(x_tape))
41+
y_fn = MOI.Utilities.scalarize(to_vaf(y_tape))
42+
for (ti, yi, xi) in zip(t_tape.variables, y_fn, x_fn)
43+
f = MOI.Utilities.operate(vcat, T, ti, 1 / T(2) * yi, xi)
44+
MOI.add_constraint(context.model, f, MOI.RotatedSecondOrderCone(3))
4345
end
44-
return conic_form!(context, t)
46+
return t_tape
4547
end
4648

4749
qol_elementwise(x::AbstractExpr, y::AbstractExpr) = QolElemAtom(x, y)

0 commit comments

Comments
 (0)