Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed May 28, 2024
1 parent 1fc69d8 commit 08713fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/src/manual/complex.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ julia> H = LinearAlgebra.Hermitian([x[1] 1im; -1im -x[2]])
-im -x[2]
julia> @constraint(model, H in HermitianPSDCone())
[x[1] im;
[x[1] im
-im -x[2]] ∈ HermitianPSDCone()
```

Expand Down
12 changes: 6 additions & 6 deletions docs/src/manual/constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ julia> @variable(model, X[1:2, 1:2], Symmetric)
X[1,2] X[2,2]
julia> @constraint(model, X == LinearAlgebra.I)
[X[1,1] - 1 X[1,2];
[X[1,1] - 1 X[1,2]
X[1,2] X[2,2] - 1] ∈ Zeros()
```

Expand Down Expand Up @@ -229,7 +229,7 @@ julia> @variable(model, X[1:2, 1:2] in HermitianPSDCone())
real(X[1,2]) - imag(X[1,2]) im real(X[2,2])
julia> @constraint(model, X == LinearAlgebra.I)
[real(X[1,1]) - 1 real(X[1,2]) + imag(X[1,2]) im;
[real(X[1,1]) - 1 real(X[1,2]) + imag(X[1,2]) im
real(X[1,2]) - imag(X[1,2]) im real(X[2,2]) - 1] ∈ Zeros()
julia> @constraint(model, X .== LinearAlgebra.I)
Expand Down Expand Up @@ -1415,7 +1415,7 @@ julia> @variable(model, X[1:2, 1:2])
X[2,1] X[2,2]
julia> @constraint(model, X >= 0, PSDCone())
[X[1,1] X[1,2];
[X[1,1] X[1,2]
X[2,1] X[2,2]] ∈ PSDCone()
```

Expand All @@ -1436,7 +1436,7 @@ julia> Y = [1 2; 2 1]
2 1
julia> @constraint(model, X >= Y, PSDCone())
[X[1,1] - 1 X[1,2] - 2;
[X[1,1] - 1 X[1,2] - 2
X[2,1] - 2 X[2,2] - 1] ∈ PSDCone()
```

Expand All @@ -1461,15 +1461,15 @@ julia> Z = [X[1, 1] X[1, 2]; X[1, 2] X[2, 2]]
X[1,2] X[2,2]
julia> @constraint(model, LinearAlgebra.Symmetric(Z) >= 0, PSDCone())
[X[1,1] X[1,2];
[X[1,1] X[1,2]
X[1,2] X[2,2]] ∈ PSDCone()
```

Note that the lower triangular entries are ignored even if they are
different so use it with caution:
```jldoctest con_psd
julia> @constraint(model, LinearAlgebra.Symmetric(X) >= 0, PSDCone())
[X[1,1] X[1,2];
[X[1,1] X[1,2]
X[1,2] X[2,2]] ∈ PSDCone()
```
(Note the `(2, 1)` element of the constraint is `X[1,2]`, not `X[2,1]`.)
Expand Down
19 changes: 6 additions & 13 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,15 @@ function function_string(
::MIME"text/plain",
A::AbstractMatrix{<:AbstractJuMPScalar},
)
str = sprint(show, MIME"text/plain"(), A)
str = sprint() do io
return show(IOContext(io, :limit => true), MIME("text/plain"), A)
end
lines = split(str, '\n')
# We drop the first line with the signature "m×n Array{...}:"
lines = lines[2:end]
popfirst!(lines)
# We replace the first space by an opening `[`
lines[1] = '[' * lines[1][2:end]
for i in 1:length(lines)
lines[i] = lines[i] * (i == length(lines) ? ']' : ';')
end
return join(lines, '\n')
return join(lines, "\n") * "]"
end

function function_string(
Expand Down Expand Up @@ -933,13 +932,7 @@ function constraint_string(mode, constraint_object::AbstractConstraint)
# Leave `mode` untyped to avoid ambiguities!
func_str = function_string(mode, constraint_object)
in_set_str = in_set_string(mode, constraint_object)
if mode == MIME("text/plain")
lines = split(func_str, '\n')
lines[1+div(length(lines), 2)] *= " " * in_set_str
return join(lines, '\n')
else
return func_str * " " * in_set_str
end
return func_str * " " * in_set_str
end

function constraint_string(
Expand Down
17 changes: 7 additions & 10 deletions src/sd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,14 @@ Consider the following example:
```jldoctest PSDCone
julia> model = Model();
julia> @variable(model, x)
x
julia> @variable(model, x);
julia> a = [ x 2x
2x x];
julia> a = [x 2x; 2x x];
julia> b = [1 2
2 4];
julia> b = [1 2; 2 4];
julia> cref = @constraint(model, a >= b, PSDCone())
[x - 1 2 x - 2;
[x - 1 2 x - 2
2 x - 2 x - 4] ∈ PSDCone()
julia> jump_function(constraint_object(cref))
Expand All @@ -119,7 +116,7 @@ is constrained to belong to the `PositiveSemidefiniteConeSquare`.
julia> using LinearAlgebra # For Symmetric
julia> cref = @constraint(model, Symmetric(a - b) in PSDCone())
[x - 1 2 x - 2;
[x - 1 2 x - 2
2 x - 2 x - 4] ∈ PSDCone()
julia> jump_function(constraint_object(cref))
Expand Down Expand Up @@ -384,7 +381,7 @@ julia> model = Model();
julia> @variable(model, Q[1:2, 1:2]);
julia> @constraint(model, LinearAlgebra.Symmetric(Q) in PSDCone())
[Q[1,1] Q[1,2];
[Q[1,1] Q[1,2]
Q[1,2] Q[2,2]] ∈ PSDCone()
```
Expand All @@ -400,7 +397,7 @@ julia> @variable(model, Q[1:2, 1:2], Symmetric)
Q[1,2] Q[2,2]
julia> @constraint(model, Q in PSDCone())
[Q[1,1] Q[1,2];
[Q[1,1] Q[1,2]
Q[1,2] Q[2,2]] ∈ PSDCone()
```
"""
Expand Down

0 comments on commit 08713fa

Please sign in to comment.