Skip to content

Commit 630c982

Browse files
authored
[breaking] remove ExponentialConeConstraint (#602)
* [breaking] remove ExponentialConeConstraint * Add test * Update * Update * Update
1 parent 3d92c35 commit 630c982

File tree

6 files changed

+57
-103
lines changed

6 files changed

+57
-103
lines changed

src/atoms/exp_cone/EntropyAtom.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ entropy_elementwise(x::AbstractExpr) = EntropyAtom(x)
3232

3333
function new_conic_form!(context::Context, e::EntropyAtom)
3434
# -x log x >= t <=> x exp(t/x) <= 1 <==> (t,x,1) in exp cone
35-
t = Variable(e.size)
3635
x = e.children[1]
37-
add_constraint!(context, ExponentialConeConstraint(t, x, ones(e.size...)))
36+
m, n = size(x)
37+
t = Variable(m, n)
38+
for i in 1:m, j in 1:n
39+
f = vcat(t[i, j], x[i, j], 1)
40+
add_constraint!(context, GenericConstraint{MOI.ExponentialCone}(f))
41+
end
3842
return conic_form!(context, t)
3943
end

src/atoms/exp_cone/ExpAtom.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ evaluate(x::ExpAtom) = exp.(evaluate(x.children[1]))
2525
Base.exp(x::AbstractExpr) = ExpAtom(x)
2626

2727
function new_conic_form!(context::Context{T}, e::ExpAtom) where {T}
28-
# exp(x) \leq z <=> (x,ones(),z) \in ExpCone
28+
# exp(x) \leq z <=> (x,1,z) \in ExpCone
2929
x = e.children[1]
30-
y = Constant(ones(size(x)))
31-
z = Variable(size(x))
32-
add_constraint!(context, ExponentialConeConstraint(x, y, z))
30+
m, n = size(x)
31+
z = Variable(m, n)
32+
for i in 1:m, j in 1:n
33+
f = vcat(x[i, j], 1, z[i, j])
34+
add_constraint!(context, GenericConstraint{MOI.ExponentialCone}(f))
35+
end
3336
return conic_form!(context, z)
3437
end

src/atoms/exp_cone/LogAtom.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ evaluate(x::LogAtom) = log.(evaluate(x.children[1]))
2525
Base.log(x::AbstractExpr) = LogAtom(x)
2626

2727
function new_conic_form!(context::Context, e::LogAtom)
28-
# log(z) \geq x <=> (x,ones(),z) \in ExpCone
28+
# log(z) \geq x <=> (x,1,z) \in ExpCone
2929
z = e.children[1]
30-
y = Constant(ones(size(z)))
31-
x = Variable(size(z))
32-
add_constraint!(context, ExponentialConeConstraint(x, y, z))
30+
m, n = size(z)
31+
x = Variable(m, n)
32+
for i in 1:m, j in 1:n
33+
f = vcat(x[i, j], 1, z[i, j])
34+
add_constraint!(context, GenericConstraint{MOI.ExponentialCone}(f))
35+
end
3336
return conic_form!(context, x)
3437
end

src/constraints/ExponentialConeConstraint.jl

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/constraints/GenericConstraint.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ end
240240

241241
(x::AbstractExpr, y::Value) = (y, x)
242242

243+
# ==============================================================================
244+
# ExponentialCone
245+
# ==============================================================================
246+
247+
head(io::IO, ::MOI.ExponentialCone) = print(io, "exp")
248+
249+
function vexity(vex, ::MOI.ExponentialCone)
250+
if !(vex == ConstVexity() || vex == AffineVexity())
251+
return NotDcp()
252+
end
253+
return ConvexVexity()
254+
end
255+
243256
# ==============================================================================
244257
# SecondOrderCone
245258
# ==============================================================================

test/test_constraints.jl

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,6 @@ function test_EqualToConstraint_dual_complex()
6464
return
6565
end
6666

67-
### constraints/ExponentialConeConstraint
68-
69-
function test_ExponentialConeConstraint()
70-
# y * exp(x / y) <= z <=> (x, y, z) in ExpCone
71-
z = Variable()
72-
# 1 * exp(1 / 1) <= z
73-
c = Convex.ExponentialConeConstraint(1, constant(1), z)
74-
p = minimize(z, [c])
75-
solve!(p, SCS.Optimizer; silent_solver = true)
76-
@test isapprox(z.value, exp(1); atol = 1e-4)
77-
@test isapprox(c.dual, [-exp(1), 0, 1]; atol = 1e-4)
78-
z = Variable()
79-
# 2 * exp(3 / 2) <= z
80-
c = Convex.ExponentialConeConstraint(constant(3), 2, z)
81-
p = minimize(z, [c])
82-
solve!(p, SCS.Optimizer; silent_solver = true)
83-
@test isapprox(z.value, 2 * exp(3 / 2); atol = 1e-4)
84-
@test isapprox(c.dual, [-exp(3 / 2), exp(3 / 2) / 2, 1]; atol = 1e-4)
85-
return
86-
end
87-
8867
### constraints/GreaterThanConstraint
8968

9069
function test_GreaterThanConstraint()
@@ -253,6 +232,30 @@ function test_GenericConstraint_SecondOrderCone_set_with_size()
253232
return
254233
end
255234

235+
### constraints/GenericConstraint_ExponentialCone
236+
237+
function test_GenericConstraint_ExponentialConeConstraint()
238+
# y * exp(x / y) <= z <=> (x, y, z) in ExpCone
239+
z = Variable()
240+
# 1 * exp(1 / 1) <= z
241+
c = Convex.GenericConstraint{MOI.ExponentialCone}(vcat(1, constant(1), z))
242+
p = minimize(z, [c])
243+
solve!(p, SCS.Optimizer; silent_solver = true)
244+
@test isapprox(z.value, exp(1); atol = 1e-4)
245+
@test isapprox(c.dual, [-exp(1), 0, 1]; atol = 1e-4)
246+
z = Variable()
247+
# 2 * exp(3 / 2) <= z
248+
c = Convex.GenericConstraint{MOI.ExponentialCone}(vcat(constant(3), 2, z))
249+
p = minimize(z, [c])
250+
solve!(p, SCS.Optimizer; silent_solver = true)
251+
@test isapprox(z.value, 2 * exp(3 / 2); atol = 1e-4)
252+
@test isapprox(c.dual, [-exp(3 / 2), exp(3 / 2) / 2, 1]; atol = 1e-4)
253+
c = Convex.GenericConstraint{MOI.ExponentialCone}(vcat(square(z), 1, z))
254+
@test vexity(c) === Convex.NotDcp()
255+
@test sprint(Convex.head, c) == "exp"
256+
return
257+
end
258+
256259
end # TestConstraints
257260

258261
TestConstraints.runtests()

0 commit comments

Comments
 (0)