@@ -1308,6 +1308,40 @@ julia> x = @variable(model, [1:3], set = SecondOrderCone())
1308
1308
You cannot delete the constraint associated with a variable constrained on
1309
1309
creation.
1310
1310
1311
+ To check if a variable was constrained on creation, use [ ` is_variable_in_set ` ] ( @ref ) ,
1312
+ and use [ ` VariableInSetRef ` ] ( @ref ) to obtain the associated constraint reference:
1313
+
1314
+ ``` jldoctest
1315
+ julia> model = Model();
1316
+
1317
+ julia> @variable(model, x[1:2, 1:2], PSD)
1318
+ 2×2 LinearAlgebra.Symmetric{VariableRef, Matrix{VariableRef}}:
1319
+ x[1,1] x[1,2]
1320
+ x[1,2] x[2,2]
1321
+
1322
+ julia> is_variable_in_set(x)
1323
+ true
1324
+
1325
+ julia> c = VariableInSetRef(x)
1326
+ [x[1,1] x[1,2]
1327
+ ⋯ x[2,2]] ∈ PSDCone()
1328
+
1329
+ julia> @variable(model, y)
1330
+ y
1331
+
1332
+ julia> is_variable_in_set(y)
1333
+ false
1334
+
1335
+ julia> @variable(model, z in Semicontinuous(1, 2))
1336
+ z
1337
+
1338
+ julia> is_variable_in_set(z)
1339
+ true
1340
+
1341
+ julia> c_z = VariableInSetRef(z)
1342
+ z ∈ MathOptInterface.Semicontinuous{Int64}(1, 2)
1343
+ ```
1344
+
1311
1345
### Example: positive semidefinite variables
1312
1346
1313
1347
An alternative to the syntax in [ Semidefinite variables] ( @ref ) , declare a matrix
@@ -1384,8 +1418,21 @@ julia> @variable(model, H[1:2, 1:2] in HermitianPSDCone())
1384
1418
This adds 4 real variables in the [ ` MOI.HermitianPositiveSemidefiniteConeTriangle ` ] ( @ref ) :
1385
1419
1386
1420
``` jldoctest hermitian_psd
1387
- julia> first(all_constraints(model, Vector{VariableRef}, MOI.HermitianPositiveSemidefiniteConeTriangle))
1388
- [real(H[1,1]), real(H[1,2]), real(H[2,2]), imag(H[1,2])] ∈ MathOptInterface.HermitianPositiveSemidefiniteConeTriangle(2)
1421
+ julia> c = VariableInSetRef(H)
1422
+ [real(H[1,1]) real(H[1,2]) + imag(H[1,2]) im
1423
+ real(H[1,2]) - imag(H[1,2]) im real(H[2,2])] ∈ HermitianPSDCone()
1424
+
1425
+ julia> o = constraint_object(c);
1426
+
1427
+ julia> o.func
1428
+ 4-element Vector{VariableRef}:
1429
+ real(H[1,1])
1430
+ real(H[1,2])
1431
+ real(H[2,2])
1432
+ imag(H[1,2])
1433
+
1434
+ julia> o.set
1435
+ MathOptInterface.HermitianPositiveSemidefiniteConeTriangle(2)
1389
1436
```
1390
1437
1391
1438
### Example: Hermitian variables
0 commit comments