Skip to content

Commit c1a01df

Browse files
Merge pull request #2040 from SciML/osmtkizecons
Fix the if statements to add symbolic constraints in `modelingtoolkitize` of `OptimizationProblem`
2 parents 80f0752 + f945acc commit c1a01df

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/systems/optimization/modelingtoolkitize.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,25 @@ function modelingtoolkitize(prob::DiffEqBase.OptimizationProblem; kwargs...)
2525

2626
if !isnothing(prob.lcons)
2727
for i in 1:num_cons
28-
!isinf(prob.lcons[i]) && prob.lcons[i] !== prob.ucons[i] &&
29-
push!(cons, prob.lcons[i] lhs[i])
30-
if !isinf(prob.ucons[i])
31-
prob.lcons[i] == prob.ucons[i] ? push!(cons, lhs[i] ~ prob.ucons[i]) :
32-
push!(cons, lhs[i] prob.ucons[i])
28+
if !isinf(prob.lcons[i])
29+
if prob.lcons[i] != prob.ucons[i] &&
30+
push!(cons, prob.lcons[i] lhs[i])
31+
else
32+
push!(cons, lhs[i] ~ prob.ucons[i])
33+
end
3334
end
3435
end
3536
end
3637

3738
if !isnothing(prob.ucons)
3839
for i in 1:num_cons
39-
if !isinf(prob.ucons[i])
40-
prob.lcons[i] == prob.ucons[i] ? push!(cons, lhs[i] ~ prob.ucons[i]) :
40+
if !isinf(prob.ucons[i]) && prob.lcons[i] != prob.ucons[i]
4141
push!(cons, lhs[i] prob.ucons[i])
4242
end
4343
end
4444
end
45-
46-
if (isnothing(prob.lcons) || all(isinf.(prob.lcons))) &&
47-
(isnothing(prob.ucons) || all(isinf.(prob.ucons)))
45+
if (isnothing(prob.lcons) || all(isinf, prob.lcons)) &&
46+
(isnothing(prob.ucons) || all(isinf, prob.ucons))
4847
throw(ArgumentError("Constraints passed have no proper bounds defined.
4948
Ensure you pass equal bounds (the scalar that the constraint should evaluate to) for equality constraints
5049
or pass the lower and upper bounds for inequality constraints."))

0 commit comments

Comments
 (0)