-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for atoms/second_order_cone (#561)
- Loading branch information
Showing
8 changed files
with
287 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
mutable struct EuclideanNormAtom <: AbstractExpr | ||
children::Tuple{AbstractExpr} | ||
size::Tuple{Int,Int} | ||
|
||
EuclideanNormAtom(x::AbstractExpr) = new((x,), (1, 1)) | ||
end | ||
|
||
head(io::IO, ::EuclideanNormAtom) = print(io, "norm2") | ||
|
||
Base.sign(::EuclideanNormAtom) = Positive() | ||
|
||
monotonicity(x::EuclideanNormAtom) = (sign(x.children[1]) * Nondecreasing(),) | ||
|
||
curvature(::EuclideanNormAtom) = ConvexVexity() | ||
|
||
evaluate(x::EuclideanNormAtom) = norm(vec(evaluate(x.children[1]))) | ||
|
||
function new_conic_form!(context::Context{T}, A::EuclideanNormAtom) where {T} | ||
x = only(AbstractTrees.children(A)) | ||
t = conic_form!(context, Variable()) | ||
obj = conic_form!(context, x) | ||
f = operate(vcat, T, sign(A), t, obj) | ||
MOI_add_constraint(context.model, f, MOI.SecondOrderCone(length(x) + 1)) | ||
return t | ||
end | ||
|
||
function LinearAlgebra.norm2(x::AbstractExpr) | ||
if sign(x) == ComplexSign() | ||
return EuclideanNormAtom([real(x); imag(x)]) | ||
end | ||
return EuclideanNormAtom(x) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.