I’m trying to find a way to obtain the dependent variables of a nonlinear system as GenericAffExpr, expressed as a function only of the independent variables of an optimization problem.
To be more precise, I have a nonlinear problem with independent variables x. The objective function is a function of both x and other dependent variables y. In order to compute the OF, is necessary to obtain the expressions of y in function of x (in type GenericAffExpr, I suppose).
These y can be found by solving a nonlinear system of equations and to do that, I wrote a second optimization model that (in my intentions) should execute this task.
To be clearer, below is reported a minimal example of what I would like to do.
using JuMP, Ipopt # define optimization problem with independent variables (x) m = Model(Ipopt.Optimizer) @variable(m, x[1:2]) # solve nonlinear system to find dependent variables (y) p = Model(Ipopt.Optimizer) @variable(p, y[1:2]) @NLconstraint(p, x * y * y == 2) @NLconstraint(p, x * y * y == 5) @objective(p, 0.0) JuMP.optimize!(p) # solve original problem @NLobjective(m, x + x^2 + sum(y)) JuMP.optimize!(m)
However, trying to define the ‘inner’ optimization p, JuMP provides the error Variable in nonlinear expression does not belong to the corresponding model in correspondence of the first @NLconstraint, since the variables x are inserted in the problem p but belong to the problem m.
My question is: does anyone know if exist a suitable way to solve this issue? Or, does exist another strategy to reach my purpose?
Thank you in advance for your help.