How to replace macro argument with expr as being typed manually?

So I assume you want to include an affine or quadratic expression within a nonlinear objective? And you followed the work-around in the docs? Nonlinear Modeling · JuMP

At present, the work-around is recommended:

function create_eq(model, x, arr)
    aux = @variable(model)
    @constraint(model, aux == sum((x - i)^2 for i in arr))
    return aux
end

model = Model()
@variable(model, x)
ex = create_eq(model, x, [1, 2, 3])
@NLobjective(model, Min, ex)

Also, please read Please read: make it easier to help you, and provide a minimal working example.

1 Like