@@ -22,8 +22,8 @@ Utility functions for identifying variables that participate in constraints.
22
22
23
23
"""
24
24
25
- import JuMP as jmp
26
- import MathOptInterface as moi
25
+ import JuMP
26
+ import MathOptInterface as MOI
27
27
28
28
import JuMPIn: get_equality_constraints
29
29
@@ -63,8 +63,8 @@ julia> display(vars)
63
63
function identify_unique_variables (
64
64
constraints:: Vector ,
65
65
# FIXME : Couldn't get this working with Vector{ConstraintRef}...
66
- ):: Vector{jmp .VariableRef}
67
- variables = Vector {jmp .VariableRef} ()
66
+ ):: Vector{JuMP .VariableRef}
67
+ variables = Vector {JuMP .VariableRef} ()
68
68
for con in constraints
69
69
append! (variables, identify_unique_variables (con))
70
70
end
@@ -81,14 +81,14 @@ Each variable appears at most one time in the returned vector.
81
81
82
82
"""
83
83
function identify_unique_variables (
84
- model:: jmp .Model ; include_inequality:: Bool = false ,
85
- ):: Vector{jmp .VariableRef}
84
+ model:: JuMP .Model ; include_inequality:: Bool = false ,
85
+ ):: Vector{JuMP .VariableRef}
86
86
if include_inequality
87
87
# Note that this may include some constraints which are not compatible
88
88
# with downstream function calls (e.g. constraints where the function
89
89
# and terms are vectors). We will allow downstream errors to be raised
90
90
# rather than silently ignoring these constraints.
91
- constraints = jmp . all_constraints (
91
+ constraints = JuMP . all_constraints (
92
92
model,
93
93
# TODO : Should this be an optional argument to this function?
94
94
include_variable_in_set_constraints= false ,
@@ -109,8 +109,8 @@ Each variable appears at most one time in the returned vector.
109
109
110
110
"""
111
111
function identify_unique_variables (
112
- constraint:: jmp .ConstraintRef ,
113
- ):: Vector{jmp .VariableRef}
112
+ constraint:: JuMP .ConstraintRef ,
113
+ ):: Vector{JuMP .VariableRef}
114
114
return identify_unique_variables (constraint, constraint. index)
115
115
end
116
116
@@ -129,13 +129,13 @@ constraint or a nonlinear constraint.
129
129
130
130
"""
131
131
function identify_unique_variables (
132
- constraint:: jmp .ConstraintRef ,
133
- index:: moi .ConstraintIndex ,
134
- ):: Vector{jmp .VariableRef}
132
+ constraint:: JuMP .ConstraintRef ,
133
+ index:: MOI .ConstraintIndex ,
134
+ ):: Vector{JuMP .VariableRef}
135
135
model = constraint. model
136
- fcn = moi . get (model, moi . ConstraintFunction (), constraint)
136
+ fcn = MOI . get (model, MOI . ConstraintFunction (), constraint)
137
137
varidxs = identify_unique_variables (fcn)
138
- varrefs = [jmp . VariableRef (model, idx) for idx in varidxs]
138
+ varrefs = [JuMP . VariableRef (model, idx) for idx in varidxs]
139
139
return varrefs
140
140
end
141
141
@@ -154,9 +154,9 @@ constraint or a nonlinear constraint.
154
154
155
155
"""
156
156
function identify_unique_variables (
157
- constraint:: jmp .ConstraintRef ,
158
- index:: moi .Nonlinear.ConstraintIndex ,
159
- ):: Vector{jmp .VariableRef}
157
+ constraint:: JuMP .ConstraintRef ,
158
+ index:: MOI .Nonlinear.ConstraintIndex ,
159
+ ):: Vector{JuMP .VariableRef}
160
160
model = constraint. model
161
161
nlmod = model. nlp_model
162
162
nlcons = nlmod. constraints
@@ -167,11 +167,11 @@ function identify_unique_variables(
167
167
# This could be its own function, but I inlined it here to allow a more
168
168
# useful error message if we ever encounter NODE_VARIABLE.
169
169
# Will be moved when/if the need arises.
170
- variables = Vector {moi .VariableIndex} ()
170
+ variables = Vector {MOI .VariableIndex} ()
171
171
for node in expr. nodes
172
- if node. type == moi . Nonlinear. NODE_MOI_VARIABLE
173
- push! (variables, moi . VariableIndex (node. index))
174
- elseif node. type == moi . Nonlinear. NODE_VARIABLE
172
+ if node. type == MOI . Nonlinear. NODE_MOI_VARIABLE
173
+ push! (variables, MOI . VariableIndex (node. index))
174
+ elseif node. type == MOI . Nonlinear. NODE_VARIABLE
175
175
# I do not know under what situation this could occur, but
176
176
# am throwing this error to be defensive.
177
177
throw (DomainError (
@@ -185,7 +185,7 @@ function identify_unique_variables(
185
185
end
186
186
187
187
# Return VariableRefs
188
- refs = [jmp . VariableRef (model, idx) for idx in variables]
188
+ refs = [JuMP . VariableRef (model, idx) for idx in variables]
189
189
return _filter_duplicates (refs)
190
190
end
191
191
@@ -204,9 +204,9 @@ function should be implemented.
204
204
205
205
"""
206
206
function identify_unique_variables (
207
- fcn:: Union{moi .ScalarQuadraticFunction, moi .ScalarAffineFunction} ,
208
- ):: Vector{moi .VariableIndex}
209
- variables = Vector {moi .VariableIndex} ()
207
+ fcn:: Union{MOI .ScalarQuadraticFunction, MOI .ScalarAffineFunction} ,
208
+ ):: Vector{MOI .VariableIndex}
209
+ variables = Vector {MOI .VariableIndex} ()
210
210
for terms in _get_variable_terms (fcn)
211
211
for term in terms
212
212
for var in identify_unique_variables (term)
@@ -219,10 +219,10 @@ end
219
219
220
220
function identify_unique_variables (
221
221
fcn:: T
222
- ):: Vector{moi .VariableIndex} where {T<: moi .AbstractVectorFunction }
222
+ ):: Vector{MOI .VariableIndex} where {T<: MOI .AbstractVectorFunction }
223
223
throw (TypeError (
224
224
fcn,
225
- Union{moi . ScalarQuadraticFunction, moi . ScalarAffineFunction},
225
+ Union{MOI . ScalarQuadraticFunction, MOI . ScalarAffineFunction},
226
226
typeof (fcn),
227
227
))
228
228
end
@@ -238,11 +238,11 @@ Currently implemented only for `ScalarQuadraticFunction` and
238
238
`ScalarAffineFunction`.
239
239
240
240
"""
241
- function _get_variable_terms (fcn:: moi .ScalarQuadraticFunction )
241
+ function _get_variable_terms (fcn:: MOI .ScalarQuadraticFunction )
242
242
return (fcn. quadratic_terms, fcn. affine_terms)
243
243
end
244
244
245
- function _get_variable_terms (fcn:: moi .ScalarAffineFunction )
245
+ function _get_variable_terms (fcn:: MOI .ScalarAffineFunction )
246
246
return (fcn. terms,)
247
247
end
248
248
@@ -260,14 +260,14 @@ Currently implemented only for `ScalarAffineTerm` and `ScalarQuadraticTerm`.
260
260
261
261
"""
262
262
function identify_unique_variables (
263
- term:: moi .ScalarAffineTerm ,
264
- ):: Vector{moi .VariableIndex}
263
+ term:: MOI .ScalarAffineTerm ,
264
+ ):: Vector{MOI .VariableIndex}
265
265
return [term. variable]
266
266
end
267
267
268
268
function identify_unique_variables (
269
- term:: moi .ScalarQuadraticTerm ,
270
- ):: Vector{moi .VariableIndex}
269
+ term:: MOI .ScalarQuadraticTerm ,
270
+ ):: Vector{MOI .VariableIndex}
271
271
# Note that this compares indices only. If somehow these indices refer to
272
272
# different models, this could be incorrect.
273
273
if term. variable_1 === term. variable_2
@@ -285,12 +285,12 @@ Return a vector of variables of indices that does not contain duplicates.
285
285
286
286
"""
287
287
function _filter_duplicates (
288
- indices:: Vector{moi .VariableIndex} ,
289
- ):: Vector{moi .VariableIndex}
288
+ indices:: Vector{MOI .VariableIndex} ,
289
+ ):: Vector{MOI .VariableIndex}
290
290
# Note that by hashing only the variable index, we implicitly assume that
291
291
# all variables come from the same model. I believe this is safe.
292
- seen = Set {moi .VariableIndex} ()
293
- filtered = Vector {moi .VariableIndex} ()
292
+ seen = Set {MOI .VariableIndex} ()
293
+ filtered = Vector {MOI .VariableIndex} ()
294
294
for idx in indices
295
295
if ! (idx in seen)
296
296
push! (seen, idx)
@@ -302,12 +302,12 @@ end
302
302
303
303
304
304
function _filter_duplicates (
305
- variables:: Vector{jmp .VariableRef} ,
306
- ):: Vector{jmp .VariableRef}
305
+ variables:: Vector{JuMP .VariableRef} ,
306
+ ):: Vector{JuMP .VariableRef}
307
307
# What happens when VariableRef gets hashed? I.e. how is the
308
308
# hash of the model computed?
309
- seen = Set {jmp .VariableRef} ()
310
- filtered = Vector {jmp .VariableRef} ()
309
+ seen = Set {JuMP .VariableRef} ()
310
+ filtered = Vector {JuMP .VariableRef} ()
311
311
for var in variables
312
312
if ! (var in seen)
313
313
push! (seen, var)
0 commit comments