Loops "for" and "while" in JuMP

Hi, I’m working with JuMP and I want to modify expressions in my model within a while or for loop, and I have problems using the “input” command. When I modify a Julia variable, which is a coefficient in a JuMP NLexpression and de code reload the JuMP model, the error appears. For example:

for i=1:2

model = Model(with_optimizer(Ipopt.Optimizer))

variable(model, empleo, start = 0.1)

@NLexpression(model, er1, -empleo + c1_0 + c1_1 * out + c1_2 * stock_k + c1_3 *((1+wage)/(1+domP) -1) + c1_4 * empleo0)

@NLobjective(model, Min, er1^2 +er2^2)

optimize!(model)

println(“El Empleo creció:”,value(empleo))

c1_1= parse(Float64, input2("si desea modificar la inversión pública ingrese la tasa de variación y presione enter: "))

end

c1_1 is a coefficient in the first NLexpression

thanks in advance!

I’m not 100% sure about what you’re asking here, but it seems like you want to allow a user to input a new value to c1_1, then solve the model again?

If so, you need to make c1_1 a NLParameter.

Perhaps something like this:

@NLparameter(model, c1_1 == 0.1)

for i=1:2 

...

user_value = parse(Float64, input2("si desea modificar la inversión pública ingrese la tasa de variación y presione enter: "))

set_value(c1_1, user_value)

Please take the time to read Please read: make it easier to help you.

In particular, it is easier to help if you can make a minimal reproducible example that demonstrates the error.

If you want to modify coefficients in a nonlinear expression, @Libbum is correct, parameters are the solution.