Optimization.jl icon indicating copy to clipboard operation
Optimization.jl copied to clipboard

Documentation of set-up of inequality constraints to work with OptimizationMOI.jl

Open avinashresearch1 opened this issue 3 years ago • 0 comments

The way an optimization problem with inequality constraints (written symbolically using the OptimizationSystem functionality of ModelingToolkit) is translated into an OptimizationProblem and conveyed to the solver wrapper (for instance OptimizationMOI) is strange. Here is a MWE:

var = @variables H, V

objective =  abs2(V-1.2)
constraints = [
     V - 0.9 ~ 0.0
    (-2.0)*sqrt(H) + (5.0)*V ~ 0.0
]
lcons = [-Inf, 0.0]
ucons = [0.0, 0.0]
u0 = Dict(V=>0.4, H => 0.5)

@named opt_sys = OptimizationSystem(objective, var, []; constraints = constraints)
prob = OptimizationProblem(opt_sys, u0, []; lcons = lcons, ucons = ucons, grad = true, hess = true, sense = Optimization.MinSense)
sol = solve(prob, Ipopt.Optimizer())

The 1st constraint is supposed to be an inequality with V <= 0.9 or -Inf <= V -0.9 <= 0.0. However, running this code gives the Optimal Solution H = 9.0 and V = 1.2 which is infeasible.

The problem is fixed if the inequality constraint is set up on the RHS as follows, giving the correct answer.

var = @variables H, V

objective =  abs2(V-1.2)
constraints = [
     0.0  ~ V - 0.9
    (-2.0)*sqrt(H) + (5.0)*V ~ 0.0
]
lcons = [-Inf, 0.0]
ucons = [0.0, 0.0]
u0 = Dict(V=>0.4, H => 0.5)

@named opt_sys = OptimizationSystem(objective, var, []; constraints = constraints)
prob = OptimizationProblem(opt_sys, u0, []; lcons = lcons, ucons = ucons, grad = true, hess = true, sense = Optimization.MinSense)
sol = solve(prob, Ipopt.Optimizer())

If this is the intended usage, it would be helpful to make this clear in the documentation/examples. This issue only arises for inequality constraints not equality constraints.

avinashresearch1 avatar Jul 17 '22 11:07 avinashresearch1