121121 @variable (tb. model, d)
122122 @variable (tb. model, e)
123123 @variable (tb. model, f)
124+ @variable (tb. model, p1a in Parameter (sin (0 )))
125+ @variable (tb. model, p1b in Parameter (sin (0.5 )))
126+ @variable (tb. model, p1c in Parameter (sin (1 )))
127+ @variable (tb. model, p2a in Parameter (1 ))
128+ @variable (tb. model, p2b in Parameter (1 ))
129+ @variable (tb. model, p2c in Parameter (1 ))
130+ @variable (tb. model, p2d in Parameter (1 ))
131+ @variable (tb. model, p2e in Parameter (1 ))
132+ @variable (tb. model, p2f in Parameter (1 ))
124133 # test _ignore_label
125134 @testset " _ignore_label" begin
126135 @test IOTO. _ignore_label (tb, All)
@@ -156,10 +165,20 @@ end
156165 end
157166 # test IOTO.transcription_variable (Parameter Function)
158167 @testset " IOTO.transcription_variable (Parameter Function)" begin
168+ # test error
169+ @test_throws ErrorException IOTO. transcription_variable (f1, tb)
170+ @test_throws ErrorException IOTO. transcription_variable (f2, tb)
159171 # test normal
160- @test IOTO. transcription_variable (f1, tb) == [sin (0 ), sin (1 )]
161- @test IOTO. transcription_variable (f1, tb, label = All) == sin .([0 , 0.5 , 1 ])
162- @test IOTO. transcription_variable (f2, tb) == ones (2 , 2 )
172+ data. infvar_mappings[f1] = [p1a, p1b, p1c]
173+ data. infvar_mappings[f2] = [p2a p2b; p2c p2d; p2e p2f]
174+ @test JuMP. parameter_value .([p1a, p1b, p1c]) == sin .([0. , 0.5 , 1. ])
175+ @test JuMP. parameter_value .([p2a p2b; p2c p2d; p2e p2f]) == ones (3 , 2 )
176+ @test IOTO. transcription_variable (f1, tb) isa Vector{JuMP. VariableRef}
177+ @test IOTO. transcription_variable (f1, tb) == [p1a, p1c]
178+ @test IOTO. transcription_variable (f1, tb, label = All) == [p1a, p1b, p1c]
179+ @test IOTO. transcription_variable (f2, tb) isa Matrix{JuMP. VariableRef}
180+ @test IOTO. transcription_variable (f2, tb) == [p2a p2b; p2e p2f]
181+ @test IOTO. transcription_variable (f2, tb, label = All) == [p2a p2b; p2c p2d; p2e p2f]
163182 end
164183 # test IOTO.transcription_variable (Fallback)
165184 @testset " IOTO.transcription_variable (Fallback)" begin
170189 @test IOTO. transcription_variable (y) == a
171190 @test IOTO. transcription_variable (x, label = All) == [a b; c d; e f]
172191 @test IOTO. transcription_variable (x0) == a
173- @test IOTO. transcription_variable (f2) == ones ( 2 , 2 )
192+ @test IOTO. transcription_variable (f2) == [p2a p2b; p2e p2f]
174193 end
175194 # test transformation_variable extension
176195 @testset " transformation_variable" begin
247266 end
248267 # test lookup_by_support (infinite parameter functions)
249268 @testset " lookup_by_support (Parameter Function)" begin
250- @test IOTO. lookup_by_support (f1, tb, [0. ]) == 0
251- @test IOTO. lookup_by_support (f2, tb, [0. , 0. , 1. ]) == 1
269+ lookups = Dict {Vector{Float64}, VariableRef} (
270+ [0. ] => p1a,
271+ [0.5 ] => p1b,
272+ [1. ] => p1c
273+ )
274+ data. infvar_lookup[f1] = lookups
275+ lookups = Dict {Vector{Float64}, VariableRef} (
276+ [0. , 0. , 0. ] => p2a,
277+ [0.5 , 0. , 0. ] => p2b,
278+ [1. , 0. , 0. ] => p2c,
279+ [0. , 1. , 1. ] => p2d,
280+ [0.5 , 1. , 1. ] => p2e,
281+ [1. , 1. , 1. ] => p2f
282+ )
283+ data. infvar_lookup[f2] = lookups
284+ # test errors
285+ @test_throws ErrorException IOTO. lookup_by_support (f1, tb, [0.75 ])
286+ @test_throws ErrorException IOTO. lookup_by_support (f2, tb, [0. , 0. , 1. ])
287+ # test normal
288+ @test IOTO. lookup_by_support (f1, tb, [0. ]) == p1a
289+ @test IOTO. lookup_by_support (f1, tb, [0.5 ]) == p1b
290+ @test IOTO. lookup_by_support (f1, tb, [1. ]) == p1c
291+ @test IOTO. lookup_by_support (f2, tb, [0.5 , 0. , 0. ]) == p2b
292+ @test IOTO. lookup_by_support (f2, tb, [0.5 , 1. , 1. ]) == p2e
252293 end
253294 # test lookup_by_support (finite vars)
254295 @testset " lookup_by_support (Finite)" begin
@@ -405,15 +446,19 @@ end
405446 @variable (tb. model, c)
406447 @variable (tb. model, d)
407448 @variable (tb. model, e in Parameter (42 ))
449+ @variable (tb. model, pf1 in Parameter (1 ))
450+ @variable (tb. model, pf2 in Parameter (1 ))
408451 # transcribe the variables and measures
409452 data = IOTO. transcription_data (tb)
410453 data. finvar_mappings[y] = a
411454 data. finvar_mappings[x0] = a
412455 data. finvar_mappings[finpar] = e
456+ data. infvar_mappings[f] = [pf1, pf2]
413457 data. infvar_mappings[x] = reshape ([a, b], :, 1 )
414458 data. measure_mappings[meas1] = fill (- 2 * zero (AffExpr))
415459 data. measure_mappings[meas2] = [a^ 2 + c^ 2 - 2 a, b^ 2 + d^ 2 - 2 a]
416460 data. infvar_lookup[x] = Dict ([0 , 0 , 0 ] => a, [1 , 0 , 0 ] => b)
461+ data. infvar_lookup[f] = Dict ([0 , 0 , 0 ] => pf1, [1 , 0 , 0 ] => pf2)
417462 data. measure_lookup[meas1] = Dict (Float64[] => 1 )
418463 data. measure_lookup[meas2] = Dict ([0 ] => 1 , [1 ] => 2 )
419464 @test IOTO. set_parameter_supports (tb, m) isa Nothing
@@ -425,14 +470,16 @@ end
425470 @testset " IOTO.transcription_expression (Infinite Variable)" begin
426471 @test IOTO. transcription_expression (x, tb, [0. , 0. , 0. ]) == a
427472 @test IOTO. transcription_expression (meas1, tb, [0. , 0. , 1. ]) == - 2 * zero (AffExpr)
428- @test IOTO. transcription_expression (f, tb, [0. , 0. , 1. ]) == 1
473+ @test IOTO. transcription_expression (f, tb, [0. , 0. , 1. ]) == pf2
429474 end
430475 # test transcription expression for semi_infinite variables with 3 args
431476 @testset " IOTO.transcription_expression (Semi-Infinite Variable)" begin
432477 # semi_infinite of parameter function
433478 rv = add_variable (m, build_variable (error, f, Dict (1 => 1. )),
434479 add_support = false )
435- @test IOTO. transcription_expression (rv, tb, [0. , 0. , 1. ]) == 1
480+ data. infvar_mappings[rv] = [pf2]
481+ data. infvar_lookup[rv] = Dict ([0 , 0 ] => pf2)
482+ @test IOTO. transcription_expression (rv, tb, [0. , 0. , 1. ]) == pf2
436483 # semi_infinite of infinite variable
437484 rv = add_variable (m, build_variable (error, x, Dict (1 => 1. )),
438485 add_support = false )
0 commit comments