Skip to content

Commit c39bbd3

Browse files
authored
[docs] use VariableInSetRef in the tutorials (#3960)
1 parent 3829fb2 commit c39bbd3

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

docs/src/manual/variables.md

+15
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,21 @@ nonnegative.
11011101
`x` must be a square 2-dimensional `Array` of JuMP variables; it cannot be a
11021102
DenseAxisArray or a SparseAxisArray.
11031103

1104+
Use [`VariableInSetRef`](@ref) to obtain the associated constraint reference:
1105+
1106+
```jldoctest
1107+
julia> model = Model();
1108+
1109+
julia> @variable(model, x[1:2, 1:2], PSD)
1110+
2×2 LinearAlgebra.Symmetric{VariableRef, Matrix{VariableRef}}:
1111+
x[1,1] x[1,2]
1112+
x[1,2] x[2,2]
1113+
1114+
julia> c = VariableInSetRef(x)
1115+
[x[1,1] x[1,2]
1116+
⋯ x[2,2]] ∈ PSDCone()
1117+
```
1118+
11041119
The `PSD` argument must be provided explicitly to the macro. Passing it via a
11051120
variable throws an error:
11061121
```jldoctest

docs/src/tutorials/conic/dualization.jl

+26-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
using JuMP
2727
import Dualization
28+
import LinearAlgebra
2829
import SCS
2930

3031
# ## Background
@@ -116,7 +117,11 @@ print(model_primal)
116117
model_dual = Model()
117118
@variable(model_dual, y[1:2])
118119
@objective(model_dual, Min, sum(y))
119-
@constraint(model_dual, dual_c, [y[1]-1 1; 1 y[2]-1] in PSDCone())
120+
@constraint(
121+
model_dual,
122+
dual_c,
123+
LinearAlgebra.Symmetric([y[1]-1 1; 1 y[2]-1]) in PSDCone(),
124+
)
120125
print(model_dual)
121126

122127
# This problem has two scalar decision variables, and a 2x2 positive
@@ -141,7 +146,11 @@ assert_is_solved_and_feasible(model_primal; dual = true)
141146

142147
# The solution we obtain is:
143148

144-
value.(X)
149+
value(X)
150+
151+
#-
152+
153+
dual(VariableInSetRef(X))
145154

146155
#-
147156

@@ -161,7 +170,11 @@ assert_is_solved_and_feasible(model_dual; dual = true)
161170

162171
# and the solution we obtain is:
163172

164-
dual.(dual_c)
173+
dual(dual_c)
174+
175+
#-
176+
177+
value(dual_c)
165178

166179
#-
167180

@@ -192,7 +205,11 @@ assert_is_solved_and_feasible(model_primal; dual = true)
192205
# The performance is the same as if we solved `model_dual`, and the correct
193206
# solution is returned to `X`:
194207

195-
value.(X)
208+
value(X)
209+
210+
#-
211+
212+
dual(VariableInSetRef(X))
196213

197214
#-
198215

@@ -207,7 +224,11 @@ assert_is_solved_and_feasible(model_dual; dual = true)
207224

208225
#-
209226

210-
dual.(dual_c)
227+
dual(dual_c)
228+
229+
#-
230+
231+
value(dual_c)
211232

212233
#-
213234

0 commit comments

Comments
 (0)