@@ -139,7 +139,7 @@ function transcribe_infinite_variables!(
139
139
vrefs = Array {JuMP.VariableRef, length(dims)} (undef, dims... )
140
140
supp_type = typeof (Tuple (ones (length (prefs)), prefs))
141
141
supps = Array {supp_type, length(dims)} (undef, dims... )
142
- lookup_dict = Dict {Vector{Float64}, JuMP.VariableRef} ()
142
+ lookup_dict = sizehint! ( Dict {Vector{Float64}, JuMP.VariableRef} (), length (vrefs) )
143
143
# create a variable for each support
144
144
for i in supp_indices
145
145
supp = index_to_support (backend, i)[param_nums]
@@ -190,7 +190,7 @@ function _transcribe_derivative_variable(dref, d, backend)
190
190
vrefs = Array {JuMP.VariableRef, length(dims)} (undef, dims... )
191
191
supp_type = typeof (Tuple (ones (length (prefs)), prefs))
192
192
supps = Array {supp_type, length(dims)} (undef, dims... )
193
- lookup_dict = Dict {Vector{Float64}, JuMP.VariableRef} ()
193
+ lookup_dict = sizehint! ( Dict {Vector{Float64}, JuMP.VariableRef} (), length (vrefs) )
194
194
# create a variable for each support
195
195
for i in supp_indices
196
196
supp = index_to_support (backend, i)[param_nums]
@@ -255,69 +255,6 @@ function transcribe_derivative_variables!(
255
255
return
256
256
end
257
257
258
- # Setup the mapping for a given semi_infinite variable
259
- function _set_semi_infinite_variable_mapping (
260
- backend:: TranscriptionBackend ,
261
- var:: InfiniteOpt.SemiInfiniteVariable ,
262
- rvref:: InfiniteOpt.GeneralVariableRef ,
263
- index_type
264
- )
265
- param_nums = var. parameter_nums
266
- ivref = var. infinite_variable_ref
267
- ivref_param_nums = InfiniteOpt. _parameter_numbers (ivref)
268
- eval_supps = var. eval_supports
269
- group_idxs = var. group_int_idxs
270
- prefs = InfiniteOpt. raw_parameter_refs (var)
271
- # prepare for iterating over its supports
272
- supp_indices = support_index_iterator (backend, group_idxs)
273
- dims = size (supp_indices)[group_idxs]
274
- vrefs = Array {JuMP.VariableRef, length(dims)} (undef, dims... )
275
- supp_type = typeof (Tuple (ones (length (prefs)), prefs))
276
- supps = Array {supp_type, length(dims)} (undef, dims... )
277
- lookup_dict = Dict {Vector{Float64}, JuMP.VariableRef} ()
278
- valid_idxs = ones (Bool, dims... )
279
- # map a variable for each support
280
- for i in supp_indices
281
- raw_supp = index_to_support (backend, i)
282
- var_idx = i. I[group_idxs]
283
- # ensure this support is valid with the reduced restriction
284
- if any (! isnan (raw_supp[ivref_param_nums[k]]) && raw_supp[ivref_param_nums[k]] != v for (k, v) in eval_supps)
285
- valid_idxs[var_idx... ] = false
286
- continue
287
- end
288
- # map to the current transcription variable
289
- supp = raw_supp[param_nums]
290
- ivref_supp = [haskey (eval_supps, j) ? eval_supps[j] : raw_supp[k]
291
- for (j, k) in enumerate (ivref_param_nums)]
292
- jump_vref = lookup_by_support (ivref, backend, ivref_supp)
293
- @inbounds vrefs[var_idx... ] = jump_vref
294
- lookup_dict[supp] = jump_vref
295
- @inbounds supps[var_idx... ] = Tuple (supp, prefs)
296
- end
297
- # truncate vrefs if any supports were skipped because of dependent parameter supps and save
298
- data = transcription_data (backend)
299
- if ! all (valid_idxs)
300
- data. infvar_mappings[rvref] = vrefs[valid_idxs]
301
- data. infvar_supports[rvref] = supps[valid_idxs]
302
- data. valid_indices[rvref] = valid_idxs
303
- else
304
- data. infvar_mappings[rvref] = vrefs
305
- data. infvar_supports[rvref] = supps
306
- end
307
- data. infvar_lookup[rvref] = lookup_dict
308
- return
309
- end
310
-
311
- # Empty mapping dispatch for infinite parameter functions
312
- function _set_semi_infinite_variable_mapping (
313
- backend:: TranscriptionBackend ,
314
- var:: InfiniteOpt.SemiInfiniteVariable ,
315
- rvref:: InfiniteOpt.GeneralVariableRef ,
316
- index_type:: Type{InfiniteOpt.ParameterFunctionIndex}
317
- )
318
- return
319
- end
320
-
321
258
"""
322
259
transcribe_semi_infinite_variables!(
323
260
backend::TranscriptionBackend,
@@ -342,8 +279,51 @@ function transcribe_semi_infinite_variables!(
342
279
var = object. variable
343
280
rvref = InfiniteOpt. GeneralVariableRef (model, idx)
344
281
# setup the mappings
345
- idx_type = InfiniteOpt. _index_type (InfiniteOpt. infinite_variable_ref (rvref))
346
- _set_semi_infinite_variable_mapping (backend, var, rvref, idx_type)
282
+ ivref = var. infinite_variable_ref
283
+ if InfiniteOpt. _index_type (ivref) != InfiniteOpt. ParameterFunctionIndex
284
+ param_nums = var. parameter_nums
285
+ ivref_param_nums = InfiniteOpt. _parameter_numbers (ivref)
286
+ eval_supps = var. eval_supports
287
+ group_idxs = var. group_int_idxs
288
+ prefs = InfiniteOpt. raw_parameter_refs (var)
289
+ # prepare for iterating over its supports
290
+ supp_indices = support_index_iterator (backend, group_idxs)
291
+ dims = size (supp_indices)[group_idxs]
292
+ vrefs = Array {JuMP.VariableRef, length(dims)} (undef, dims... )
293
+ supp_type = typeof (Tuple (ones (length (prefs)), prefs))
294
+ supps = Array {supp_type, length(dims)} (undef, dims... )
295
+ lookup_dict = sizehint! (Dict {Vector{Float64}, JuMP.VariableRef} (), length (vrefs))
296
+ valid_idxs = ones (Bool, dims... )
297
+ # map a variable for each support
298
+ for i in supp_indices
299
+ raw_supp = index_to_support (backend, i)
300
+ var_idx = i. I[group_idxs]
301
+ # ensure this support is valid with the reduced restriction
302
+ if any (! isnan (raw_supp[ivref_param_nums[k]]) && raw_supp[ivref_param_nums[k]] != v for (k, v) in eval_supps)
303
+ valid_idxs[var_idx... ] = false
304
+ continue
305
+ end
306
+ # map to the current transcription variable
307
+ supp = raw_supp[param_nums]
308
+ ivref_supp = [haskey (eval_supps, j) ? eval_supps[j] : raw_supp[k]
309
+ for (j, k) in enumerate (ivref_param_nums)]
310
+ jump_vref = lookup_by_support (ivref, backend, ivref_supp)
311
+ @inbounds vrefs[var_idx... ] = jump_vref
312
+ lookup_dict[supp] = jump_vref
313
+ @inbounds supps[var_idx... ] = Tuple (supp, prefs)
314
+ end
315
+ # truncate vrefs if any supports were skipped because of dependent parameter supps and save
316
+ data = transcription_data (backend)
317
+ if ! all (valid_idxs)
318
+ data. infvar_mappings[rvref] = vrefs[valid_idxs]
319
+ data. infvar_supports[rvref] = supps[valid_idxs]
320
+ data. valid_indices[rvref] = valid_idxs
321
+ else
322
+ data. infvar_mappings[rvref] = vrefs
323
+ data. infvar_supports[rvref] = supps
324
+ end
325
+ data. infvar_lookup[rvref] = lookup_dict
326
+ end
347
327
end
348
328
return
349
329
end
@@ -570,7 +550,7 @@ function transcribe_measures!(
570
550
exprs = Array {JuMP.AbstractJuMPScalar, length(dims)} (undef, dims... )
571
551
supp_type = typeof (Tuple (ones (length (prefs)), prefs))
572
552
supps = Array {supp_type, length(dims)} (undef, dims... )
573
- lookup_dict = Dict {Vector{Float64}, Int} ()
553
+ lookup_dict = sizehint! ( Dict {Vector{Float64}, Int} (), length (exprs) )
574
554
# map a variable for each support
575
555
for (lin_idx, i) in enumerate (supp_indices)
576
556
raw_supp = index_to_support (backend, i)
0 commit comments