Skip to content

Commit 6dbc375

Browse files
feat: respect array variable bounds in OptimizationSystem
1 parent 9017fbf commit 6dbc375

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/systems/optimization/optimizationsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ function OptimizationSystem(op, unknowns, ps;
101101
gui_metadata = nothing)
102102
name === nothing &&
103103
throw(ArgumentError("The `name` keyword must be provided. Please consider using the `@named` macro"))
104-
constraints = value.(scalarize(constraints))
105-
unknowns′ = value.(scalarize(unknowns))
104+
constraints = value.(reduce(vcat, scalarize(constraints); init = []))
105+
unknowns′ = value.(reduce(vcat, scalarize(unknowns); init = []))
106106
ps′ = value.(ps)
107107
op′ = value(scalarize(op))
108108

test/optimizationsystem.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,13 @@ end
358358
@mtkbuild sys = OptimizationSystem(obj, [x, y, z], []; constraints = cons)
359359
@test is_variable(sys, z)
360360
@test !is_variable(sys, y)
361+
362+
@variables x[1:3] [bounds = ([-Inf, -1.0, -2.0], [Inf, 1.0, 2.0])]
363+
obj = x[1]^2 + x[2]^2 + x[3]^2
364+
cons = [x[2] ~ 2x[1] + 3, x[3] ~ x[1] + x[2]]
365+
@mtkbuild sys = OptimizationSystem(obj, [x], []; constraints = cons)
366+
@test length(unknowns(sys)) == 2
367+
@test !is_variable(sys, x[1])
368+
@test is_variable(sys, x[2])
369+
@test is_variable(sys, x[3])
361370
end

0 commit comments

Comments
 (0)